@@ -222,32 +222,23 @@ std::string wstring_to_utf8(const std::wstring& str)
222222 return myconv.to_bytes (str);
223223}
224224
225- char buffer[ 0x100 ] = { 0 ,} ;
226- const char * GetConfigFilePath ()
225+ CString GetModuleFileName (_Inout_opt_ DWORD* pdwLastError = nullptr ) ;
226+ const CStringA GetConfigFilePath ()
227227{
228- TCHAR lpszDrive[_MAX_DRIVE] = { 0 , };
229- TCHAR lpszDirectory[_MAX_DIR] = { 0 , };
230- TCHAR lpszFilename[_MAX_FNAME] = { 0 , };
231- TCHAR lpszExtension[_MAX_EXT] = { 0 , };
232- TCHAR lpszFullPath[0x1000 /* _MAX_PATH */ ] = { 0 , };
233- const DWORD nLength = 0x1000 /* _MAX_PATH */ ;
234-
235228 WCHAR* lpszSpecialFolderPath = nullptr ;
236229 if ((SHGetKnownFolderPath (FOLDERID_Profile, 0 , nullptr , &lpszSpecialFolderPath)) == S_OK)
237230 {
238231 std::wstring result (lpszSpecialFolderPath);
239232 CoTaskMemFree (lpszSpecialFolderPath);
240233 result += _T (" \\ ConfigLink.xml" );
241- strcpy (buffer, wstring_to_utf8 (result).c_str ());
242- return buffer;
234+ return wstring_to_utf8 (result).c_str ();
243235 }
244236
245- GetModuleFileName (nullptr , lpszFullPath, nLength);
246- _tsplitpath_s (lpszFullPath, lpszDrive, _MAX_DRIVE, lpszDirectory, _MAX_DIR, lpszFilename, _MAX_FNAME, lpszExtension, _MAX_EXT);
247- _tmakepath_s (lpszFullPath, 0x1000 /* _MAX_PATH */ , lpszDrive, lpszDirectory, lpszFilename, _T (" .xml" ));
248-
249- strcpy (buffer, wstring_to_utf8 (lpszFullPath).c_str ());
250- return buffer;
237+ CString strFilePath{ GetModuleFileName () };
238+ std::filesystem::path strFullPath{ strFilePath.GetString () };
239+ strFullPath.replace_filename (_T (" ConfigLink" ));
240+ strFullPath.replace_extension (_T (" .xml" ));
241+ return wstring_to_utf8 (strFullPath).c_str ();
251242}
252243
253244bool CLinkSnapshot::LoadConfig ()
0 commit comments