Skip to content

Commit 84140ab

Browse files
committed
Moved configurations directory from build\bin\Debug\configurations to build\bin\resources\configurations. This change update the build directory structure to match the installation directory structure making the source code and install more alike.
1 parent ea455e0 commit 84140ab

File tree

10 files changed

+87
-49
lines changed

10 files changed

+87
-49
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,7 @@ install(FILES ${CMAKE_SOURCE_DIR}/resources/installer/bin/register.bat
378378
DESTINATION ${SHELLANYTHING_INSTALL_BIN_DIR})
379379

380380
# Resources
381+
install(DIRECTORY "${CMAKE_SOURCE_DIR}/resources/configurations" DESTINATION ${SHELLANYTHING_INSTALL_RESOURCE_DIR})
381382
install(DIRECTORY "${CMAKE_SOURCE_DIR}/resources/Windows Icon Tables" DESTINATION ${SHELLANYTHING_INSTALL_RESOURCE_DIR})
382383
install(FILES ${CMAKE_SOURCE_DIR}/resources/icons/shellanything.ico
383384
${CMAKE_SOURCE_DIR}/resources/icons/0.1.0.ico

resources/configurations/shellanything.xml

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -36,51 +36,51 @@
3636

3737
<menu name="CONTRIBUTING">
3838
<menu name="markdown">
39-
<visibility exists="${application.directory}\..\CONTRIBUTING.md" />
39+
<visibility exists="${application.install.directory}\CONTRIBUTING.md" />
4040
<icon fileextension="md" />
4141
<actions>
42-
<open path="${application.directory}\..\CONTRIBUTING.md" />
42+
<open path="${application.install.directory}\CONTRIBUTING.md" />
4343
</actions>
4444
</menu>
4545
<menu name="html">
46-
<visibility exists="${application.directory}\..\CONTRIBUTING.html" />
46+
<visibility exists="${application.install.directory}\CONTRIBUTING.html" />
4747
<icon fileextension="html" />
4848
<actions>
49-
<open path="${application.directory}\..\CONTRIBUTING.html" />
49+
<open path="${application.install.directory}\CONTRIBUTING.html" />
5050
</actions>
5151
</menu>
5252
</menu>
5353

5454
<menu name="README">
5555
<menu name="markdown">
56-
<visibility exists="${application.directory}\..\README.md" />
56+
<visibility exists="${application.install.directory}\README.md" />
5757
<icon fileextension="md" />
5858
<actions>
59-
<open path="${application.directory}\..\README.md" />
59+
<open path="${application.install.directory}\README.md" />
6060
</actions>
6161
</menu>
6262
<menu name="html">
63-
<visibility exists="${application.directory}\..\README.html" />
63+
<visibility exists="${application.install.directory}\README.html" />
6464
<icon fileextension="html" />
6565
<actions>
66-
<open path="${application.directory}\..\README.html" />
66+
<open path="${application.install.directory}\README.html" />
6767
</actions>
6868
</menu>
6969
</menu>
7070

7171
<menu name="UserManual">
7272
<menu name="markdown">
73-
<visibility exists="${application.directory}\..\UserManual.md" />
73+
<visibility exists="${application.install.directory}\UserManual.md" />
7474
<icon fileextension="md" />
7575
<actions>
76-
<open path="${application.directory}\..\UserManual.md" />
76+
<open path="${application.install.directory}\UserManual.md" />
7777
</actions>
7878
</menu>
7979
<menu name="html">
80-
<visibility exists="${application.directory}\..\UserManual.html" />
80+
<visibility exists="${application.install.directory}\UserManual.html" />
8181
<icon fileextension="html" />
8282
<actions>
83-
<open path="${application.directory}\..\UserManual.html" />
83+
<open path="${application.install.directory}\UserManual.html" />
8484
</actions>
8585
</menu>
8686
</menu>
@@ -136,45 +136,45 @@
136136
<menu name="Windows 10 Home">
137137
<menu name="shell32.dll">
138138
<actions>
139-
<open path="${application.directory}\..\resources\Windows Icon Tables\Win 10 Home - shell32.dll icons.png" />
139+
<open path="${application.install.directory}\resources\Windows Icon Tables\Win 10 Home - shell32.dll icons.png" />
140140
</actions>
141141
</menu>
142142
<menu name="ieframe.dll">
143143
<actions>
144-
<open path="${application.directory}\..\resources\Windows Icon Tables\Win 10 Home - ieframe.dll icons.png" />
144+
<open path="${application.install.directory}\resources\Windows Icon Tables\Win 10 Home - ieframe.dll icons.png" />
145145
</actions>
146146
</menu>
147147
<menu name="imageres.dll">
148148
<actions>
149-
<open path="${application.directory}\..\resources\Windows Icon Tables\Win 10 Home - imageres.dll icons.png" />
149+
<open path="${application.install.directory}\resources\Windows Icon Tables\Win 10 Home - imageres.dll icons.png" />
150150
</actions>
151151
</menu>
152152
<menu name="netshell.dll">
153153
<actions>
154-
<open path="${application.directory}\..\resources\Windows Icon Tables\Win 10 Home - netshell.dll icons.png" />
154+
<open path="${application.install.directory}\resources\Windows Icon Tables\Win 10 Home - netshell.dll icons.png" />
155155
</actions>
156156
</menu>
157157
</menu>
158158

159159
<menu name="Windows 11 Pro">
160160
<menu name="shell32.dll">
161161
<actions>
162-
<open path="${application.directory}\..\resources\Windows Icon Tables\Win 11 Pro - shell32.dll icons.png" />
162+
<open path="${application.install.directory}\resources\Windows Icon Tables\Win 11 Pro - shell32.dll icons.png" />
163163
</actions>
164164
</menu>
165165
<menu name="ieframe.dll">
166166
<actions>
167-
<open path="${application.directory}\..\resources\Windows Icon Tables\Win 11 Pro - ieframe.dll icons.png" />
167+
<open path="${application.install.directory}\resources\Windows Icon Tables\Win 11 Pro - ieframe.dll icons.png" />
168168
</actions>
169169
</menu>
170170
<menu name="imageres.dll">
171171
<actions>
172-
<open path="${application.directory}\..\resources\Windows Icon Tables\Win 11 Pro - imageres.dll icons.png" />
172+
<open path="${application.install.directory}\resources\Windows Icon Tables\Win 11 Pro - imageres.dll icons.png" />
173173
</actions>
174174
</menu>
175175
<menu name="netshell.dll">
176176
<actions>
177-
<open path="${application.directory}\..\resources\Windows Icon Tables\Win 11 Pro - netshell.dll icons.png" />
177+
<open path="${application.install.directory}\resources\Windows Icon Tables\Win 11 Pro - netshell.dll icons.png" />
178178
</actions>
179179
</menu>
180180
</menu>
@@ -183,7 +183,7 @@
183183
<menu name="More configurations files...">
184184
<icon path="C:\Windows\system32\shell32.dll" index="69" />
185185
<actions>
186-
<open path="${application.directory}\configurations" />
186+
<open path="${application.directory}\resources\configurations" />
187187
</actions>
188188
</menu>
189189

src/CMakeLists.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,6 @@ add_custom_target(src_dummy_target
4848
"${CMAKE_CURRENT_SOURCE_DIR}/version.rc.in"
4949
)
5050

51-
install(DIRECTORY ${CMAKE_SOURCE_DIR}/resources/configurations
52-
DESTINATION ${SHELLANYTHING_INSTALL_BIN_DIR}
53-
)
54-
5551
install(FILES ${LIBMAGIC_MGC_DIR}/magic.mgc
5652
${LIBMAGIC_MGC_DIR}/file.exe
5753
${ZLIB_INCLUDE_DIRS}/../bin/zlib.dll

src/core/App.cpp

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,20 @@ namespace shellanything
233233
return config_dir;
234234
}
235235

236+
std::string App::GetBinDirectory()
237+
{
238+
const std::string module_path = GetCurrentModulePathUtf8();
239+
const std::string bin_dir = ra::filesystem::GetParentPath(module_path);
240+
return bin_dir;
241+
}
242+
243+
std::string App::GetInstallDirectory()
244+
{
245+
const std::string bin_dir = GetBinDirectory();
246+
const std::string install_dir = ra::filesystem::GetParentPath(bin_dir);
247+
return install_dir;
248+
}
249+
236250
bool App::Start()
237251
{
238252
SetupGlobalProperties();
@@ -289,8 +303,7 @@ namespace shellanything
289303

290304
void App::InstallDefaultConfigurations(const std::string& dest_dir)
291305
{
292-
std::string app_path = GetCurrentModulePathUtf8();
293-
std::string app_dir = ra::filesystem::GetParentPath(app_path);
306+
const std::string install_dir = shellanything::App::GetInstallDirectory();
294307

295308
static const char* default_files[] = {
296309
"default.xml",
@@ -304,7 +317,7 @@ namespace shellanything
304317
for (size_t i = 0; i < num_files; i++)
305318
{
306319
const char* filename = default_files[i];
307-
std::string source_path = app_dir + "\\configurations\\" + filename;
320+
std::string source_path = install_dir + "\\resources\\configurations\\" + filename;
308321
std::string target_path = dest_dir + "\\" + filename;
309322

310323
SA_LOG(INFO) << "Installing configuration file: " << target_path;

src/core/App.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,19 @@ namespace shellanything
215215
/// <returns>Returns true if the directory is valid for reading configurations. Returns false otherwise.</returns>
216216
bool IsValidConfigDirectory(const std::string& path);
217217

218+
/// <summary>
219+
/// Get the application's bin directory. The bin directory contains all ShellAnything's executables and binaries.
220+
/// </summary>
221+
/// <returns>Returns the path of the bin directory.</returns>
222+
static std::string GetBinDirectory();
223+
224+
/// <summary>
225+
/// Get the application's installation directory. The installation directory is the root directory selected when the application was installed.
226+
/// When running in debug mode or within a development environment, the installation directory is set to the parent directory of `${CMAKE_BIN_DIR}\build\bin\Debug`.
227+
/// </summary>
228+
/// <returns>Returns the path of the installation directory.</returns>
229+
static std::string GetInstallDirectory();
230+
218231
/// <summary>
219232
/// Initialize and start the application ready for usage.
220233
/// </summary>

src/core/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ source_group("Default Configuration Files" FILES ${CONFIGURATION_DEFAUL
114114
# Copy default configuration files database to target dir
115115
add_custom_command( TARGET sa.core POST_BUILD
116116
COMMAND ${CMAKE_COMMAND} -E copy_directory
117-
${CMAKE_SOURCE_DIR}/resources/configurations $<TARGET_FILE_DIR:sa.core>/configurations
117+
${CMAKE_SOURCE_DIR}/resources/configurations $<TARGET_FILE_DIR:sa.core>/../resources/configurations
118118
COMMENT "Copying default configurations files database.")
119119

120120
# Copy registration and unregistration scripts to target dir

src/core/PropertyManager.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -648,9 +648,8 @@ namespace shellanything
648648
shellanything::App& app = shellanything::App::GetInstance();
649649

650650
//define global properties
651-
std::string prop_core_module_path = GetCurrentModulePathUtf8();
652-
std::string prop_application_directory = ra::filesystem::GetParentPath(prop_core_module_path);
653-
std::string prop_install_directory = ra::filesystem::GetParentPath(prop_application_directory);
651+
std::string prop_application_directory = app.GetBinDirectory();
652+
std::string prop_install_directory = app.GetInstallDirectory();
654653
std::string prop_path_separator = ra::filesystem::GetPathSeparatorStr();
655654
std::string prop_line_separator = ra::environment::GetLineSeparator();
656655

src/tests/TestConfigManager.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
*********************************************************************************/
2424

2525
#include "TestConfigManager.h"
26+
#include "App.h"
2627
#include "Workspace.h"
2728
#include "QuickLoader.h"
2829
#include "ConfigManager.h"
@@ -338,7 +339,9 @@ namespace shellanything
338339
{
339340
ConfigManager& mgr = ConfigManager::GetInstance();
340341

341-
const std::string path = "configurations/default.xml";
342+
const std::string install_dir = shellanything::App::GetInstallDirectory();
343+
344+
const std::string path = install_dir + "/resources/configurations/default.xml";
342345
std::string error_message = ra::testing::GetTestQualifiedName(); //init error message to an unexpected string
343346
ConfigFile* config = ConfigFile::LoadFile(path, error_message);
344347

src/tests/TestConfiguration.cpp

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,13 @@
2323
*********************************************************************************/
2424

2525
#include "TestConfiguration.h"
26+
#include "App.h"
2627
#include "Workspace.h"
2728
#include "ConfigManager.h"
2829
#include "ConfigFile.h"
2930
#include "Menu.h"
3031
#include "ActionExecute.h"
32+
#include "SaUtils.h"
3133

3234
#include "rapidassist/filesystem_utf8.h"
3335
#include "rapidassist/testing.h"
@@ -94,17 +96,17 @@ namespace shellanything
9496
TEST_F(TestConfiguration, testIsValidConfigFile)
9597
{
9698
static const char* files[] = {
97-
//default configuration files
98-
"configurations\\default.xml",
99-
"configurations\\Microsoft Office 2003.xml",
100-
"configurations\\Microsoft Office 2007.xml",
101-
"configurations\\Microsoft Office 2010.xml",
102-
"configurations\\Microsoft Office 2013.xml",
103-
"configurations\\Microsoft Office 2016.xml",
104-
"configurations\\shellanything.xml",
105-
"configurations\\WinDirStat.xml",
106-
107-
//test configuration files
99+
//default configuration files (relative to bin directory)
100+
"..\\resources\\configurations\\default.xml",
101+
"..\\resources\\configurations\\Microsoft Office 2003.xml",
102+
"..\\resources\\configurations\\Microsoft Office 2007.xml",
103+
"..\\resources\\configurations\\Microsoft Office 2010.xml",
104+
"..\\resources\\configurations\\Microsoft Office 2013.xml",
105+
"..\\resources\\configurations\\Microsoft Office 2016.xml",
106+
"..\\resources\\configurations\\shellanything.xml",
107+
"..\\resources\\configurations\\WinDirStat.xml",
108+
109+
//test configuration files (relative to bin directory)
108110
"test_files\\samples.xml",
109111
"test_files\\TestConfigManager.testAssignCommandId.1.xml",
110112
"test_files\\TestConfigManager.testAssignCommandId.2.xml",
@@ -129,10 +131,13 @@ namespace shellanything
129131
};
130132
const size_t num_files = sizeof(files) / sizeof(files[0]);
131133

134+
const std::string bin_dir = shellanything::App::GetBinDirectory();
135+
132136
//for each test files
133137
for (size_t i = 0; i < num_files; i++)
134138
{
135-
const std::string path = files[i];
139+
const std::string relative_path = files[i];
140+
const std::string path = bin_dir + "\\" + relative_path;
136141
ASSERT_TRUE(ra::filesystem::FileExists(path.c_str())) << "File '" << path.c_str() << "' is not found.";
137142
ASSERT_TRUE(shellanything::ConfigFile::IsValidConfigFile(path)) << "The file '" << path.c_str() << "' is not a valid configuration file.";
138143
}
@@ -141,7 +146,8 @@ namespace shellanything
141146
TEST_F(TestConfiguration, testIsValidConfigFileUtf8)
142147
{
143148
static const std::string separator = ra::filesystem::GetPathSeparatorStr();
144-
const std::string source_path = "configurations/default.xml";
149+
const std::string install_dir = shellanything::App::GetInstallDirectory();
150+
const std::string source_path = install_dir + "/resources/configurations/default.xml";
145151
std::string target_path = ra::filesystem::GetTemporaryDirectory() + separator + ra::testing::GetTestQualifiedName() + ".psi_\xCE\xA8_psi.xml";
146152

147153
//copy default config to the new utf-8 path
@@ -153,7 +159,8 @@ namespace shellanything
153159
//--------------------------------------------------------------------------------------------------
154160
TEST_F(TestConfiguration, testLoadFile)
155161
{
156-
const std::string path = "configurations/default.xml";
162+
const std::string install_dir = shellanything::App::GetInstallDirectory();
163+
const std::string path = install_dir + "/resources/configurations/default.xml";
157164
std::string error_message = ra::testing::GetTestQualifiedName(); //init error message to an unexpected string
158165
ConfigFile* config = ConfigFile::LoadFile(path, error_message);
159166

@@ -168,8 +175,9 @@ namespace shellanything
168175
{
169176
//This test validates that Configuration::LoadFile() supports filename with utf-8 characters.
170177

178+
const std::string install_dir = shellanything::App::GetInstallDirectory();
171179
static const std::string separator = ra::filesystem::GetPathSeparatorStr();
172-
const std::string source_path = "configurations/default.xml";
180+
const std::string source_path = install_dir + "/resources/configurations/default.xml";
173181
std::string target_path = ra::filesystem::GetTemporaryDirectory() + separator + ra::testing::GetTestQualifiedName() + ".psi_\xCE\xA8_psi.xml";
174182

175183
//copy default config to the new utf-8 path

src/tests/TestSelectionContext.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,11 @@
2323
*********************************************************************************/
2424

2525
#include "TestSelectionContext.h"
26+
#include "App.h"
2627
#include "SelectionContext.h"
2728
#include "PropertyManager.h"
29+
#include "SaUtils.h"
30+
2831
#include "rapidassist/process.h"
2932
#include "rapidassist/filesystem.h"
3033
#include "rapidassist/testing.h"
@@ -525,11 +528,13 @@ namespace shellanything
525528
{
526529
PropertyManager& pmgr = PropertyManager::GetInstance();
527530

531+
const std::string install_dir = shellanything::App::GetInstallDirectory();
532+
528533
SelectionContext context;
529534
#ifdef _WIN32
530535
{
531536
StringList elements;
532-
elements.push_back(ra::process::GetCurrentProcessDir() + "\\configurations\\default.xml");
537+
elements.push_back(install_dir + "\\resources\\configurations\\default.xml");
533538
context.SetElements(elements);
534539
}
535540
#else

0 commit comments

Comments
 (0)