Exemplo n.º 1
0
ProMan::RegistryCodes FilePushProfile(wxFileConfig *cfg) {
	wxFileName configFileName;
	wxString tcPath;
	cfg->Read(PRO_CFG_TC_ROOT_FOLDER, &tcPath);

	if ( cfg->Exists(INT_CONFIG_FILE_LOCATION) ) {
		wxString configFileNameString;
		if (cfg->Read(INT_CONFIG_FILE_LOCATION, &configFileNameString)) {
			configFileName.Assign(configFileNameString);
		} else {
			wxLogError(_T("Unable to retrieve Config File location even though config says key exists"));
			return ProMan::UnknownError;
		}
	} else {
		configFileName = GetPlatformDefaultConfigFilePath(tcPath);
	}
	wxASSERT_MSG( configFileName.Normalize(),
		wxString::Format(_T("Unable to normalize PlatformDefaultConfigFilePath (%s)"),
		configFileName.GetFullPath().c_str()));

	if ( !configFileName.FileExists() && configFileName.DirExists() ) {
		// was given a directory name
		configFileName.SetFullName(FSO_CONFIG_FILENAME);
	}

	wxFFileInputStream configFileInputStream(configFileName.GetFullPath());
	wxStringInputStream configBlankInputStream(_T("")); // in case ini file doesn't exist
	wxInputStream* configInputStreamPtr = &configFileInputStream;
	
	if (!configFileInputStream.IsOk()) {
		wxLogDebug(_T("Could not read from ini file %s, writing new file"),
			configFileName.GetFullPath().c_str());
		configInputStreamPtr = &configBlankInputStream;
	}
	wxFileConfig outConfig(*configInputStreamPtr, wxMBConvUTF8());
	bool ret;
	
	// most settings are written to "Default" folder
	outConfig.SetPath(REG_KEY_DEFAULT_FOLDER_CFG);

	// Video
	int width, height, bitdepth;
	cfg->Read(PRO_CFG_VIDEO_RESOLUTION_WIDTH, &width, DEFAULT_VIDEO_RESOLUTION_WIDTH);
	cfg->Read(PRO_CFG_VIDEO_RESOLUTION_HEIGHT, &height, DEFAULT_VIDEO_RESOLUTION_HEIGHT);
	cfg->Read(PRO_CFG_VIDEO_BIT_DEPTH, &bitdepth, DEFAULT_VIDEO_BIT_DEPTH);

	wxString videocardValue = wxString::Format(_T("OGL -(%dx%d)x%d bit"), width, height, bitdepth);

	ret = outConfig.Write(REG_KEY_VIDEO_RESOLUTION_DEPTH, videocardValue);
	ReturnChecker(ret, __LINE__);

	
	wxString filterMethod;
	cfg->Read(PRO_CFG_VIDEO_TEXTURE_FILTER, &filterMethod, DEFAULT_VIDEO_TEXTURE_FILTER);
	int filterMethodValue = ( filterMethod.StartsWith(_T("Bilinear"))) ? 0 : 1;
	
	ret = outConfig.Write(REG_KEY_VIDEO_TEXTURE_FILTER, filterMethodValue);
	ReturnChecker(ret, __LINE__);
	

	int oglAnisotropicFilter;
	cfg->Read(PRO_CFG_VIDEO_ANISOTROPIC, &oglAnisotropicFilter, DEFAULT_VIDEO_ANISOTROPIC);

	// Caution: FSO expects anisotropic values to be a string,
	// but since we're writing to an .ini file, we can write it out as an int
	ret = outConfig.Write(REG_KEY_VIDEO_ANISOTROPIC, oglAnisotropicFilter);
	ReturnChecker(ret, __LINE__);
	

	int oglAntiAliasSample;
	cfg->Read(PRO_CFG_VIDEO_ANTI_ALIAS, &oglAntiAliasSample, DEFAULT_VIDEO_ANTI_ALIAS);

	ret = outConfig.Write(REG_KEY_VIDEO_ANTI_ALIAS, oglAntiAliasSample);
	ReturnChecker(ret, __LINE__);


	// Audio
	wxString soundDevice;
	cfg->Read(PRO_CFG_OPENAL_DEVICE, &soundDevice, DEFAULT_AUDIO_OPENAL_DEVICE);

	ret = outConfig.Write(REG_KEY_AUDIO_OPENAL_DEVICE, soundDevice);
	ReturnChecker(ret, __LINE__);


	// new sound code settings are written to "Sound" folder
	outConfig.SetPath(REG_KEY_AUDIO_FOLDER_CFG);


	wxString playbackDevice;
	cfg->Read(
		PRO_CFG_OPENAL_DEVICE,
		&playbackDevice,
		DEFAULT_AUDIO_OPENAL_PLAYBACK_DEVICE);

	ret = outConfig.Write(REG_KEY_AUDIO_OPENAL_PLAYBACK_DEVICE, playbackDevice);
	ReturnChecker(ret, __LINE__);


	wxString captureDevice;
	bool hasEntry = cfg->Read(
		PRO_CFG_OPENAL_CAPTURE_DEVICE,
		&captureDevice,
		DEFAULT_AUDIO_OPENAL_CAPTURE_DEVICE);

	if (hasEntry) {
		ret = outConfig.Write(REG_KEY_AUDIO_OPENAL_CAPTURE_DEVICE, captureDevice);
		ReturnChecker(ret, __LINE__);
	}


	int enableEFX;
	hasEntry = cfg->Read(PRO_CFG_OPENAL_EFX, &enableEFX, DEFAULT_AUDIO_OPENAL_EFX);

	if (hasEntry) {
		ret = outConfig.Write(REG_KEY_AUDIO_OPENAL_EFX, enableEFX);
		ReturnChecker(ret, __LINE__);
	}


	int sampleRate;
	cfg->Read(
		PRO_CFG_OPENAL_SAMPLE_RATE,
		&sampleRate,
		DEFAULT_AUDIO_OPENAL_SAMPLE_RATE);

	if (sampleRate != DEFAULT_AUDIO_OPENAL_SAMPLE_RATE) {
		ret = outConfig.Write(REG_KEY_AUDIO_OPENAL_SAMPLE_RATE, sampleRate);
		ReturnChecker(ret, __LINE__);
	}


	outConfig.SetPath(REG_KEY_DEFAULT_FOLDER_CFG);


	// Speech
#if IS_WIN32 // speech is currently not supported in OS X or Linux (although Windows doesn't use this code)
	int speechVoice;
	cfg->Read(PRO_CFG_SPEECH_VOICE, &speechVoice, DEFAULT_SPEECH_VOICE);

	ret = outConfig.Write(REG_KEY_SPEECH_VOICE, speechVoice);
	ReturnChecker(ret, __LINE__);


	int speechVolume;
	cfg->Read(PRO_CFG_SPEECH_VOLUME, &speechVolume, DEFAULT_SPEECH_VOLUME);

	ret = outConfig.Write(REG_KEY_SPEECH_VOLUME, speechVolume);
	ReturnChecker(ret, __LINE__);


	int inTechroom, inBriefings, inGame, inMulti;
	cfg->Read(PRO_CFG_SPEECH_IN_TECHROOM, &inTechroom, DEFAULT_SPEECH_IN_TECHROOM);
	cfg->Read(PRO_CFG_SPEECH_IN_BRIEFINGS, &inBriefings, DEFAULT_SPEECH_IN_BRIEFINGS);
	cfg->Read(PRO_CFG_SPEECH_IN_GAME, &inGame, DEFAULT_SPEECH_IN_GAME);
	cfg->Read(PRO_CFG_SPEECH_IN_MULTI, &inMulti, DEFAULT_SPEECH_IN_MULTI);

	ret = outConfig.Write(REG_KEY_SPEECH_IN_TECHROOM, inTechroom);
	ReturnChecker(ret, __LINE__);

	ret = outConfig.Write(REG_KEY_SPEECH_IN_BRIEFINGS, inBriefings);
	ReturnChecker(ret, __LINE__);

	ret = outConfig.Write(REG_KEY_SPEECH_IN_GAME, inGame);
	ReturnChecker(ret, __LINE__);

	ret = outConfig.Write(REG_KEY_SPEECH_IN_MULTI, inMulti);
	ReturnChecker(ret, __LINE__);
#endif


	// Joystick
	int currentJoystick;
	cfg->Read(PRO_CFG_JOYSTICK_ID, &currentJoystick, DEFAULT_JOYSTICK_ID);

	ret = outConfig.Write(REG_KEY_JOYSTICK_ID, currentJoystick);
	ReturnChecker(ret, __LINE__);


	int joystickForceFeedback;
	cfg->Read(
		PRO_CFG_JOYSTICK_FORCE_FEEDBACK,
		&joystickForceFeedback,
		DEFAULT_JOYSTICK_FORCE_FEEDBACK);

	ret = outConfig.Write(REG_KEY_JOYSTICK_FORCE_FEEDBACK, joystickForceFeedback);
	ReturnChecker(ret, __LINE__);


	int joystickHit;
	cfg->Read(PRO_CFG_JOYSTICK_DIRECTIONAL, &joystickHit, DEFAULT_JOYSTICK_DIRECTIONAL);

	ret = outConfig.Write(REG_KEY_JOYSTICK_DIRECTIONAL, joystickHit);
	ReturnChecker(ret, __LINE__);


	// Network
	wxString networkConnectionValue;
	cfg->Read(PRO_CFG_NETWORK_TYPE, &networkConnectionValue, DEFAULT_NETWORK_TYPE);

	ret = outConfig.Write(REG_KEY_NETWORK_TYPE, networkConnectionValue);
	ReturnChecker(ret, __LINE__);


	wxString connectionSpeedValue;
	cfg->Read(PRO_CFG_NETWORK_SPEED, &connectionSpeedValue, DEFAULT_NETWORK_SPEED);

	ret = outConfig.Write(REG_KEY_NETWORK_SPEED, connectionSpeedValue);
	ReturnChecker(ret, __LINE__);


	int forcedport;
	cfg->Read(PRO_CFG_NETWORK_PORT, &forcedport, DEFAULT_NETWORK_PORT);

	if (forcedport != DEFAULT_NETWORK_PORT) {
		ret = outConfig.Write(REG_KEY_NETWORK_PORT, forcedport);
		ReturnChecker(ret, __LINE__);
	} else if (outConfig.Exists(REG_KEY_NETWORK_PORT)) {
		ret = outConfig.DeleteEntry(REG_KEY_NETWORK_PORT, false);
		ReturnChecker(ret, __LINE__);
	}


	// custom IP is written to "Network" folder
	outConfig.SetPath(REG_KEY_NETWORK_FOLDER_CFG);

	wxString networkIP;
	cfg->Read(PRO_CFG_NETWORK_IP, &networkIP, DEFAULT_NETWORK_IP);

	if (networkIP != DEFAULT_NETWORK_IP) {
		ret = outConfig.Write(REG_KEY_NETWORK_IP, networkIP);
		ReturnChecker(ret, __LINE__);
	} else if (outConfig.Exists(REG_KEY_NETWORK_IP)) {
		ret = outConfig.DeleteEntry(REG_KEY_NETWORK_IP, false);
		ReturnChecker(ret, __LINE__);
	}

	outConfig.SetPath(REG_KEY_DEFAULT_FOLDER_CFG);


	wxLogDebug(_T("Writing fs2_open.ini to %s"), configFileName.GetFullPath().c_str());
	wxFFileOutputStream outFileStream(configFileName.GetFullPath());

	outConfig.Save(outFileStream);

	return PushCmdlineFSO(cfg);
}
Exemplo n.º 2
0
	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,
			&regHandle
			);
		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;
	}