From cf6e5ae21ab4d81af94c83be72d59a031a44de09 Mon Sep 17 00:00:00 2001 From: somewhatlurker <52014015+somewhatlurker@users.noreply.github.com> Date: Wed, 10 Jul 2019 04:07:41 +1000 Subject: [PATCH] launcher: components saving automatically add section to components.ini if required and added loop to save components on quit --- source/plugins/Launcher/framework.h | 51 ++++++++++++++++++++++++++++- source/plugins/Launcher/ui.h | 18 ++++++++-- 2 files changed, 66 insertions(+), 3 deletions(-) diff --git a/source/plugins/Launcher/framework.h b/source/plugins/Launcher/framework.h index 2ea4789..741e057 100644 --- a/source/plugins/Launcher/framework.h +++ b/source/plugins/Launcher/framework.h @@ -4,6 +4,7 @@ // Windows Header Files #include #include +#include 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 }, -}; \ No newline at end of file +}; + +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(fileStream)), std::istreambuf_iterator()); + + std::string outStr = newStr; + outStr += origStr; + + fileStream.seekg(0, std::ios::beg); + fileStream << outStr; + fileStream.close(); +} \ No newline at end of file diff --git a/source/plugins/Launcher/ui.h b/source/plugins/Launcher/ui.h index 6d7717d..ac9fe4a 100644 --- a/source/plugins/Launcher/ui.h +++ b/source/plugins/Launcher/ui.h @@ -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(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){ }