Skip to content

Commit a677788

Browse files
committed
Implemented the following environment variable options:
* `SA_OPTION_CONFIGURATIONS_DIR`: Set to a custom value to change/override the directory where Configuration Files are stored. * `SA_OPTION_LOGS_DIR`: Set to a custom value to change/override the directory where Log Files are stored. #108
1 parent 0513e63 commit a677788

File tree

4 files changed

+57
-7
lines changed

4 files changed

+57
-7
lines changed

UserManual.md

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ This manual includes a description of the system functionalities and capabilitie
4646
* [Multi-selection-based properties](#multi-selection-based-properties)
4747
* [Fixed properties](#fixed-properties)
4848
* [Default properties](#default-properties)
49-
* [Environment variables](#environment-variables)
49+
* [Environment Variables options](#environment-variables-options)
5050
* [Tools](#tools)
5151
* [file_explorer_renew](#file_explorer_renew)
5252
* [arguments.debugger](#argumentsdebugger)
@@ -169,14 +169,16 @@ A *configuration file* contains the definition of all [<menu>](#Menu) elem
169169

170170
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.
171171

172-
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.
172+
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 you can paste `C:\Users\%USERNAME%\ShellAnything\configurations` into an *address bar* of *Windows Explorer* to quickly jump to the directory.
173173

174174
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.
175175

176176
When a *configuration file* is deleted, the application automatically detect the missing file and properly unload the associated menus which stop displaying their content.
177177

178178
To temporary disable a *configuration file*, one can simply change the file extension from `xml` to `txt`. Change the file extension back to `xml` to re-enable the file.
179179

180+
**Note:** The *Configuration Files* directory can be modified with the `SA_OPTION_CONFIGURATIONS_DIR` environment variable option. See [Environment Variables options](#environment-variables-options) section for details.
181+
180182

181183

182184
## Basic Xml Document ##
@@ -1822,7 +1824,7 @@ For example, the following would define `services.wce.command.start` and `servic
18221824

18231825

18241826

1825-
# Environment variables #
1827+
# Environment Variables options #
18261828

18271829
ShellAnything default startup behavior can be modified by setting specific pre-defined environment variables. Some features or configuration options can also be enabled or disabled through environment variables. For example, one can define an environment variables to enable verbose logging.
18281830

@@ -1834,10 +1836,11 @@ All ShellAnything environment variables names are prefixed with `SA_`.
18341836

18351837
The following table defines the list of pre-defined environment variables for ShellAnything:
18361838

1837-
| Name | Description |
1838-
|--------------------------------|--------------------------------------------------------------------------------------------------------------------|
1839-
| SA_OPTION_LOGGING_VERBOSE | Enables [verbose logging](#verbose-logging) when set to a value that evaluates to [true](#istrue-attribute). |
1840-
1839+
| Name | Description |
1840+
|--------------------------------|----------------------------------------------------------------------------------------------------------------------|
1841+
| SA_OPTION_LOGGING_VERBOSE | Enables [verbose logging](#verbose-logging) when set to a value that evaluates to [true](#istrue-attribute). |
1842+
| SA_OPTION_CONFIGURATIONS_DIR | Set to a custom value to change/override the directory where [Configuration Files](#configuration-files) are stored. |
1843+
| SA_OPTION_LOGS_DIR | Set to a custom value to change/override the directory where [Log Files](#logging-support) are stored. |
18411844

18421845

18431846

@@ -2653,6 +2656,9 @@ The logging directory is unique for each users of the system.
26532656

26542657
The log files are stored in `%LOCALAPPDATA%\ShellAnything\logs` directory. For example, the user `JohnSmith` can find his own ShellAnything log files in directory `C:\Users\JohnSmith\AppData\Local\ShellAnything\logs`.
26552658

2659+
**Note:** The logging directory can be modified with the `SA_OPTION_LOGS_DIR` environment variable option. See [Environment Variables options](#environment-variables-options) section for details.
2660+
2661+
26562662

26572663
### Filename Format ###
26582664

src/core/App.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "LoggerHelper.h"
2727
#include "ConfigManager.h"
2828
#include "PropertyManager.h"
29+
#include "Environment.h"
2930

3031
#include "rapidassist/process_utf8.h"
3132
#include "rapidassist/user_utf8.h"
@@ -204,6 +205,15 @@ namespace shellanything
204205

205206
//By default, GLOG will output log files in %TEMP% directory.
206207

208+
// Issue #108. Log files directory can be overriden with an option.
209+
Environment& env = Environment::GetInstance();
210+
if (env.IsOptionSet(Environment::SYSTEM_LOGS_DIR_OVERRIDE_ENVIRONMENT_VARIABLE_NAME))
211+
{
212+
std::string log_dir = env.GetOptionValue(Environment::SYSTEM_LOGS_DIR_OVERRIDE_ENVIRONMENT_VARIABLE_NAME);
213+
if (IsValidLogDirectory(log_dir))
214+
return log_dir;
215+
}
216+
207217
// Issue #108. Log files should be stored in %LOCALAPPDATA%\ShellAnything\logs
208218
std::string localappdata_dir = ra::environment::GetEnvironmentVariableUtf8("LOCALAPPDATA");
209219
if (!localappdata_dir.empty() && ra::filesystem::DirectoryExistsUtf8(localappdata_dir.c_str()))
@@ -239,6 +249,15 @@ namespace shellanything
239249

240250
std::string App::GetConfigurationsDirectory()
241251
{
252+
// Issue #108. Configuration Files directory can be overriden with an option.
253+
Environment& env = Environment::GetInstance();
254+
if (env.IsOptionSet(Environment::SYSTEM_CONFIGURATIONS_DIR_OVERRIDE_ENVIRONMENT_VARIABLE_NAME))
255+
{
256+
std::string config_dir = env.GetOptionValue(Environment::SYSTEM_CONFIGURATIONS_DIR_OVERRIDE_ENVIRONMENT_VARIABLE_NAME);
257+
if (IsValidConfigDirectory(config_dir))
258+
return config_dir;
259+
}
260+
242261
//get home directory of the user
243262
std::string home_dir = ra::user::GetHomeDirectoryUtf8();
244263
std::string app_dir = home_dir + "\\" + app_name;

src/core/Environment.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ namespace shellanything
3333
static const std::string EMPTY_VALUE;
3434

3535
const std::string Environment::SYSTEM_LOGGING_VERBOSE_ENVIRONMENT_VARIABLE_NAME = "SA_OPTION_LOGGING_VERBOSE";
36+
const std::string Environment::SYSTEM_CONFIGURATIONS_DIR_OVERRIDE_ENVIRONMENT_VARIABLE_NAME = "SA_OPTION_CONFIGURATIONS_DIR";
37+
const std::string Environment::SYSTEM_LOGS_DIR_OVERRIDE_ENVIRONMENT_VARIABLE_NAME = "SA_OPTION_LOGS_DIR";
3638

3739
Environment::Environment()
3840
{
@@ -67,6 +69,12 @@ namespace shellanything
6769
return is_true;
6870
}
6971

72+
std::string Environment::GetOptionValue(const std::string& name) const
73+
{
74+
std::string value = ra::environment::GetEnvironmentVariableUtf8(name.c_str());
75+
return value;
76+
}
77+
7078
bool Environment::IsOptionFalse(const std::string& name) const
7179
{
7280
std::string value = ra::environment::GetEnvironmentVariableUtf8(name.c_str());

src/core/Environment.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,16 @@ namespace shellanything
5454
/// </summary>
5555
static const std::string SYSTEM_LOGGING_VERBOSE_ENVIRONMENT_VARIABLE_NAME;
5656

57+
/// <summary>
58+
/// Name of the environment variable that defines the configurations directory path override.
59+
/// </summary>
60+
static const std::string SYSTEM_CONFIGURATIONS_DIR_OVERRIDE_ENVIRONMENT_VARIABLE_NAME;
61+
62+
/// <summary>
63+
/// Name of the environment variable that defines the logs directory path override.
64+
/// </summary>
65+
static const std::string SYSTEM_LOGS_DIR_OVERRIDE_ENVIRONMENT_VARIABLE_NAME;
66+
5767
public:
5868

5969
/// <summary>
@@ -64,6 +74,13 @@ namespace shellanything
6474
/// <returns>Returns true if the environment variable is set. Returns false otherwise.</returns>
6575
bool IsOptionSet(const std::string& name) const;
6676

77+
/// <summary>
78+
/// Get the value of an option.
79+
/// </summary>
80+
/// <param name="name">The name of the environment variable to check.</param>
81+
/// <returns>Returns the value of the given environment variable.</returns>
82+
std::string GetOptionValue(const std::string& name) const;
83+
6784
/// <summary>
6885
/// Check if an environment variable evaluates to true.
6986
/// An empty environment variable value returns false.

0 commit comments

Comments
 (0)