/* * Init gtm master ----------------------------------------------------------------- */ static cmd_t * prepare_initGtmMaster(void) { cmd_t *cmdInitGtmMaster, *cmdGtmConf, *cmdGxid; char date[MAXTOKEN+1]; FILE *f; char **fileList = NULL; /* Kill current gtm, bild work directory and run initgtm */ cmdInitGtmMaster = initCmd(sval(VAR_gtmMasterServer)); snprintf(newCommand(cmdInitGtmMaster), MAXLINE, "killall -u %s -9 gtm; rm -rf %s; mkdir -p %s;initgtm -Z gtm -D %s", sval(VAR_pgxcUser), sval(VAR_gtmMasterDir), sval(VAR_gtmMasterDir), sval(VAR_gtmMasterDir)); /* Then prepare gtm.conf file */ /* Prepare local Stdin */ appendCmdEl(cmdInitGtmMaster, (cmdGtmConf = initCmd(sval(VAR_gtmMasterServer)))); if ((f = prepareLocalStdin(newFilename(cmdGtmConf->localStdin), MAXPATH, NULL)) == NULL) { cleanCmd(cmdInitGtmMaster); return(NULL); } fprintf(f, "#===============================================\n" "# Added at initialization, %s\n" "listen_addresses = '*'\n", timeStampString(date, MAXTOKEN)); if (!is_none(sval(VAR_gtmExtraConfig))) AddMember(fileList, sval(VAR_gtmExtraConfig)); if (!is_none(sval(VAR_gtmMasterSpecificExtraConfig))) AddMember(fileList, sval(VAR_gtmMasterSpecificExtraConfig)); appendFiles(f, fileList); CleanArray(fileList); fprintf(f, "port = %s\n" "nodename = '%s'\n" "startup = ACT\n" "# End of addition\n", sval(VAR_gtmMasterPort), sval(VAR_gtmName)); fclose(f); /* other options */ snprintf(newCommand(cmdGtmConf), MAXLINE, "cat >> %s/gtm.conf", sval(VAR_gtmMasterDir)); /* Setup GTM with appropriate GXID value */ appendCmdEl(cmdGtmConf, (cmdGxid = initCmd(sval(VAR_gtmMasterServer)))); snprintf(newCommand(cmdGxid), MAXLINE, "(gtm -x 2000 -D %s &); sleep 1; gtm_ctl stop -Z gtm -D %s", sval(VAR_gtmMasterDir), sval(VAR_gtmMasterDir)); return cmdInitGtmMaster; }
/* * Assumes Gtm Slave is configured. * Caller should check this. */ static cmd_t * prepare_initGtmSlave(void) { char date[MAXTOKEN+1]; cmd_t *cmdInitGtm, *cmdGtmConf; FILE *f; char **fileList = NULL; if (!isVarYes(VAR_gtmSlave) || (sval(VAR_gtmSlaveServer) == NULL) || is_none(sval(VAR_gtmSlaveServer))) { elog(ERROR, "ERROR: GTM slave is not configured.\n"); return(NULL); } /* Kill current gtm, build work directory and run initgtm */ cmdInitGtm = initCmd(sval(VAR_gtmSlaveServer)); snprintf(newCommand(cmdInitGtm), MAXLINE, "killall -u %s -9 gtm; rm -rf %s; mkdir -p %s; initgtm -Z gtm -D %s", sval(VAR_pgxcUser), sval(VAR_gtmSlaveDir), sval(VAR_gtmSlaveDir), sval(VAR_gtmSlaveDir)); /* Prepare gtm.conf file */ /* Prepare local Stdin */ appendCmdEl(cmdInitGtm, (cmdGtmConf = initCmd(sval(VAR_gtmSlaveServer)))); snprintf(newCommand(cmdGtmConf), MAXLINE, "cat >> %s/gtm.conf", sval(VAR_gtmSlaveDir)); if ((f = prepareLocalStdin(newFilename(cmdGtmConf->localStdin), MAXPATH, NULL)) == NULL) { cleanCmd(cmdInitGtm); return(NULL); } fprintf(f, "#===============================================\n" "# Added at initialization, %s\n" "listen_addresses = '*'\n", timeStampString(date, MAXPATH+1)); if (!is_none(sval(VAR_gtmExtraConfig))) AddMember(fileList, sval(VAR_gtmExtraConfig)); if (!is_none(sval(VAR_gtmMasterSpecificExtraConfig))) AddMember(fileList, sval(VAR_gtmMasterSpecificExtraConfig)); appendFiles(f, fileList); CleanArray(fileList); fprintf(f, "port = %s\n" "nodename = '%s'\n" "startup = STANDBY\n" "active_host = '%s'\n" "active_port = %d\n" "# End of addition\n", sval(VAR_gtmSlavePort), sval(VAR_gtmName), sval(VAR_gtmMasterServer), atoi(sval(VAR_gtmMasterPort))); fclose(f); return (cmdInitGtm); }
/* * Reconnect to the current GTM master -------------------------------------------------- * * When failed over, the current Master must have been updated. * Remember to update gtm_proxy configuration file so that it * connects to the new master at the next start. * Please note that we assume GTM has already been failed over. * First argument is gtm_proxy nodename */ static cmd_t * prepare_reconnectGtmProxy(char *nodeName) { cmd_t *cmdGtmCtl, *cmdGtmProxyConf; int idx; FILE *f; char date[MAXTOKEN+1]; if ((idx = gtmProxyIdx(nodeName)) < 0) { elog(ERROR, "ERROR: Specified name %s is not GTM Proxy\n", nodeName); return(NULL); } /* gtm_ctl reconnect */ cmdGtmCtl = initCmd(aval(VAR_gtmProxyServers)[idx]); snprintf(newCommand(cmdGtmCtl), MAXLINE, "gtm_ctl reconnect -Z gtm_proxy -D %s -o \\\"-s %s -t %s\\\"", aval(VAR_gtmProxyDirs)[idx], sval(VAR_gtmMasterServer), sval(VAR_gtmMasterPort)); /* gtm_proxy.conf */ appendCmdEl(cmdGtmCtl, (cmdGtmProxyConf = initCmd(aval(VAR_gtmProxyServers)[idx]))); if ((f = prepareLocalStdin(newFilename(cmdGtmProxyConf->localStdin), MAXPATH, NULL)) == NULL) { cleanCmd(cmdGtmCtl); return(NULL); } fprintf(f, "#===================================================\n" "# Updated due to GTM Proxy reconnect\n" "# %s\n" "gtm_host = '%s'\n" "gtm_port = %s\n" "#----End of reconfiguration -------------------------\n", timeStampString(date, MAXTOKEN), sval(VAR_gtmMasterServer), sval(VAR_gtmMasterPort)); fclose(f); snprintf(newCommand(cmdGtmProxyConf), MAXLINE, "cat >> %s/gtm_proxy.conf", aval(VAR_gtmProxyDirs)[idx]); return(cmdGtmCtl); }
void MainMenu::loadGameSaveButtonClicked(Button *) { getSound()->playSound( "Click" ); if( file_exists( const_cast<char*>(mFilename.c_str()) ) ){ std::cout << "remove( " << mFilename << ")\n"; remove( mFilename.c_str() ); } /* Build filename */ std::stringstream newStart; newStart << slotNr << "_Y"; newStart << std::setfill('0') << std::setw(5); fprintf(stderr,"total_time %i\n",total_time); newStart << total_time/1200; newStart << "_Tech"; newStart << std::setfill('0') << std::setw(3); newStart << tech_level/10000; newStart << "_Cash"; if (total_money >= 0) { newStart << "+";} else { newStart << "-";} newStart << std::setfill('0') << std::setw(3); int money = abs(total_money); if (money > 1000000000) { newStart << money/1000000000 << "G";} else if (money > 1000000) { newStart << money/1000000 << "M";} else if(money > 1000) { newStart << money/1000 << "K";} else { newStart << money << "_";} newStart << "_P"; newStart << std::setfill('0') << std::setw(5); newStart << housed_population + people_pool; std::string newFilename( newStart.str() ); saveCityNG( newFilename ); fillLoadMenu( true ); }
void GameCubeConfigPane::ChooseSlotPath(bool is_slot_a, TEXIDevices device_type) { bool memcard = (device_type == EXIDEVICE_MEMORYCARD); std::string path; std::string cardname; std::string ext; std::string pathA = SConfig::GetInstance().m_strMemoryCardA; std::string pathB = SConfig::GetInstance().m_strMemoryCardB; if (!memcard) { pathA = SConfig::GetInstance().m_strGbaCartA; pathB = SConfig::GetInstance().m_strGbaCartB; } SplitPath(is_slot_a ? pathA : pathB, &path, &cardname, &ext); std::string filename = WxStrToStr(wxFileSelector( _("Choose a file to open"), StrToWxStr(path), StrToWxStr(cardname), StrToWxStr(ext), memcard ? _("GameCube Memory Cards (*.raw,*.gcp)") + "|*.raw;*.gcp" : _("Game Boy Advance Carts (*.gba)") + "|*.gba")); if (!filename.empty()) { if (File::Exists(filename)) { if (memcard) { GCMemcard memorycard(filename); if (!memorycard.IsValid()) { WxUtils::ShowErrorDialog(wxString::Format(_("Cannot use that file as a memory card.\n%s\n" "is not a valid GameCube memory card file"), filename.c_str())); return; } } } wxFileName newFilename(filename); newFilename.MakeAbsolute(); filename = newFilename.GetFullPath(); #ifdef _WIN32 // If the Memory Card file is within the Exe dir, we can assume that the user wants it to be // stored relative // to the executable, so it stays set correctly when the probably portable Exe dir is moved. // TODO: Replace this with a cleaner, non-wx solution once std::filesystem is standard std::string exeDir = File::GetExeDirectory() + '\\'; if (wxString(filename).Lower().StartsWith(wxString(exeDir).Lower())) filename.erase(0, exeDir.size()); std::replace(filename.begin(), filename.end(), '\\', '/'); #endif // also check that the path isn't used for the other memcard... wxFileName otherFilename(is_slot_a ? pathB : pathA); otherFilename.MakeAbsolute(); if (newFilename.GetFullPath().compare(otherFilename.GetFullPath()) != 0) { if (memcard) { if (is_slot_a) SConfig::GetInstance().m_strMemoryCardA = filename; else SConfig::GetInstance().m_strMemoryCardB = filename; } else { if (is_slot_a) SConfig::GetInstance().m_strGbaCartA = filename; else SConfig::GetInstance().m_strGbaCartB = filename; } if (Core::IsRunning()) { // Change memcard to the new file ExpansionInterface::ChangeDevice(is_slot_a ? 0 : 1, // SlotA: channel 0, SlotB channel 1 device_type, 0); // SP1 is device 2, slots are device 0 } } else { WxUtils::ShowErrorDialog(_("Are you trying to use the same file in both slots?")); } } }
/* * Does not check if node name is valid. */ static cmd_t * prepare_initGtmProxy(char *nodeName) { cmd_t *cmdInitGtm, *cmdGtmProxyConf; int idx; FILE *f; char timestamp[MAXTOKEN+1]; char **fileList = NULL; if ((idx = gtmProxyIdx(nodeName)) < 0) { elog(ERROR, "ERROR: Specified name %s is not GTM Proxy configuration.\n", nodeName); return NULL; } /* Build directory and run initgtm */ cmdInitGtm = initCmd(aval(VAR_gtmProxyServers)[idx]); snprintf(newCommand(cmdInitGtm), MAXLINE, "killall -u %s -9 gtm_proxy;" "rm -rf %s;" "mkdir -p %s;" "initgtm -Z gtm_proxy -D %s", sval(VAR_pgxcUser), aval(VAR_gtmProxyDirs)[idx], aval(VAR_gtmProxyDirs)[idx], aval(VAR_gtmProxyDirs)[idx]); /* Configure gtm_proxy.conf */ appendCmdEl(cmdInitGtm, (cmdGtmProxyConf = initCmd(aval(VAR_gtmProxyServers)[idx]))); if ((f = prepareLocalStdin(newFilename(cmdGtmProxyConf->localStdin), MAXPATH, NULL)) == NULL) { cleanCmd(cmdInitGtm); return NULL; } fprintf(f, "#===========================\n" "# Added at initialization, %s\n" "listen_addresses = '*'\n" "worker_threads = 1\n" "gtm_connect_retry_interval = 1\n", timeStampString(timestamp, MAXTOKEN));; if (!is_none(sval(VAR_gtmPxyExtraConfig))) AddMember(fileList, sval(VAR_gtmPxyExtraConfig)); if (!is_none(aval(VAR_gtmPxySpecificExtraConfig)[idx])) AddMember(fileList, aval(VAR_gtmPxySpecificExtraConfig)[idx]); appendFiles(f, fileList); CleanArray(fileList); fprintf(f, "nodename = '%s'\n" "port = %s\n" "gtm_host = '%s'\n" "gtm_port = %s\n" "# End of addition\n", aval(VAR_gtmProxyNames)[idx], aval(VAR_gtmProxyPorts)[idx], sval(VAR_gtmMasterServer), sval(VAR_gtmMasterPort)); fclose(f); snprintf(newCommand(cmdGtmProxyConf), MAXLINE, "cat >> %s/gtm_proxy.conf", aval(VAR_gtmProxyDirs)[idx]); return(cmdInitGtm); }
/* * Failover the gtm ------------------------------------------------------ */ int failover_gtm(void) { char date[MAXTOKEN+1]; char *stdIn; int rc; FILE *f; elog(INFO, "Failover gtm\n"); if (!isVarYes(VAR_gtmSlave) || (sval(VAR_gtmSlaveServer) == NULL) || is_none(sval(VAR_gtmSlaveServer))) { elog(ERROR, "ERROR: GTM slave is not configured. Cannot failover.\n"); return(1); } if (do_gtm_ping(sval(VAR_gtmSlaveServer), atoi(sval(VAR_gtmSlavePort))) != 0) { elog(ERROR, "ERROR: GTM slave is not running\n"); return(1); } /* Promote the slave */ elog(NOTICE, "Running \"gtm_ctl promote -Z gtm -D %s\"\n", sval(VAR_gtmSlaveDir)); rc = doImmediate(sval(VAR_gtmSlaveServer), NULL, "gtm_ctl promote -Z gtm -D %s", sval(VAR_gtmSlaveDir)); if (WEXITSTATUS(rc) != 0) { elog(ERROR, "ERROR: could not promote gtm (host:%s, dir:%s)\n", sval(VAR_gtmSlaveServer), sval(VAR_gtmSlaveDir)); return 1; } /* Configure promoted gtm */ if ((f = prepareLocalStdin(newFilename(stdIn), MAXPATH, NULL)) == NULL) return(1); fprintf(f, "#===================================================\n" "# Updated due to GTM failover\n" "# %s\n" "startup = ACT\n" "#----End of reconfiguration -------------------------\n", timeStampString(date, MAXTOKEN+1)); fclose(f); elog(NOTICE, "Updating gtm.conf at %s:%s\n", sval(VAR_gtmSlaveServer), sval(VAR_gtmSlaveDir)); rc = doImmediate(sval(VAR_gtmSlaveServer), stdIn, "cat >> %s/gtm.conf", sval(VAR_gtmSlaveDir)); if (WEXITSTATUS(rc) != 0) { elog(ERROR, "ERROR: could not update gtm.conf (host: %s, dir:%s)\n", sval(VAR_gtmSlaveServer), sval(VAR_gtmSlaveDir)); return 1; } /* Update and backup configuration file */ if ((f = prepareLocalStdin(stdIn, MAXPATH, NULL)) == NULL) return(1); fprintf(f, "#===================================================\n" "# pgxc configuration file updated due to GTM failover\n" "# %s\n" "gtmMasterServer=%s\n" "gtmMasterPort=%s\n" "gtmMasterDir=%s\n" "gtmSlave=n\n" "gtmSlaveServer=none\n" "gtmSlavePort=0\n" "gtmSlaveDir=none\n" "#----End of reconfiguration -------------------------\n", timeStampString(date, MAXTOKEN+1), sval(VAR_gtmSlaveServer), sval(VAR_gtmSlavePort), sval(VAR_gtmSlaveDir)); fclose(f); rc = doImmediate(NULL, stdIn, "cat >> %s", pgxc_ctl_config_path); if (WEXITSTATUS(rc) != 0) { elog(ERROR, "ERROR: could not update gtm.conf (host: %s, dir:%s)\n", sval(VAR_gtmSlaveServer), sval(VAR_gtmSlaveDir)); return 1; } freeAndReset(stdIn); backup_configuration(); /* Reconfigure myself */ assign_val(VAR_gtmMasterServer, VAR_gtmSlaveServer); reset_var(VAR_gtmSlaveServer); assign_val(VAR_gtmMasterPort, VAR_gtmSlavePort); reset_var(VAR_gtmSlavePort); assign_val(VAR_gtmMasterDir, VAR_gtmSlaveDir); reset_var(VAR_gtmSlaveDir); assign_sval(VAR_gtmSlaveServer, "none"); assign_sval(VAR_gtmSlavePort, "0"); assign_sval(VAR_gtmSlaveDir, "none"); assign_sval(VAR_gtmSlave, "n"); return 0; }