Skip to content

Commit 73d2757

Browse files
committed
Fixed issue #124: Property 'application.path' resolves to sa.core.dll instead of sa.shellextension.dll.
1 parent f6eb775 commit 73d2757

File tree

5 files changed

+45
-8
lines changed

5 files changed

+45
-8
lines changed

CHANGES

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Changes for 0.8.0
1818
* Fixed issue #118: Registry corruption while registering the extension.
1919
* Fixed issue #119: Disable logs when the shell extension is loaded by registry editor (regedit.exe).
2020
* Fixed issue #121: ShellAnything Errors out when opening a context on Google Docs/Sheets/etc.
21+
* Fixed issue #124: Property 'application.path' resolves to sa.core.dll instead of sa.shellextension.dll.
2122

2223

2324
Changes for 0.7.0

src/core/PropertyManager.cpp

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ namespace shellanything
3838
const std::string PropertyManager::SYSTEM_FALSE_PROPERTY_NAME = "system.false";
3939
const std::string PropertyManager::SYSTEM_FALSE_DEFAULT_VALUE = "false";
4040

41+
std::string PropertyManager::application_path;
42+
4143
PropertyManager::PropertyManager()
4244
{
4345
RegisterEnvironmentVariables();
@@ -200,6 +202,16 @@ namespace shellanything
200202
return output;
201203
}
202204

205+
const std::string& PropertyManager::GetApplicationPath()
206+
{
207+
return application_path;
208+
}
209+
210+
void PropertyManager::SetApplicationPath(const std::string& value)
211+
{
212+
application_path = value;
213+
}
214+
203215
void PropertyManager::SplitAndExpand(const std::string& input_value, const char* separator, StringList& output_list)
204216
{
205217
PropertyManager& pmgr = PropertyManager::GetInstance();
@@ -261,11 +273,19 @@ namespace shellanything
261273
void PropertyManager::RegisterDefaultProperties()
262274
{
263275
//define global properties
264-
std::string prop_application_path = GetCurrentModulePathUtf8();
265-
std::string prop_application_directory = ra::filesystem::GetParentPath(prop_application_path);
276+
std::string prop_core_module_path = GetCurrentModulePathUtf8();
277+
std::string prop_application_directory = ra::filesystem::GetParentPath(prop_core_module_path);
266278
std::string prop_path_separator = ra::filesystem::GetPathSeparatorStr();
267279
std::string prop_line_separator = ra::environment::GetLineSeparator();
268280

281+
// Issue #124. Define property 'application.path'.
282+
// We can not call usual function to detect the path of the application.
283+
// For example,
284+
// GetCurrentModulePathUtf8() returns the path of sa.core.dll. Not sa.tests.exe or sa.shellextension.dll.
285+
// GetCurrentProcessPath() would return the path of explorer.exe when the shell extension is loaded.
286+
//
287+
std::string prop_application_path = PropertyManager::GetApplicationPath();
288+
269289
SetProperty("application.path", prop_application_path);
270290
SetProperty("application.directory", prop_application_directory);
271291
SetProperty("path.separator", prop_path_separator);

src/core/PropertyManager.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,18 @@ namespace shellanything
144144
/// <returns>Returns a copy of the given value with the property references expanded.</returns>
145145
std::string ExpandOnce(const std::string& value) const;
146146

147+
/// <summary>
148+
/// Gets the path of the current application or module running ShellAnything. Must be set manually by the application.
149+
/// </summary>
150+
/// <returns>Returns the value of the path. Returns an empty string if never set.</returns>
151+
static const std::string& GetApplicationPath();
152+
153+
/// <summary>
154+
/// Sets the path of the current application or module running ShellAnything. Must be set manually by the application.
155+
/// </summary>
156+
/// <param name="value">The value of the path.</param>
157+
static void SetApplicationPath(const std::string& value);
158+
147159
/// <summary>
148160
/// Split a given string that contains multiple joined values and then expand each values individually.
149161
/// </summary>
@@ -165,6 +177,7 @@ namespace shellanything
165177
void RegisterEnvironmentVariables();
166178
void RegisterDefaultProperties();
167179
PropertyStore properties;
180+
static std::string application_path;
168181
};
169182

170183
} //namespace shellanything

src/shellextension/dllmain.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,10 @@ extern "C" int APIENTRY DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpRe
355355
{
356356
// Initialize Google's logging library.
357357
shellanything::InitLogger();
358+
359+
//Issue #124. Define property 'application.path'.
360+
std::string dll_path = GetCurrentModulePathUtf8();
361+
shellanything::PropertyManager::SetApplicationPath(dll_path);
358362
}
359363

360364
LogEnvironment();

src/tests/main.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -120,14 +120,13 @@ int main(int argc, char** argv)
120120
std::string log_dir = fLS::FLAGS_log_dir;
121121
printf("Using log directory: '%s'.\n", log_dir.c_str());
122122

123-
//define global properties
124-
std::string prop_application_path = GetCurrentModulePathUtf8();
125-
std::string prop_application_directory = ra::filesystem::GetParentPath(prop_application_path);
126-
std::string prop_log_directory = ra::unicode::AnsiToUtf8(shellanything::GetLogDirectory());
123+
//Issue #124. Define property 'application.path'.
124+
std::string exec_path = ra::process::GetCurrentProcessPathUtf8();
125+
shellanything::PropertyManager::SetApplicationPath(exec_path);
127126

127+
//define global properties
128128
shellanything::PropertyManager& pmgr = shellanything::PropertyManager::GetInstance();
129-
pmgr.SetProperty("application.path", prop_application_path);
130-
pmgr.SetProperty("application.directory", prop_application_directory);
129+
std::string prop_log_directory = ra::unicode::AnsiToUtf8(shellanything::GetLogDirectory());
131130
pmgr.SetProperty("log.directory", prop_log_directory);
132131

133132
int exit_code = SetTestPreferedRootDirectory();

0 commit comments

Comments
 (0)