yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
file_util.h
Go to the documentation of this file.
1#ifndef YAZE_UTIL_FILE_UTIL_H_
2#define YAZE_UTIL_FILE_UTIL_H_
3
4#include <functional>
5#include <optional>
6#include <string>
7#include <vector>
8
9namespace yaze {
10namespace util {
11
13 std::string label;
14 std::string spec; // Comma-delimited extensions (e.g., "sfc,smc") or "*".
15};
16
18 std::vector<FileDialogFilter> filters;
19};
20
21// One-shot destination-picker result for owned GUI tests. Empty means Cancel.
22// Process-scoped because the test coroutine and UI may run on different threads.
38
40 public:
41 static std::optional<std::string> ConsumeSaveFileDialogResultForTesting();
46 static std::string ShowOpenFileDialog();
47 static std::string ShowOpenFileDialog(const FileDialogOptions& options);
48 static void ShowOpenFileDialogAsync(
49 const FileDialogOptions& options,
50 std::function<void(const std::string&)> callback);
51
56 static std::string ShowOpenFolderDialog();
57
62 static std::string ShowSaveFileDialog(
63 const std::string& default_name = "",
64 const std::string& default_extension = "");
65
66 // Specific implementations for testing
67 static std::string ShowOpenFileDialogNFD();
68 static std::string ShowOpenFileDialogBespoke();
69 static std::string ShowSaveFileDialogNFD(
70 const std::string& default_name = "",
71 const std::string& default_extension = "");
72 static std::string ShowSaveFileDialogBespoke(
73 const std::string& default_name = "",
74 const std::string& default_extension = "");
75 static std::string ShowOpenFolderDialogNFD();
76 static std::string ShowOpenFolderDialogBespoke();
77 static std::vector<std::string> GetSubdirectoriesInFolder(
78 const std::string& folder_path);
79 static std::vector<std::string> GetFilesInFolder(
80 const std::string& folder_path);
81};
82
83FileDialogOptions MakeRomFileDialogOptions(bool include_all_files = true);
84
90
92
101std::string GetFileExtension(const std::string& filename);
102
111std::string GetFileName(const std::string& filename);
112std::string GetResourcePath(const std::string& resource_path);
113void SaveFile(const std::string& filename, const std::string& data);
114
123std::string LoadFile(const std::string& filename);
124
131std::string LoadFileFromConfigDir(const std::string& filename);
132
133} // namespace util
134} // namespace yaze
135
136#endif // YAZE_UTIL_FILE_UTIL_H_
static void ShowOpenFileDialogAsync(const FileDialogOptions &options, std::function< void(const std::string &)> callback)
static std::string ShowSaveFileDialogBespoke(const std::string &default_name="", const std::string &default_extension="")
static std::string ShowOpenFileDialogBespoke()
static std::string ShowSaveFileDialogNFD(const std::string &default_name="", const std::string &default_extension="")
static std::string ShowOpenFolderDialogNFD()
static std::string ShowSaveFileDialog(const std::string &default_name="", const std::string &default_extension="")
ShowSaveFileDialog opens a save file dialog and returns the selected filepath. Uses global feature fl...
static std::optional< std::string > ConsumeSaveFileDialogResultForTesting()
Definition file_util.cc:44
static std::string ShowOpenFileDialog()
ShowOpenFileDialog opens a file dialog and returns the selected filepath. Uses global feature flag to...
static std::string ShowOpenFolderDialog()
ShowOpenFolderDialog opens a file dialog and returns the selected folder path. Uses global feature fl...
static std::vector< std::string > GetFilesInFolder(const std::string &folder_path)
static std::vector< std::string > GetSubdirectoriesInFolder(const std::string &folder_path)
static std::string ShowOpenFolderDialogBespoke()
static std::string ShowOpenFileDialogNFD()
ScopedSaveFileDialogResultForTesting(const ScopedSaveFileDialogResultForTesting &)=delete
ScopedSaveFileDialogResultForTesting & operator=(const ScopedSaveFileDialogResultForTesting &)=delete
void SaveFile(const std::string &filename, const std::string &contents)
Definition file_util.cc:96
std::string GetFileName(const std::string &filename)
Gets the filename from a full path.
Definition file_util.cc:59
std::string GetResourcePath(const std::string &resource_path)
Definition file_util.cc:110
std::string LoadFileFromConfigDir(const std::string &filename)
Loads a file from the user's config directory.
Definition file_util.cc:78
FileDialogOptions MakeRomFileDialogOptions(bool include_all_files)
Definition file_util.cc:127
std::string GetFileExtension(const std::string &filename)
Gets the file extension from a filename.
Definition file_util.cc:55
std::string GetBundleResourcePath()
GetBundleResourcePath returns the path to the bundle resource directory. Specific to MacOS.
std::string LoadFile(const std::string &filename)
Loads the entire contents of a file into a string.
Definition file_util.cc:63
std::vector< FileDialogFilter > filters
Definition file_util.h:18