Skip to content

Commit

Permalink
Changed Configuration Files directory to `C:\Users\%USERNAME%\ShellAn…
Browse files Browse the repository at this point in the history
…ything\configurations`.
  • Loading branch information
end2endzone committed Oct 26, 2024
1 parent 8848eb9 commit 1388ba1
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 11 deletions.
4 changes: 3 additions & 1 deletion CHANGES
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 1 addition & 1 deletion UserManual.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
59 changes: 50 additions & 9 deletions src/core/App.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
}

Expand Down
14 changes: 14 additions & 0 deletions src/core/App.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,15 @@ namespace shellanything
/// <returns>Returns true if the directory is valid for logging. Returns false otherwise.</returns>
bool IsValidLogDirectory(const std::string& path);

/// <summary>
/// Get the application's configurations legacy directory.
/// </summary>
/// <remarks>
/// Directory was change in issue #108.
/// </remarks>
/// <returns>Returns the path of the legacy directory of the user's Configuration Files.</returns>
std::string GetLegacyConfigurationsDirectory();

/// <summary>
/// Get the application's configurations directory.
/// </summary>
Expand All @@ -219,6 +228,11 @@ namespace shellanything
/// <param name="dest_dir">The destination directory.</param>
void InstallDefaultConfigurations(const std::string& dest_dir);

/// <summary>
/// Moved any Configuration Files from the given legacy directory to the official configurations directory.
/// </summary>
void ClearLegacyConfigurationDirectory(const std::string& legacy_dir);

/// <summary>
/// Initialize the Configuration Manager to the user's stall the original configuration files to the specified destination directory.
/// </summary>
Expand Down

0 comments on commit 1388ba1

Please sign in to comment.