Reload linked files before upgrading legacy data.
Before this commit, if constraints with newly introduced params were loaded from a file that linked other files, the upgrade code would attempt to look up a non-existent entity.pull/36/merge
parent
9301dec98d
commit
dbc567ed89
|
@ -62,8 +62,6 @@ int main(int argc, char **argv) {
|
||||||
[&] {
|
[&] {
|
||||||
if(!SS.LoadFromFile(filename))
|
if(!SS.LoadFromFile(filename))
|
||||||
return false;
|
return false;
|
||||||
if(!SS.ReloadAllImported(/*canCancel=*/false))
|
|
||||||
return false;
|
|
||||||
SS.AfterNewFile();
|
SS.AfterNewFile();
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
|
|
17
src/file.cpp
17
src/file.cpp
|
@ -426,7 +426,7 @@ void SolveSpaceUI::LoadUsingTable(char *key, char *val) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SolveSpaceUI::LoadFromFile(const std::string &filename) {
|
bool SolveSpaceUI::LoadFromFile(const std::string &filename, bool canCancel) {
|
||||||
allConsistent = false;
|
allConsistent = false;
|
||||||
fileLoadError = false;
|
fileLoadError = false;
|
||||||
|
|
||||||
|
@ -512,7 +512,9 @@ bool SolveSpaceUI::LoadFromFile(const std::string &filename) {
|
||||||
NewFile();
|
NewFile();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if(!ReloadAllImported(filename, canCancel)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
UpgradeLegacyData();
|
UpgradeLegacyData();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -876,8 +878,9 @@ static void PathSepNormalize(std::string &filename)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SolveSpaceUI::ReloadAllImported(bool canCancel)
|
bool SolveSpaceUI::ReloadAllImported(const std::string &filename, bool canCancel)
|
||||||
{
|
{
|
||||||
|
std::string saveFile = filename.empty() ? SS.saveFile : filename;
|
||||||
std::map<std::string, std::string> linkMap;
|
std::map<std::string, std::string> linkMap;
|
||||||
allConsistent = false;
|
allConsistent = false;
|
||||||
|
|
||||||
|
@ -906,7 +909,7 @@ bool SolveSpaceUI::ReloadAllImported(bool canCancel)
|
||||||
// In a newly created group we only have an absolute path.
|
// In a newly created group we only have an absolute path.
|
||||||
if(!g->linkFileRel.empty()) {
|
if(!g->linkFileRel.empty()) {
|
||||||
std::string rel = PathSepUnixToPlatform(g->linkFileRel);
|
std::string rel = PathSepUnixToPlatform(g->linkFileRel);
|
||||||
std::string fromRel = MakePathAbsolute(SS.saveFile, rel);
|
std::string fromRel = MakePathAbsolute(saveFile, rel);
|
||||||
FILE *test = ssfopen(fromRel, "rb");
|
FILE *test = ssfopen(fromRel, "rb");
|
||||||
if(test) {
|
if(test) {
|
||||||
fclose(test);
|
fclose(test);
|
||||||
|
@ -922,14 +925,14 @@ bool SolveSpaceUI::ReloadAllImported(bool canCancel)
|
||||||
try_load_file:
|
try_load_file:
|
||||||
if(LoadEntitiesFromFile(g->linkFile, &(g->impEntity), &(g->impMesh), &(g->impShell)))
|
if(LoadEntitiesFromFile(g->linkFile, &(g->impEntity), &(g->impMesh), &(g->impShell)))
|
||||||
{
|
{
|
||||||
if(!SS.saveFile.empty()) {
|
if(!saveFile.empty()) {
|
||||||
// Record the linked file's name relative to our filename;
|
// Record the linked file's name relative to our filename;
|
||||||
// if the entire tree moves, then everything will still work
|
// if the entire tree moves, then everything will still work
|
||||||
std::string rel = MakePathRelative(SS.saveFile, g->linkFile);
|
std::string rel = MakePathRelative(saveFile, g->linkFile);
|
||||||
g->linkFileRel = PathSepPlatformToUnix(rel);
|
g->linkFileRel = PathSepPlatformToUnix(rel);
|
||||||
} else {
|
} else {
|
||||||
// We're not yet saved, so can't make it absolute.
|
// We're not yet saved, so can't make it absolute.
|
||||||
// This will only be used for display purposes, as SS.saveFile
|
// This will only be used for display purposes, as saveFile
|
||||||
// is always nonempty when we are actually writing anything.
|
// is always nonempty when we are actually writing anything.
|
||||||
g->linkFileRel = g->linkFile;
|
g->linkFileRel = g->linkFile;
|
||||||
}
|
}
|
||||||
|
|
|
@ -123,7 +123,7 @@ bool SolveSpaceUI::LoadAutosaveFor(const std::string &filename) {
|
||||||
|
|
||||||
if(LoadAutosaveYesNo() == DIALOG_YES) {
|
if(LoadAutosaveYesNo() == DIALOG_YES) {
|
||||||
unsaved = true;
|
unsaved = true;
|
||||||
return LoadFromFile(autosaveFile);
|
return LoadFromFile(autosaveFile, /*canCancel=*/true);
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
@ -131,11 +131,9 @@ bool SolveSpaceUI::LoadAutosaveFor(const std::string &filename) {
|
||||||
|
|
||||||
bool SolveSpaceUI::OpenFile(const std::string &filename) {
|
bool SolveSpaceUI::OpenFile(const std::string &filename) {
|
||||||
bool autosaveLoaded = LoadAutosaveFor(filename);
|
bool autosaveLoaded = LoadAutosaveFor(filename);
|
||||||
bool fileLoaded = autosaveLoaded || LoadFromFile(filename);
|
bool fileLoaded = autosaveLoaded || LoadFromFile(filename, /*canCancel=*/true);
|
||||||
if(fileLoaded)
|
if(fileLoaded) {
|
||||||
saveFile = filename;
|
saveFile = filename;
|
||||||
bool success = fileLoaded && ReloadAllImported(/*canCancel=*/true);
|
|
||||||
if(success) {
|
|
||||||
AddToRecentList(filename);
|
AddToRecentList(filename);
|
||||||
} else {
|
} else {
|
||||||
saveFile = "";
|
saveFile = "";
|
||||||
|
@ -143,7 +141,7 @@ bool SolveSpaceUI::OpenFile(const std::string &filename) {
|
||||||
}
|
}
|
||||||
AfterNewFile();
|
AfterNewFile();
|
||||||
unsaved = autosaveLoaded;
|
unsaved = autosaveLoaded;
|
||||||
return success;
|
return fileLoaded;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SolveSpaceUI::Exit() {
|
void SolveSpaceUI::Exit() {
|
||||||
|
|
|
@ -812,11 +812,11 @@ public:
|
||||||
void NewFile();
|
void NewFile();
|
||||||
bool SaveToFile(const std::string &filename);
|
bool SaveToFile(const std::string &filename);
|
||||||
bool LoadAutosaveFor(const std::string &filename);
|
bool LoadAutosaveFor(const std::string &filename);
|
||||||
bool LoadFromFile(const std::string &filename);
|
bool LoadFromFile(const std::string &filename, bool canCancel = false);
|
||||||
void UpgradeLegacyData();
|
void UpgradeLegacyData();
|
||||||
bool LoadEntitiesFromFile(const std::string &filename, EntityList *le,
|
bool LoadEntitiesFromFile(const std::string &filename, EntityList *le,
|
||||||
SMesh *m, SShell *sh);
|
SMesh *m, SShell *sh);
|
||||||
bool ReloadAllImported(bool canCancel=false);
|
bool ReloadAllImported(const std::string &filename = "", bool canCancel = false);
|
||||||
// And the various export options
|
// And the various export options
|
||||||
void ExportAsPngTo(const std::string &filename);
|
void ExportAsPngTo(const std::string &filename);
|
||||||
void ExportMeshTo(const std::string &filename);
|
void ExportMeshTo(const std::string &filename);
|
||||||
|
|
|
@ -185,8 +185,7 @@ bool Test::Helper::CheckLoad(const char *file, int line, const char *fixture) {
|
||||||
bool fixtureExists = (f != NULL);
|
bool fixtureExists = (f != NULL);
|
||||||
if(f) fclose(f);
|
if(f) fclose(f);
|
||||||
|
|
||||||
bool result = fixtureExists &&
|
bool result = fixtureExists && SS.LoadFromFile(fixturePath);
|
||||||
SS.LoadFromFile(fixturePath) && SS.ReloadAllImported(/*canCancel=*/false);
|
|
||||||
if(!RecordCheck(result)) {
|
if(!RecordCheck(result)) {
|
||||||
PrintFailure(file, line,
|
PrintFailure(file, line,
|
||||||
ssprintf("loading file '%s'", fixturePath.c_str()));
|
ssprintf("loading file '%s'", fixturePath.c_str()));
|
||||||
|
|
Loading…
Reference in New Issue