Make sure file from a recent menu exists before using it.
Otherwise it can result in a very confusing error that does not suggest at all that the file is missing.
This commit is contained in:
parent
beea4444ab
commit
eb7e12b829
@ -345,8 +345,13 @@ static void PopulateMenuWithPathnames(Platform::MenuRef menu,
|
||||
menuItem->SetEnabled(false);
|
||||
} else {
|
||||
for(Platform::Path pathname : pathnames) {
|
||||
Platform::MenuItemRef menuItem = menu->AddItem(pathname.raw,
|
||||
[=]() { onTrigger(pathname); }, /*mnemonics=*/false);
|
||||
Platform::MenuItemRef menuItem = menu->AddItem(pathname.raw, [=]() {
|
||||
if(FileExists(pathname)) {
|
||||
onTrigger(pathname);
|
||||
} else {
|
||||
Error(_("File '%s' does not exist."), pathname.raw.c_str());
|
||||
}
|
||||
}, /*mnemonics=*/false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -405,6 +405,13 @@ FILE *OpenFile(const Platform::Path &filename, const char *mode) {
|
||||
#endif
|
||||
}
|
||||
|
||||
bool FileExists(const Platform::Path &filename) {
|
||||
FILE *f = OpenFile(filename, "rb");
|
||||
if(f == NULL) return false;
|
||||
fclose(f);
|
||||
return true;
|
||||
}
|
||||
|
||||
void RemoveFile(const Platform::Path &filename) {
|
||||
ssassert(filename.raw.length() == strlen(filename.raw.c_str()),
|
||||
"Unexpected null byte in middle of a path");
|
||||
|
@ -55,6 +55,7 @@ struct PathLess {
|
||||
};
|
||||
|
||||
// File manipulation functions.
|
||||
bool FileExists(const Platform::Path &filename);
|
||||
FILE *OpenFile(const Platform::Path &filename, const char *mode);
|
||||
bool ReadFile(const Platform::Path &filename, std::string *data);
|
||||
bool WriteFile(const Platform::Path &filename, const std::string &data);
|
||||
|
@ -138,7 +138,6 @@ enum class Command : uint32_t;
|
||||
#include "platform/gui.h"
|
||||
|
||||
const size_t MAX_RECENT = 8;
|
||||
extern Platform::Path RecentFile[MAX_RECENT];
|
||||
|
||||
#define AUTOSAVE_EXT "slvs~"
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user