wxFileName GetPlatformDefaultConfigFilePath(const wxString& tcPath) { wxFileName path; if (FlagListManager::GetFlagListManager()->GetBuildCaps() & FlagListManager::BUILD_CAPS_SDL) { path = GetPlatformDefaultConfigFilePathNew(); } else { #if IS_LINUX || IS_APPLE // write to folder in home dir path = GetPlatformDefaultConfigFilePathOld().GetFullPath().c_str(); #else path.AssignDir(tcPath); #endif } return path; }
bool SynchronizeOldPilots(ProMan* profileManager) { if (!(FlagListManager::GetFlagListManager()->GetBuildCaps() & FlagListManager::BUILD_CAPS_SDL)) { // Nothing to do, we have an old build return true; } wxLogStatus(_T("Synchronizing old pilot files...")); wxFileName oldConfigFolder; #if IS_WIN32 wxString rootPath; if (!profileManager->ProfileRead(PRO_CFG_TC_ROOT_FOLDER, &rootPath)) { wxLogWarning(_T("No TC root folder in configuration!")); return false; } oldConfigFolder.AssignDir(rootPath, wxPATH_NATIVE); #else oldConfigFolder.Assign(GetPlatformDefaultConfigFilePathOld()); #endif oldConfigFolder.AppendDir(_T("data")); oldConfigFolder.AppendDir(_T("players")); wxFileName newConfigFolder(GetPlatformDefaultConfigFilePathNew()); newConfigFolder.AppendDir(_T("data")); newConfigFolder.AppendDir(_T("players")); if (!oldConfigFolder.DirExists()) { // No old config folder so there are no pilot files to copy wxLogStatus(_T(" Old pilot directory does not exist, nothing to be done.")); return true; } // Heuristic to determine if the files were copied before if (newConfigFolder.DirExists()) { // new players directory already exists so it was already used before // Don't try to copy in this case wxLogStatus(_T(" New pilot directory already exists, was probably copied before.")); return true; } if (!newConfigFolder.Mkdir(0777, wxPATH_MKDIR_FULL)) { wxLogError(_T("Failed to create directory '%s'"), newConfigFolder.GetFullPath().c_str()); return false; } // If we are here we need to copy the old pilot files wxDir oldDir(oldConfigFolder.GetFullPath()); wxString pilotFile; bool cont = oldDir.GetFirst(&pilotFile, wxEmptyString, wxDIR_FILES); wxLogStatus(_T("Copying pilot files from '%s' to '%s'."), oldConfigFolder.GetFullPath().c_str(), newConfigFolder.GetFullPath().c_str()); while (cont) { wxFileName pilotFileName; pilotFileName.Assign(oldConfigFolder.GetFullPath(), pilotFile); wxFileName newPilotFile; newPilotFile.Assign(newConfigFolder.GetFullPath(), pilotFile); wxLogStatus(_T(" Copying '%s' to '%s'"), pilotFileName.GetFullPath().c_str(), newPilotFile.GetFullPath().c_str()); if (!wxCopyFile(pilotFileName.GetFullPath(), newPilotFile.GetFullPath())) { wxLogError(_T("Failed to copy pilot file '%s'!"), pilotFileName.GetFullPath().c_str()); } cont = oldDir.GetNext(&pilotFile); } wxLogStatus(_T(" Done copying pilot files.")); return true; }
ProMan::RegistryCodes FilePullProfile(wxFileConfig *cfg) { wxFileName inFileName; if ( cfg->Exists(INT_CONFIG_FILE_LOCATION) ) { wxString inFileNameString; if (cfg->Read(INT_CONFIG_FILE_LOCATION, &inFileNameString)) { inFileName.Assign(inFileNameString); } else { wxLogError(_T("Unable to retrieve Config File location even though config says key exists")); return ProMan::UnknownError; } } else { inFileName = GetPlatformDefaultConfigFilePathNew(); inFileName.SetFullName(FSO_CONFIG_FILENAME); if (!inFileName.FileExists()) { inFileName = GetPlatformDefaultConfigFilePathOld(); inFileName.SetFullName(FSO_CONFIG_FILENAME); } } wxASSERT( inFileName.Normalize() ); if ( !inFileName.FileExists() && inFileName.DirExists() ) { // was given a directory name inFileName.SetFullName(FSO_CONFIG_FILENAME); } if (!inFileName.FileExists()) { return ProMan::InputFileDoesNotExist; } wxFFileInputStream inConfigStream(inFileName.GetFullPath(), _T("rb")); wxFileConfig inConfig(inConfigStream, wxMBConvUTF8()); wxString readString; int readNumber; // Video if ( inConfig.Read(REG_KEY_VIDEO_RESOLUTION_DEPTH, &readString) ) { // parses VideocardFS2open into its parts wxString videoCard(readString); wxString rest, rest1, rest2, rest3; long width = 0, height = 0, bitdepth = 0; if ( videoCard.StartsWith(_T("OGL -("), &rest) ) { int xLocation = rest.Find(_T('x')); if ( xLocation != wxNOT_FOUND ) { wxString widthStr(rest.Mid(0, xLocation)); rest1 = rest.Mid(xLocation); if ( !widthStr.ToLong(&width, 10) ) { width = 0; } int bLocation = rest1.Find(_T(')')); if ( bLocation != wxNOT_FOUND ) { wxString heightStr(rest1.Mid(0, bLocation)); rest2 = rest1.Mid(bLocation+1); if ( !heightStr.ToLong(&height, 10) ) { height = 0; } int spaceLoc = rest2.Find(_T(' ')); if ( spaceLoc != wxNOT_FOUND ) { wxString bitStr(rest2.Mid(0, spaceLoc)); if ( !bitStr.ToLong(&bitdepth, 10) ) { bitdepth = 0; } } } } } if ( width > 0 ) { cfg->Write(PRO_CFG_VIDEO_RESOLUTION_WIDTH, width); } if ( height > 0 ) { cfg->Write(PRO_CFG_VIDEO_RESOLUTION_HEIGHT, height); } if ( bitdepth > 0 ) { cfg->Write(PRO_CFG_VIDEO_BIT_DEPTH, bitdepth); } } if ( inConfig.Read(REG_KEY_VIDEO_TEXTURE_FILTER, &readNumber) ) { cfg->Write(PRO_CFG_VIDEO_TEXTURE_FILTER, readNumber); } if ( inConfig.Read(REG_KEY_VIDEO_ANISOTROPIC, &readString) ) { long anisotropic; // necessary because FSO expects registry value to be a string if ( readString.ToLong(&anisotropic) ) { cfg->Write(PRO_CFG_VIDEO_ANISOTROPIC, anisotropic); } } if ( inConfig.Read(REG_KEY_VIDEO_ANTI_ALIAS, &readNumber) ) { cfg->Write(PRO_CFG_VIDEO_ANTI_ALIAS, readNumber); } // Audio if ( inConfig.Read(REG_KEY_AUDIO_OPENAL_DEVICE, &readString) ) { cfg->Write(PRO_CFG_OPENAL_DEVICE, readString); } if ( inConfig.Read(REG_KEY_AUDIO_OPENAL_PLAYBACK_DEVICE, &readString) && !inConfig.Exists(PRO_CFG_OPENAL_DEVICE)) { cfg->Write(PRO_CFG_OPENAL_DEVICE, readString); } if ( inConfig.Read(REG_KEY_AUDIO_OPENAL_CAPTURE_DEVICE, &readString) ) { cfg->Write(PRO_CFG_OPENAL_CAPTURE_DEVICE, readString); } if ( inConfig.Read(REG_KEY_AUDIO_OPENAL_EFX, &readNumber) ) { cfg->Write(PRO_CFG_OPENAL_EFX, readNumber); } if ( inConfig.Read(REG_KEY_AUDIO_OPENAL_SAMPLE_RATE, &readNumber) ) { cfg->Write(PRO_CFG_OPENAL_SAMPLE_RATE, readNumber); } // Speech #if IS_WIN32 // Linux/OS X don't yet support speech if ( inConfig.Read(REG_KEY_SPEECH_VOICE, &readNumber) ) { cfg->Write(PRO_CFG_SPEECH_VOICE, readNumber); } if ( inConfig.Read(REG_KEY_SPEECH_VOLUME, &readNumber) ) { cfg->Write(PRO_CFG_SPEECH_VOLUME, readNumber); } if ( inConfig.Read(REG_KEY_SPEECH_IN_TECHROOM, &readNumber) ) { cfg->Write(PRO_CFG_SPEECH_IN_TECHROOM, readNumber); } if ( inConfig.Read(REG_KEY_SPEECH_IN_BRIEFINGS, &readNumber) ) { cfg->Write(PRO_CFG_SPEECH_IN_BRIEFINGS, readNumber); } if ( inConfig.Read(REG_KEY_SPEECH_IN_GAME, &readNumber) ) { cfg->Write(PRO_CFG_SPEECH_IN_GAME, readNumber); } if ( inConfig.Read(REG_KEY_SPEECH_IN_MULTI, &readNumber) ) { cfg->Write(PRO_CFG_SPEECH_IN_MULTI, readNumber); } #endif // Joystick if ( inConfig.Read(REG_KEY_JOYSTICK_ID, &readNumber) ) { cfg->Write(PRO_CFG_JOYSTICK_ID, readNumber); } if ( inConfig.Read(REG_KEY_JOYSTICK_FORCE_FEEDBACK, &readNumber) ) { cfg->Write(PRO_CFG_JOYSTICK_FORCE_FEEDBACK, readNumber); } if ( inConfig.Read(REG_KEY_JOYSTICK_DIRECTIONAL, &readNumber) ) { cfg->Write(PRO_CFG_JOYSTICK_DIRECTIONAL, readNumber); } // Network if ( inConfig.Read(REG_KEY_NETWORK_TYPE, &readString) ) { cfg->Write(PRO_CFG_NETWORK_TYPE, readString); } if ( inConfig.Read(REG_KEY_NETWORK_SPEED, &readString) ) { cfg->Write(PRO_CFG_NETWORK_SPEED, readString); } if ( inConfig.Read(REG_KEY_NETWORK_PORT, &readNumber) ) { cfg->Write(PRO_CFG_NETWORK_PORT, readNumber); } if ( inConfig.Read(REG_KEY_NETWORK_IP, &readString) ) { cfg->Write(PRO_CFG_NETWORK_IP, readString); } return ProMan::NoError; }
bool MigrateOldConfig() { if (!(FlagListManager::GetFlagListManager()->GetBuildCaps() & FlagListManager::BUILD_CAPS_SDL)) { // Nothing to do, we have an old build return true; } wxFileName newName = GetPlatformDefaultConfigFilePathNew(); newName.SetFullName(FSO_CONFIG_FILENAME); if (wxFile::Exists(newName.GetFullPath())) { // New file already exists, nothing to do here return true; } wxLogStatus(_T("Migrating old configuration...")); #if IS_WIN32 // On Windows this is implemented by iterating through the registry and copying the values to the config file wxString keyName; HKEY useKey = GetRegistryKeyname(keyName); LONG ret = ERROR_SUCCESS; HKEY regHandle = 0; ret = RegOpenKeyExW(useKey, keyName.wc_str(), 0, KEY_READ, ®Handle ); if (ret != ERROR_SUCCESS) { // Key does not exists or some other error, assume it doesn't exist return true; // No old config, nothing to do here } wxStringInputStream configBlankInputStream(_T("")); wxFileConfig outConfig(configBlankInputStream, wxMBConvUTF8()); copyValuesIntoConfig(regHandle, outConfig, REG_KEY_DEFAULT_FOLDER_CFG); for (DWORD i = 0;; ++i) { WCHAR subkey[255]; DWORD subkeyLen = 255; LONG res = RegEnumKeyExW(regHandle, i, subkey, &subkeyLen, NULL, NULL, NULL, NULL); if (res != ERROR_SUCCESS) break; HKEY handle; res = RegOpenKeyExW(regHandle, subkey, 0, KEY_READ, &handle); if (res != ERROR_SUCCESS) { continue; } wxString sectionName(subkey, subkeyLen); sectionName = wxString::FromAscii("/") + sectionName; copyValuesIntoConfig(handle, outConfig, sectionName); RegCloseKey(handle); } RegCloseKey(regHandle); wxLogStatus(_T("Writing fs2_open.ini to %s"), newName.GetFullPath().c_str()); wxFFileOutputStream outFileStream(newName.GetFullPath()); outConfig.Save(outFileStream, wxMBConvUTF8()); #else wxFileName oldName = GetPlatformDefaultConfigFilePathOld(); oldName.SetFullName(FSO_CONFIG_FILENAME); if (!wxFile::Exists(oldName.GetFullPath())) { // Old file does not exist, probably first run. return true; } if (!wxCopyFile(oldName.GetFullPath(), newName.GetFullPath())) { wxLogError(_T("Failed to copy old configuration file to new location!")); return false; } #endif wxLogStatus(_T("Migration finished.")); return true; }