Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: solvespace/solvespace
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: beea4444abd1
Choose a base ref
...
head repository: solvespace/solvespace
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: eb7e12b829fb
Choose a head ref
  • 1 commit
  • 4 files changed
  • 1 contributor

Commits on May 24, 2019

  1. 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.
    whitequark committed May 24, 2019
    Copy the full SHA
    eb7e12b View commit details
Showing with 15 additions and 3 deletions.
  1. +7 −2 src/graphicswin.cpp
  2. +7 −0 src/platform/platform.cpp
  3. +1 −0 src/platform/platform.h
  4. +0 −1 src/solvespace.h
9 changes: 7 additions & 2 deletions src/graphicswin.cpp
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
7 changes: 7 additions & 0 deletions src/platform/platform.cpp
Original file line number Diff line number Diff line change
@@ -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");
1 change: 1 addition & 0 deletions src/platform/platform.h
Original file line number Diff line number Diff line change
@@ -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);
1 change: 0 additions & 1 deletion src/solvespace.h
Original file line number Diff line number Diff line change
@@ -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~"