From 1388ba1a9f035cc8cc74fcea159c0729552ce758 Mon Sep 17 00:00:00 2001 From: Antoine Beauchamp Date: Sat, 26 Oct 2024 13:03:56 -0400 Subject: [PATCH] Changed Configuration Files directory to `C:\Users\%USERNAME%\ShellAnything\configurations`. --- CHANGES | 4 +++- UserManual.md | 2 +- src/core/App.cpp | 59 ++++++++++++++++++++++++++++++++++++++++-------- src/core/App.h | 14 ++++++++++++ 4 files changed, 68 insertions(+), 11 deletions(-) diff --git a/CHANGES b/CHANGES index 1b18202..e168403 100644 --- a/CHANGES +++ b/CHANGES @@ -1,9 +1,11 @@ Changes for 0.10.0 +* **Breaking change:** The _Configuration Files_ directory has moved from `%USERPROFILE%\ShellAnything` to `%USERPROFILE%\ShellAnything\configurations`. On first application launch, Configuration Files in the old directory will move to the new directory automatically. Other files in `%USERPROFILE%\ShellAnything` will not be moved. * ShellAnything has a new high-resolution logo icon! * Shellanything now features verbose logging mode and command line arguments debugging tools. -* ShellAnything now packages icons from [icons8/flat-color-icons](https://github.com/icons8/flat-color-icons) +* ShellAnything now packages icons from [icons8/flat-color-icons](https://github.com/icons8/flat-color-icons). +Fixes: * Fixed issue #6 : (twice) Right-click on a directory with Windows Explorer in the left panel shows the menus twice. * Fixed issue #31 : (twice) Error in logs for CContextMenu::GetCommandString() * Fixed issue #109: Implement default and verbose logging. diff --git a/UserManual.md b/UserManual.md index c33cb8c..93575b3 100644 --- a/UserManual.md +++ b/UserManual.md @@ -169,7 +169,7 @@ A *configuration file* contains the definition of all [<menu>](#Menu) elem When a user right-click on a file in *Windows Explorer*, the application will load all available *configuration files* and display their content into the displayed context menu. -The list of *Configuration Files* is unique for each users of the system. The files are stored in `C:\Users\%USERNAME%\ShellAnything` directory where `%USERNAME%` is your current Windows session *username*. Note that *Windows Explorer* also support copy & pasting `C:\Users\%USERNAME%\ShellAnything` into an *address bar* to quickly jump to the directory. +The list of *Configuration Files* is unique for each users of the system. The files are stored in `C:\Users\%USERNAME%\ShellAnything\configurations` directory where `%USERNAME%` is your current Windows session *username*. Note that *Windows Explorer* also support copy & pasting `C:\Users\%USERNAME%\ShellAnything\configurations` into an *address bar* to quickly jump to the directory. The application support multiple *configuration files* at the same time. One can add new files in the *configuration directory* and the system will automatically detect and load them. diff --git a/src/core/App.cpp b/src/core/App.cpp index 7869dac..5509f28 100644 --- a/src/core/App.cpp +++ b/src/core/App.cpp @@ -212,21 +212,23 @@ namespace shellanything return log_dir; } + std::string App::GetLegacyConfigurationsDirectory() + { + //get home directory of the user + std::string home_dir = ra::user::GetHomeDirectoryUtf8(); + std::string legacy_dir = home_dir + "\\" + app_name; + return legacy_dir; + } + std::string App::GetConfigurationsDirectory() { //get home directory of the user std::string home_dir = ra::user::GetHomeDirectoryUtf8(); std::string app_dir = home_dir + "\\" + app_name; - std::string config_dir; + std::string config_dir = app_dir + +"\\configurations"; - if (!app_dir.empty()) - { - //We got the %USERPROFILE% directory. - //Now add our custom path to it - config_dir = app_dir + +"\\configurations"; - if (IsValidConfigDirectory(config_dir)) - return config_dir; - } + if (IsValidConfigDirectory(config_dir)) + return config_dir; return config_dir; } @@ -314,16 +316,55 @@ namespace shellanything } } + void App::ClearLegacyConfigurationDirectory(const std::string& legacy_dir) + { + const std::string config_dir = GetConfigurationsDirectory(); + if (legacy_dir == config_dir) + return; // nothing to do + + // Search for xml files directly under legacy_dir + ra::strings::StringVector files; + static const int depth = 0; // Do not search recursively + bool success = ra::filesystem::FindFilesUtf8(files, legacy_dir.c_str(), depth); + if (!success) + return; // aborted + + // for each file found + for (size_t i = 0; i < files.size(); i++) + { + const std::string& file_path = files[i]; + + // Is that a configuration file ? + if (ConfigFile::IsValidConfigFile(file_path)) + { + // It does not belongs there. Move it to the new configuration directory. + + std::string file_name = ra::filesystem::GetFilename(file_path.c_str()); + std::string old_path = file_path; + std::string new_path = config_dir + "\\" + file_name; + + SA_LOG(INFO) << "Moving legacy configuration file '" << old_path << "' to '" << new_path << "'."; + bool moved = RenameFileUtf8(old_path, new_path); + if (!moved) + { + SA_LOG(ERROR) << "Failed moving configuration file '" << old_path << "' to target file '" << new_path << "'."; + } + } + } + } + void App::InitConfigManager() { shellanything::ConfigManager& cmgr = shellanything::ConfigManager::GetInstance(); + std::string legacy_dir = GetLegacyConfigurationsDirectory(); std::string config_dir = GetConfigurationsDirectory(); bool first_run = IsFirstApplicationRun(app_name, app_version); if (first_run) { SA_LOG(INFO) << "First application launch."; + ClearLegacyConfigurationDirectory(legacy_dir); // Issue #108 moved Configuration Files directory to a new location. InstallDefaultConfigurations(config_dir); } diff --git a/src/core/App.h b/src/core/App.h index 1aa31b7..76e1be2 100644 --- a/src/core/App.h +++ b/src/core/App.h @@ -194,6 +194,15 @@ namespace shellanything /// Returns true if the directory is valid for logging. Returns false otherwise. bool IsValidLogDirectory(const std::string& path); + /// + /// Get the application's configurations legacy directory. + /// + /// + /// Directory was change in issue #108. + /// + /// Returns the path of the legacy directory of the user's Configuration Files. + std::string GetLegacyConfigurationsDirectory(); + /// /// Get the application's configurations directory. /// @@ -219,6 +228,11 @@ namespace shellanything /// The destination directory. void InstallDefaultConfigurations(const std::string& dest_dir); + /// + /// Moved any Configuration Files from the given legacy directory to the official configurations directory. + /// + void ClearLegacyConfigurationDirectory(const std::string& legacy_dir); + /// /// Initialize the Configuration Manager to the user's stall the original configuration files to the specified destination directory. ///