void GetUserDataPath(char *buf) { HANDLE hndl; WIN32_FIND_DATA data; char ispth[MAX_PATH]; sprintf(ispth,"%s\\appdata",szInstallPath); hndl = FindFirstFile(ispth, &data); if (hndl != INVALID_HANDLE_VALUE) { sprintf(buf, "%s\\appdata\\", szInstallPath); FindClose(hndl); } else if (SHGetFolderPathA(NULL, CSIDL_APPDATA, NULL, 0, buf) == S_OK) { if (buf[strlen(buf)-1] != '\\') strcat(buf,"\\"); strcat(buf,"Orange C\\"); mkdir(buf); } else { strcpy(buf,szInstallPath); strcat(buf,"\\"); } }
static const char *fish_cache_path (void) { struct stat stat_buf; static char path[4096]; strncpy (path, FALLBACK_CACHE_PATH, 4096); #ifndef _WIN32 if (getenv ("HOME")) sprintf (path, "%s/.cache/babl/babl-fishes", getenv("HOME")); #else { char win32path[4096]; if (SHGetFolderPathA (NULL, CSIDL_LOCAL_APPDATA, NULL, SHGFP_TYPE_CURRENT, win32path) == S_OK) sprintf (path, "%s\\%s\\babl-fishes.txt", win32path, BABL_LIBRARY); else if (getenv ("TEMP")) sprintf (path, "%s\\babl-fishes.txt", getenv("TEMP")); } #endif if (stat (path, &stat_buf)==0 && S_ISREG(stat_buf.st_mode)) return path; if (mk_ancestry (path) != 0) return FALLBACK_CACHE_PATH; return path; }
Logger::Logger() { std::string tmp; char path[ MAX_PATH ]; HRESULT err; BOOL ok; err = SHGetFolderPathA( NULL, CSIDL_LOCAL_APPDATA, NULL, 0, path ); require_noerr( err, exit ); tmp = path; // Create Logs subdir tmp += "\\Apple"; ok = CreateDirectoryA( tmp.c_str(), NULL ); require_action( ( ok || ( GetLastError() == ERROR_ALREADY_EXISTS ) ), exit, err = -1 ); // Create Logs subdir tmp += "\\Bonjour"; ok = CreateDirectoryA( tmp.c_str(), NULL ); require_action( ( ok || ( GetLastError() == ERROR_ALREADY_EXISTS ) ), exit, err = -1 ); // Create log file tmp += "\\PrinterSetupLog.txt"; open( tmp.c_str()); *this << currentTime() << " Log started" << std::endl; exit: return; }
int log_open(void) { if(global_options.output_file) { /* 'output' option specified */ outfile=file_open(global_options.output_file, global_options.log_file_mode); #if defined(USE_WIN32) && !defined(_WIN32_WCE) if(!outfile) { char appdata[MAX_PATH], *path; if(SHGetFolderPathA(NULL, CSIDL_LOCAL_APPDATA|CSIDL_FLAG_CREATE, NULL, 0, appdata)==S_OK) { path=str_printf("%s\\%s", appdata, global_options.output_file); outfile=file_open(path, global_options.log_file_mode); if(outfile) s_log(LOG_NOTICE, "Logging to %s", path); str_free(path); } } #endif if(!outfile) { s_log(LOG_ERR, "Cannot open log file: %s", global_options.output_file); return 1; } } log_flush(LOG_MODE_CONFIGURED); return 0; }
bool Windows::LoadProfile() { #ifdef WIN32 char szPath[MAX_PATH]; ALLEGRO_PATH* alPath; bool res; if( al_filename_exists( "c4a-prof" ) ) return ParseProfileFile( "c4a-prof" ); if( SHGetFolderPathA( 0, CSIDL_PERSONAL, 0, 0, (char*)&szPath ) == S_OK ) { alPath = al_create_path( (char*)&szPath ); al_append_path_component( alPath, "c4a-prof" ); if( al_filename_exists( al_path_cstr( alPath, '/' ) ) ) res = ParseProfileFile( (char*)al_path_cstr( alPath, '/' ) ); al_destroy_path( alPath ); return res; } return false; #else return false; #endif }
QDir appDataDir() { QString path; #ifdef Q_OS_WIN if ( ( QSysInfo::WindowsVersion & QSysInfo::WV_DOS_based ) == 0 ) { // Use this for non-DOS-based Windowses char acPath[MAX_PATH]; HRESULT h = SHGetFolderPathA( NULL, CSIDL_LOCAL_APPDATA | CSIDL_FLAG_CREATE, NULL, 0, acPath ); if ( h == S_OK ) { path = QString::fromLocal8Bit( acPath ); } } #elif defined(Q_OS_MAC) path = appSupportFolderPath(); #elif defined(Q_OS_LINUX) path = QDir::home().filePath( ".local/share" ); #else path = QCoreApplication::applicationDirPath(); #endif path += "/" + QCoreApplication::organizationName(); QDir d( path ); d.mkpath( path ); return d; }
Vector<const char*>* CreateFontDirectories() { auto directories = new Vector<const char*>; char path[MAX_PATH]; SHGetFolderPathA(nullptr, CSIDL_WINDOWS, nullptr, 0, path); // Any back-slashes must be converted to forward slashes. After this we need to append the "Fonts" directory. size_t i = 0; for (; i < MAX_PATH && path[i] != 0; ++i) { if (path[i] == '\\') { path[i] = '/'; } } // 'i' will be at the null terminator. We must have enough room to store the "/Fonts" string. if (i + 6 < MAX_PATH) { path[i++] = '/'; path[i++] = 'F'; path[i++] = 'o'; path[i++] = 'n'; path[i++] = 't'; path[i++] = 's'; path[i] = '\0'; directories->PushBack(Strings::Create(path)); } return directories; }
static QDir dataDotDot() { #ifdef WIN32 if ((QSysInfo::WindowsVersion & QSysInfo::WV_DOS_based) == 0) { // Use this for non-DOS-based Windowses char path[MAX_PATH]; HRESULT h = SHGetFolderPathA( NULL, CSIDL_LOCAL_APPDATA | CSIDL_FLAG_CREATE, NULL, 0, path ); if (h == S_OK) return QString::fromLocal8Bit( path ); } return QDir::home(); #elif defined(Q_WS_MAC) return QDir::home().filePath( "Library/Application Support" ); #elif defined(Q_WS_X11) return QDir::home().filePath( ".local/share" ); #else return QDir::home(); #endif }
extern "C" void __declspec(dllexport) CreateMediaCenterShortcut( HWND hwndParent, int string_size, char *variables, stack_t **stacktop) { EXDLL_INIT(); char *cBinPath = NULL; cBinPath = (char*)GlobalAlloc(GPTR, string_size); popstring( cBinPath ); char shortcutLink[MAX_PATH]; sprintf( shortcutLink, "\"%s\" -media", cBinPath ); HRESULT hr = CoInitialize(NULL); char *mediaCenterPath = (char*)GlobalAlloc(GPTR, string_size); hr = SHGetFolderPathA( NULL, CSIDL_COMMON_APPDATA, NULL, SHGFP_TYPE_CURRENT, mediaCenterPath ); char shortcutPath[MAX_PATH]; char filename[MAX_PATH]; sprintf( shortcutPath, "%s\\Media Center Programs\\Darwinia", mediaCenterPath ); sprintf( filename, "%s\\darwinia.lnk", shortcutPath ); CreateLink( cBinPath, shortcutPath, filename, "", "-mediacenter" ); }
EXTERN_C BOOL InitializeSym(HANDLE hProcess, BOOL fInvadeProcess) { // Provide default symbol search path // https://msdn.microsoft.com/en-us/library/windows/desktop/ms680689.aspx // http://msdn.microsoft.com/en-gb/library/windows/hardware/ff558829.aspx char szSymSearchPathBuf[MAX_PATH * 2]; const char *szSymSearchPath = NULL; if (getenv("_NT_SYMBOL_PATH") == NULL && getenv("_NT_ALT_SYMBOL_PATH") == NULL) { char szLocalAppData[MAX_PATH]; HRESULT hr = SHGetFolderPathA(NULL, CSIDL_LOCAL_APPDATA, NULL, 0, szLocalAppData); assert(SUCCEEDED(hr)); if (SUCCEEDED(hr)) { _snprintf(szSymSearchPathBuf, sizeof szSymSearchPathBuf, "srv*%s\\drmingw*http://msdl.microsoft.com/download/symbols", szLocalAppData); szSymSearchPath = szSymSearchPathBuf; } else { // No cache szSymSearchPath = "srv*http://msdl.microsoft.com/download/symbols"; } } return SymInitialize(hProcess, szSymSearchPath, fInvadeProcess); }
/** * Builds a list of predefined paths for the User folder * according to the running system. * @return List of data paths. */ std::vector<std::string> findUserFolders() { std::vector<std::string> list; #ifdef _WIN32 char path[MAX_PATH]; // Get Documents folder if (SUCCEEDED(SHGetFolderPathA(NULL, CSIDL_PERSONAL, NULL, SHGFP_TYPE_CURRENT, path))) { PathAppendA(path, "OpenXcom\\"); list.push_back(path); } // Get binary directory if (GetModuleFileNameA(NULL, path, MAX_PATH) != 0) { PathRemoveFileSpecA(path); PathAppendA(path, "user\\"); list.push_back(path); } // Get working directory if (GetCurrentDirectoryA(MAX_PATH, path) != 0) { PathAppendA(path, "user\\"); list.push_back(path); } #else #ifdef __HAIKU__ list.push_back("/boot/apps/OpenXcom/"); #endif char const *home = getHome(); char path[MAXPATHLEN]; // Get user folders if (char const *const xdg_data_home = getenv("XDG_DATA_HOME")) { snprintf(path, MAXPATHLEN, "%s/openxcom/", xdg_data_home); } else { #ifdef __APPLE__ snprintf(path, MAXPATHLEN, "%s/Library/Application Support/OpenXcom/", home); #else snprintf(path, MAXPATHLEN, "%s/.local/share/openxcom/", home); #endif } list.push_back(path); // Get old-style folder snprintf(path, MAXPATHLEN, "%s/.openxcom/", home); list.push_back(path); // Get working directory list.push_back("./user/"); #endif return list; }
static char* GetPath_XDG_CONFIG_HOME(void) { char* path = NULL; #if defined(WIN32) path = calloc(MAX_PATH, sizeof(char)); if (!path) return NULL; if (FAILED(SHGetFolderPathA(0, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT, path))) { free(path); return NULL; } #else char* home = NULL; /** * There is a single base directory relative to which user-specific configuration files should be written. * This directory is defined by the environment variable $XDG_CONFIG_HOME. * * $XDG_CONFIG_HOME defines the base directory relative to which user specific configuration files should be stored. * If $XDG_CONFIG_HOME is either not set or empty, a default equal to $HOME/.config should be used. */ path = GetEnvAlloc("XDG_CONFIG_HOME"); if (path) return path; home = GetPath_HOME(); if (!home) home = GetPath_TEMP(); if (!home) return NULL; #ifdef ANDROID path = (char*) malloc(strlen(home) + strlen("/data/.config") + 1); #else path = (char*) malloc(strlen(home) + strlen("/.config") + 1); #endif if (!path) { free(home); return NULL; } #ifdef ANDROID sprintf(path, "%s%s", home, "/data/.config"); #else sprintf(path, "%s%s", home, "/.config"); #endif free(home); #endif return path; }
std::string GetAppDataPath() { char szPath[ MAX_PATH ]; if(SUCCEEDED(SHGetFolderPathA(NULL, CSIDL_APPDATA, NULL, 0, szPath))) { return std::string(szPath); } return std::string(); }
std::string getUserHomeDirectory() { char buff[MAX_PATH]; HRESULT res = SHGetFolderPathA(NULL, CSIDL_FLAG_CREATE | CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT, buff); if (res != S_OK) assert(0 && "Failed to get user home directory"); return buff; }
bool GetKnownFolder(int shell_folder, REFKNOWNFOLDERID known_folder, bool create, FString &path) { static GKFP SHGetKnownFolderPath = NULL; static bool tested = false; if (!tested) { tested = true; HMODULE shell32 = GetModuleHandle("shell32.dll"); if (shell32 != NULL) { SHGetKnownFolderPath = (GKFP)GetProcAddress(shell32, "SHGetKnownFolderPath"); } } char pathstr[MAX_PATH]; // SHGetKnownFolderPath knows about more folders than SHGetFolderPath, but is // new to Vista, hence the reason we support both. if (SHGetKnownFolderPath == NULL) { if (shell_folder < 0) { // Not supported by SHGetFolderPath return false; } if (create) { shell_folder |= CSIDL_FLAG_CREATE; } if (FAILED(SHGetFolderPathA(NULL, shell_folder, NULL, 0, pathstr))) { return false; } path = pathstr; return true; } else { PWSTR wpath; if (FAILED(SHGetKnownFolderPath(known_folder, create ? KF_FLAG_CREATE : 0, NULL, &wpath))) { return false; } // FIXME: Support Unicode, at least for filenames. This function // has no MBCS equivalent, so we have to convert it since we don't // support Unicode. :( bool converted = false; if (WideCharToMultiByte(GetACP(), WC_NO_BEST_FIT_CHARS, wpath, -1, pathstr, countof(pathstr), NULL, NULL) > 0) { path = pathstr; converted = true; } CoTaskMemFree(wpath); return converted; } }
void getOmegaRCPath() { #ifndef WIN32 sprintf(Str1, "%s/.omegarc", getenv("HOME")); #else SHGetFolderPathA(NULL, CSIDL_LOCAL_APPDATA, NULL, 0, Str1); strcat(Str1, "\\.omegarc"); #endif }
//! \brief Finds the OS specific directory path to save and retrieve user config data static const std::string _SetupUserConfigPath() { #if defined _WIN32 char path[MAX_PATH]; // %APPDATA% (%USERPROFILE%\Application Data) if(SUCCEEDED(SHGetFolderPathA(nullptr, CSIDL_APPDATA, nullptr, 0, path))) { std::string user_path = std::string(path) + "/" APPUPCASEDIRNAME "/"; if(!DoesFileExist(user_path)) MakeDirectory(user_path); _CopyOldSettingsFile(user_path); return user_path; } #elif defined __APPLE__ passwd *pw = getpwuid(getuid()); if(pw) { std::string path = std::string(pw->pw_dir) + "/Library/Preferences/" APPUPCASEDIRNAME "/"; if(!DoesFileExist(path)) MakeDirectory(path); return path; } #else // Linux, BSD, other POSIX systems // Implementation of the freedesktop specs (at least partially) // http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html // $XDG_CONFIG_HOME/valyriatear/ // equals to: ~/.config/valyriatear/ most of the time if (getenv("XDG_CONFIG_HOME")) { std::string path = std::string(getenv("XDG_CONFIG_HOME")) + "/" APPSHORTNAME "/"; if(!DoesFileExist(path)) MakeDirectory(path); _CopyOldSettingsFile(path); return path; } // We create a sane default: ~/.config/valyriatear passwd *pw = getpwuid(getuid()); if(pw) { std::string path = std::string(pw->pw_dir) + "/.config/"; if(!DoesFileExist(path)) MakeDirectory(path); path += "/" APPSHORTNAME "/"; if(!DoesFileExist(path)) MakeDirectory(path); _CopyOldSettingsFile(path); return path; } #endif // Default path if a specific solution could not be found. Note that this path may // not be writable by the user since it could be installed in administrator/root space PRINT_WARNING << "could not idenfity user config path, defaulting to system path" << std::endl; return "data/"; }
static QDir dataDotDot() { #ifdef WIN32 if ((QSysInfo::WindowsVersion & QSysInfo::WV_DOS_based) == 0) { // Use this for non-DOS-based Windowses char path[MAX_PATH]; HRESULT h = SHGetFolderPathA( NULL, CSIDL_LOCAL_APPDATA | CSIDL_FLAG_CREATE, NULL, 0, path ); if (h == S_OK) return QString::fromLocal8Bit( path ); } return QDir::home(); #elif defined(Q_WS_MAC) #define EIT( x ) { OSErr err = x; if (err != noErr) throw 1; } try { short vRefNum = 0; long dirId; EIT( ::FindFolder( kOnAppropriateDisk, kApplicationSupportFolderType, kDontCreateFolder, &vRefNum, &dirId ) ); // Now we have a vRefNum and a dirID - but *not* an Unix-Path as string. // Lets make one based from this: FSSpec fsspec; EIT( ::FSMakeFSSpec( vRefNum, dirId, NULL, &fsspec ) ); // ...and build an FSRef based on thes FSSpec. FSRef fsref; EIT( ::FSpMakeFSRef( &fsspec, &fsref ) ); // ...then extract the Unix Path as a C-String from the FSRef unsigned char path[512]; EIT( ::FSRefMakePath( &fsref, path, 512 ) ); return QDir::homePath() + QString::fromUtf8( (char*)path ); } catch (int) { return QDir::home().filePath( "Library/Application Support" ); } #elif defined(Q_WS_X11) return QDir::home().filePath( ".local/share" ); #else return QDir::home(); #endif }
std::string getDesktopPath(){ CHAR pth[MAX_PATH]; HRESULT result = SHGetFolderPathA(NULL, CSIDL_DESKTOP, NULL, 0, pth); if (result != S_OK) return ""; std::string ret = pth; ret+='\\'; return ret; }
std::string getDocumentsPath(){ CHAR pth[MAX_PATH]; HRESULT result = SHGetFolderPathA(NULL, CSIDL_PERSONAL, NULL, 0, pth); if (result != S_OK) return ""; std::string ret = pth; ret+='\\'; return ret; }
std::string getAppDataPath(){ CHAR pth[MAX_PATH]; HRESULT result = SHGetFolderPathA(NULL, CSIDL_APPDATA, NULL, 0, pth); if (result != S_OK) return ""; std::string ret = pth; ret+='\\'; return ret; }
void get_gcin_dir(char *tt) { #if WIN32 SHGetFolderPathA(NULL,CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT, tt); strcat(tt,"\\gcin"); #else strcpy(tt,(char *)getenv("HOME")); strcat(tt,"/.gcin"); #endif }
std::string getSystemPath(){ CHAR pth[MAX_PATH]; HRESULT result = SHGetFolderPathA(NULL, CSIDL_SYSTEMX86, NULL, 0, pth); if (result != S_OK) return ""; std::string ret = pth; ret+='\\'; return ret; }
std::string getCSIDLPath(long csidl){ CHAR pth[MAX_PATH]; HRESULT result = SHGetFolderPathA(NULL, csidl, NULL, 0, pth); if (result != S_OK) return ""; std::string ret = pth; ret+='\\'; return ret; }
int Frigid::init() { //Load stuff //TODO: Change to the refresh rate of the monitor. //mWindow.setFramerateLimit(30); //Get the user folder path. char path[MAX_PATH]; if (SHGetFolderPathA(NULL, CSIDL_PROFILE, NULL, 0, path) != S_OK) { _error("Could not get the user path") } mPrefs = Preferences::instance(); mPrefs->setHomeDir(path); mPrefs->setConfigDir(String(path) + "/Documents/_quark"); BindingManager::instance()->setDefaultBindings(); loadConfig(); uint32 w = mPrefs->getStartingWindowWidth(); uint32 h = mPrefs->getStartingWindowHeight(); bool m = mPrefs->getStartMaximized(); if (w == 0 || h == 0) { m = true; w = 1024; h = 600; } mWindow = new RenderWindow(VideoMode(w, h, 32, m), "Quark"); mMainPanel = Panel(); tempHelpText = Text("Press control + ? for help.", *mPrefs->getFont(), 12); getPreferences(); CodeEditor *editor = new CodeEditor(); mMainPanel.setWidget(editor); Input::initInput(); WindowEvent e; e.type = WindowEvent::Resized; e.size.width = mWindow->getWidth(); e.size.height = mWindow->getHeight(); Rectf visibleArea(0, 0, staticCastf(e.size.width), staticCastf(e.size.height)); mWindow->setView(View(visibleArea)); mMainPanel.resizeEvent(e); update(); quit(); return 0; }
const String FileSystem::GetPublicDocumentsPath() { char * szPath = new char[MAX_PATH]; SHGetFolderPathA(NULL, CSIDL_COMMON_DOCUMENTS, NULL, SHGFP_TYPE_CURRENT, szPath); int32 n = strlen(szPath); szPath[n] = '\\'; szPath[n+1] = 0; String str(szPath); delete[] szPath; return str; }
Path getUserDataPath() { Path result; char l_path[MAX_PATH]; if (SUCCEEDED(SHGetFolderPathA(NULL, CSIDL_APPDATA, NULL, 0, l_path))) { result = reinterpret_cast<char*>(l_path); } return result; }
std::string system_config_directory() { // Use explicitly wide char functions and compile for unicode. char app_data_path[MAX_PATH]; auto result = SHGetFolderPathA(NULL, CSIDL_COMMON_APPDATA, NULL, SHGFP_TYPE_CURRENT, app_data_path); if (SUCCEEDED(result)) return std::string(app_data_path); return ""; }
static inline bool init_system_path(void) { HRESULT hr = SHGetFolderPathA(NULL, CSIDL_SYSTEM, NULL, SHGFP_TYPE_CURRENT, system_path); if (hr != S_OK) { hlog("Failed to get windows system path: %08lX", hr); return false; } return true; }
// retrieve the user's cookie directory. // WinXP // C:\Documents and Settings\<username>\Cookies // WinVista/Win7 // C:\Documents and Settings\<username>\Application Data\Roaming\Microsoft\Windows\Cookies // C:\Documents and Settings\<username>\Application Data\Roaming\Microsoft\Windows\Cookies\Low // void get_internet_explorer_cookie_path( bool low_rights, std::string& path ) { #ifdef _WIN32 CHAR szBuffer[MAX_PATH]; if (SUCCEEDED(SHGetFolderPathA(NULL, CSIDL_COOKIES|CSIDL_FLAG_CREATE, NULL, SHGFP_TYPE_CURRENT, szBuffer))) { path = std::string(szBuffer); path += std::string("\\"); if (low_rights) { path += std::string("Low\\"); } } #endif }