Exemplo n.º 1
0
void emu_settings::OpenCorrectionDialog(QWidget* parent)
{
	if (m_broken_types.size() && QMessageBox::question(parent, tr("Fix invalid settings?"),
		tr(
			"Your config file contained one or more unrecognized settings.\n"
			"Their default value will be used until they are corrected.\n"
			"Consider that a correction might render them invalid for other versions of RPCS3.\n"
			"\n"
			"Do you wish to let the program correct them for you?\n"
			"This change will only be final when you save the config."
		),
		QMessageBox::Yes | QMessageBox::No, QMessageBox::No) == QMessageBox::Yes)
	{
		for (const auto& type : m_broken_types)
		{
			std::string def = GetSettingDefault(type);
			std::string old = GetSetting(type);
			SetSetting(type, def);
			LOG_SUCCESS(GENERAL, "The config entry '%s' was corrected from '%s' to '%s'", GetSettingName(type), old, def);
		}

		m_broken_types.clear();
		LOG_SUCCESS(GENERAL, "You need to save the settings in order to make these changes permanent!");
	}
}
//----------------------------------------------------------------------------------------------
//	LoadRegistry
//----------------------------------------------------------------------------------------------
VOID CSetting::LoadRegistry()
{
	//	コントローラーの設定、設定の名称の領域を開放する
	if( Setting != NULL )
	{
		LocalFree( Setting );
	}
	if( SettingName != NULL )
	{
		for( LONG Index = 0; Index < SettingCount; Index ++ )
		{
			LocalFree( SettingName[Index] );
		}
		LocalFree( SettingName );
	}

	//	現在のコントローラーの設定を取得する
	GetDefaultSetting( &CurrentSetting );
	GetRegistry( &CurrentSetting, REG_BINARY, sizeof( SETTING ), CURRENT_SETTING );

	//	現在のコントローラーの設定の順番を取得する
	CurrentSettingIndex	= 0;
	GetRegistry( &CurrentSettingIndex, REG_DWORD, sizeof( LONG ), CURRENT_SETTING_INDEX );

	//	コントローラーの設定数を取得する
	SettingCount	= 1;
	GetRegistry( &SettingCount, REG_DWORD, sizeof( LONG ), SETTING_COUNT );

	//	コントローラーの設定、設定の名称を保存するための領域を確保する
	Setting		= (SETTING *)LocalAlloc( LPTR, SettingCount * sizeof( SETTING ) );
	SettingName	= (WCHAR * *)LocalAlloc( LPTR, SettingCount * sizeof( WCHAR * ) );
	for( LONG Index = 0; Index < SettingCount; Index ++ )
	{
		SettingName[Index]	= (WCHAR *)LocalAlloc( LPTR, sizeof( WCHAR ) * MAX_PATH );
	}

	//	標準の設定を取得する
	GetDefaultSetting( &Setting[0] );
	LoadString( Instance, IDS_DEFAULT_SETTING, SettingName[0], sizeof( WCHAR ) * MAX_PATH );

	//	コントローラーの設定、設定の名称を取得する
	for( LONG Index = 1; Index < SettingCount; Index ++ )
	{
		GetSetting( Index, &Setting[Index] );
		GetSettingName( Index, SettingName[Index], sizeof( WCHAR ) * MAX_PATH );
	}

	//	変更済みフラグを取得する
	ModifiedFlag	= FALSE;
	GetRegistry( &ModifiedFlag, REG_BINARY, sizeof( BOOLEAN ), MODIFIED_FLAG );

	//	設定の自動切換えを取得する
	AutoSettingChange	= FALSE;
	GetRegistry( &AutoSettingChange, REG_BINARY, sizeof( BOOLEAN ), AUTO_SETTING_CHANGE );
}
Exemplo n.º 3
0
void emu_settings::EnhanceDoubleSpinBox(QDoubleSpinBox* spinbox, SettingsType type, const QString& prefix, const QString& suffix)
{
	if (!spinbox)
	{
		LOG_FATAL(GENERAL, "EnhanceDoubleSpinBox '%s' was used with an invalid object", GetSettingName(type));
		return;
	}

	QStringList range = GetSettingOptions(type);
	bool ok_def, ok_sel, ok_min, ok_max;

	double def = qstr(GetSettingDefault(type)).toDouble(&ok_def);
	double min = range.first().toDouble(&ok_min);
	double max = range.last().toDouble(&ok_max);

	if (!ok_def || !ok_min || !ok_max)
	{
		LOG_FATAL(GENERAL, "EnhanceDoubleSpinBox '%s' was used with an invalid type", GetSettingName(type));
		return;
	}

	std::string selected = GetSetting(type);
	double val = qstr(selected).toDouble(&ok_sel);

	if (!ok_sel || val < min || val > max)
	{
		LOG_ERROR(GENERAL, "EnhanceDoubleSpinBox '%s' tried to set an invalid value: %f. Setting to default: %f. Allowed range: [%f, %f]", GetSettingName(type), val, def, min, max);
		val = def;
		m_broken_types.insert(type);
	}

	spinbox->setPrefix(prefix);
	spinbox->setSuffix(suffix);
	spinbox->setRange(min, max);
	spinbox->setValue(val);

	connect(spinbox, QOverload<const QString &>::of(&QDoubleSpinBox::valueChanged), [=](const QString&/* value*/)
	{
		SetSetting(type, sstr(spinbox->cleanText()));
	});
}
Exemplo n.º 4
0
void emu_settings::EnhanceSlider(QSlider* slider, SettingsType type)
{
	if (!slider)
	{
		LOG_FATAL(GENERAL, "EnhanceSlider '%s' was used with an invalid object", GetSettingName(type));
		return;
	}

	QStringList range = GetSettingOptions(type);
	bool ok_def, ok_sel, ok_min, ok_max;

	int def = qstr(GetSettingDefault(type)).toInt(&ok_def);
	int min = range.first().toInt(&ok_min);
	int max = range.last().toInt(&ok_max);

	if (!ok_def || !ok_min || !ok_max)
	{
		LOG_FATAL(GENERAL, "EnhanceSlider '%s' was used with an invalid SettingsType", GetSettingName(type));
		return;
	}

	QString selected = qstr(GetSetting(type));
	int val = selected.toInt(&ok_sel);

	if (!ok_sel || val < min || val > max)
	{
		LOG_ERROR(GENERAL, "EnhanceSlider '%s' tried to set an invalid value: %d. Setting to default: %d. Allowed range: [%d, %d]", GetSettingName(type), val, def, min, max);
		val = def;
		m_broken_types.insert(type);
	}

	slider->setRange(min, max);
	slider->setValue(val);

	connect(slider, &QSlider::valueChanged, [=](int value)
	{
		SetSetting(type, sstr(value));
	});
}
Exemplo n.º 5
0
void emu_settings::EnhanceCheckBox(QCheckBox* checkbox, SettingsType type)
{
	if (!checkbox)
	{
		LOG_FATAL(GENERAL, "EnhanceCheckBox '%s' was used with an invalid object", GetSettingName(type));
		return;
	}

	std::string def = GetSettingDefault(type);
	std::transform(def.begin(), def.end(), def.begin(), ::tolower);

	if (def != "true" && def != "false")
	{
		LOG_FATAL(GENERAL, "EnhanceCheckBox '%s' was used with an invalid SettingsType", GetSettingName(type));
		return;
	}

	std::string selected = GetSetting(type);
	std::transform(selected.begin(), selected.end(), selected.begin(), ::tolower);

	if (selected == "true")
	{
		checkbox->setChecked(true);
	}
	else if (selected != "false")
	{
		LOG_ERROR(GENERAL, "EnhanceCheckBox '%s' tried to set an invalid value: %s. Setting to default: %s", GetSettingName(type), selected, def);
		checkbox->setChecked(def == "true");
		m_broken_types.insert(type);
	}

	connect(checkbox, &QCheckBox::stateChanged, [=](int val)
	{
		std::string str = val != 0 ? "true" : "false";
		SetSetting(type, str);
	});
}
Exemplo n.º 6
0
void emu_settings::EnhanceComboBox(QComboBox* combobox, SettingsType type, bool is_ranged, bool use_max, int max)
{
	if (!combobox)
	{
		LOG_FATAL(GENERAL, "EnhanceComboBox '%s' was used with an invalid object", GetSettingName(type));
		return;
	}

	if (is_ranged)
	{
		QStringList range = GetSettingOptions(type);

		int max_item = use_max ? max : range.last().toInt();

		for (int i = range.first().toInt(); i <= max_item; i++)
		{
			combobox->addItem(QString::number(i), QVariant(QString::number(i)));
		}
	}
	else
	{
		for (QString setting : GetSettingOptions(type))
		{
			combobox->addItem(tr(setting.toStdString().c_str()), QVariant(setting));
		}
	}

	std::string selected = GetSetting(type);
	int index = combobox->findData(qstr(selected));

	if (index == -1)
	{
		std::string def = GetSettingDefault(type);
		LOG_ERROR(GENERAL, "EnhanceComboBox '%s' tried to set an invalid value: %s. Setting to default: %s", GetSettingName(type), selected, def);
		combobox->setCurrentIndex(combobox->findData(qstr(def)));
		m_broken_types.insert(type);
	}
	else
	{
		combobox->setCurrentIndex(index);
	}

	connect(combobox, static_cast<void(QComboBox::*)(int)>(&QComboBox::currentIndexChanged), [=](int index)
	{
		SetSetting(type, sstr(combobox->itemData(index)));
	});
}