@@ -11,52 +11,50 @@ Config& Config::Instance() {
1111 return instance;
1212}
1313
14- wstring StringToWString (const string& str) {
15- if (str.empty ()) return wstring ();
16-
17- int size_needed = MultiByteToWideChar (CP_UTF8, 0 , str.c_str (), -1 , nullptr , 0 );
18- if (size_needed == 0 ) return wstring (); // Conversion failed
19-
20- wstring wstr (size_needed, 0 );
21- MultiByteToWideChar (CP_UTF8, 0 , str.c_str (), -1 , &wstr[0 ], size_needed);
22-
23- return wstr;
14+ wstring ExePath () {
15+ wchar_t buffer[MAX_PATH] = { 0 };
16+ GetModuleFileNameW (NULL , buffer, MAX_PATH);
17+ wstring fullPath (buffer);
18+ wstring::size_type pos = fullPath.find_last_of (L" \\ /" );
19+ return fullPath.substr (0 , pos);
2420}
2521
26-
27- bool FileExists (string filename) {
22+ bool FileExists (wstring filename) {
2823 ifstream file_check (filename);
2924 if (file_check) return true ;
3025 else return false ;
3126}
3227
33- ProgramResult Config::Load (const string & filename) {
28+ ProgramResult Config::Load (const wstring & filename) {
3429 if (!FileExists (filename)) return ErrorResult (" Could not find config file" );
3530
3631 toml::table config;
3732 try {
3833 config = toml::parse_file (filename);
3934
4035 } catch (const toml::parse_error& err) {
41- cerr << err << endl;
42- return ErrorResult (" Failed to parse config file " + filename);
36+ wcerr << L" Error while parsing " << filename;
37+ cerr << " : " << err << endl;
38+ return ErrorResult (" Failed to parse config file " );
4339 }
4440
41+ auto current_path = ExePath ();
42+
4543#if _WIN64
46- string default_dll = " injectable_server_x64.dll" ;
44+ wstring default_dll = current_path + L" \\ injectable_server_x64.dll" ;
4745#else
48- string default_dll = " injectable_server_x86.dll" ;
46+ wstring default_dll = current_path + L" \\ injectable_server_x86.dll" ;
4947#endif
5048 key_extractor_dll_ = config[" Settings" ][" key_extractor_dll_path" ].value_or (default_dll);
5149 if (!FileExists (key_extractor_dll_)) {
52- cerr << " Could not find a default \n " ;
50+ cerr << " Default DLL not set in the config file \n " ;
5351 if (!FileExists (default_dll)) return ErrorResult (" Could not find a valid DLL" );
54- cerr << " Specified path to DLL does not exist. Defaulting to " << default_dll << endl;
52+ wcerr << " Specified path to DLL does not exist. Defaulting to " << default_dll << endl;
5553 }
5654
5755 return OkResult (" Configuration successfully loaded" );
5856}
5957
6058std::wstring Config::GetKeyExtractorDLLPath () const {
61- return StringToWString ( key_extractor_dll_) ;
59+ return key_extractor_dll_;
6260}
0 commit comments