@@ -255,105 +255,6 @@ Some auxillary functionalities might be affected. Please report this message if
255255 return buffer;
256256 }
257257
258- std::string get_folder_path(special_folder f)
259- {
260- std::string res;
261- #ifdef _WIN32
262-
263- if (f == temp_folder)
264- {
265- TCHAR buf[MAX_PATH];
266- if (GetTempPath(MAX_PATH, buf) != 0)
267- {
268- char str[1024];
269- wcstombs(str, buf, 1023);
270- res = str;
271- }
272- }
273- else
274- {
275- GUID folder;
276- HRESULT hr;
277- switch (f)
278- {
279- case user_desktop: folder = FOLDERID_Desktop;
280- break;
281- case user_documents: folder = FOLDERID_Documents;
282- // The user's Documents folder location may get overridden, as we know OneDrive does in certain circumstances.
283- // In such cases, the new function, SHGetKnownFolderPath, does not always return the new path, while the deprecated
284- // function does.
285- CHAR path[MAX_PATH];
286- CHECK_HR(SHGetFolderPathA(NULL, CSIDL_PERSONAL, NULL, 0, path));
287-
288- res = path;
289- res += " \\" ;
290- return res;
291- case user_pictures: folder = FOLDERID_Pictures;
292- break;
293- case user_videos: folder = FOLDERID_Videos;
294- break;
295- case app_data: folder = FOLDERID_RoamingAppData;
296- break;
297- default:
298- throw std::invalid_argument(
299- std::string(" Value of f (" ) + std::to_string(f) + std::string(" ) is not supported" ));
300- }
301-
302- PWSTR folder_path = NULL;
303- hr = SHGetKnownFolderPath(folder, KF_FLAG_DEFAULT_PATH, NULL, &folder_path);
304- if (SUCCEEDED(hr))
305- {
306- char str[1024];
307- wcstombs(str, folder_path, 1023);
308- CoTaskMemFree(folder_path);
309- res = str;
310- res += " \\" ;
311- }
312- else
313- {
314- throw std::runtime_error(" Failed to get requested special folder" );
315- }
316- }
317- #endif //_WIN32
318- #if defined __linux__ || defined __APPLE__
319- if (f == special_folder::temp_folder)
320- {
321- const char* tmp_dir = getenv(" TMPDIR" );
322- res = tmp_dir ? tmp_dir : " /tmp/" ;
323- }
324- else
325- {
326- const char* home_dir = getenv(" HOME" );
327- if (!home_dir)
328- {
329- struct passwd* pw = getpwuid(getuid());
330- home_dir = (pw && pw->pw_dir) ? pw->pw_dir : " " ;
331- }
332- if (home_dir)
333- {
334- res = home_dir;
335- switch (f)
336- {
337- case user_desktop: res += " /Desktop/" ;
338- break;
339- case user_documents: res += " /Documents/" ;
340- break;
341- case user_pictures: res += " /Pictures/" ;
342- break;
343- case user_videos: res += " /Videos/" ;
344- break;
345- case app_data: res += " /." ;
346- break;
347- default:
348- throw std::invalid_argument(
349- std::string(" Value of f (" ) + std::to_string(f) + std::string(" ) is not supported" ));
350- }
351- }
352- }
353- #endif // defined __linux__ || defined __APPLE__
354- return res;
355- }
356-
357258 bool ends_with(const std::string& s, const std::string& suffix)
358259 {
359260 auto i = s.rbegin(), j = suffix.rbegin();
0 commit comments