Skip to content

Commit

Permalink
#5825: Add unit test checking the support of absolute paths as snapsh…
Browse files Browse the repository at this point in the history
…ot folder
  • Loading branch information
codereader committed Feb 27, 2022
1 parent 3b1ae25 commit b90cf49
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
9 changes: 5 additions & 4 deletions radiantcore/map/autosaver/AutoSaver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,15 @@ void AutoMapSaver::saveSnapshot()
fullPath = GlobalFileSystem().findFile(fullPath.string()) + fullPath.string();
}

// Append the the snapshot folder to the path
// Assemble the absolute path to the snapshot folder
fs::path snapshotPath = fullPath;
snapshotPath.remove_filename();

// If the snapshots folder in the registry is absolute, operator/= will use the absolute one
snapshotPath /= GlobalRegistry().get(RKEY_AUTOSAVE_SNAPSHOTS_FOLDER);

// Retrieve the mapname
std::string mapName = fullPath.filename().string();
auto mapName = fullPath.filename().string();

// Check if the folder exists and create it if necessary
if (os::fileOrDirExists(snapshotPath.string()) || os::makeDirectory(snapshotPath.string()))
Expand All @@ -115,8 +117,7 @@ void AutoMapSaver::saveSnapshot()
}
else
{
rError() << "Snapshot save failed.. unable to create directory";
rError() << snapshotPath << std::endl;
rError() << "Snapshot save failed, unable to create directory " << snapshotPath << std::endl;
}
}

Expand Down
29 changes: 29 additions & 0 deletions test/MapSavingLoading.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1312,6 +1312,35 @@ TEST_F(MapSavingTest, AutoSaveSnapshotsSupportRelativePaths)
}
}

TEST_F(MapSavingTest, AutoSaveSnapshotsSupportAbsolutePaths)
{
std::string modRelativePath = "maps/altar.map";
GlobalCommandSystem().executeCommand("OpenMap", modRelativePath);
checkAltarScene();

// Set this to an absolute path
auto snapshotFolder = _context.getTemporaryDataPath() + "customsnapshots/";
registry::setValue(map::RKEY_AUTOSAVE_SNAPSHOTS_ENABLED, true);
registry::setValue(map::RKEY_AUTOSAVE_SNAPSHOTS_FOLDER, snapshotFolder);

// We expect the file to end up there
std::string expectedSnapshotPath = snapshotFolder + "altar.0.map";

EXPECT_FALSE(GlobalFileSystem().openTextFileInAbsolutePath(expectedSnapshotPath)) << "Snapshot already exists in " << expectedSnapshotPath;

// Trigger an auto save now
GlobalAutoSaver().performAutosave();

EXPECT_TRUE(GlobalFileSystem().openTextFileInAbsolutePath(expectedSnapshotPath)) << "Snapshot should now exist in " << expectedSnapshotPath;

// Load and confirm the saved scene
GlobalCommandSystem().executeCommand("OpenMap", expectedSnapshotPath);
checkAltarScene();

fs::remove(os::replaceExtension(expectedSnapshotPath, "darkradiant"));
fs::remove(expectedSnapshotPath);
}

namespace
{

Expand Down

0 comments on commit b90cf49

Please sign in to comment.