13namespace fs = std::filesystem;
16 return fs::path(filename).extension().string();
20 return fs::path(filename).filename().string();
23std::string
LoadFile(
const std::string& filename) {
25 std::ifstream file(filename);
27 std::stringstream buffer;
28 buffer << file.rdbuf();
29 contents = buffer.str();
33 throw std::runtime_error(
"Could not open file: " + filename);
40 if (!config_dir.ok()) {
44 fs::path filepath = *config_dir / filename;
46 std::ifstream file(filepath);
48 std::stringstream buffer;
49 buffer << file.rdbuf();
50 contents = buffer.str();
56void SaveFile(
const std::string& filename,
const std::string& contents) {
58 if (!config_dir.ok()) {
62 fs::path filepath = *config_dir / filename;
63 std::ofstream file(filepath);
74 if (resource_path.rfind(
"assets/", 0) == 0) {
75 return kBundlePath + resource_path;
77 return kBundlePath +
"assets/" + resource_path;
89 options.
filters.push_back({
"ROM Files",
"sfc,smc"});
90 if (include_all_files) {
91 options.
filters.push_back({
"All Files",
"*"});
void SaveFile(const std::string &filename, const std::string &contents)
std::string GetFileName(const std::string &filename)
Gets the filename from a full path.
std::string GetResourcePath(const std::string &resource_path)
std::string LoadFileFromConfigDir(const std::string &filename)
Loads a file from the user's config directory.
FileDialogOptions MakeRomFileDialogOptions(bool include_all_files)
std::string GetFileExtension(const std::string &filename)
Gets the file extension from a filename.
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.
std::vector< FileDialogFilter > filters