void project_info::flush() { std::string file = get_config_path() + "/" + id + ".prj"; std::string tmpfile = get_config_path() + "/" + id + ".prj.tmp"; std::string bakfile = get_config_path() + "/" + id + ".prj.bak"; std::ofstream f(tmpfile); if(!f) throw std::runtime_error("Can't write project file"); write(f); if(!f) throw std::runtime_error("Can't write project file"); f.close(); std::ifstream f2(file); if(f2) { std::ofstream f3(bakfile); if(!f3) throw std::runtime_error("Can't backup project file"); while(f2) { std::string tmp; std::getline(f2, tmp); f3 << tmp << std::endl; } f2.close(); f3.close(); } #if defined(_WIN32) || defined(_WIN64) || defined(TEST_WIN32_CODE) if(MoveFileEx(tmpfile.c_str(), file.c_str(), MOVEFILE_REPLACE_EXISTING) < 0) #else if(rename(tmpfile.c_str(), file.c_str()) < 0) #endif throw std::runtime_error("Can't replace project file"); }
static int usage(void) { printf("\n%s: [options]\n", prog); printf("\n"); printf(" Options:\n"); printf(" -c <path> Path to config file (default: %s).\n", get_config_path()); printf(" -g <list of group names> Only run on the directories of clients that\n"); printf(" are in one of the groups specified.\n"); printf(" The list is comma-separated. To put a client in a\n"); printf(" group, use the 'dedup_group' option in the client\n"); printf(" configuration file on the server.\n"); printf(" -h|-? Print this text and exit.\n"); printf(" -d Delete any duplicate files found.\n"); printf(" (non-burp mode only)\n"); printf(" -l Hard link any duplicate files found.\n"); printf(" -m <number> Maximum number of hard links to a single file.\n"); printf(" (non-burp mode only - in burp mode, use the\n"); printf(" max_hardlinks option in the configuration file)\n"); printf(" The default is %d. On ext3, the maximum number\n", DEF_MAX_LINKS); printf(" of links possible is 32000, but space is needed\n"); printf(" for the normal operation of burp.\n"); printf(" -n <list of directories> Non-burp mode. Deduplicate any (set of) directories.\n"); printf(" -v Print duplicate paths.\n"); printf(" -V Print version and exit.\n"); printf("\n"); printf("By default, %s will read %s and deduplicate client storage\n", prog, get_config_path()); printf("directories using special knowledge of the structure.\n"); printf("\n"); printf("With '-n', this knowledge is turned off and you have to specify the directories\n"); printf("to deduplicate on the command line. Running with '-n' is therefore dangerous\n"); printf("if you are deduplicating burp storage directories.\n\n"); return 1; }
void create_config_file(void) { int status; char *home_path; char config_path[STR_BUFFER_SIZE]; char config_dir[STR_BUFFER_SIZE]; /*check out $HOME in system env.*/ home_path = getenv("HOME"); if (!home_path) { fprintf(stderr, "You have to set the env:$HOME\n"); exit(EXIT_FAILURE); } get_config_path(config_path); get_config_dir(config_dir); /*check out if the config file exsit.*/ if(access(config_path, F_OK) == -1) { /*create dir.*/ status = mkdir(config_dir, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH); /*create file.`*/ status = open(config_path, O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH); } }
static void usage_server(void) { #ifndef HAVE_WIN32 printf("\nThe configuration file specifies whether burp runs in server or client mode.\n"); printf("\nServer usage: %s [options]\n", progname()); printf("\n"); printf(" Options:\n"); printf(" -a s Run the status monitor.\n"); printf(" -a S Screen dump of the status monitor (for reporting).\n"); printf(" -c <path> Path to config file (default: %s).\n", get_config_path()); printf(" -d <path> a single client in the status monitor\n"); printf(" -F Stay in the foreground.\n"); printf(" -g Generate initial CA certificates and exit.\n"); printf(" -h|-? Print this text and exit.\n"); printf(" -i Print index of symbols and exit\n"); printf(" -l <path> Path to log file.\n"); printf(" -n Do not fork any children (implies '-F').\n"); printf(" -v Print version and exit.\n"); printf("Options to use with '-a S':\n"); printf(" -C <client> Show a particular client\n"); printf(" -b <number> Show listable files in a particular backup (requires -C)\n"); printf(" -z <file> Dump a particular log file in a backup (requires -C and -b)\n"); printf(" -d <path> Show a particular path in a backup (requires -C and -b)\n"); printf("\n"); #endif }
static void usage_client(void) { printf("\nClient usage: %s [options]\n", progname()); printf("\n"); printf(" Options:\n"); printf(" -a <action> The action can be one of the following.\n"); printf(" b: backup\n"); printf(" e: estimate\n"); printf(" l: list (this is the default when an action is not given)\n"); printf(" L: long list\n"); printf(" r: restore\n"); printf(" t: timed backup\n"); printf(" v: verify\n"); printf(" -b <number> Backup number (default: the most recent backup)\n"); printf(" -c <path> Path to config file (default: %s).\n", get_config_path()); printf(" -d <directory> Directory to restore to, or directory to list\n"); printf(" -f Allow overwrite during restore.\n"); printf(" -h|-? Print this text and exit.\n"); printf(" -i Print index of symbols and exit\n"); printf(" -l <path> Path to log file.\n"); printf(" -r <regex> Specify a regular expression.\n"); printf(" -s <number> Number of leading path components to strip during restore.\n"); printf(" -v Print version and exit.\n"); printf("\n"); #ifndef HAVE_WIN32 printf(" See http://burp.grke.net/ or the man page ('man burp') for usage examples\n"); printf(" and additional configuration options.\n\n"); #else printf(" See http://burp.grke.net/ for usage examples and additional configuration\n"); printf(" options.\n\n"); #endif }
void user_config_restore_device( unicap_handle_t handle ) { GKeyFile *keyfile; gchar *config_path; gchar *ini_path; gchar *file_name; unicap_device_t device; unicap_get_device( handle, &device ); config_path = get_config_path(); file_name = g_strconcat( "_", device.identifier, ".ini", NULL ); ini_path = g_build_path( G_DIR_SEPARATOR_S, config_path, file_name, NULL ); g_free( file_name ); g_free( config_path ); keyfile = g_key_file_new( ); if( g_key_file_load_from_file( keyfile, ini_path, G_KEY_FILE_NONE, NULL ) ) { unicapgtk_load_device_state( handle, keyfile, UNICAPGTK_DEVICE_STATE_PROPERTIES ); } g_free( ini_path ); }
bool load_config(const char *file) { input_init(); char *path; if (file != NULL) { path = strdup(file); } else { path = get_config_path(); } sway_log(L_INFO, "Loading config from %s", path); if (path == NULL) { sway_log(L_ERROR, "Unable to find a config file!"); return false; } FILE *f = fopen(path, "r"); if (!f) { fprintf(stderr, "Unable to open %s for reading", path); free(path); return false; } free(path); bool config_load_success; if (config) { config_load_success = read_config(f, true); } else { config_load_success = read_config(f, false); } fclose(f); return config_load_success; }
std::map<std::string, std::string> project_state::enumerate() { std::set<std::string> projects; std::map<std::string, std::string> projects2; projects = directory::enumerate(get_config_path(), ".*\\.prj"); for(auto i : projects) { std::string id = i; size_t split; #ifdef FUCKED_SYSTEM split = id.find_last_of("\\/"); #else split = id.find_last_of("/"); #endif if(split < id.length()) id = id.substr(split + 1); id = id.substr(0, id.length() - 4); try { projects2[id] = project_getname(id); } catch(...) { messages << "Failed to load name for ID '" << id << "'" << std::endl; } } return projects2; }
UserConfig UserConfig::try_read_data(const Files::Filesystem& fs) { UserConfig ret; try { auto maybe_pghs = Paragraphs::get_paragraphs(fs, get_config_path()); if (const auto p_pghs = maybe_pghs.get()) { const auto& pghs = *p_pghs; std::unordered_map<std::string, std::string> keys; if (pghs.size() > 0) keys = pghs[0]; for (size_t x = 1; x < pghs.size(); ++x) { for (auto&& p : pghs[x]) keys.insert(p); } ret.user_id = keys["User-Id"]; ret.user_time = keys["User-Since"]; ret.user_mac = keys["Mac-Hash"]; ret.last_completed_survey = keys["Survey-Completed"]; } } catch (...) { } return ret; }
int parse_config(clit_config *config){ char *path = get_config_path(); FILE *fp = fopen(path,"r"); if(!fp){ //fprintf(stderr,"Error:cannot open config file!\n"); return -1; } if(config == NULL) config = malloc(sizeof(clit_config)); char line[100]; memset(line,100,'\0'); fgets(line,100,fp); config->key = parse_value(line); memset(line,100,'\0'); fgets(line,100,fp); config->secret = parse_value(line); memset(line,100,'\0'); fgets(line,100,fp); config->user_id = parse_value(line); memset(line,100,'\0'); fgets(line,100,fp); config->screen_name = parse_value(line); if(config->key == NULL || config->secret == NULL || config->user_id == NULL || config->screen_name == NULL) return -1; free(path); return 0; }
//passing by reference in C can suck my balls int load_preferences(struct volk_arch_pref **prefs) { FILE *config_file; char path[512], line[512], function[128], arch[32]; int n_arch_prefs = 0; struct volk_arch_pref *t_pref; //get the config path get_config_path(path); config_file = fopen(path, "r"); if(!config_file) return; //no prefs found while(fgets(line, 512, config_file) != NULL) { if(sscanf(line, "%s %s", function, arch) == 2 && !strncmp(function, "volk_", 5)) { n_arch_prefs++; } } //now allocate the memory required for volk_arch_prefs (*prefs) = (struct volk_arch_pref *) malloc(n_arch_prefs * sizeof(struct volk_arch_pref)); t_pref = (*prefs); //reset the file pointer and write the prefs into volk_arch_prefs rewind(config_file); while(fgets(line, 512, config_file) != NULL) { if(sscanf(line, "%s %s", function, arch) == 2 && !strncmp(function, "volk_", 5)) { strncpy(t_pref->name, function, 128); strncpy(t_pref->arch, arch, 32); t_pref++; } } fclose(config_file); return n_arch_prefs; }
jboolean write_config(JNIEnv* env, jobject this_obj, const char* profile_name_s) { FILE* fp = 0; char path[PATH_MAX+1]; jboolean res = 0; Config_var* cfg_var_p; if (!profile_name_s) return 0; if (get_config_path(env,this_obj,path,sizeof(path),"%s.cnf",profile_name_s)) goto err; if (!(fp = fopen(path,"w"))) { LOGE("Could not open config file %s for writing", path); goto err; } for (cfg_var_p = config_vars; cfg_var_p->name; cfg_var_p++) { char buf[512]; if ((*cfg_var_p->printer)(env,this_obj,cfg_var_p,buf,sizeof(buf))) goto err; fprintf(fp,"%s=%s\n",cfg_var_p->lookup_name,buf); } res = 1; err: if (fp) fclose(fp); return res; }
static si_t application_load_config() { /** * TODO load config from file **/ global_application.icon_root_path = get_config_path(""); global_application.server_path = "/tmp/server"; return 0; }
static void tack_full_path(wxString &s, const wxString &app = wxEmptyString) { // regenerate path, including nonexistent dirs this time wxPathList full_config_path; get_config_path(full_config_path, false); for (int i = 0; i < full_config_path.size(); i++) s += wxT("\n\t") + full_config_path[i] + app; }
/** * @brief 用text_line全局样式对象初始化text_line对象 * * @param tl text_line指针 * * @return 成功返回0,否则返回-1 **/ static si_t text_line_init_with_default_style(struct text_line * tl) { char tmp_str[TMP_ARRAY_SIZE] = {'\0'}; si_t tmp_int = -1; char *config_path = get_config_path("text_line.cfg"); struct widget_style_entry extra[] = { {.key="frame_color_r", .type=WIDGET_STYLE_TYPE_INT, .val=&(text_line_default_style.frame_color_r)}, {.key="frame_color_g", .type=WIDGET_STYLE_TYPE_INT,
static bool setup_from_config(lwan_t *lwan) { config_t conf; config_line_t line; bool has_listener = false; char path_buf[PATH_MAX]; const char *path; path = get_config_path(path_buf); lwan_status_info("Loading configuration file: %s", path); lwan->url_map_trie = lwan_trie_new(destroy_urlmap); if (!config_open(&conf, path)) return false; while (config_read_line(&conf, &line)) { switch (line.type) { case CONFIG_LINE_TYPE_LINE: if (!strcmp(line.line.key, "keep_alive_timeout")) lwan->config.keep_alive_timeout = parse_int(line.line.value, default_config.keep_alive_timeout); else if (!strcmp(line.line.key, "quiet")) lwan->config.quiet = parse_bool(line.line.value, default_config.quiet); else if (!strcmp(line.line.key, "reuse_port")) lwan->config.reuse_port = parse_bool(line.line.value, default_config.reuse_port); else config_error(&conf, "Unknown config key: %s", line.line.key); break; case CONFIG_LINE_TYPE_SECTION: if (!has_listener) { has_listener = true; if (!strcmp(line.section.name, "listener")) parse_listener(&conf, &line, lwan); else config_error(&conf, "Unknown section type: %s", line.section.name); } else { config_error(&conf, "Only one listener supported"); } break; case CONFIG_LINE_TYPE_SECTION_END: config_error(&conf, "Unexpected section end"); } } if (conf.error_message) { lwan_status_critical("Error on config file \"%s\", line %d: %s", path, conf.line, conf.error_message); } config_close(&conf); return true; }
String OS_Haiku::get_cache_path() const { if (has_environment("XDG_CACHE_HOME")) { return get_environment("XDG_CACHE_HOME"); } else if (has_environment("HOME")) { return get_environment("HOME").plus_file("config/cache"); } else { return get_config_path(); } }
String OS_Haiku::get_data_path() const { if (has_environment("XDG_DATA_HOME")) { return get_environment("XDG_DATA_HOME"); } else if (has_environment("HOME")) { return get_environment("HOME").plus_file("config/data"); } else { return get_config_path(); } }
/** * @brief 用tab全局样式对象初始化tab对象 * * @param style tab样式对象指针 * @param b tab指针 * * @return 成功返回0,否则返回-1 **/ static si_t tab_init_with_default_style(struct tab * b) { char *config_path = get_config_path("tab.cfg"); si_t res = widget_init_with_default_style(config_path, WIDGET_POINTER(b), &tab_default_style.common, NULL, 0); free(config_path); return res; }
/* Delete the RC file */ int tilp_config_delete(void) { char* ini_file; int result; ini_file = get_config_path(); result = unlink(ini_file); g_free(ini_file); return result; }
/** * Loads a configuration file and parses it. */ void WMConfig::load() { // This is meant to help out the unit tests, which would otherwise have // 'reset()' calls sprinkled about reset(); std::string config_path = get_config_path(); const char *c_filename = const_cast<const char*>(config_path.c_str()); ini_parse(c_filename, &WMConfig::config_parser, this); }
/** * @brief 用panel全局样式对象初始化panel对象 * * @param style panel样式对象指针 * @param p panel指针 * * @return 成功返回0,否则返回-1 **/ static si_t panel_init_with_default_style(struct panel * p) { char *config_path = get_config_path("panel.cfg"); si_t res = widget_init_with_default_style(config_path, WIDGET_POINTER(p), &panel_default_style.common, NULL, 0); free(config_path); return res; }
void parse_argv(int *argcp, char ***argvp, struct settings *s) { const char *optstr = "r" // postfix (rpn) "p" // prefix (pn) "i" // infix "c" // print config path "w" // print settings "h" // show help ; int c; while ((c = getopt(*argcp, *argvp, optstr)) != -1) switch (c) { case 'r': s->notation = POSTFIX; break; case 'p': s->notation = PREFIX; break; case 'i': s->notation = INFIX; break; case 'c': { char path[PATH_MAX]; get_config_path(path); printf("%s\n", path); exit(EXIT_SUCCESS); } case 'w': write_settings(s, stdout); exit(EXIT_SUCCESS); case 'h': usage(EXIT_SUCCESS); case '?': default: usage(EXIT_FAILURE); } *argcp -= optind - 1; *argvp += optind - 1; }
int load_site_config() { FILE *fp; char config_path[255]; char line[255]; int i =0; get_config_path(config_path); fp = fopen(config_path, "r"); if (fp == NULL) { printf("Error ! \n"); return -1; } while (fgets(line, 255, fp) != NULL) { char var[255]; char value[255]; /* avoid comments */ if (line[0] == '#') continue; if (split_line(line, var, value) != 0) continue; strcpy(config_site.var[i].var, var); /* If this variable is empty we use config_site.dest_directory * as default value. This way it is faster to get a first try * of the software without setting/understanding this variable. */ if (strcmp(var, "site_url") == 0) { char path[PATH_MAX+1]; char site_url[PATH_MAX+1]; getcwd(path, PATH_MAX); sprintf(site_url, "%s/%s", path, config_site.dest_directory); strcpy(config_site.var[i].value, site_url); } else { strcpy(config_site.var[i].value, value); } i++; } strcpy(config_site.var[i].var, ""); strcpy(config_site.var[i].value, ""); fclose(fp); return 0; }
int save_config(clit_config *config){ FILE *fp = fopen(get_config_path(),"w+"); if(!fp){ fprintf(stderr,"Error:cannot open config file!\n"); return -1; } fprintf(fp,"key = %s\n",config->key); fprintf(fp,"secret = %s\n", config->secret); fprintf(fp,"user_id = %s\n", config->user_id); fprintf(fp,"screen_name = %s\n", config->screen_name); fclose(fp); return 0; }
wxString wxvbamApp::GetConfigurationPath() { // first check if config files exists in reverse order // (from system paths to more local paths.) if (data_path.empty()) { get_config_path(config_path); for (int i = config_path.size() - 1; i >= 0 ; i--) { wxFileName fn(config_path[i], wxT("vbam.ini")); if (fn.FileExists() && fn.IsFileWritable()) { data_path = config_path[i]; break; } } } // if no config file was not found, search for writable config // dir or parent to create it in in OnInit in normal order // (from user paths to system paths.) if (data_path.empty()) { for (int i = 0; i < config_path.size() ; i++) { // Check if path is writeable if (wxIsWritable(config_path[i])) { data_path = config_path[i]; break; } // check if parent of path is writable, so we can // create the path in OnInit wxFileName parent_dir = wxFileName::DirName(config_path[i] + wxT("//..")); parent_dir.MakeAbsolute(); if (parent_dir.IsDirWritable()) { data_path = config_path[i]; break; } } } return data_path; }
void save_settings(Preferences *pref) { gchar *path; gchar *dir; GKeyFile* key; GError *err = NULL; gchar *data; gsize data_len = 0; GtkWidget *dialog; path = get_config_path(); dir = g_dirname(path); key = g_key_file_new(); g_key_file_load_from_file(key, path, G_KEY_FILE_KEEP_COMMENTS|G_KEY_FILE_KEEP_TRANSLATIONS, NULL); g_key_file_set_integer(key, "core", "backend", pref->backend); g_key_file_set_string(key, "core", "download_dir", pref->download_dir); g_key_file_set_integer(key, "core", "max_concurrent_downloads", pref->max_concurrent_downloads); g_key_file_set_boolean(key, "core", "use_schedule", pref->use_schedule); g_key_file_set_integer(key, "core", "start_time_hour", pref->start_time_hour); g_key_file_set_integer(key, "core", "start_time_minute", pref->start_time_minute); g_key_file_set_integer(key, "core", "end_time_hour", pref->end_time_hour); g_key_file_set_integer(key, "core", "end_time_minute", pref->end_time_minute); data = g_key_file_to_data(key, &data_len, &err); if (err) { dialog = gtk_message_dialog_new (GTK_WINDOW(g_GAria2), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, "Error: %s", err->message); gtk_dialog_run (GTK_DIALOG (dialog)); gtk_widget_destroy (dialog); g_error_free(err); } if (!g_file_test(dir, G_FILE_TEST_EXISTS)) { g_mkdir_with_parents(dir, 0700); } g_file_set_contents(path, data, data_len, NULL); g_free(data); g_free(path); g_free(dir); g_key_file_free(key); }
/* Rom browser which is called FIRST before all other init Return values : 1 - file chosen, name is written at *romname 0 - no file */ int gui_LoadFile(char *romname) { int result = 0; // get current working dir before it's modified by load_file get_config_path(); // do early initialize of SDL gui_video_early_init(); if(load_file(file_ext, romname) != -1) result = 1; // deinit to be fine gui_video_early_deinit(); return result; }
static void fetch_element_table (GstPlugin * plugin) { gchar *path; gchar *config, *s; GstStructure *tmp, *element; element_table = gst_plugin_get_cache_data (plugin); if (element_table) return; path = get_config_path (); if (!g_file_get_contents (path, &config, NULL, NULL)) { g_warning ("could not find config file '%s'.. using defaults!", path); config = (gchar *) default_config; } gst_plugin_add_dependency_simple (plugin, "ONX_CONFIG", path, NULL, GST_PLUGIN_DEPENDENCY_FLAG_NONE); g_free (path); GST_DEBUG ("parsing config:\n%s", config); tmp = gst_structure_empty_new ("element_table"); s = config; while ((element = gst_structure_from_string (s, &s))) { const gchar *element_name = gst_structure_get_name (element); gst_structure_set (tmp, element_name, GST_TYPE_STRUCTURE, element, NULL); } if (config != default_config) g_free (config); GST_DEBUG ("element_table=%" GST_PTR_FORMAT, tmp); gst_plugin_set_cache_data (plugin, tmp); element_table = tmp; }
/* Return TiLP version number */ int tilp_config_get_version(char *version) { char *ini_file; FILE *txt; char buffer[256]; int i = 0; char *p; strcpy(version, ""); if (tilp_config_exist() == 0) return -1; ini_file = get_config_path(); txt = fopen(ini_file, "rt"); g_free(ini_file); if (txt == NULL) return -1; for (i = 0; i < 5; i++) { if (fgets(buffer, 256, txt) == NULL) { fclose(txt); return -1; } } p = strchr(buffer, '='); if (p == NULL) return -1; strcpy(version, ++p); p = strchr(version, '\r'); if (p) *p = '\0'; p = strchr(version, '\n'); if (p) *p = '\0'; fclose(txt); return 0; }