19 size_t dot = filename.find_last_of(
".");
20 if (dot == std::string::npos) {
23 return filename.substr(dot + 1);
27 size_t slash = filename.find_last_of(
"/");
28 if (slash == std::string::npos) {
31 return filename.substr(slash + 1);
34std::string
LoadFile(
const std::string &filename) {
36 std::ifstream file(filename);
38 std::stringstream buffer;
39 buffer << file.rdbuf();
40 contents = buffer.str();
44 throw std::runtime_error(
"Could not open file: " + filename);
54#elif defined(__APPLE__)
60 std::ifstream file(filepath);
62 std::stringstream buffer;
63 buffer << file.rdbuf();
64 contents = buffer.str();
70void SaveFile(
const std::string &filename,
const std::string &contents,
73 std::ofstream file(filepath);
81 std::string config_directory =
".yaze";
84 config_directory =
"~/AppData/Roaming/yaze";
88 config_directory =
"~/.config/yaze";
93 return config_directory;
99 CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);
101 IFileDialog *pfd = NULL;
103 CoCreateInstance(CLSID_FileOpenDialog, NULL, CLSCTX_ALL, IID_IFileDialog,
104 reinterpret_cast<void **
>(&pfd));
105 std::string file_path_windows;
108 hr = pfd->Show(NULL);
110 IShellItem *psiResult;
111 hr = pfd->GetResult(&psiResult);
115 psiResult->GetDisplayName(SIGDN_FILESYSPATH, &pszFilePath);
117 wcstombs(str, pszFilePath, 128);
118 file_path_windows = str;
119 psiResult->Release();
120 CoTaskMemFree(pszFilePath);
127 return file_path_windows;
131 CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);
133 IFileDialog *pfd = NULL;
135 CoCreateInstance(CLSID_FileOpenDialog, NULL, CLSCTX_ALL, IID_IFileDialog,
136 reinterpret_cast<void **
>(&pfd));
137 std::string folder_path_windows;
141 hr = pfd->GetOptions(&dwOptions);
143 hr = pfd->SetOptions(dwOptions | FOS_PICKFOLDERS);
145 hr = pfd->Show(NULL);
147 IShellItem *psiResult;
148 hr = pfd->GetResult(&psiResult);
152 psiResult->GetDisplayName(SIGDN_FILESYSPATH, &pszFolderPath);
154 wcstombs(str, pszFolderPath, 128);
155 folder_path_windows = str;
156 psiResult->Release();
157 CoTaskMemFree(pszFolderPath);
166 return folder_path_windows;
170 const std::string &folder_path) {
171 std::vector<std::string> subdirectories;
172 WIN32_FIND_DATA findFileData;
173 HANDLE hFind = FindFirstFile((folder_path +
"\\*").c_str(), &findFileData);
174 if (hFind != INVALID_HANDLE_VALUE) {
176 if (findFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
177 if (strcmp(findFileData.cFileName,
".") != 0 &&
178 strcmp(findFileData.cFileName,
"..") != 0) {
179 subdirectories.push_back(findFileData.cFileName);
182 }
while (FindNextFile(hFind, &findFileData) != 0);
185 return subdirectories;
189 const std::string &folder_path) {
190 std::vector<std::string> files;
191 WIN32_FIND_DATA findFileData;
192 HANDLE hFind = FindFirstFile((folder_path +
"\\*").c_str(), &findFileData);
193 if (hFind != INVALID_HANDLE_VALUE) {
195 if (!(findFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
196 files.push_back(findFileData.cFileName);
198 }
while (FindNextFile(hFind, &findFileData) != 0);
204#elif defined(__linux__)
210 nfdu8char_t *out_path = NULL;
211 nfdu8filter_item_t filters[1] = {{
"Rom File",
"sfc,smc"}};
212 nfdopendialogu8args_t args = {0};
213 args.filterList = filters;
214 args.filterCount = 1;
215 nfdresult_t result = NFD_OpenDialogU8_With(&out_path, &args);
216 if (result == NFD_OKAY) {
217 std::string file_path_linux(out_path);
220 return file_path_linux;
221 }
else if (result == NFD_CANCEL) {
226 return "Error: NFD_OpenDialog";
231 nfdu8char_t *out_path = NULL;
232 nfdresult_t result = NFD_PickFolderU8(&out_path);
233 if (result == NFD_OKAY) {
234 std::string folder_path_linux(out_path);
237 return folder_path_linux;
238 }
else if (result == NFD_CANCEL) {
243 return "Error: NFD_PickFolder";
247 const std::string &folder_path) {
248 std::vector<std::string> subdirectories;
251 if ((dir = opendir(folder_path.c_str())) != NULL) {
252 while ((ent = readdir(dir)) != NULL) {
253 if (ent->d_type == DT_DIR) {
254 if (strcmp(ent->d_name,
".") != 0 && strcmp(ent->d_name,
"..") != 0) {
255 subdirectories.push_back(ent->d_name);
261 return subdirectories;
265 const std::string &folder_path) {
266 std::vector<std::string> files;
269 if ((dir = opendir(folder_path.c_str())) != NULL) {
270 while ((ent = readdir(dir)) != NULL) {
271 if (ent->d_type == DT_REG) {
272 files.push_back(ent->d_name);
static std::vector< std::string > GetFilesInFolder(const std::string &folder_path)
static std::string ShowOpenFileDialog()
ShowOpenFileDialog opens a file dialog and returns the selected filepath.
static std::string ShowOpenFolderDialog()
ShowOpenFolderDialog opens a file dialog and returns the selected folder path.
static std::vector< std::string > GetSubdirectoriesInFolder(const std::string &folder_path)
std::string LoadFile(const std::string &filename)
std::string GetConfigDirectory(Platform platform)
std::string LoadConfigFile(const std::string &filename)
void SaveFile(const std::string &filename, const std::string &contents, Platform platform)
std::string GetFileName(const std::string &filename)
std::string GetFileExtension(const std::string &filename)
Main namespace for the application.