Skip to content

Commit

Permalink
Fixed error in how to define the application's file name based on run…
Browse files Browse the repository at this point in the history
…ning from the shell extension's (i.e: through explorer.exe) or from unit tests executable.
  • Loading branch information
end2endzone committed Dec 3, 2023
1 parent 380f867 commit 154bd4a
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 20 deletions.
30 changes: 18 additions & 12 deletions src/logger/glog/GlogUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

#include "GlogUtils.h"
#include "App.h"
#include "PropertyManager.h"
#include "ErrorManager.h"
#include "SaUtils.h"

Expand All @@ -40,7 +41,7 @@
#include "rapidassist/user.h"

//Global declarations
char g_Path[4096]; // Path to this DLL.
char g_Path[4096]; // Path to this DLL.
char* g_argv[] = { g_Path, "" }; // For google::InitGoogleLogging(g_argv[0])

namespace shellanything
Expand All @@ -49,8 +50,6 @@ namespace logging
{
namespace glog
{
extern void ShowErrorMessage(const std::string& title, const std::string& message);

int DateTimeToSeconds(const GLOG_DATETIME& dt)
{
int total_seconds = 0;
Expand Down Expand Up @@ -163,21 +162,22 @@ namespace glog
std::string GetLogDestination(int level)
{
shellanything::App& app = shellanything::App::GetInstance();
shellanything::PropertyManager& pmgr = shellanything::PropertyManager::GetInstance();

//For issue #7 - Change the default filename format for log files
//NATIVE FORMAT: sa.shellextension-d.dll.MYCOMPUTERNAME.johnsmith.log.INFO.20180120-124422.8732.log
//DESIRED FORMAT: sa.shellextension-d.dll.INFO.20180120-124422.8732.log

// The function google::SetLogDestination() is expecting a full path (including the destination directory)

std::string module_path = GetCurrentModulePath();
std::string module_filename = ra::filesystem::GetFilename(module_path.c_str());
const std::string & app_path = pmgr.GetApplicationPath();
std::string app_filename = ra::filesystem::GetFilename(app_path.c_str());

std::string path;

path += app.GetLogDirectory();
path += "\\";
path += module_filename;
path += app_filename;
path += ".";
path += google::GetLogSeverityName(level);
path += ".";
Expand All @@ -187,12 +187,15 @@ namespace glog

std::string GetLogFilename(int level, const std::string& date, const std::string& time, uint32_t process_id)
{
std::string module_path = GetCurrentModulePath();
std::string module_filename = ra::filesystem::GetFilename(module_path.c_str());
shellanything::App& app = shellanything::App::GetInstance();
shellanything::PropertyManager& pmgr = shellanything::PropertyManager::GetInstance();

const std::string& app_path = pmgr.GetApplicationPath();
std::string app_filename = ra::filesystem::GetFilename(app_path.c_str());

std::string filename;

filename.append(module_filename);
filename.append(app_filename);
filename.append(".");
filename += google::GetLogSeverityName(level);

Expand All @@ -209,11 +212,14 @@ namespace glog

bool IsLogFile(const std::string& path)
{
std::string module_path = GetCurrentModulePath();
std::string module_filename = ra::filesystem::GetFilename(module_path.c_str());
shellanything::App& app = shellanything::App::GetInstance();
shellanything::PropertyManager& pmgr = shellanything::PropertyManager::GetInstance();

const std::string& app_path = pmgr.GetApplicationPath();
std::string app_filename = ra::filesystem::GetFilename(app_path.c_str());

//validate that 'path' contains the dll filename
size_t pos = path.find(module_filename);
size_t pos = path.find(app_filename);
if (pos == std::string::npos)
return false;

Expand Down
6 changes: 3 additions & 3 deletions src/shellextension/dllmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -353,12 +353,12 @@ extern "C" int APIENTRY DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpRe

if (!app.IsTestingEnvironment())
{
// Initialize Google's logging library.
glog::InitGlog();

//Issue #124. Define property 'application.path'.
std::string dll_path = GetCurrentModulePathUtf8();
shellanything::PropertyManager::SetApplicationPath(dll_path);

// Initialize Google's logging library.
glog::InitGlog();
}

LogEnvironment();
Expand Down
3 changes: 2 additions & 1 deletion src/shellextension/shellext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,8 @@ void InitConfigManager()
cmgr.AddSearchPath(config_dir);
cmgr.Refresh();

std::string prop_log_directory = ra::unicode::AnsiToUtf8(app.GetLogDirectory());
std::string log_dir = app.GetLogDirectory();
std::string prop_log_directory = ra::unicode::AnsiToUtf8(log_dir);

//define global properties
shellanything::PropertyManager& pmgr = shellanything::PropertyManager::GetInstance();
Expand Down
8 changes: 4 additions & 4 deletions src/tests/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ int main(int argc, char** argv)

shellanything::App& app = shellanything::App::GetInstance();

//Issue #124. Define property 'application.path'.
std::string exec_path = ra::process::GetCurrentProcessPathUtf8();
shellanything::PropertyManager::SetApplicationPath(exec_path);

// Initialize Google's logging library.
glog::InitGlog();

Expand All @@ -128,10 +132,6 @@ int main(int argc, char** argv)
std::string log_dir = app.GetLogDirectory();
printf("Using log directory: '%s'.\n", log_dir.c_str());

//Issue #124. Define property 'application.path'.
std::string exec_path = ra::process::GetCurrentProcessPathUtf8();
shellanything::PropertyManager::SetApplicationPath(exec_path);

//define global properties
shellanything::PropertyManager& pmgr = shellanything::PropertyManager::GetInstance();
std::string prop_log_directory = ra::unicode::AnsiToUtf8(log_dir);
Expand Down

0 comments on commit 154bd4a

Please sign in to comment.