Skip to content

Commit dd273ed

Browse files
committed
Updated GetConfigFilePath to use std::filesystem::path.
1 parent 31c98c8 commit dd273ed

File tree

8 files changed

+79
-190
lines changed

8 files changed

+79
-190
lines changed

LinkList.cpp

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -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

253244
bool CLinkSnapshot::LoadConfig()

ReleaseNotes.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,12 @@ <h2>History</h2>
8787
</ul>
8888
</li>
8989
<li>Version 1.21 (September 20<sup>th</sup>, 2024): Fixed loading/saving of XML configuration file.</li>
90-
<li>Version 1.22 (TBD):
90+
<li>Version 1.22 (February 13<sup>th</sup>, 2025):
9191
<ul>
9292
<li>Updated copyright information.</li>
9393
<li>Fixed limitation to <code>_MAX_PATH</code> for long path names.</li>
94-
<li>Updated Lee Thomason's <code>TinyXML2</code> library to the latest version available.</li>
94+
<li>Updated Lee Thomason's <code>TinyXML2</code> library to the latest version available.</li>
95+
<li>Updated <code>GetConfigFilePath</code> to use <code>std::filesystem::path</code>.</li>
9596
</ul>
9697
</li>
9798
</ul>

0 commit comments

Comments
 (0)