launcher: components saving

automatically add section to components.ini if required and added loop to save components on quit
This commit is contained in:
somewhatlurker
2019-07-10 04:07:41 +10:00
parent 6e4a4947c3
commit cf6e5ae21a
2 changed files with 66 additions and 3 deletions
+50 -1
View File
@@ -4,6 +4,7 @@
// Windows Header Files
#include <windows.h>
#include <string>
#include <fstream>
int (__cdecl* divaMain)(int argc, const char** argv, const char** envp) = (int(__cdecl*)(int argc, const char** argv, const char** envp))0x140194D90;
@@ -109,4 +110,52 @@ componentInfo componentsArray[] = {
{ L"fps_limiter", L"FPS Limiter", L"Lets you set a framerate cap. The value of the limit is in the options tab.", System::IntPtr::Zero },
{ L"target_inspector", L"Target Inspector", L"Enables hold transfers.", System::IntPtr::Zero },
};
};
bool IsLineInFile(LPCSTR searchLine, LPCWSTR fileName)
{
bool result = false;
std::ifstream fileStream(fileName);
if (!fileStream.is_open())
return false;
std::string line;
while (std::getline(fileStream, line))
{
if (line.compare(searchLine) == 0)
{
result = true;
break;
}
}
fileStream.close();
return result;
}
void PrependFile(LPCSTR newStr, LPCWSTR fileName)
{
std::fstream fileStream(fileName);
if (!fileStream.is_open())
return;
std::string origStr;
// this is apparently more efficient than just going straight into the string
fileStream.seekg(0, std::ios::end);
origStr.reserve(fileStream.tellg());
fileStream.seekg(0, std::ios::beg);
origStr.assign((std::istreambuf_iterator<char>(fileStream)), std::istreambuf_iterator<char>());
std::string outStr = newStr;
outStr += origStr;
fileStream.seekg(0, std::ios::beg);
fileStream << outStr;
fileStream.close();
}
+16 -2
View File
@@ -27,9 +27,17 @@ namespace Launcher {
this->ClientSize = Drawing::Size(444, 323);
TabPadding^ tabpad = gcnew TabPadding(tabControl);
// if components.ini has no section name, add one
if (!IsLineInFile("[components]", COMPONENTS_FILE))
{
PrependFile("[components]\n", COMPONENTS_FILE);
}
this->panel_Components->SuspendLayout();
// Beta version, components not working yet and tab disabled
tabPage_Components->Enabled = false;
// populate components from array in framework
// (easier than manually setting everything up)
int componentsY = 3;
for (componentInfo& component : componentsArray)
{
@@ -953,6 +961,12 @@ private: System::Void SaveSettings() {
userInput = Convert::ToInt32(checkBox_SkipLauncher->Checked).ToString();
input = msclr::interop::marshal_as<std::wstring>(userInput);
WritePrivateProfileStringW(L"launcher", L"skip", input.c_str(), CONFIG_FILE);
for (componentInfo& component : componentsArray)
{
bool enabled = ((CheckBox^)CheckBox::FromHandle(component.cb))->Checked;
WritePrivateProfileStringW(L"components", component.name, enabled ? L"true" : L"false", COMPONENTS_FILE);
}
}
private: System::Void Ui_Load(System::Object^ sender, System::EventArgs^ e){
}