refactor: move COM type and guard into independent file

- move COM types and guard into independent file and namespace COMHelper because not only dialog, but also other parts also need to use COM related fucntion.
- remove ParserHelper.cpp because it is empty (ParserHelper is header only namespace).
- Add a function fetching LOCALAPPDATA in WinFctHelper.
This commit is contained in:
2024-06-17 12:46:32 +08:00
parent 8465d80a54
commit e20c03a5f1
9 changed files with 153 additions and 85 deletions

View File

@ -2,6 +2,7 @@
#if YYCC_OS == YYCC_OS_WINDOWS
#include "EncodingHelper.hpp"
#include "COMHelper.hpp"
namespace YYCC::WinFctHelper {
@ -70,6 +71,17 @@ namespace YYCC::WinFctHelper {
return YYCC::EncodingHelper::WcharToUTF8(wpath.c_str(), ret);
}
bool GetLocalAppData(std::string& ret) {
// fetch path
LPWSTR _known_path;
HRESULT hr = SHGetKnownFolderPath(FOLDERID_LocalAppData, KF_FLAG_CREATE, NULL, &_known_path);
if (FAILED(hr)) return false;
COMHelper::SmartLPWSTR known_path(_known_path);
// convert to utf8
return YYCC::EncodingHelper::WcharToUTF8(known_path.get(), ret);
}
}
#endif