string config_handler::get_config_file() { if( config_file == "" ) { if( get_config_file_path() != "" ) config_file += get_config_file_path(); else config_file += utils::get_base_dir(); if( get_config_file_name() != "" ) config_file += get_config_file_name(); else config_file += "config"; // TODO - make default } return config_file; }
bool mmg_app::OnInit() { #ifdef __WXMAC__ ProcessSerialNumber PSN; GetCurrentProcess(&PSN); TransformProcessType(&PSN, kProcessTransformToForegroundApplication); #endif wxImage::AddHandler(new wxPNGHandler); mtx_common_init("mmg"); wxConfigBase *cfg; uint32_t i; wxString k, v; int index; prepare_mmg_data_folder(); #if defined(SYS_WINDOWS) cfg = new wxConfig(wxT("mkvmergeGUI")); #else cfg = new wxFileConfig(wxT("mkvmergeGUI"), wxEmptyString, get_config_file_name()); #endif cfg->SetExpandEnvVars(false); wxConfigBase::Set(cfg); init_ui_locale(); cfg->SetPath(wxT("/GUI")); cfg->Read(wxT("last_directory"), &last_open_dir, wxEmptyString); for (i = 0; i < 4; i++) { k.Printf(wxT("last_settings %u"), i); if (cfg->Read(k, &v) && wxFile::Exists(v)) last_settings.push_back(v); k.Printf(wxT("last_chapters %u"), i); if (cfg->Read(k, &v) && wxFile::Exists(v)) last_chapters.push_back(v); } cfg->SetPath(wxT("/chapter_editor")); cfg->Read(wxT("default_language"), &k, wxT("und")); g_default_chapter_language = wxMB(k); index = map_to_iso639_2_code(g_default_chapter_language.c_str()); if (-1 == index) g_default_chapter_language = "und"; else g_default_chapter_language = iso639_languages[index].iso639_2_code; if (cfg->Read(wxT("default_country"), &k) && (0 < k.length())) g_default_chapter_country = wxMB(k); if (!is_valid_cctld(g_default_chapter_country.c_str())) g_default_chapter_country = ""; app = this; mdlg = new mmg_dialog(); mdlg->Show(true); handle_command_line_arguments(); return true; }
static void reload_config(void) { pool_log("reload config files."); pool_get_config(get_config_file_name(), RELOAD_CONFIG); if (pool_config->enable_pool_hba) load_hba(get_hba_file_name()); reload_config_request = 0; }
int Snes9xConfig::load_config_file (void) { struct stat file_info; char *pathname; xmlDoc *xml_doc = NULL; xmlNodePtr xml_root = NULL; load_defaults (); pathname = get_config_dir (); if (stat (pathname, &file_info)) { if (mkdir (pathname, 0755)) { fprintf (stderr, _("Couldn't create config directory: %s\n"), pathname); return -1; } } else { chmod (pathname, 0755); } free (pathname); pathname = get_config_file_name (); if (stat (pathname, &file_info)) { save_config_file (); } xml_doc = xmlReadFile (pathname, NULL, 0); if (!xml_doc) { fprintf (stderr, _("Couldn't open config file: %s\n"), pathname); return -2; } free (pathname); xml_root = xmlDocGetRootElement (xml_doc); parse_snes9x (xml_root); xmlFreeDoc (xml_doc); return 0; }
void MainWindow::remove() { //printf("line %d, active index %d, name %s\n", __LINE__, active_index_, // applist[active_index_].name_.toLocal8Bit().constData()); char *fname = get_config_file_name(applist[active_index_].name_.toLocal8Bit().constData()); if (fname) { unlink(fname); applist.removeAt(active_index_); // update hide(); show(); update(); } free(fname); }
void mmg_app::init_config_base() const { auto cfg = static_cast<wxConfigBase *>(nullptr); #if defined(SYS_WINDOWS) if (m_is_installed) cfg = new wxConfig{wxT("mkvmergeGUI")}; #endif if (!cfg) cfg = new wxFileConfig{wxT("mkvmergeGUI"), wxEmptyString, get_config_file_name()}; cfg->SetExpandEnvVars(false); wxConfigBase::Set(cfg); }
void config_handler::print() { // // Display internal settings set from reading steering // string mn = "print:"; string def = "<default>"; int w1=30; //arbitrary spacing size that makes formatting look pretty for data names int w2=30; //arbitrary spacing size that makes formatting look pretty for data options cout<<cn<<mn<<" >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" <<"\n"<<setw(w1)<<"DEBUG: " <<setw(w2)<<(debug? "ON":"OFF") <<"\n"<<setw(w1)<<"RUN IN BACKGROUND: " <<setw(w2)<<(get_background()? "ON":"OFF") <<"\n"<<setw(w1)<<"SIMULATION: " <<setw(w2)<<(get_simulate()? "ON":"OFF") <<"\n"<<setw(w1)<<"FILTER FIRST: " <<setw(w2)<<(get_filter()? "ON":"OFF") <<"\n"<<setw(w1)<<"SAVE RECORDINGS: " <<setw(w2)<<(get_save_rec()? "ON":"OFF") <<"\n"<<setw(w1)<<"HUMAN READABLE OUTPUT: " <<setw(w2)<<(get_output_formatted()? "ON":"OFF") <<"\n"<<setw(w1)<<"Output Type ID: " <<setw(w2)<<"\""<<get_output_type_id()<<"\"" <<"\n"<<setw(w1)<<"RPi Latitude: " <<setw(w2)<<"\""<<get_latitude()<<"\"" <<"\n"<<setw(w1)<<"RPi Longitude: " <<setw(w2)<<"\""<<get_longitude()<<"\"" <<"\n"<<setw(w1)<<"RPi ID: " <<setw(w2)<<"\""<<get_rpid()<<"\"" <<"\n"<<setw(w1)<<"Simulation Data Dir: " <<setw(w2)<<"\""<<get_simulate_dir()<<"\"" <<"\n"<<setw(w1)<<"Config Path: " <<setw(w2)<<"\""<<get_config_file_path()<<"\"" <<"\n"<<setw(w1)<<"Config Name: " <<setw(w2)<<"\""<<get_config_file_name()<<"\"" <<"\n"<<setw(w1)<<"Config File: " <<setw(w2)<<"\""<<get_config_file()<<"\"" <<"\n"<<setw(w1)<<"Final Feature Format: " <<setw(w2)<<"\""<<get_final_feature_format()<<"\"" <<"\n"<<setw(w1)<<"Filter Vector Path: " <<setw(w2)<<"\""<<get_fv_filter_path()<<"\"" <<"\n"<<setw(w1)<<"Filter Vector Name: " <<setw(w2)<<"\""<<get_fv_filter_name()<<"\"" <<"\n"<<setw(w1)<<"Filter Vector File: " <<setw(w2)<<"\""<<get_fv_filter()<<"\"" <<"\n"<<setw(w1)<<"Feature Vector Path: " <<setw(w2)<<"\""<<get_fv_file_path()<<"\"" <<"\n"<<setw(w1)<<"Feature Vector Name: " <<setw(w2)<<"\""<<get_fv_file_name()<<"\"" <<"\n"<<setw(w1)<<"Feature Vector File: " <<setw(w2)<<"\""<<get_fv_file()<<"\"" <<"\n"<<setw(w1)<<"Analysis File(s) Path: " <<setw(w2)<<"\""<<get_analysis_location()<<"\"" <<"\n"<<setw(w1)<<"Data File(s) Path: " <<setw(w2)<<"\""<<get_data_location()<<"\"" <<"\n"<<setw(w1)<<"Media Location File Path: " <<setw(w2)<<"\""<<get_media_location()<<"\"" <<"\n"<<setw(w1)<<"Recording Extention: " <<setw(w2)<<"\""<<get_rec_extention()<<"\"" <<"\n"<<setw(w1)<<"Recording File Name Prefix: " <<setw(w2)<<"\""<<get_rec_file_name_prefix()<<"\"" <<"\n"<<setw(w1)<<"Recording Rate: " <<setw(w2)<<"\""<<get_samp_rate()<<"\"" <<"\n"<<setw(w1)<<"Recording Duration: " <<setw(w2)<<"\""<<get_rec_duration()<<"\"" <<"\n"<<setw(w1)<<"Recording Number: " <<setw(w2)<<"\""<<get_rec_number()<<"\""<<endl; cout<<cn<<mn<<" <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"<<endl; return; }
void read_config_file() { char config_file[BUFF_LEN]; char config_dir[BUFF_LEN]; clear_config_cache(); if ( get_config_file_name( config_file, sizeof( config_file ) ) != 0 ) { return; } if ( get_config_dir_name( config_dir, sizeof( config_dir ) ) != 0 ) { return; } if ( dir_exists( config_dir ) ) { if ( file_exists( config_file ) ) { /* File exists -- let's try to evaluate it. */ if ( Tcl_EvalFile( g_game.tcl_interp, config_file ) != TCL_OK ) { handle_error( 1, "error evalating %s: %s", config_file, Tcl_GetStringResult( g_game.tcl_interp ) ); } } return; } /* File does not exist -- look for old version */ if ( get_old_config_file_name( config_file, sizeof( config_file ) ) != 0 ) { return; } if ( !file_exists( config_file ) ) { return; } /* Old file exists -- let's try to evaluate it. */ if ( Tcl_EvalFile( g_game.tcl_interp, config_file ) != TCL_OK ) { handle_error( 1, "error evalating deprecated %s: %s", config_file, Tcl_GetStringResult( g_game.tcl_interp ) ); } else { /* Remove old file and save info in new file location */ remove(config_file); write_config_file(); } }
void mmg_app::prepare_mmg_data_folder() { // The 'jobs' folder is part of the application data // folder. Therefore both directories will be creatd. // 'prepare_path' treats the last part of the path as a file name; // therefore append a dummy file name so that all directory parts // will be created. mm_file_io_c::prepare_path(wxMB(get_jobs_folder() + wxT("/dummy"))); #if !defined(SYS_WINDOWS) // Migrate the config file from its old location ~/.mkvmergeGUI to // the new location ~/.mkvtoolnix/config wxString old_config_name; wxGetEnv(wxT("HOME"), &old_config_name); old_config_name += wxT("/.mkvmergeGUI"); if (wxFileExists(old_config_name)) wxRenameFile(old_config_name, get_config_file_name()); #endif }
config_handler::config_handler( string fpath, string fname = "" ) { string mn = "config_handler:"; cout<<mn<<" Constructor started for file \""<<fname<<"\"."<<endl; debug = true; init(); if( fpath == "" ) fpath = utils::get_home_dir(); if( fname == "" ) utils::get_base( fpath ); if( fname == "" ) fname = "cirainbow.conf"; // make sure default or custom config file is found // User coice, home directory "cirainbow.conf", local directory "sound_settings.conf" if( utils::is_file_readable( utils::pathify(fpath) + fname ) == false ) { cout<<cn<<mn<<" Initial config file not accesable at: \""<<utils::pathify(fpath)+fname<<"\"."<<endl; fpath = utils::get_base_dir(); fname = "sound_settings.conf"; } //cout<<cn<<mn<<" Config file here: \""<<utils::pathify(fpath)+fname<<"\"."<<endl; //TEST //exit( 0 ); //TEST set_config_file_path( fpath ); set_config_file_name( fname ); string configFile = get_config_file_path() + get_config_file_name(); set_config_file( configFile ); cout<<cn<<mn<<" Config file here: \""<<get_config_file()<<"\"."<<endl; read_config( configFile ); cout<<cn<<mn<<" Constructor finished for file \""<<fname<<"\"."<<endl; }
void write_config_file() { FILE *config_stream; char config_file[BUFF_LEN]; char config_dir[BUFF_LEN]; struct param *parm; int i; #ifdef __APPLE__ // Don't save the config file on iphone, no use for it. return; #endif if ( get_config_file_name( config_file, sizeof( config_file ) ) != 0 ) { return; } if ( get_config_dir_name( config_dir, sizeof( config_dir ) ) != 0 ) { return; } if ( !dir_exists( config_dir ) ) { #if defined(WIN32) && !defined(__CYGWIN__) if (mkdir( config_dir ) != 0) { return; } #else if (mkdir( config_dir, 0775) != 0) { return; } #endif } config_stream = fopen( config_file, "w" ); if ( config_stream == NULL ) { print_warning( CRITICAL_WARNING, "couldn't open %s for writing: %s", config_file, strerror(errno) ); return; } fprintf( config_stream, "# Tux Racer " VERSION " configuration file\n" "#\n" ); for (i=0; i<sizeof(Params)/sizeof(struct param); i++) { parm = (struct param*)&Params + i; //FIXME : dans la version simulateur, on ne veut as qu'il enregistre le data_dir car il change à chaque fois et sinon c'est la merde if (!strcmp(parm->name,"data_dir")) continue; // Don't save the resolution if (!strcmp(parm->name,"x_resolution")) continue; if (!strcmp(parm->name,"y_resolution")) continue; if ( parm->comment != NULL ) { fprintf( config_stream, "\n# %s\n#\n%s\n#\n", parm->name, parm->comment ); } switch ( parm->type ) { case PARAM_STRING: fetch_param_string( parm ); fprintf( config_stream, "set %s \"%s\"\n", parm->name, parm->val.string_val ); break; case PARAM_CHAR: fetch_param_char( parm ); fprintf( config_stream, "set %s %c\n", parm->name, parm->val.char_val ); break; case PARAM_INT: fetch_param_int( parm ); fprintf( config_stream, "set %s %d\n", parm->name, parm->val.int_val ); break; case PARAM_BOOL: fetch_param_bool( parm ); fprintf( config_stream, "set %s %s\n", parm->name, parm->val.bool_val ? "true" : "false" ); break; default: code_not_reached(); } } if ( fclose( config_stream ) != 0 ) { perror( "fclose" ); } }
/* * perform accept() and return new fd */ static POOL_CONNECTION *do_accept(int unix_fd, int inet_fd, struct timeval *timeout) { fd_set readmask; int fds; int save_errno; SockAddr saddr; int fd = 0; int afd; int inet = 0; POOL_CONNECTION *cp; #ifdef ACCEPT_PERFORMANCE struct timeval now1, now2; static long atime; static int cnt; #endif struct timeval *timeoutval; struct timeval tv1, tv2, tmback = {0, 0}; set_ps_display("wait for connection request", false); /* Destroy session context for just in case... */ pool_session_context_destroy(); FD_ZERO(&readmask); FD_SET(unix_fd, &readmask); if (inet_fd) FD_SET(inet_fd, &readmask); if (timeout->tv_sec == 0 && timeout->tv_usec == 0) timeoutval = NULL; else { timeoutval = timeout; tmback.tv_sec = timeout->tv_sec; tmback.tv_usec = timeout->tv_usec; gettimeofday(&tv1, NULL); #ifdef DEBUG pool_log("before select = {%d, %d}", timeoutval->tv_sec, timeoutval->tv_usec); pool_log("g:before select = {%d, %d}", tv1.tv_sec, tv1.tv_usec); #endif } fds = select(Max(unix_fd, inet_fd)+1, &readmask, NULL, NULL, timeoutval); save_errno = errno; /* check backend timer is expired */ if (backend_timer_expired) { pool_backend_timer(); backend_timer_expired = 0; } /* * following code fragment computes remaining timeout val in a * portable way. Linux does this automatically but other platforms do not. */ if (timeoutval) { gettimeofday(&tv2, NULL); tmback.tv_usec -= tv2.tv_usec - tv1.tv_usec; tmback.tv_sec -= tv2.tv_sec - tv1.tv_sec; if (tmback.tv_usec < 0) { tmback.tv_sec--; if (tmback.tv_sec < 0) { timeout->tv_sec = 0; timeout->tv_usec = 0; } else { tmback.tv_usec += 1000000; timeout->tv_sec = tmback.tv_sec; timeout->tv_usec = tmback.tv_usec; } } #ifdef DEBUG pool_log("g:after select = {%d, %d}", tv2.tv_sec, tv2.tv_usec); pool_log("after select = {%d, %d}", timeout->tv_sec, timeout->tv_usec); #endif } errno = save_errno; if (fds == -1) { if (errno == EAGAIN || errno == EINTR) return NULL; pool_error("select() failed. reason %s", strerror(errno)); return NULL; } /* timeout */ if (fds == 0) { return NULL; } if (FD_ISSET(unix_fd, &readmask)) { fd = unix_fd; } if (FD_ISSET(inet_fd, &readmask)) { fd = inet_fd; inet++; } /* * Note that some SysV systems do not work here. For those * systems, we need some locking mechanism for the fd. */ memset(&saddr, 0, sizeof(saddr)); saddr.salen = sizeof(saddr.addr); #ifdef ACCEPT_PERFORMANCE gettimeofday(&now1,0); #endif retry_accept: /* wait if recovery is started */ while (*InRecovery == 1) { pause(); } afd = accept(fd, (struct sockaddr *)&saddr.addr, &saddr.salen); save_errno = errno; /* check backend timer is expired */ if (backend_timer_expired) { pool_backend_timer(); backend_timer_expired = 0; } errno = save_errno; if (afd < 0) { if (errno == EINTR && *InRecovery) goto retry_accept; /* * "Resource temporarily unavailable" (EAGAIN or EWOULDBLOCK) * can be silently ignored. And EINTR can be ignored. */ if (errno != EAGAIN && errno != EWOULDBLOCK && errno != EINTR) pool_error("accept() failed. reason: %s", strerror(errno)); return NULL; } #ifdef ACCEPT_PERFORMANCE gettimeofday(&now2,0); atime += (now2.tv_sec - now1.tv_sec)*1000000 + (now2.tv_usec - now1.tv_usec); cnt++; if (cnt % 100 == 0) { pool_log("cnt: %d atime: %ld", cnt, atime); } #endif /* reload config file */ if (got_sighup) { pool_get_config(get_config_file_name(), RELOAD_CONFIG); if (pool_config->enable_pool_hba) { load_hba(get_hba_file_name()); if (strcmp("", pool_config->pool_passwd)) pool_reopen_passwd_file(); } if (pool_config->parallel_mode) pool_memset_system_db_info(system_db_info->info); got_sighup = 0; } connection_count_up(); accepted = 1; if (pool_config->parallel_mode) { /* * do not accept new connection if any of DB node or SystemDB is down when operating in * parallel mode */ int i; for (i=0;i<NUM_BACKENDS;i++) { if (BACKEND_INFO(i).backend_status == CON_DOWN || SYSDB_STATUS == CON_DOWN) { StartupPacket *sp; char *msg = "pgpool is not available in parallel query mode"; if (SYSDB_STATUS == CON_DOWN) pool_log("Cannot accept() new connection. SystemDB is down"); else pool_log("Cannot accept() new connection. %d th backend is down", i); if ((cp = pool_open(afd)) == NULL) { close(afd); child_exit(1); } sp = read_startup_packet(cp); if (sp == NULL) { /* failed to read the startup packet. return to the accept() loop */ pool_close(cp); child_exit(1); } pool_debug("do_accept: send error message to frontend"); if (sp->major == PROTO_MAJOR_V3) { char buf[256]; if (SYSDB_STATUS == CON_DOWN) snprintf(buf, sizeof(buf), "SystemDB is down"); else snprintf(buf, sizeof(buf), "%d th backend is down", i); pool_send_error_message(cp, sp->major, "08S01", msg, buf, ((SYSDB_STATUS == CON_DOWN) ? "repair the SystemDB and restart pgpool" : "repair the backend and restart pgpool"), __FILE__, __LINE__); } else { pool_send_error_message(cp, sp->major, 0, msg, "", "", "", 0); } pool_close(cp); child_exit(1); } } } else { /* * do not accept new connection if all DB nodes are down when operating in * non parallel mode */ int i; int found = 0; for (i=0;i<NUM_BACKENDS;i++) { if (VALID_BACKEND(i)) { found = 1; } } if (found == 0) { pool_log("Cannot accept() new connection. all backends are down"); child_exit(1); } } pool_debug("I am %d accept fd %d", getpid(), afd); pool_getnameinfo_all(&saddr, remote_host, remote_port); snprintf(remote_ps_data, sizeof(remote_ps_data), remote_port[0] == '\0' ? "%s" : "%s(%s)", remote_host, remote_port); set_ps_display("accept connection", false); /* log who is connecting */ if (pool_config->log_connections) { pool_log("connection received: host=%s%s%s", remote_host, remote_port[0] ? " port=" : "", remote_port); } /* set NODELAY and KEEPALIVE options if INET connection */ if (inet) { int on = 1; if (setsockopt(afd, IPPROTO_TCP, TCP_NODELAY, (char *) &on, sizeof(on)) < 0) { pool_error("do_accept: setsockopt() failed: %s", strerror(errno)); close(afd); return NULL; } if (setsockopt(afd, SOL_SOCKET, SO_KEEPALIVE, (char *) &on, sizeof(on)) < 0) { pool_error("do_accept: setsockopt() failed: %s", strerror(errno)); close(afd); return NULL; } } if ((cp = pool_open(afd)) == NULL) { close(afd); return NULL; } /* save ip address for hba */ memcpy(&cp->raddr, &saddr, sizeof(SockAddr)); if (cp->raddr.addr.ss_family == 0) cp->raddr.addr.ss_family = AF_UNIX; return cp; }
static int run_amz_file(clamz_downloader *dl, const clamz_config *cfg, FILE *amzfile, const char *fname) { char *inbuf; unsigned char *xml; size_t sz; clamz_playlist *pl; int i; int status, rv = 0; char *logname; FILE *logfile; sz = 0; inbuf = NULL; while (!feof(amzfile) && !ferror(amzfile)) { if (inbuf) inbuf = realloc(inbuf, (sz + 1024) * sizeof(char)); else inbuf = malloc((sz + 1024) * sizeof(char)); sz += fread(&inbuf[sz], 1, 1024, amzfile); } if (amzfile != stdin) fclose(amzfile); if (cfg->printonly && cfg->printasxml) { xml = decrypt_amz_file(inbuf, sz, fname); if (!xml) { free(inbuf); return 2; } printf("%s", xml); free(xml); free(inbuf); return 0; } else { if (!cfg->printonly) { if (write_backup_file(inbuf, sz, getbasename(fname))) { free(inbuf); return 3; } } pl = new_playlist(); if (read_amz_file(pl, inbuf, sz, fname)) { free(inbuf); free_playlist(pl); return 2; } if (!cfg->printonly) { logname = get_config_file_name("logs", getbasename(fname), ".log"); if (!logname) { free(inbuf); return 1; } logfile = fopen(logname, "w"); if (!logfile) { perror(logname); free(logname); free(inbuf); return 3; } free(logname); set_download_log_file(dl, logfile); } else { logfile = NULL; } if (cfg->printonly || cfg->verbose) print_pl_info(pl, fname); for (i = 0; i < pl->num_tracks; i++) { if (cfg->printonly || cfg->verbose) print_tr_info(pl->tracks[i], i + 1); status = download_track(dl, pl->tracks[i]); if (!rv) rv = status; fputc('\n', stderr); } set_download_log_file(dl, NULL); free(inbuf); free_playlist(pl); if (logfile) fclose(logfile); return rv; } }
int main(int argc, char *argv[]) { try{ // used to catch all unhandled Errors and Assertions // print copyright notice std::cout << "PlanetPenguin Racer " VERSION " -- http://racer.planetpenguin.de\n" << "(c) 2004-2006 PlanetPenguin Racer team\n" << "(c) 1999-2001 Jasmin F. Patry\n" << "<*****@*****.**>\n" << "PlanetPenguin Racer comes with ABSOLUTELY NO WARRANTY.\n" << "This is free software,\nand you are welcome to redistribute it under certain conditions.\n" << "See http://www.gnu.org/copyleft/gpl.html for details.\n" << std::endl; // initialize performance test if activated ppogl::initPerftest(); // set current directory to be used as base ppogl::os::setBaseDir(); // set user directory to "~/.ppracer/" ppogl::os::setUserDir(ppogl::os::getHomeDir()+".ppracer/"); // parse comandline options getopts(argc,argv); // set logging to be verbose if possible if(verbose){ init_log(); ppogl::Log::Instance()->setLevel(ppogl::LogUnknown); if(verbose>1){ // set log system to print long messages ppogl::Log::Instance()->setVerbose(true); init_log(); } } // seed the random number generator srand( time(NULL) ); if(GameMode::exp_multiscreen==GameMode::MULTISCREEN_NONE){ GameMgr::getInstance().numPlayers = 1; }else{ GameMgr::getInstance().numPlayers = 2; } ppogl::Config::getInstance().init(&script,"ppconfig"); register_cfile_callbacks(); bool create_cfile=true; if(cfile.empty()){ cfile=get_config_file_name(); } if( !resetConfig && ppogl::os::isFile(cfile) ){ script.doFile(cfile); // check whether the user set the data directory per commandline option if(data_dir.empty()){ data_dir = PPConfig.getString("data_dir"); } PP_MESSAGE("Load config file"); create_cfile=false; }else if(data_dir.empty()){ data_dir = DATA_DIR; } if(ppogl::os::isDirectory(data_dir)==false){ PP_ERROR("Unable to find data dir: " << data_dir <<"\n\tUse \"ppracer -d YOUR_DATA_DIRECTORY\""); } if(ppogl::os::isFile(data_dir+"/config.nut")==false){ PP_ERROR("Unable to find needed file config.nut in the data dir: " << data_dir <<"\n\tUse \"ppracer -d YOUR_DATA_DIRECTORY\""); } script.doFile(data_dir+"/config.nut"); PPConfig.setString("data_dir",data_dir); if(create_cfile){ write_config_file(); } /* * Initialize rendering context, create window */ winsys_init(WINDOW_TITLE, WINDOW_TITLE); /* * Initial OpenGL settings */ gl::BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // init compiled_vertex extension gl::EXTcompiledVertexArrayInit(); // print OpenGL debugging information if(verbose) print_gl_info(); /* * Load the game data and initialize game state */ register_key_frame_callbacks(); Course::registerCallbacks(); FogPlane::registerCallbacks(); register_course_light_callbacks(); PartSys::registerCallbacks(); register_course_manager_callbacks(); register_hier_callbacks(); register_tux_callbacks(); // init audio PP_MESSAGE("Init audio"); if(PPConfig.getBool("disable_audio")==false){ bool stereo = PPConfig.getBool("audio_stereo"); ppogl::AudioMgr::Format format; int freq; switch(PPConfig.getInt("audio_format_mode")){ case 0: format = ppogl::AudioMgr::FORMAT_8; break; case 1: format = ppogl::AudioMgr::FORMAT_16; break; default: format = ppogl::AudioMgr::FORMAT_8; } switch(PPConfig.getInt("audio_freq_mode")){ case 0: freq = ppogl::AudioMgr::FQ_11; break; case 1: freq = ppogl::AudioMgr::FQ_22; break; case 2: freq = ppogl::AudioMgr::FQ_44; break; default: freq = ppogl::AudioMgr::FQ_11; } ppogl::AudioMgr::getInstance().init(freq,format,stereo); if(PPConfig.getBool("sound_enabled")==false){ ppogl::AudioMgr::getInstance().enableSound(false); } if(PPConfig.getBool("music_enabled")==false){ ppogl::AudioMgr::getInstance().enableMusic(false); } // set volumes ppogl::AudioMgr::getInstance().setMusicVolume( PPConfig.getInt("music_volume")); ppogl::AudioMgr::getInstance().setSoundVolume( PPConfig.getInt("sound_volume")); } PP_MESSAGE("Load translation: " << PPConfig.getString("ui_language")); // Setup translations script.doFile(data_dir+"/translations/languages.nut"); script.doFile(data_dir+"/translations/"+PPConfig.getString("ui_language")+".nut"); script.doFile(data_dir+"/init.nut"); // load "cached" configuration values GameConfig::update(); fpsCounter.setMaxFPS(PPConfig.getInt("gui_max_fps")); PP_MESSAGE("Init joystick"); GameMode::joystick.init(); init_ui_snow(); for(int i=0; i<GameMgr::getInstance().numPlayers; i++){ // Placeholder name until we give players way to enter name players[i].name = "tux"; players[i].loadData(); players[i].num = i; } GameMode::mode = GameMode::NO_MODE; if(Benchmark::getMode()==Benchmark::NONE){ GameMode::setMode(GameMode::SPLASH); }else{ GameMode::setMode(GameMode::BENCHMARK); } GameMgr::getInstance().difficulty = CourseData::DIFFICULTY_NORMAL; SDL_ShowCursor(false); PP_MESSAGE("Entering event loop"); winsys_process_events(); return 0; }catch(ppogl::Error &e){ /* * It's possible that an exception is thrown outside of main. * In most cases this is a problem with the object * destruction during program termination. * If we see the abort message (see below) we known * that the exception is thrown within main(). */ std::cerr << "Aborting main function :(" << std::endl; abort(); } }
void config_handler::init() { // const std::string MyClass::valid = "something else again"; const string DEF_CONFIG_NAME = "cirainbow.conf"; const string DEF_FILTER_NAME = "featureplan_filter"; const string DEF_FEATURE_NAME = "featureplan"; const string DEF_REC_PREFIX = "rec_"; const string DEF_REC_EXT = ".wav"; const string DEF_FINAL_FORMAT = "WRAPPED"; const string DEF_LAT = "0.0000 N"; const string DEF_LON = "0.0000 W"; const string DEF_RPID = "-1"; const int DEF_SOUND_ID = 0; // TODO - What should this be by default? const string DEF_DATA_DIR = "data/"; const string DEF_ANALYSIS_DIR = "analysis/"; const string DEF_MEDIA_DIR = "media/"; cn = " config_handler::"; set_config_file_path ( utils::get_home_dir() ); set_config_file_name ( DEF_CONFIG_NAME ); // TODO - make hardcoded elsewhere set_config_file ( get_config_file_path() + get_config_file_name() ); set_fv_filter_path ( utils::get_base_dir() ); set_fv_filter_name ( DEF_FILTER_NAME ); set_fv_filter ( get_fv_filter_path() + get_fv_filter_name() ); set_fv_file_path ( utils::get_base_dir() ); set_fv_file_name ( DEF_FEATURE_NAME ); set_fv_file ( get_fv_file_path() + get_fv_file_name() ); // set_data_location ( utils::get_base_dir() + DEF_DATA_DIR ); //TODO - make hardcoded elsewhere // set_analysis_location ( utils::get_base_dir() + DEF_ANALYSIS_DIR ); // TODO - make hardcoded elsewhere set_data_location ( utils::get_home_dir() + DEF_DATA_DIR ); set_analysis_location ( utils::get_base_dir() + DEF_ANALYSIS_DIR ); set_rec_file_name_prefix( DEF_REC_PREFIX ); // TODO - make hardcoded elsewhere set_media_location ( get_data_location() + DEF_MEDIA_DIR ); // TODO - make hardcoded elsewhere set_rec_extention ( DEF_REC_EXT ); // TODO - make hardcoded elsewhere set_samp_rate ( -1 ); set_rec_number ( -1 ); set_rec_duration ( -1 ); set_latitude( DEF_LAT ); // TODO - make hardcoded elsewhere set_longitude( DEF_LON ); // TODO - make hardcoded elsewhere set_rpid( DEF_RPID ); set_final_feature_format( DEF_FINAL_FORMAT ); //Foramts: WRAPPED, FILES set_output_type_id( DEF_SOUND_ID ); //Numeric represetning the type of data this is. TODO - WHAT SHOULD THIS BE? set_simulate( false ); //simulate a run (dont actually do one). set_simulate_dir( "" ); //default sim data dir set_background( false ); //run in forground by default set_filter( false ); //filtering is ONLY done if requested set_analysis( false ); //feature extraction only done if user wants it set_save_rec( true ); //Always save recordings by default set_output_formatted( true ); //It makes sense to always format output return; }
int Snes9xConfig::save_config_file (void) { xmlTextWriterPtr xml; char *filename; char buffer[256]; filename = get_config_file_name (); xml = xmlNewTextWriterFilename (filename, 0); free (filename); xmlTextWriterSetIndent (xml, 1); xmlTextWriterStartDocument (xml, NULL, NULL, NULL); xmlTextWriterStartElement (xml, BAD_CAST "snes9x"); xmlTextWriterStartElement (xml, BAD_CAST "preferences"); xml_out_int (xml, "full_screen_on_open", full_screen_on_open); xml_out_int (xml, "change_display_resolution", change_display_resolution); xml_out_int (xml, "video_mode", xrr_index); xml_out_int (xml, "video_mode_width", xrr_width); xml_out_int (xml, "video_mode_height", xrr_height); xml_out_int (xml, "scale_to_fit", scale_to_fit); xml_out_int (xml, "maintain_aspect_ratio", maintain_aspect_ratio); xml_out_int (xml, "aspect_ratio", aspect_ratio); xml_out_int (xml, "scale_method", scale_method); xml_out_int (xml, "overscan", overscan); xml_out_int (xml, "hires_effect", hires_effect); xml_out_int (xml, "force_inverted_byte_order", force_inverted_byte_order); xml_out_int (xml, "multithreading", multithreading); xml_out_string (xml, "last_directory", last_directory); xml_out_string (xml, "sram_directory", sram_directory); xml_out_string (xml, "savestate_directory", savestate_directory); xml_out_string (xml, "cheat_directory", cheat_directory); xml_out_string (xml, "patch_directory", patch_directory); xml_out_string (xml, "export_directory", export_directory); xml_out_int (xml, "window_width", window_width); xml_out_int (xml, "window_height", window_height); xml_out_int (xml, "preferences_width", preferences_width); xml_out_int (xml, "preferences_height", preferences_height); xml_out_int (xml, "pause_emulation_on_switch", pause_emulation_on_switch); xml_out_int (xml, "num_threads", num_threads); xml_out_int (xml, "default_esc_behavior", default_esc_behavior); xml_out_int (xml, "prevent_screensaver", prevent_screensaver); if (default_esc_behavior != ESC_TOGGLE_MENUBAR) xml_out_int (xml, "fullscreen", 0); else xml_out_int (xml, "fullscreen", fullscreen); xml_out_int (xml, "ui_visible", ui_visible); xml_out_int (xml, "statusbar_visible", statusbar_visible); xml_out_int (xml, "modal_dialogs", modal_dialogs); xml_out_float (xml, "ntsc_hue", ntsc_setup.hue); xml_out_float (xml, "ntsc_saturation", ntsc_setup.saturation); xml_out_float (xml, "ntsc_contrast", ntsc_setup.contrast); xml_out_float (xml, "ntsc_brightness", ntsc_setup.brightness); xml_out_float (xml, "ntsc_sharpness", ntsc_setup.sharpness); xml_out_float (xml, "ntsc_artifacts", ntsc_setup.artifacts); xml_out_float (xml, "ntsc_gamma", ntsc_setup.gamma); xml_out_float (xml, "ntsc_bleed", ntsc_setup.bleed); xml_out_float (xml, "ntsc_fringing", ntsc_setup.fringing); xml_out_float (xml, "ntsc_resolution", ntsc_setup.resolution); xml_out_int (xml, "ntsc_merge_fields", ntsc_setup.merge_fields); xml_out_int (xml, "ntsc_scanline_intensity", ntsc_scanline_intensity); xml_out_int (xml, "scanline_filter_intensity", scanline_filter_intensity); xml_out_int (xml, "hw_accel", hw_accel); xml_out_int (xml, "bilinear_filter", bilinear_filter); #ifdef USE_OPENGL xml_out_int (xml, "sync_to_vblank", sync_to_vblank); xml_out_int (xml, "sync_every_frame", sync_every_frame); xml_out_int (xml, "use_pbos", use_pbos); xml_out_int (xml, "pbo_format", pbo_format); xml_out_int (xml, "npot_textures", npot_textures); xml_out_int (xml, "use_shaders", use_shaders); xml_out_string (xml, "fragment_shader", fragment_shader); #endif #ifdef USE_JOYSTICK xml_out_int (xml, "joystick_threshold", joystick_threshold); #endif xml_out_int (xml, "netplay_is_server", netplay_is_server); xml_out_int (xml, "netplay_sync_reset", netplay_sync_reset); xml_out_int (xml, "netplay_send_rom", netplay_send_rom); xml_out_int (xml, "netplay_default_port", netplay_default_port); xml_out_int (xml, "netplay_max_frame_loss", netplay_max_frame_loss); xml_out_int (xml, "netplay_last_port", netplay_last_port); xml_out_string (xml, "netplay_last_rom", netplay_last_rom); xml_out_string (xml, "netplay_last_host", netplay_last_host); xml_out_int (xml, "mute_sound", mute_sound); xml_out_int (xml, "sound_buffer_size", sound_buffer_size); xml_out_int (xml, "sound_driver", sound_driver); xml_out_int (xml, "sound_input_rate", sound_input_rate); xml_out_int (xml, "sound_sync", Settings.SoundSync); /* Snes9X core-stored variables */ xml_out_int (xml, "transparency", Settings.Transparency); xml_out_int (xml, "show_frame_rate", Settings.DisplayFrameRate); xml_out_int (xml, "frameskip", Settings.SkipFrames); xml_out_int (xml, "save_sram_after_secs", Settings.AutoSaveDelay); xml_out_int (xml, "16bit_sound", Settings.SixteenBitSound); xml_out_int (xml, "stereo", Settings.Stereo); xml_out_int (xml, "reverse_stereo", Settings.ReverseStereo); xml_out_int (xml, "playback_rate", gui_config->sound_playback_rate); xml_out_int (xml, "block_invalid_vram_access", Settings.BlockInvalidVRAMAccessMaster); xml_out_int (xml, "upanddown", Settings.UpAndDown); xmlTextWriterEndElement (xml); /* preferences */ xmlTextWriterStartElement (xml, BAD_CAST "controls"); #ifdef USE_JOYSTICK for (int i = 0; joystick[i]; i++) { xmlTextWriterStartElement (xml, BAD_CAST "calibration"); snprintf (buffer, 256, "%d", i); xmlTextWriterWriteAttribute (xml, BAD_CAST "joystick", BAD_CAST buffer); for (int j = 0; j < joystick[i]->num_axes; j++) { xmlTextWriterStartElement (xml, BAD_CAST "axis"); snprintf (buffer, 256, "%d", j); xmlTextWriterWriteAttribute (xml, BAD_CAST "number", BAD_CAST buffer); snprintf (buffer, 256, "%d", joystick[i]->calibration[j].min); xmlTextWriterWriteAttribute (xml, BAD_CAST "min", BAD_CAST buffer); snprintf (buffer, 256, "%d", joystick[i]->calibration[j].max); xmlTextWriterWriteAttribute (xml, BAD_CAST "max", BAD_CAST buffer); snprintf (buffer, 256, "%d", joystick[i]->calibration[j].center); xmlTextWriterWriteAttribute (xml, BAD_CAST "center", BAD_CAST buffer); xmlTextWriterEndElement (xml); /* axis */ } xmlTextWriterEndElement (xml); /* Calibration */ } #endif for (int i = 0; i < NUM_JOYPADS; i++) { Binding *joypad = (Binding *) &pad[i]; xmlTextWriterStartElement (xml, BAD_CAST "joypad"); snprintf (buffer, 256, "%d", i); xmlTextWriterWriteAttribute (xml, BAD_CAST "number", BAD_CAST buffer); for (int j = 0; j < NUM_JOYPAD_LINKS; j++) { xml_out_binding (xml, b_links[j].snes9x_name, joypad[j].hex ()); } xmlTextWriterEndElement (xml); /* joypad */ } for (int i = NUM_JOYPAD_LINKS; b_links[i].snes9x_name; i++) { xml_out_binding (xml, b_links[i].snes9x_name, shortcut[i - NUM_JOYPAD_LINKS].hex ()); } xmlTextWriterEndElement (xml); /* controls */ xmlTextWriterEndElement (xml); /* snes9x */ xmlTextWriterEndDocument (xml); xmlFreeTextWriter (xml); return 0; }
static int read_user_config(clamz_config *cfg) { static const char default_config[] = "## Clamz configuration file\n" "\n" "## Default format for output filenames. This may contain any of\n" "## the following variables:\n" "##\n" "## ${title} ${creator} ${album} ${tracknum} ${album_artist}\n" "## ${genre} ${discnum} ${suffix} ${asin} ${album_asin}\n" "##\n" "## The name format may also contain slashes, if you'd like to\n" "## categorize your files in subdirectories.\n" "NameFormat \"${tracknum} - ${title}.${suffix}\"\n" "\n" "## The base directory in which to store downloaded music.\n" "## If unset, it defaults to the current directory.\n" "# OutputDir \"/home/me/Music\"\n" "\n" "## Set to True to allow uppercase in filenames.\n" "## False to convert to lowercase.\n" "AllowUppercase True\n" "\n" "## Set to True to output UTF-8 filenames, False to output ASCII only,\n" "## UseLocale to check the system locale setting.\n" "AllowUTF8 UseLocale\n" "\n" "## The set of ASCII characters which are disallowed. (Control\n" "## characters and slashes are always disallowed.)\n" "ForbidChars \"!\\\"$*:;<>?\\\\`|~\"\n" "\n"; char *cfgname; FILE *cfgfile; char buf[1024]; int linenum = 0; char *p; cfgname = get_config_file_name(NULL, "config", NULL); if (!cfgname) return 1; cfgfile = fopen(cfgname, "r"); if (!cfgfile) { cfgfile = fopen(cfgname, "w+"); if (!cfgfile) { print_error("Unable to open configuration file '%s'", cfgname); free(cfgname); return 1; } fputs(default_config, cfgfile); fseek(cfgfile, 0L, SEEK_SET); } while (fgets(buf, sizeof(buf), cfgfile)) { linenum++; if ((p = strchr(buf, '#'))) *p = 0; p = buf; while (*p == ' ' || *p == '\t' || *p == '\n') p++; if (!*p) continue; if ((p = checkcmd(buf, "NameFormat"))) { if (cfg->name_format) free(cfg->name_format); cfg->name_format = strdup(p); if (!cfg->name_format) { print_error("Out of memory"); return 1; } } else if ((p = checkcmd(buf, "OutputDir"))) { if (cfg->output_dir) free(cfg->output_dir); cfg->output_dir = strdup(p); if (!cfg->output_dir) { print_error("Out of memory"); return 1; } } else if ((p = checkcmd(buf, "ForbidChars"))) { if (cfg->forbid_chars) free(cfg->forbid_chars); cfg->forbid_chars = NULL; if (add_forbidden_chars(cfg, p)) return 1; } else if ((p = checkcmd(buf, "AllowUppercase"))) { if (*p == 't' || *p == 'T') cfg->allowupper = 1; else cfg->allowupper = 0; } else if ((p = checkcmd(buf, "AllowUTF8"))) { if (*p == 't' || *p == 'T') cfg->allowutf8 = 1; else if (*p == 'f' || *p == 'F') cfg->allowutf8 = 0; else cfg->allowutf8 = cfg->utf8locale; } } fclose(cfgfile); free(cfgname); return 0; }