// // Get file name string ofxConfig::getFullFilename(const char *f) { // Use current if (f == NULL) return currentFileName; // Make filename std::ostringstream os; // Cinder file #ifdef CINDER #ifdef CINDER_COCOA_TOUCH os << getHomeDirectory() << f; #else os << getHomeDirectory() << "/Dev/Cinder/config/" << f; #endif // openFrameworks File #else #ifdef FREEFRAME os << "/uvjs/" << f; #else #ifdef RELEASE os << ofToDataPath(f); // BUNDLED #else os << "../../../data/" << f; #endif // release #endif // freeframe #endif // of return os.str(); }
bool ConfigService::loadSavedConfig ( const std::string& filename, const StringConfigMap& commandLineSettings ) { S_LOG_INFO ( "Loading shared config file from " << getSharedConfigDirectory() + "/"+ filename << "." ); bool success = mGlobalConfig->readFromFile ( getSharedConfigDirectory() + "/"+ filename, varconf::GLOBAL ); std::string userConfigPath ( getHomeDirectory() + "/" + filename ); std::ifstream file ( userConfigPath.c_str() ); if ( !file.fail() ) { S_LOG_INFO ( "Loading user config file from "<< getHomeDirectory() + "/" + filename <<"." ); try { mUserConfig->parseStream ( file, varconf::USER ); } catch ( varconf::ParseError& p ) { S_LOG_FAILURE ( "Error loading user config file: " << p ); success = false; } } else { S_LOG_INFO ( "Could not find any user config file." ); } //after loading the config from file, override with command time settings for (StringConfigMap::const_iterator I = commandLineSettings.begin(); I != commandLineSettings.end(); ++I) { for (std::map<std::string, std::string>::const_iterator J = I->second.begin(); J != I->second.end(); ++J) { S_LOG_INFO("Setting command line config option " << I->first << ":" << J->first << " to " << J->second); mCommandLineConfig->setItem(I->first, J->first, J->second); EventChangedConfigItem(I->first, J->first); } } return success; }
UString Platform::getConfigDirectory() { UString directory; #if defined(WIN32) // Windows: $APPDATA/xoreos/ or $USERPROFILE/xoreos/ or ./ const WindowsVersion windowsVersion = getWindowsVersion(); if (windowsVersion >= kWindowsVersion2000) { // Try the Application Data directory directory = getWindowsVariable(L"APPDATA"); if (!directory.empty()) directory += "\\xoreos"; // Try the User Profile directory if (directory.empty()) { directory = getWindowsVariable(L"USERPROFILE"); if (!directory.empty()) directory += "\\xoreos"; } } // If all else fails (or the Windows version is too low), use the current directory if (directory.empty()) directory = "."; #elif defined(MACOSX) // Mac OS X: ~/Library/Preferences/xoreos/ directory = getHomeDirectory(); if (!directory.empty()) directory += "/Library/Preferences/xoreos"; if (directory.empty()) directory = "."; #elif defined(UNIX) // Default Unixoid: $XDG_CONFIG_HOME/xoreos/ or ~/.config/xoreos/ const char *pathStr = getenv("XDG_CONFIG_HOME"); if (pathStr) { directory = UString(pathStr) + "/xoreos"; } else { directory = getHomeDirectory(); if (!directory.empty()) directory += "/.config/xoreos"; } if (directory.empty()) directory = "."; #else // Fallback: Current directory directory = "."; #endif return FilePath::canonicalize(directory); }
/** * Get the user's configuration directory. * * NOTE: This function does NOT cache the directory name. * Callers should cache it locally. * * @return User's configuration directory (without trailing slash), or empty string on error. */ string getConfigDirectory(void) { string config_dir; // Check $XDG_CONFIG_HOME first. const char *const xdg_config_home_env = getenv("XDG_CONFIG_HOME"); if (xdg_config_home_env && xdg_config_home_env[0] == '/') { // Make sure this is a writable directory. if (isWritableDirectory(xdg_config_home_env)) { // $XDG_CACHE_HOME is a writable directory. config_dir = xdg_config_home_env; // Remove trailing slashes. removeTrailingSlashes(config_dir); // If the path was "/", this will result in an empty directory. if (!config_dir.empty()) { return config_dir; } } } // Get the user's home directory. config_dir = getHomeDirectory(); if (config_dir.empty()) { // No home directory... return string(); } config_dir += "/.config"; return config_dir; }
const std::string& osqueryHomeDirectory() { static std::string homedir; if (homedir.size() == 0) { // Try to get the caller's home directory boost::system::error_code ec; auto userdir = getHomeDirectory(); if (userdir.is_initialized() && isWritable(*userdir).ok()) { auto osquery_dir = (fs::path(*userdir) / ".osquery"); if (isWritable(osquery_dir) || boost::filesystem::create_directories(osquery_dir, ec)) { homedir = osquery_dir.make_preferred().string(); return homedir; } } // Fail over to a temporary directory (used for the shell). auto temp = fs::temp_directory_path(ec) / fs::unique_path("osquery%%%%%%%%", ec); boost::filesystem::create_directories(temp, ec); homedir = temp.make_preferred().string(); } return homedir; }
void msaFluidParticlesApp::keyDown( KeyEvent event ) { switch( event.getChar() ) { case 'a': drawFluid = !drawFluid; break; case 'd': drawFluidTex = !drawFluidTex; break; case 'f': setFullScreen( ! isFullScreen() ); break; case ' ': fluidSolver.randomizeColor(); break; case 'p': drawParticles = ! drawParticles; break; case 'b': { Timer timer; timer.start(); const int ITERS = 1000; for( int i = 0; i < ITERS; ++i ) fluidSolver.update(); timer.stop(); console() << ITERS << " iterations took " << timer.getSeconds() << " seconds." << std::endl; } break; case 's': writeImage( getHomeDirectory() / "cinder" / "saveImage_" / ( toString( getElapsedFrames() ) + ".png" ), copyWindowSurface() ); break; } }
std::string CrossPlatform::getConfigPath() { #if defined(__unix__) char *maybeConfigHome = getenv("XDG_CONFIG_HOME"); if (maybeConfigHome == nullptr || *maybeConfigHome == '\0') return getHomeDirectory() + "/.config/falltergeist"; return std::string(maybeConfigHome) + "/falltergeist"; #elif defined(__MACH__) return getHomeDirectory() + "/Library/Application Support/falltergeist"; #elif defined(_WIN32) || defined(WIN32) char path[256]; SHGetFolderPath(nullptr, CSIDL_APPDATA | CSIDL_FLAGS_CREATE, NULL, 0, path); return std::string(path) + "/falltergeist"; #error Platform not supported: CrossPlatform::getConfigPath not implemented #else #endif }
std::string CrossPlatform::getDataPath() { #if defined(__unix__) char *maybeDataHome = getenv("XDG_DATA_HOME"); if (maybeDataHome == nullptr || *maybeDataHome == '\0') return getHomeDirectory() + "/.local/share/falltergeist"; return std::string(maybeDataHome) + "/falltergiest"; #else return getConfigPath(); #endif }
UString Platform::getUserDataDirectory() { UString directory; #if defined(WIN32) // Windows: Same as getConfigDirectory() directory = getConfigDirectory(); #elif defined(MACOSX) // Mac OS X: ~/Library/Application\ Support/xoreos/ directory = getHomeDirectory(); if (!directory.empty()) directory += "/Library/Application Support/xoreos"; if (directory.empty()) directory = "."; #elif defined(UNIX) // Default Unixoid: $XDG_DATA_HOME/xoreos/ or ~/.local/share/xoreos/ const char *pathStr = getenv("XDG_DATA_HOME"); if (pathStr) { directory = UString(pathStr) + "/xoreos"; } else { directory = getHomeDirectory(); if (!directory.empty()) directory += "/.local/share/xoreos"; } if (directory.empty()) directory = "."; #else // Fallback: Same as getConfigDirectory() directory = getConfigDirectory(); #endif return FilePath::canonicalize(directory); }
string mareklib::getPreferencesDirectory(string appName) { string prefsDir = getHomeDirectory() + "/Library/Preferences/"+appName; struct stat stFileInfo; // Attempt to get the file attributes if(stat(prefsDir.c_str(),&stFileInfo)!=0) { if(mkdir(prefsDir.c_str(), 0777)==0) { return prefsDir; } else { printf("Failed to create preferences directory: %s\n", prefsDir.c_str()); return ""; } } }
UString FilePath::absolutize(const UString &p) { path source = convertToSlash(p.c_str()).native(); // Resolve ~ as the user's home directory path::iterator itr = source.begin(); if ((itr != source.end()) && (itr->string() == "~")) { path newSource = getHomeDirectory().c_str(); for (++itr; itr != source.end(); ++itr) newSource /= *itr; source = newSource; } return convertToSlash(boost::filesystem::absolute(source)).string().c_str(); }
const std::string& ConfigService::getEmberDataDirectory() const { if ( hasItem ( "paths", "datadir" ) ) { static std::string path ( static_cast<std::string> ( getValue ( "paths", "datadir" ) ) + "/" ); return path; } else { //#ifdef __APPLE__ // return getBundleResourceDirPath(); //#elif __WIN32__ // return baseDir; //#else // return BR_EMBER_DATADIR("/games/ember/"); //#endif return getHomeDirectory(); } }
const char * getOverrideDirectory (void) { static const char *directory = NULL; if (!directory) { static const char subdirectory[] = "." PACKAGE_NAME; { char *homeDirectory = getHomeDirectory(); if (homeDirectory) { directory = makePath(homeDirectory, subdirectory); free(homeDirectory); if (directory) goto gotDirectory; } } { char *workingDirectory = getWorkingDirectory(); if (workingDirectory) { directory = makePath(workingDirectory, subdirectory); free(workingDirectory); if (directory) goto gotDirectory; } } directory = ""; logMessage(LOG_WARNING, "no override directory"); goto ready; gotDirectory: logMessage(LOG_INFO, "Override Directory: %s", directory); registerProgramMemory("override-directory", &directory); } ready: return *directory? directory: NULL; }
std::string Windows::getDatabaseDirectory () { return getHomeDirectory(); }
string mareklib::getDesktopPath() { return getHomeDirectory() + "/Desktop"; }
const std::string& ConfigService::getUserMediaDirectory() const { static std::string path ( getHomeDirectory() + "/user-media/" ); return path; }
UString FilePath::normalize(const UString &p, bool resolveSymLinks) { boost::filesystem::path source = convertToSlash(p.c_str()).native(); boost::filesystem::path result; // Resolve ~ as the user's home directory boost::filesystem::path::iterator itr = source.begin(); if ((itr != source.end()) && (itr->string() == "~")) { boost::filesystem::path newSource = getHomeDirectory().c_str(); for (++itr; itr != source.end(); ++itr) newSource /= *itr; source = newSource; } bool scan = true; while (scan) { scan = false; result.clear(); for (itr = source.begin(); itr != source.end(); ++itr) { // Resolve . if (itr->string() == ".") continue; // Resolve .., but only if symbolic links are also resolved if (resolveSymLinks && (itr->string() == "..")) { if (result != source.root_path()) result.remove_filename(); continue; } result /= *itr; /* If the resolving of symbolic links was requested, check if the current path * is one. If it is, resolve it and restart normalization. */ if (!resolveSymLinks) continue; boost::system::error_code ec; boost::filesystem::path link = boost::filesystem::read_symlink(result, ec); if (!link.empty()) { result.remove_filename(); if (link.is_absolute()) { for (++itr; itr != source.end(); ++itr) link /= *itr; source = link; } else { boost::filesystem::path newSource = result; newSource /= link; for (++itr; itr != source.end(); ++itr) newSource /= *itr; source = newSource; } scan = true; break; } } } if (!result.has_root_directory()) result = boost::filesystem::absolute(result); return convertToSlash(result).string().c_str(); }