MacroApp::MacroApp(HINSTANCE hInstance, HWND hWnd) : m_hInstance(hInstance), m_hWnd(hWnd), m_systray(hInstance, hWnd) { static NotificationThreadData data; WCHAR * filepath; if (!SUCCEEDED(SHGetKnownFolderPath(FOLDERID_LocalAppData, 0, NULL, &filepath))) { MessageBox(0, "SHGetKnownFolderPath() failed.", 0, MB_OK); return; } m_settingsPath = filepath; m_settingsPath += L"\\Macro"; CreateDirectoryW(m_settingsPath.c_str(), NULL); m_settingsFile = m_settingsPath + L"\\macro-settings.py"; if (!fileExists(m_settingsFile.c_str())) { std::ofstream out(m_settingsFile.c_str()); extern const char * DEFAULT_CONFIG_FILE; out << DEFAULT_CONFIG_FILE; out.close(); } data.notificationHandle = FindFirstChangeNotificationW(m_settingsPath.c_str(), FALSE, FILE_NOTIFY_CHANGE_LAST_WRITE); if (data.notificationHandle != INVALID_HANDLE_VALUE) { data.hwnd = m_hWnd; CreateThread(NULL, 0, FileChangeNotificationThread, &data, 0, NULL); } }
/// <summary> /// /// </summary> void TileGroup::AddNameFilter(LPCWSTR name) { if (_wcsicmp(name, L".computer") == 0) { mHiddenItems.emplace(L"::{20D04FE0-3AEA-1069-A2D8-08002B30309D}"); } else if (_wcsicmp(name, L".recycleBin") == 0) { mHiddenItems.emplace(L"::{645FF040-5081-101B-9F08-00AA002F954E}"); } else if (_wcsicmp(name, L".controlPanel") == 0) { mHiddenItems.emplace(L"::{26EE0668-A00A-44D7-9371-BEB064C98683}"); mHiddenItems.emplace(L"::{5399E694-6CE5-4D6C-8FCE-1D8870FDCBA0}"); } else if (_wcsicmp(name, L".libraries") == 0) { mHiddenItems.emplace(L"::{031E4825-7B94-4DC3-B131-E946B44C8DD5}"); } else if (_wcsicmp(name, L".network") == 0) { mHiddenItems.emplace(L"::{F02C1A0D-BE21-4350-88B0-7367FC96EF3C}"); } else if (_wcsicmp(name, L".homegroup") == 0) { mHiddenItems.emplace(L"::{B4FB3F98-C1EA-428D-A78A-D1F5659CBA93}"); } else if (_wcsicmp(name, L".onedrive") == 0) { LPWSTR path; if (SUCCEEDED(SHGetKnownFolderPath(FOLDERID_SkyDrive, 0, nullptr, &path))) { mHiddenItems.emplace(path); CoTaskMemFree(path); } } else if (_wcsicmp(name, L".user") == 0) { LPWSTR path; if (SUCCEEDED(SHGetKnownFolderPath(FOLDERID_Profile, 0, nullptr, &path))) { mHiddenItems.emplace(path); CoTaskMemFree(path); } } else { mHiddenItems.emplace(name); } }
std::wstring GetAppDataPath() { if (appDataPath.empty()) { if (IsWindowsVistaOrLater()) { WCHAR* pathBuffer; if (FAILED(SHGetKnownFolderPath(FOLDERID_LocalAppDataLow, 0, 0, &pathBuffer))) throw std::runtime_error("Unable to find app data directory"); appDataPath.assign(pathBuffer); CoTaskMemFree(pathBuffer); } else { std::auto_ptr<wchar_t> pathBuffer(new wchar_t[MAX_PATH]); if (!SHGetSpecialFolderPathW(0, pathBuffer.get(), CSIDL_LOCAL_APPDATA, true)) throw std::runtime_error("Unable to find app data directory"); appDataPath.assign(pathBuffer.get()); } appDataPath += L"\\Adblock Plus for IE"; // Ignore errors here, this isn't a critical operation ::CreateDirectoryW(appDataPath.c_str(), NULL); } return appDataPath; }
wstring CFileSystemServiceImpl::makeValidPath(const wstring& path1) { wstring path = path1; size_t p = path.find(L'%'); while (p != wstring::npos) { size_t e = path.find(L'%', p+1); if (e == wstring::npos) break; wstring variableName = path.substr(p+1, e-p-1); wstring variableValue = getenv(variableName); replaceStringInPlace(path, path.substr(p, e+1-p), variableValue); p = path.find(L'%'); } p = path.find(L'{'); while (p != wstring::npos) { size_t e = path.find(L'}', p+1); if (e == wstring::npos) break; wstring variableName = path.substr(p, e-p+1); GUID guid; if (CLSIDFromString(variableName.c_str(), &guid) == S_OK) { LPWSTR folderPath = NULL; SHGetKnownFolderPath(guid, 0, NULL, &folderPath); if (folderPath) { replaceStringInPlace(path, path.substr(p, e+1-p), folderPath); CoTaskMemFree(folderPath); } } p = path.find(L'{'); } return path; }
UnicodeString Logfile::getFilename(const UnicodeString& logfileName) { auto logsDirectory = UnicodeString::Period; #ifdef WINDOWS // On Windows logfiles are put into the current user's AppData/Roaming/<client name> directory auto path = PWSTR(); SHGetKnownFolderPath(FOLDERID_RoamingAppData, 0, nullptr, &path); logsDirectory = FileSystem::joinPaths(fromUTF16(path), Globals::getClientName()); CoTaskMemFree(path); #elif defined(LINUX) // On Linux logfiles are put into the ~/.<client name> directory logsDirectory = FileSystem::joinPaths(FileSystem::getHomeDirectory(), String::Period + Globals::getClientName()); #elif defined(APPLE) // Put logfiles under ~/Library/Logs logsDirectory = FileSystem::joinPaths(FileSystem::getUserLibraryDirectory(), "Logs"); #ifdef MACOS logsDirectory = FileSystem::joinPaths(logsDirectory, Globals::getClientName()); #endif #endif return FileSystem::joinPaths(logsDirectory, logfileName + ".html"); }
// Creates a set of sample files in the current user's Documents directory to use as items in the // custom category inserted into the Jump List. HRESULT CreateSampleFiles() { PWSTR pszPathDocuments; HRESULT hr = SHGetKnownFolderPath(FOLDERID_Documents, KF_FLAG_CREATE, NULL, &pszPathDocuments); if (SUCCEEDED(hr)) { for (UINT i = 0; SUCCEEDED(hr) && i < ARRAYSIZE(c_rgpszFiles); i++) { WCHAR szPathSample[MAX_PATH]; hr = PathCombine(szPathSample, pszPathDocuments, c_rgpszFiles[i]) ? S_OK : E_FAIL; if (SUCCEEDED(hr)) { IStream *pstm; hr = SHCreateStreamOnFileEx(szPathSample, (STGM_WRITE | STGM_FAILIFTHERE), FILE_ATTRIBUTE_NORMAL, TRUE, NULL, &pstm); if (SUCCEEDED(hr)) { PCWSTR pszText = L"This is a sample file for the CustomJumpListSample.\r\n"; ULONG cb = (sizeof(pszText[0]) * (lstrlen(pszText) + 1)); hr = IStream_Write(pstm, pszText, cb); pstm->Release(); } else if (HRESULT_FROM_WIN32(ERROR_FILE_EXISTS) == hr) { // If the file exists, we're ok, we'll just reuse it hr = S_OK; } } } CoTaskMemFree(pszPathDocuments); } return hr; }
QString getKnownFolderPath(REFKNOWNFOLDERID id) { wchar_t* result; win_throw_on_fail( SHGetKnownFolderPath(id, 0, nullptr, &result) ); OLEPtr<wchar_t> ptr(result); return QString((QChar*)ptr.get()); }
// get a xliveless-compatible save game directory static std::wstring GetOriginalSavePath() { PWSTR documentsPath; // get the Documents folder if (SUCCEEDED(SHGetKnownFolderPath(FOLDERID_Documents, 0, nullptr, &documentsPath))) { // put it into a string and free it std::wstring savePath(documentsPath); CoTaskMemFree(documentsPath); // append the R* bits AppendPathComponent(savePath, L"\\Rockstar Games"); AppendPathComponent(savePath, L"\\GTA IV"); AppendPathComponent(savePath, L"\\savegames"); // append a final separator savePath += L"\\"; // and return the path return savePath; } // if not working, panic FatalError("Could not get Documents folder path for save games."); }
// get our Citizen save game directory static std::wstring GetCitizenSavePath() { PWSTR saveBasePath; // get the 'Saved Games' shell directory if (SUCCEEDED(SHGetKnownFolderPath(FOLDERID_SavedGames, 0, nullptr, &saveBasePath))) { // create a STL string and free the used memory std::wstring savePath(saveBasePath); CoTaskMemFree(saveBasePath); // append our path components AppendPathComponent(savePath, L"\\CitizenFX"); AppendPathComponent(savePath, L"\\GTA4"); // append a final separator savePath += L"\\"; // and return the path return savePath; } return GetOriginalSavePath(); }
static void initialize_launchers( HWND hwnd ) { HRESULT hr, init; TEXTMETRICW tm; int icon_size; if (!(get_icon_text_metrics( hwnd, &tm ))) return; icon_cx = GetSystemMetrics( SM_CXICON ); icon_cy = GetSystemMetrics( SM_CYICON ); icon_size = max( icon_cx, icon_cy ); title_cy = tm.tmHeight * 2; title_cx = max( tm.tmAveCharWidth * TITLE_CHARS, icon_size + PADDING_SIZE + title_cy ); launcher_size = BORDER_SIZE + title_cx + BORDER_SIZE; icon_offset_cx = (launcher_size - icon_cx) / 2; icon_offset_cy = BORDER_SIZE + (icon_size - icon_cy) / 2; title_offset_cx = BORDER_SIZE; title_offset_cy = BORDER_SIZE + icon_size + PADDING_SIZE; desktop_width = GetSystemMetrics( SM_CXSCREEN ); launchers_per_row = desktop_width / launcher_size; hr = SHGetKnownFolderPath( &FOLDERID_Desktop, KF_FLAG_CREATE, NULL, &desktop_folder ); if (FAILED( hr )) { WINE_ERR("Could not get user desktop folder\n"); return; } hr = SHGetKnownFolderPath( &FOLDERID_PublicDesktop, KF_FLAG_CREATE, NULL, &desktop_folder_public ); if (FAILED( hr )) { WINE_ERR("Could not get public desktop folder\n"); CoTaskMemFree( desktop_folder ); return; } if ((launchers = HeapAlloc( GetProcessHeap(), 0, 2 * sizeof(launchers[0]) ))) { nb_allocated = 2; init = CoInitialize( NULL ); add_folder( desktop_folder ); add_folder( desktop_folder_public ); if (SUCCEEDED( init )) CoUninitialize(); CreateThread( NULL, 0, watch_desktop_folders, hwnd, 0, NULL ); } }
void InitLua() { CHAR version[64]; lua = luaL_newstate(); if(lua == nullptr) { return; } luaL_openlibs(lua); luaL_newlib(lua, luaFuncs); lua_setglobal(lua, u8"crvmgr"); //skk-version _snprintf_s(version, _TRUNCATE, "%s", WCTOU8(TEXTSERVICE_NAME L" " TEXTSERVICE_VER)); lua_pushstring(lua, version); lua_setglobal(lua, u8"SKK_VERSION"); //%AppData%\\CorvusSKK\\init.lua if(luaL_dofile(lua, WCTOU8(pathinitlua)) == LUA_OK) { return; } ZeroMemory(pathinitlua, sizeof(pathinitlua)); #ifdef _DEBUG //<module directory>\\init.lua if(GetModuleFileNameW(nullptr, pathinitlua, _countof(pathinitlua)) != 0) { WCHAR *pdir = wcsrchr(pathinitlua, L'\\'); if(pdir != nullptr) { *(pdir + 1) = L'\0'; wcsncat_s(pathinitlua, fninitlua, _TRUNCATE); } } #else PWSTR knownfolderpath = nullptr; //%SystemRoot%\\IME\\IMCRVSKK\\init.lua if(SUCCEEDED(SHGetKnownFolderPath(FOLDERID_Windows, KF_FLAG_DONT_VERIFY, nullptr, &knownfolderpath))) { _snwprintf_s(pathinitlua, _TRUNCATE, L"%s\\%s\\%s\\%s", knownfolderpath, L"IME", TEXTSERVICE_DIR, fninitlua); CoTaskMemFree(knownfolderpath); } #endif if(luaL_dofile(lua, WCTOU8(pathinitlua)) == LUA_OK) { return; } UninitLua(); }
SpotifySession::SpotifySession() : loggedInEvent(CreateEvent(NULL, FALSE, FALSE, NULL)), threadData(spotifyCS), decoderOwner(NULL) { processEventsEvent = CreateEvent(NULL, FALSE, FALSE, NULL); threadData.processEventsEvent = processEventsEvent; threadData.sess = getAnyway(); memset(&initOnce, 0, sizeof(INIT_ONCE)); static sp_session_callbacks session_callbacks = {}; static sp_session_config spconfig = {}; PWSTR path; if (SHGetKnownFolderPath(FOLDERID_LocalAppData, 0, NULL, &path)) throw pfc::exception("couldn't get local app data path"); size_t num; char lpath[MAX_PATH]; if (wcstombs_s(&num, lpath, MAX_PATH, path, MAX_PATH)) { CoTaskMemFree(path); throw pfc::exception("couldn't convert local app data path"); } CoTaskMemFree(path); if (strcat_s(lpath, "\\foo_input_spotify")) throw pfc::exception("couldn't append to path"); spconfig.api_version = SPOTIFY_API_VERSION, spconfig.cache_location = lpath; spconfig.settings_location = lpath; spconfig.application_key = g_appkey; spconfig.application_key_size = g_appkey_size; spconfig.user_agent = "spotify-foobar2000-faux-" MYVERSION; spconfig.userdata = this; spconfig.callbacks = &session_callbacks; session_callbacks.logged_in = &logged_in; session_callbacks.notify_main_thread = ¬ify_main_thread; session_callbacks.music_delivery = &music_delivery; session_callbacks.play_token_lost = &play_token_lost; session_callbacks.end_of_track = &end_of_track; session_callbacks.log_message = &log_message; session_callbacks.message_to_user = &message_to_user; session_callbacks.start_playback = &start_playback; { LockedCS lock(spotifyCS); if (NULL == CreateThread(NULL, 0, &spotifyThread, &threadData, 0, NULL)) { throw pfc::exception("Couldn't create thread"); } assertSucceeds("creating session", sp_session_create(&spconfig, &sp)); } }
string GetSpecialPath(KNOWNFOLDERID kfid) { PWSTR res = nullptr; string result; if (SHGetKnownFolderPath(kfid, 0, nullptr, &res) == S_OK) { result = str::u16string(res); } if (res) ::CoTaskMemFree(res); return result; }
CString CSVNStatusCache::GetSpecialFolder(REFKNOWNFOLDERID rfid) { PWSTR pszPath = NULL; if (SHGetKnownFolderPath(rfid, KF_FLAG_CREATE, NULL, &pszPath) != S_OK) return CString(); CString path = pszPath; CoTaskMemFree(pszPath); return path; }
void StatTracker::Reset( void ) { m_fTimePlayed = 0; m_fBuildPhaseTime = 0; m_fSurvivalTime = 0; m_fDistanceWalked = 0; m_fBloodSpilled = 0; m_uGrenadesThrown = 0; m_uTotalShotsFired = 0; m_uMachineGunBullets = 0; m_uShotgunShells = 0; m_uRPGRounds = 0; m_uHatTrickShots = 0; m_uWallsPlaced = 0; m_uWallsPickedUp = 0; m_uWindowsPlaced = 0; m_uWindowsPickedUp = 0; m_uTowersBought = 0; m_uTowersSold = 0; m_uTrapsBought = 0; m_uTrapsSold = 0; m_uMoneySpent = 0; m_uTotalKills = 0; m_uRoundsSurvived = 0; m_uConsecutiveRoundsSurvived = 0; HRESULT hr; ostringstream stringstream; char path[MAX_PATH]; LPWSTR wszPath = NULL; size_t size; // Get the path to the app data folder hr = SHGetKnownFolderPath(FOLDERID_RoamingAppData, 0, 0, &wszPath); // Convert from LPWSTR to char[] wcstombs_s(&size, path, MAX_PATH, wszPath, MAX_PATH); // Convert char types if (hr == S_OK) stringstream << path; string pathtowrite = stringstream.str(); // Add the company and game information pathtowrite += "\\RazorBalloon\\"; // Create our directory SHCreateDirectoryEx(NULL, pathtowrite.c_str(), 0); // Create our save file pathtowrite += "stats.xml"; Save(pathtowrite.c_str()); }
bstr_t GetProgramFilesPath() { PWSTR path; SHGetKnownFolderPath(GetFolderId(), 0, nullptr, &path); bstr_t ret = path; CoTaskMemFree(path); return ret; }
std::string known_folder_path(const KNOWNFOLDERID& id) { std::string path; WCHAR* buffer; HRESULT result = SHGetKnownFolderPath(id, 0, NULL, &buffer); if (result == S_OK) { path = unicode_to_mb(buffer); CoTaskMemFree(buffer); } return path; }
static std::string WIN32_GetKnownFolderPath(REFKNOWNFOLDERID rfid) { std::string path; wchar_t* wpath = nullptr; if (SUCCEEDED(SHGetKnownFolderPath(rfid, KF_FLAG_CREATE, nullptr, &wpath))) { path = String::ToUtf8(std::wstring(wpath)); } CoTaskMemFree(wpath); return path; }
std::string et::documentsBaseFolder() { wchar_t* path = nullptr; SHGetKnownFolderPath(FOLDERID_Documents, 0, nullptr, &path); if (path == nullptr) return std::string(); std::string result = addTrailingSlash(unicodeToUtf8(path)); CoTaskMemFree(path); return result; }
std::string et::libraryBaseFolder() { wchar_t* path = nullptr; SHGetKnownFolderPath(FOLDERID_RoamingAppData, 0, nullptr, &path); if (path == nullptr) return emptyString; std::string result = addTrailingSlash(unicodeToUtf8(path)); CoTaskMemFree(path); return result; }
static bool initialiseProgramDataDir(wchar_t *path, size_t pathLen) { PWSTR programData; if (SUCCEEDED(SHGetKnownFolderPath(FOLDERID_ProgramData, 0, NULL, &programData))) { wcscpy_s(path, pathLen, programData); CoTaskMemFree(programData); if (initialiseDir(path, HSP_PUBLISHER)) { return initialiseDir(path, HSP_PRODUCT_NAME); } } return false; }
ff::String ff::GetKnownDirectory(REFGUID id, bool bCreate) { String szReturnPath; LPWSTR szPath = nullptr; assertHrRetVal(SHGetKnownFolderPath(id, bCreate ? KF_FLAG_CREATE : 0, nullptr, &szPath), szReturnPath); szReturnPath = szPath; CoTaskMemFree(szPath); return szReturnPath; }
std::string getConfigDirectory() { PWSTR path; auto result = std::string { "." }; if (SUCCEEDED(SHGetKnownFolderPath(FOLDERID_RoamingAppData, 0, NULL, &path))) { result = platform::fromWinApiString(path); CoTaskMemFree(path); } return result; }
string GetHomeFolderFilename() { PWSTR docsPath; SHGetKnownFolderPath(FOLDERID_Documents, KF_FLAG_SIMPLE_IDLIST | KF_FLAG_DONT_UNEXPAND, NULL, &docsPath); wstring documents = docsPath; CoTaskMemFree(docsPath); if(documents[documents.size() - 1] == '/' || documents[documents.size() - 1] == '\\') documents.pop_back(); return StringFormat::Wide2UTF8(documents); }
std::wstring CPathUtils::GetAppDataPath(HMODULE hMod) { PWSTR path = nullptr; if (SHGetKnownFolderPath(FOLDERID_RoamingAppData, KF_FLAG_CREATE, nullptr, &path) == S_OK) { std::wstring sPath = path; sPath += L"\\"; sPath += CPathUtils::GetFileNameWithoutExtension(CPathUtils::GetModulePath(hMod)); CreateDirectory(sPath.c_str(), nullptr); return sPath; } return CPathUtils::GetModuleDir(hMod); }
void GBAConfigDirectory(char* out, size_t outLength) { struct VFile* portable; #ifdef _WIN32 wchar_t wpath[MAX_PATH]; wchar_t wprojectName[MAX_PATH]; MultiByteToWideChar(CP_UTF8, 0, projectName, -1, wprojectName, MAX_PATH); HMODULE hModule = GetModuleHandleW(NULL); GetModuleFileNameW(hModule, wpath, MAX_PATH); PathRemoveFileSpecW(wpath); WideCharToMultiByte(CP_UTF8, 0, wpath, -1, out, outLength, 0, 0); StringCchCatA(out, outLength, "\\portable.ini"); portable = VFileOpen(out, O_RDONLY); if (portable) { portable->close(portable); } else { wchar_t* home; SHGetKnownFolderPath(&FOLDERID_RoamingAppData, 0, NULL, &home); StringCchPrintfW(wpath, MAX_PATH, L"%ws\\%ws", home, wprojectName); CoTaskMemFree(home); CreateDirectoryW(wpath, NULL); } WideCharToMultiByte(CP_UTF8, 0, wpath, -1, out, outLength, 0, 0); #elif defined(PSP2) UNUSED(portable); snprintf(out, outLength, "cache0:/%s", projectName); sceIoMkdir(out, 0777); #elif defined(GEKKO) UNUSED(portable); snprintf(out, outLength, "/%s", projectName); mkdir(out, 0777); #elif defined(_3DS) UNUSED(portable); snprintf(out, outLength, "/%s", projectName); FSUSER_CreateDirectory(sdmcArchive, fsMakePath(PATH_ASCII, out), 0); #else getcwd(out, outLength); strncat(out, PATH_SEP "portable.ini", outLength - strlen(out)); portable = VFileOpen(out, O_RDONLY); if (portable) { getcwd(out, outLength); portable->close(portable); return; } char* home = getenv("HOME"); snprintf(out, outLength, "%s/.config", home); mkdir(out, 0755); snprintf(out, outLength, "%s/.config/%s", home, binaryName); mkdir(out, 0755); #endif }
CString CodeCollaboratorInfo::GetPathToCollabGuiExe() { // this will work for X86 and X64 if the matching 'bitness' client has been installed PWSTR pszPath = NULL; if (SHGetKnownFolderPath(FOLDERID_ProgramFiles, KF_FLAG_CREATE, NULL, &pszPath) != S_OK) return CString(); CString path = pszPath; CoTaskMemFree(pszPath); path += L"Collaborator Client\\ccollabgui.exe"; if (PathFileExists(path)) return path; #ifdef _WIN64 // if running on x64 OS, but installed X86 client - get try getting directory from there // on X86 this just returns %ProgramFiles% if (SHGetKnownFolderPath(FOLDERID_ProgramFilesX86, KF_FLAG_CREATE, NULL, &pszPath) != S_OK) return CString(); path += L"Collaborator Client\\ccollabgui.exe"; if (PathFileExists(path)) return path; #endif return CString(); }
void CSetOverlayHandlers::OnBnClickedRegedt() { PWSTR pszPath = nullptr; if (SHGetKnownFolderPath(FOLDERID_Windows, KF_FLAG_CREATE, nullptr, &pszPath) == S_OK) { CString path = pszPath; CoTaskMemFree(pszPath); path += L"\\regedit.exe"; // regedit stores the key it showed last in // HKEY_Current_User\Software\Microsoft\Windows\CurrentVersion\Applets\Regedit\LastKey // we set that here to // HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\ShellIconOverlayIdentifiers // so when we start regedit, it will show that key on start CRegString regLastKey(L"Software\\Microsoft\\Windows\\CurrentVersion\\Applets\\Regedit\\LastKey"); regLastKey = L"HKEY_Local_Machine\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\ShellIconOverlayIdentifiers"; SHELLEXECUTEINFO si = { sizeof(SHELLEXECUTEINFO) }; si.hwnd = GetSafeHwnd(); si.lpVerb = L"open"; si.lpFile = path; si.nShow = SW_SHOW; ShellExecuteEx(&si); } }
std::string user_cache_directory() { #if UTILS_OS_LINUX auto xds_cache_home = std::getenv("XDS_CACHE_HOME"); if (xds_cache_home && *xds_cache_home != '\0') return xds_cache_home; auto home = user_home_directory(); if (!home.empty()) return home + "/.cache"; #elif UTILS_OS_MAC auto home = user_home_directory(); if (!home.empty()) return home + "/Library/Caches"; #elif UTILS_OS_WINDOWS wchar_t* utf16Path = nullptr; if (SHGetKnownFolderPath(FOLDERID_LocalAppData, 0, nullptr, &utf16Path) != S_OK) return {}; char utf8Path[4 * MAX_PATH]; int len = WideCharToMultiByte(CP_UTF8, 0, utf16Path, lstrlenW(utf16Path), utf8Path, sizeof(utf8Path), nullptr, nullptr); CoTaskMemFree(utf16Path); return {utf8Path, len}; #else static_assert(false, "Unsupported OS"); #endif return {}; }
boost::filesystem::path LootPaths::getLocalAppDataPath() { #ifdef _WIN32 HWND owner = 0; PWSTR path; if (SHGetKnownFolderPath(FOLDERID_LocalAppData, 0, NULL, &path) != S_OK) throw std::system_error(GetLastError(), std::system_category(), boost::locale::translate("Failed to get %LOCALAPPDATA% path.")); boost::filesystem::path localAppDataPath(FromWinWide(path)); CoTaskMemFree(path); return localAppDataPath; #else // Use XDG_CONFIG_HOME environmental variable if it's available. const char * xdgConfigHome = getenv("XDG_CONFIG_HOME"); if (xdgConfigHome != nullptr) return boost::filesystem::path(xdgConfigHome); // Otherwise, use the HOME env. var. if it's available. xdgConfigHome = getenv("HOME"); if (xdgConfigHome != nullptr) return boost::filesystem::path(xdgConfigHome) / ".config"; // If somehow both are missing, use the current path. return boost::filesystem::current_path(); #endif }