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){ }