launcher: try using simpleini for config BACKUP YOUR CONFIG BEFORE TESTING!!

This commit is contained in:
somewhatlurker
2020-11-16 05:09:53 +11:00
parent 143426e049
commit a0bf8a6ac3
40 changed files with 8215 additions and 112 deletions
@@ -12,6 +12,7 @@
#include <msclr\marshal_cppstd.h>
#include "PluginConfigApi.h"
#include "IniReader.h"
using namespace System;
using namespace System::Windows::Forms;
@@ -23,26 +24,7 @@ int Col2Width = 90;
int ConfigBtnLeft = 120;
int ControlSpacing = 6;
// Custom function. Works like GetPrivateProfileIntW but returns bool. Can detect a numeric value or string.
bool GetPrivateProfileBoolW(LPCWSTR lpAppName, LPCWSTR lpKeyName, bool default, LPCWSTR lpFileName)
{
wchar_t buffer[8];
GetPrivateProfileStringW(lpAppName, lpKeyName, L"", buffer, 8, lpFileName);
//MessageBoxW(NULL, buffer, NULL, 0);
for (wchar_t& chr : buffer)
chr = towlower(chr);
bool out;
if ((lstrcmpW(buffer, L"true") == 0) || (lstrcmpW(buffer, L"1") == 0))
out = true;
else if ((lstrcmpW(buffer, L"false") == 0) || (lstrcmpW(buffer, L"0") == 0))
out = false;
else
out = default;
return out;
}
// declare this early (actual definitions below)
class ConfigOptionBase;
@@ -342,7 +324,7 @@ public:
CheckBox^ cb = gcnew CheckBox();
cb->Text = gcnew String(_friendlyName);
cb->Checked = GetPrivateProfileBoolW(_iniSectionName, _iniVarName, _defaultVal, _iniFilePath);
cb->Checked = GetIniBool(_iniSectionName, _iniVarName, _defaultVal, _iniFilePath);
cb->Left = left + 2;
cb->Top = top;
cb->AutoSize = true;
@@ -378,12 +360,7 @@ public:
virtual void SaveOption()
{
bool boolEnabled = ((CheckBox^)CheckBox::FromHandle(mainControlHandle))->Checked;
if (_saveAsString)
WritePrivateProfileStringW(_iniSectionName, _iniVarName, boolEnabled ? L"true" : L"false", _iniFilePath);
else
WritePrivateProfileStringW(_iniSectionName, _iniVarName, boolEnabled ? L"1" : L"0", _iniFilePath);
SetIniBool(_iniSectionName, _iniVarName, ((CheckBox^)CheckBox::FromHandle(mainControlHandle))->Checked, _iniFilePath, _saveAsString);
}
};
@@ -422,8 +399,8 @@ public:
numberbox->Minimum = _minVal;
numberbox->Maximum = _maxVal;
numberbox->Value = (int)GetPrivateProfileIntW(_iniSectionName, _iniVarName, _defaultVal, _iniFilePath); // cast to int because this returns uint and breaks -1
// it seems it does read negative values correctly though... but eventually a parser that properly supports negative numbers would be ideal
numberbox->Value = GetIniInt(_iniSectionName, _iniVarName, _defaultVal, _iniFilePath);
numberbox->Left = left + Col2Left;
numberbox->Top = top;
numberbox->Width = Col2Width;
@@ -459,12 +436,7 @@ public:
virtual void SaveOption()
{
System::String^ tempSysStr;
std::wstring tempWStr;
tempSysStr = Convert::ToInt32(((NumericUpDown^)NumericUpDown::FromHandle(mainControlHandle))->Value).ToString();
tempWStr = msclr::interop::marshal_as<std::wstring>(tempSysStr);
WritePrivateProfileStringW(_iniSectionName, _iniVarName, tempWStr.c_str(), _iniFilePath);
SetIniInt(_iniSectionName, _iniVarName, Convert::ToInt32(((NumericUpDown^)NumericUpDown::FromHandle(mainControlHandle))->Value), _iniFilePath);
}
};
@@ -491,8 +463,7 @@ public:
Label^ label = gcnew Label();
TextBox^ textbox = gcnew TextBox();
WCHAR stringBuf[256];
char utf8Buf[256];
const wchar_t* stringBuf;
label->Text = gcnew String(_friendlyName);
label->Left = left;
@@ -501,11 +472,7 @@ public:
label->AutoSize = true;
label->FlatStyle = System::Windows::Forms::FlatStyle::Flat;
GetPrivateProfileStringW(_iniSectionName, _iniVarName, _defaultVal, stringBuf, 256, _iniFilePath);
if (_useUtf8 && wcscmp(_defaultVal, stringBuf) != 0) { // don't convert default value
WideCharToMultiByte(CP_ACP, 0, stringBuf, -1, utf8Buf, 256, NULL, NULL); // convert back to the original ANSI as read from file
MultiByteToWideChar(CP_UTF8, 0, utf8Buf, -1, stringBuf, 256); // now use those bytes to convert from UTF8
}
stringBuf = GetIniString(_iniSectionName, _iniVarName, _defaultVal, _iniFilePath, _useUtf8);
textbox->Text = gcnew String(stringBuf);
textbox->Left = left + Col2Left;
@@ -554,20 +521,11 @@ public:
System::String^ tempSysStr;
std::wstring tempWStr;
WCHAR stringBuf[256];
char utf8Buf[256];
tempSysStr = ((TextBox^)TextBox::FromHandle(mainControlHandle))->Text;
tempWStr = msclr::interop::marshal_as<std::wstring>(tempSysStr);
tempWStr.copy(stringBuf, 256, 0);
stringBuf[tempWStr.length()] = 0;
if (_useUtf8) {
WideCharToMultiByte(CP_UTF8, 0, stringBuf, -1, utf8Buf, 256, NULL, NULL); // convert to UTF8
MultiByteToWideChar(CP_ACP, 0, utf8Buf, -1, stringBuf, 256); // now convert that to wide chars as if it's ANSI so it saves properly after conversion to ANSI by windows
}
WritePrivateProfileStringW(_iniSectionName, _iniVarName, stringBuf, _iniFilePath);
SetIniString(_iniSectionName, _iniVarName, tempWStr.c_str(), _iniFilePath, _useUtf8);
}
};
@@ -604,7 +562,7 @@ public:
for (LPCWSTR& choice : _valueStrings) {
combobox->Items->Add(msclr::interop::marshal_as<System::String^>(choice));
}
combobox->SelectedIndex = GetPrivateProfileIntW(_iniSectionName, _iniVarName, _defaultVal, _iniFilePath);
combobox->SelectedIndex = GetIniInt(_iniSectionName, _iniVarName, _defaultVal, _iniFilePath);
combobox->Left = left + Col2Left;
combobox->Top = top;
combobox->Width = Col2Width;
@@ -642,12 +600,7 @@ public:
virtual void SaveOption()
{
System::String^ tempSysStr;
std::wstring tempWStr;
tempSysStr = Convert::ToInt32(((ComboBox^)ComboBox::FromHandle(mainControlHandle))->SelectedIndex).ToString();
tempWStr = msclr::interop::marshal_as<std::wstring>(tempSysStr);
WritePrivateProfileStringW(_iniSectionName, _iniVarName, tempWStr.c_str(), _iniFilePath);
SetIniInt(_iniSectionName, _iniVarName, Convert::ToInt32(((ComboBox^)ComboBox::FromHandle(mainControlHandle))->SelectedIndex), _iniFilePath);
}
};
@@ -678,8 +631,7 @@ public:
Label^ label = gcnew Label();
ComboBox^ combobox = gcnew ComboBox();
WCHAR stringBuf[256];
char utf8Buf[256];
const wchar_t* stringBuf;
label->Text = gcnew String(_friendlyName);
label->Left = left;
@@ -692,11 +644,7 @@ public:
combobox->Items->Add(msclr::interop::marshal_as<System::String^>(choice));
}
GetPrivateProfileStringW(_iniSectionName, _iniVarName, _defaultVal, stringBuf, 256, _iniFilePath);
if (_useUtf8 && wcscmp(_defaultVal, stringBuf) != 0) { // don't convert default value
WideCharToMultiByte(CP_ACP, 0, stringBuf, -1, utf8Buf, 256, NULL, NULL); // convert back to the original ANSI as read from file
MultiByteToWideChar(CP_UTF8, 0, utf8Buf, -1, stringBuf, 256); // now use those bytes to convert from UTF8
}
stringBuf = GetIniString(_iniSectionName, _iniVarName, _defaultVal, _iniFilePath, _useUtf8);
combobox->Text = gcnew String(stringBuf);
combobox->Left = left + Col2Left;
@@ -755,20 +703,11 @@ public:
System::String^ tempSysStr;
std::wstring tempWStr;
WCHAR stringBuf[256];
char utf8Buf[256];
tempSysStr = ((ComboBox^)ComboBox::FromHandle(mainControlHandle))->Text;
tempWStr = msclr::interop::marshal_as<std::wstring>(tempSysStr);
tempWStr.copy(stringBuf, 256, 0);
stringBuf[tempWStr.length()] = 0;
if (_useUtf8) {
WideCharToMultiByte(CP_UTF8, 0, stringBuf, -1, utf8Buf, 256, NULL, NULL); // convert to UTF8
MultiByteToWideChar(CP_ACP, 0, utf8Buf, -1, stringBuf, 256); // now convert that to wide chars as if it's ANSI so it saves properly after conversion to ANSI by windows
}
WritePrivateProfileStringW(_iniSectionName, _iniVarName, stringBuf, _iniFilePath);
SetIniString(_iniSectionName, _iniVarName, tempWStr.c_str(), _iniFilePath, _useUtf8);
}
};
@@ -810,7 +749,7 @@ public:
combobox->Items->Add(Convert::ToInt32(choice).ToString());
}
tempSysStr = Convert::ToInt32((int)GetPrivateProfileIntW(_iniSectionName, _iniVarName, _defaultVal, _iniFilePath)).ToString();
tempSysStr = Convert::ToInt32(GetIniInt(_iniSectionName, _iniVarName, _defaultVal, _iniFilePath)).ToString();
combobox->Text = gcnew String(tempSysStr);
combobox->Left = left + Col2Left;
@@ -866,7 +805,7 @@ public:
tempSysStr = ((ComboBox^)ComboBox::FromHandle(mainControlHandle))->Text;
tempWStr = msclr::interop::marshal_as<std::wstring>(tempSysStr);
WritePrivateProfileStringW(_iniSectionName, _iniVarName, tempWStr.c_str(), _iniFilePath);
SetIniString(_iniSectionName, _iniVarName, tempWStr.c_str(), _iniFilePath, false);
}
};
@@ -924,8 +863,8 @@ public:
combobox->Items->Add(tempSysStr);
}
int width = GetPrivateProfileIntW(_iniSectionName, _iniVarName, -39, _iniFilePath);
int height = GetPrivateProfileIntW(_iniSectionName, _iniVarName2, -39, _iniFilePath);
int width = GetIniInt(_iniSectionName, _iniVarName, -39, _iniFilePath);
int height = GetIniInt(_iniSectionName, _iniVarName2, -39, _iniFilePath);
if (width == -39 || height == -39) {
if (_defaultVal.width == -1 || _defaultVal.height == -1)
width = -1;
@@ -1007,11 +946,11 @@ public:
tempSysStr = resolutionArray[0];
tempWStr = msclr::interop::marshal_as<std::wstring>(tempSysStr);
WritePrivateProfileStringW(_iniSectionName, _iniVarName, tempWStr.c_str(), _iniFilePath);
SetIniString(_iniSectionName, _iniVarName, tempWStr.c_str(), _iniFilePath, false);
tempSysStr = resolutionArray[1];
tempWStr = msclr::interop::marshal_as<std::wstring>(tempSysStr);
WritePrivateProfileStringW(_iniSectionName, _iniVarName2, tempWStr.c_str(), _iniFilePath);
SetIniString(_iniSectionName, _iniVarName2, tempWStr.c_str(), _iniFilePath, false);
}
};
@@ -1086,7 +1025,7 @@ public:
Button^ button = gcnew Button();
cb->Text = gcnew String(_friendlyName);
cb->Checked = GetPrivateProfileBoolW(_iniSectionName, _iniVarName, _defaultVal, _iniFilePath);
cb->Checked = GetIniBool(_iniSectionName, _iniVarName, _defaultVal, _iniFilePath);
cb->Left = left + 2;
cb->Top = top + 3;
cb->AutoSize = true;
@@ -1142,9 +1081,7 @@ public:
virtual void SaveOption()
{
bool boolEnabled = ((CheckBox^)CheckBox::FromHandle(mainControlHandle))->Checked;
WritePrivateProfileStringW(_iniSectionName, _iniVarName, boolEnabled ? L"1" : L"0", _iniFilePath);
SetIniBool(_iniSectionName, _iniVarName, ((CheckBox^)CheckBox::FromHandle(mainControlHandle))->Checked, _iniFilePath, false);
for (ConfigOptionBase* opt : _configopts)
{
@@ -0,0 +1,97 @@
#pragma once
// kinda rushed and hacky wrapper around simpleini for use by ConfigOption
// (has a similar API to windows GetPrivateProfile/SetPrivateProfile stuff)
#include <SimpleIni.h>
CSimpleIniW ini_reader;
std::wstring loaded_ini_file;
bool LoadIni(const wchar_t* filename, bool use_utf8=false)
{
if (ini_reader.IsUnicode() == use_utf8 && loaded_ini_file == filename)
{
return true;
}
ini_reader.Reset();
ini_reader.SetUnicode(use_utf8);
if (ini_reader.LoadFile(filename) != 0)
{
loaded_ini_file = L"";
return false;
}
else
{
loaded_ini_file = filename;
return true;
}
}
const wchar_t* GetIniString(const wchar_t* section, const wchar_t* key, const wchar_t* default, const wchar_t* filename, bool use_utf8)
{
if (!LoadIni(filename, use_utf8))
{
return default;
}
return ini_reader.GetValue(section, key, default);
}
int GetIniInt(const wchar_t* section, const wchar_t* key, int default, const wchar_t* filename)
{
if (!LoadIni(filename))
{
return default;
}
return ini_reader.GetLongValue(section, key, default);
}
bool GetIniBool(const wchar_t* section, const wchar_t* key, bool default, const wchar_t* filename)
{
if (!LoadIni(filename))
{
return default;
}
return ini_reader.GetBoolValue(section, key, default);
}
void SetIniString(const wchar_t* section, const wchar_t* key, const wchar_t* value, const wchar_t* filename, bool use_utf8)
{
if (!LoadIni(filename, use_utf8))
{
return;
}
ini_reader.SetValue(section, key, value);
ini_reader.SaveFile(filename);
}
void SetIniInt(const wchar_t* section, const wchar_t* key, int value, const wchar_t* filename)
{
if (!LoadIni(filename))
{
return;
}
ini_reader.SetLongValue(section, key, value);
ini_reader.SaveFile(filename);
}
void SetIniBool(const wchar_t* section, const wchar_t* key, bool value, const wchar_t* filename, bool use_string)
{
if (!LoadIni(filename))
{
return;
}
if (use_string)
ini_reader.SetValue(section, key, value ? L"true" : L"false");
else
ini_reader.SetValue(section, key, value ? L"1" : L"0");
ini_reader.SaveFile(filename);
}
@@ -63,7 +63,7 @@
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>..\..\..\dependencies\WineVer;..\..\..\dependencies\GPUModel;..\..\..\dependencies\PluginConfigApi;..\..\..\dependencies\freeglut\include;..\..\..\dependencies\detours\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>..\..\..\dependencies\simpleini;..\..\..\dependencies\WineVer;..\..\..\dependencies\GPUModel;..\..\..\dependencies\PluginConfigApi;..\..\..\dependencies\freeglut\include;..\..\..\dependencies\detours\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<LanguageStandard>stdcpp17</LanguageStandard>
<AdditionalOptions>-d2FH4- %(AdditionalOptions)</AdditionalOptions>
</ClCompile>
@@ -83,7 +83,7 @@
</PrecompiledHeaderFile>
<WarningLevel>Level3</WarningLevel>
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>..\..\..\dependencies\WineVer;..\..\..\dependencies\GPUModel;..\..\..\dependencies\PluginConfigApi;..\..\..\dependencies\freeglut\include;..\..\..\dependencies\detours\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>..\..\..\dependencies\simpleini;..\..\..\dependencies\WineVer;..\..\..\dependencies\GPUModel;..\..\..\dependencies\PluginConfigApi;..\..\..\dependencies\freeglut\include;..\..\..\dependencies\detours\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<LanguageStandard>stdcpp17</LanguageStandard>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<AdditionalOptions>-d2FH4- %(AdditionalOptions)</AdditionalOptions>
@@ -111,6 +111,7 @@
<ItemGroup>
<ClInclude Include="ConfigOption.h" />
<ClInclude Include="framework.h" />
<ClInclude Include="IniReader.h" />
<ClInclude Include="PluginConfig.h" />
<ClInclude Include="SkinnedMessageBox.h" />
<ClInclude Include="TabPadding.h" />
+14 -24
View File
@@ -339,7 +339,7 @@ namespace Launcher {
private: System::Windows::Forms::TabPage^ tabPage_Credits;
private: System::Windows::Forms::TextBox^ textBox1;
private: System::Windows::Forms::TextBox^ creditsTextBox;
private: System::Windows::Forms::GroupBox^ groupBox_Details;
private: System::Windows::Forms::Panel^ panel_Details;
private: System::Windows::Forms::Panel^ panel_Custom;
@@ -397,7 +397,7 @@ private: System::Windows::Forms::Panel^ panel_Custom;
this->panel_Custom = (gcnew System::Windows::Forms::Panel());
this->panel_Plugins = (gcnew System::Windows::Forms::Panel());
this->tabPage_Credits = (gcnew System::Windows::Forms::TabPage());
this->textBox1 = (gcnew System::Windows::Forms::TextBox());
this->creditsTextBox = (gcnew System::Windows::Forms::TextBox());
this->button_Discord = (gcnew System::Windows::Forms::Button());
this->button_github = (gcnew System::Windows::Forms::Button());
this->toolTip1 = (gcnew System::Windows::Forms::ToolTip(this->components));
@@ -507,7 +507,6 @@ private: System::Windows::Forms::Panel^ panel_Custom;
this->groupBox_Details->TabIndex = 11;
this->groupBox_Details->TabStop = false;
this->groupBox_Details->Text = L"Details";
this->groupBox_Details->Enter += gcnew System::EventHandler(this, &ui::groupBox1_Enter);
//
// panel_Details
//
@@ -651,7 +650,7 @@ private: System::Windows::Forms::Panel^ panel_Custom;
//
// tabPage_Credits
//
this->tabPage_Credits->Controls->Add(this->textBox1);
this->tabPage_Credits->Controls->Add(this->creditsTextBox);
this->tabPage_Credits->Location = System::Drawing::Point(4, 29);
this->tabPage_Credits->Name = L"tabPage_Credits";
this->tabPage_Credits->Padding = System::Windows::Forms::Padding(3);
@@ -659,22 +658,20 @@ private: System::Windows::Forms::Panel^ panel_Custom;
this->tabPage_Credits->TabIndex = 5;
this->tabPage_Credits->Text = L"Credits";
this->tabPage_Credits->UseVisualStyleBackColor = true;
this->tabPage_Credits->Click += gcnew System::EventHandler(this, &ui::tabPage_Credits_Click);
//
// textBox1
// creditsTextBox
//
this->textBox1->BackColor = System::Drawing::Color::FromArgb(static_cast<System::Int32>(static_cast<System::Byte>(64)), static_cast<System::Int32>(static_cast<System::Byte>(64)),
this->creditsTextBox->BackColor = System::Drawing::Color::FromArgb(static_cast<System::Int32>(static_cast<System::Byte>(64)), static_cast<System::Int32>(static_cast<System::Byte>(64)),
static_cast<System::Int32>(static_cast<System::Byte>(64)));
this->textBox1->ForeColor = System::Drawing::Color::White;
this->textBox1->Location = System::Drawing::Point(0, 0);
this->textBox1->Multiline = true;
this->textBox1->Name = L"textBox1";
this->textBox1->ReadOnly = true;
this->textBox1->ScrollBars = System::Windows::Forms::ScrollBars::Both;
this->textBox1->Size = System::Drawing::Size(769, 432);
this->textBox1->TabIndex = 0;
this->textBox1->Text = resources->GetString(L"textBox1.Text");
this->textBox1->TextChanged += gcnew System::EventHandler(this, &ui::textBox1_TextChanged);
this->creditsTextBox->ForeColor = System::Drawing::Color::White;
this->creditsTextBox->Location = System::Drawing::Point(0, 0);
this->creditsTextBox->Multiline = true;
this->creditsTextBox->Name = L"creditsTextBox";
this->creditsTextBox->ReadOnly = true;
this->creditsTextBox->ScrollBars = System::Windows::Forms::ScrollBars::Both;
this->creditsTextBox->Size = System::Drawing::Size(769, 432);
this->creditsTextBox->TabIndex = 0;
this->creditsTextBox->Text = resources->GetString(L"creditsTextBox.Text");
//
// button_Discord
//
@@ -969,12 +966,5 @@ private: String^ GPUIssueText;
private: System::Void LinkLabelLinkClickedGPUIssueHandler(System::Object^ sender, System::Windows::Forms::LinkLabelLinkClickedEventArgs^ e) {
SkinnedMessageBox::Show(this, GPUIssueText, "PD Launcher", MessageBoxButtons::OK, MessageBoxIcon::Warning);
}
private: System::Void tabPage_Credits_Click(System::Object^ sender, System::EventArgs^ e) {
}
private: System::Void textBox1_TextChanged(System::Object^ sender, System::EventArgs^ e) {
}
private: System::Void groupBox1_Enter(System::Object^ sender, System::EventArgs^ e) {
}
};
}
+25 -1
View File
@@ -117,7 +117,7 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="textBox1.Text" xml:space="preserve">
<data name="creditsTextBox.Text" xml:space="preserve">
<value>PD Loader is intended for educational purposes only; not for piracy.
Users should possess a legally-obtained dump of the game to use this software.
Please check your local laws/regulataions to verify the legality of tampering
@@ -204,6 +204,30 @@ Launcher, Patches, Render and TLAC plugins utilize files from FreeGLUT:
in this Software without prior written authorization from Pawel W. Olszta.
Launcher uses SimpleIni, licensed under MIT License:
The MIT License (MIT)
Copyright (c) 2006-2013 Brodie Thiesfield
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
DivaSound uses miniaudio (public domain or MIT-0) and BASSASIO (free for
non-commercial use only)