27#ifdef SPECIALFOLDERLOCATION_TEST
40std::string getSpecialFolderLocation(
const KNOWNFOLDERID &folderId)
45 HRESULT hr = SHGetKnownFolderPath(folderId, 0, NULL, &widePath);
50 if (wcstombs_s(&len,
nullptr, 0, widePath, 0) == 0)
53 if (wcstombs_s(
nullptr, ret.data(), len, widePath, len - 1) != 0)
58 CoTaskMemFree(widePath);
63#ifdef SPECIALFOLDERLOCATION_TEST
66 std::cout <<
"RoamingAppData " << getSpecialFolderLocation(FOLDERID_RoamingAppData)
68 std::cout <<
"Desktop " << getSpecialFolderLocation(FOLDERID_Desktop)
70 std::cout <<
"LocalAppData " << getSpecialFolderLocation(FOLDERID_LocalAppData)
72 std::cout <<
"Pictures " << getSpecialFolderLocation(FOLDERID_Pictures)
74 std::cout <<
"Documents " << getSpecialFolderLocation(FOLDERID_Documents)
81#include <CoreFoundation/CFBundle.h>
83std::string getResourcesLocation()
85 CFBundleRef mainBundle = CFBundleGetMainBundle();
86 CFURLRef resourcesURL = CFBundleCopyResourcesDirectoryURL(mainBundle);
88 if (!CFURLGetFileSystemRepresentation(resourcesURL, TRUE, (UInt8 *)path,
91 fprintf(stderr,
"Can't find Resources directory\n");
93 CFRelease(resourcesURL);
int main(int argc, char *argv[])
std::string_view path(std::string_view fullFilePath)
Returns the path without the file name.