Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 37 additions & 2 deletions Explorer++/Explorer++/App.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,27 @@ void App::LoadSettings(std::vector<WindowStorageData> &windows)
appStorage->LoadApplications(&m_applicationModel);
appStorage->LoadDialogStates();
appStorage->LoadDefaultColumns(m_config.globalFolderSettings.folderColumns);
appStorage->LoadFrequentLocations(&m_frequentLocationsModel);

if (m_savePreferencesToXmlFile)
{
auto frequentLocationsStorage = XmlAppStorageFactory::MaybeCreate(
Storage::GetFrequentLocationsFilePath(), Storage::OperationType::Load);

if (frequentLocationsStorage)
{
frequentLocationsStorage->LoadFrequentLocations(&m_frequentLocationsModel);
}
else
{
// Older versions stored frequent locations in config.xml. Fall back to that data so
// that it can be migrated to the separate file the next time settings are saved.
appStorage->LoadFrequentLocations(&m_frequentLocationsModel);
}
}
else
{
appStorage->LoadFrequentLocations(&m_frequentLocationsModel);
}

ValidateColumns(m_config.globalFolderSettings.folderColumns);
}
Expand Down Expand Up @@ -219,7 +239,22 @@ void App::SaveSettings()
appStorage->SaveApplications(&m_applicationModel);
appStorage->SaveDialogStates();
appStorage->SaveDefaultColumns(m_config.globalFolderSettings.folderColumns);
appStorage->SaveFrequentLocations(&m_frequentLocationsModel);

if (m_savePreferencesToXmlFile)
{
auto frequentLocationsStorage = XmlAppStorageFactory::MaybeCreate(
Storage::GetFrequentLocationsFilePath(), Storage::OperationType::Save);

if (frequentLocationsStorage)
{
frequentLocationsStorage->SaveFrequentLocations(&m_frequentLocationsModel);
frequentLocationsStorage->Commit();
}
}
else
{
appStorage->SaveFrequentLocations(&m_frequentLocationsModel);
}

appStorage->Commit();
}
Expand Down
8 changes: 8 additions & 0 deletions Explorer++/Explorer++/Storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,12 @@ std::wstring GetConfigFilePath()
return configFilePath.c_str();
}

std::wstring GetFrequentLocationsFilePath()

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think GetConfigFilePath should probably be refactored so that it takes a filename of a config file and returns the path. Something like GetPathForXmlStorageFile. GetConfigFilePath and GetFrequentLocationsFilePath can then both call that.

{
std::filesystem::path frequentLocationsFilePath(GetConfigFilePath());
frequentLocationsFilePath.replace_filename(FREQUENT_LOCATIONS_FILE_FILENAME);

return frequentLocationsFilePath.c_str();
}

}
2 changes: 2 additions & 0 deletions Explorer++/Explorer++/Storage.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ inline const wchar_t CONFIG_FILE_FILENAME[] = L"config.xml";
inline const wchar_t CONFIG_FILE_ROOT_NODE_NAME[] = L"ExplorerPlusPlus";
inline const wchar_t CONFIG_FILE_SETTINGS_NODE_NAME[] = L"Settings";
inline const wchar_t CONFIG_FILE_ENV_VAR_NAME[] = L"EXPLORERPP_CONFIG";
inline const wchar_t FREQUENT_LOCATIONS_FILE_FILENAME[] = L"frequent_locations.xml";

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The filename here definitely needs to change. The name config.xml was a bad choice and should really be changed, but new files should use a clearer naming scheme. Perhaps explorer++_frequent_locations.xml.


std::wstring GetConfigFilePath();
std::wstring GetFrequentLocationsFilePath();

}
18 changes: 18 additions & 0 deletions Explorer++/TestExplorer++/StorageTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,21 @@ TEST(StorageTest, ConfigEnvVar)
path = Storage::GetConfigFilePath();
ASSERT_TRUE(path.ends_with(L"config.xml"));
}

TEST(StorageTest, FrequentLocationsFilePath)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the change above, GetFrequentLocationsFilePath would be a simple wrapper, so there would be no need for this test.

{
auto set = SetEnvironmentVariable(Storage::CONFIG_FILE_ENV_VAR_NAME, NULL);
ASSERT_TRUE(set);
auto path = Storage::GetFrequentLocationsFilePath();
ASSERT_TRUE(path.ends_with(L"frequent_locations.xml"));

set = SetEnvironmentVariable(L"FOO", L"BAR");
ASSERT_TRUE(set);
set = SetEnvironmentVariable(Storage::CONFIG_FILE_ENV_VAR_NAME, L"%FOO%\\explorerpp.xml");
ASSERT_TRUE(set);
path = Storage::GetFrequentLocationsFilePath();
ASSERT_EQ(path, L"BAR\\frequent_locations.xml");

set = SetEnvironmentVariable(Storage::CONFIG_FILE_ENV_VAR_NAME, NULL);
ASSERT_TRUE(set);
}