From 653ca504334489391770fab6e40acedb80bd5732 Mon Sep 17 00:00:00 2001 From: Bear Date: Mon, 30 Dec 2024 19:37:35 -0500 Subject: [PATCH 01/13] Fixed base path for configuration --- Lampray/Control/lampConfig.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Lampray/Control/lampConfig.h b/Lampray/Control/lampConfig.h index 2be0bd0..2c298a6 100644 --- a/Lampray/Control/lampConfig.h +++ b/Lampray/Control/lampConfig.h @@ -35,10 +35,9 @@ namespace Lamp::Core { } lampConfig(lampConfig const&) = delete; - void operator=(lampConfig const&) = delete; + void operator=(lampConfig const&) = delete; - //((std::string)std::getenv("HOME")) + "/.lamp/ - const lampString baseDataPath = "Lamp_Data/"; + const lampString baseDataPath = lampString(std::getenv("HOME")) + "/.lampray/"; const lampString saveDataPath = baseDataPath + "Mod_Lists/"; const lampString archiveDataPath = baseDataPath + "Archives/"; const lampString ConfigDataPath = baseDataPath + "Config/"; From 092eb5dc9ea92075986869799d7bd64675562764 Mon Sep 17 00:00:00 2001 From: Bear Date: Mon, 30 Dec 2024 19:41:45 -0500 Subject: [PATCH 02/13] Fixed typo --- Lampray/Control/lampConfig.cpp | 10 +++++----- Lampray/Control/lampConfig.h | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Lampray/Control/lampConfig.cpp b/Lampray/Control/lampConfig.cpp index b44e5ef..f9d1600 100644 --- a/Lampray/Control/lampConfig.cpp +++ b/Lampray/Control/lampConfig.cpp @@ -7,17 +7,17 @@ bool Lamp::Core::lampConfig::init() { Base::lampLog::getInstance().log("Initializing Lampray"); - if((std::string)bit7zLibaryLocation == "") { + if((std::string)bit7zLibraryLocation == "") { Base::lampLog::getInstance().log("Searching for 7z.so"); std::filesystem::path f{"/usr/libexec/p7zip/7z.so"}; if (std::filesystem::exists(f)) { - bit7zLibaryLocation = "/usr/libexec/p7zip/7z.so"; + bit7zLibraryLocation = "/usr/libexec/p7zip/7z.so"; } else if (exists(std::filesystem::path{"/usr/lib/p7zip/7z.so"})) { - bit7zLibaryLocation = "/usr/lib/p7zip/7z.so"; + bit7zLibraryLocation = "/usr/lib/p7zip/7z.so"; } else if (exists(std::filesystem::path{"/usr/lib64/p7zip/7z.so"})) { - bit7zLibaryLocation = "/usr/lib64/p7zip/7z.so"; + bit7zLibraryLocation = "/usr/lib64/p7zip/7z.so"; } else if (exists(std::filesystem::path{"/usr/libexec/7z.so"})) { - bit7zLibaryLocation = "/usr/libexec/7z.so"; + bit7zLibraryLocation = "/usr/libexec/7z.so"; } else { Base::lampLog::getInstance().log("Fatal. Cannot locate 7z.so", Base::lampLog::ERROR, true, Base::lampLog::LMP_NO7ZP); diff --git a/Lampray/Control/lampConfig.h b/Lampray/Control/lampConfig.h index 2c298a6..3740016 100644 --- a/Lampray/Control/lampConfig.h +++ b/Lampray/Control/lampConfig.h @@ -44,7 +44,7 @@ namespace Lamp::Core { const lampString DeploymentDataPath = baseDataPath + "Deployment/"; const lampString workingPaths = baseDataPath + "WorkingDirectories/"; - lampString bit7zLibaryLocation = ""; + lampString bit7zLibraryLocation = ""; const bool defaultCheckForUpdateAtStart = true; bool checkForUpdatesAtStartup = true; From 916d067d058c0ab467f710658c55a5e15bfef7a6 Mon Sep 17 00:00:00 2001 From: Bear Date: Mon, 30 Dec 2024 19:46:14 -0500 Subject: [PATCH 03/13] Libary -> Library typo fix --- Lampray/Filesystem/lampExtract.cpp | 8 ++++---- Lampray/Filesystem/lampIO.cpp | 2 +- Lampray/Filesystem/lampShare.cpp | 4 ++-- main.cpp | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Lampray/Filesystem/lampExtract.cpp b/Lampray/Filesystem/lampExtract.cpp index 19df6c3..36fb2f3 100644 --- a/Lampray/Filesystem/lampExtract.cpp +++ b/Lampray/Filesystem/lampExtract.cpp @@ -17,7 +17,7 @@ Lamp::Core::FS::lampReturn Lamp::Core::FS::lampExtract::extract(const Base::lamp Base::lampLog::getInstance().log("Extracting File: " + mod->ArchivePath, Base::lampLog::LOG); if (std::regex_match((std::string)mod->ArchivePath, std::regex("^.*\\.(zip)$"))) { try { - bit7z::Bit7zLibrary lib{Lamp::Core::lampConfig::getInstance().bit7zLibaryLocation}; + bit7z::Bit7zLibrary lib{Lamp::Core::lampConfig::getInstance().bit7zLibraryLocation}; bit7z::BitArchiveReader reader{lib, mod->ArchivePath, bit7z::BitFormat::Zip}; reader.test(); reader.extract(workingDir + "/ext/" + std::filesystem::path(mod->ArchivePath).filename().stem().string()); @@ -28,14 +28,14 @@ Lamp::Core::FS::lampReturn Lamp::Core::FS::lampExtract::extract(const Base::lamp } } else if (std::regex_match((std::string)mod->ArchivePath, std::regex("^.*\\.(rar)$"))) { try { - bit7z::Bit7zLibrary lib{Lamp::Core::lampConfig::getInstance().bit7zLibaryLocation}; + bit7z::Bit7zLibrary lib{Lamp::Core::lampConfig::getInstance().bit7zLibraryLocation}; bit7z::BitArchiveReader reader{lib, mod->ArchivePath, bit7z::BitFormat::Rar5}; reader.test(); reader.extract(workingDir + "/ext/" + std::filesystem::path(mod->ArchivePath).filename().stem().string()); return Base::lampLog::getInstance().pLog({1, "Extraction Successful. : "+ mod->ArchivePath}, Base::lampLog::LOG); } catch (const bit7z::BitException &ex) { try { - bit7z::Bit7zLibrary lib{Lamp::Core::lampConfig::getInstance().bit7zLibaryLocation}; + bit7z::Bit7zLibrary lib{Lamp::Core::lampConfig::getInstance().bit7zLibraryLocation}; bit7z::BitArchiveReader reader{lib, mod->ArchivePath, bit7z::BitFormat::Rar}; reader.test(); reader.extract(workingDir + "/ext/" + std::filesystem::path(mod->ArchivePath).filename().stem().string()); @@ -47,7 +47,7 @@ Lamp::Core::FS::lampReturn Lamp::Core::FS::lampExtract::extract(const Base::lamp } } else if (std::regex_match((std::string)mod->ArchivePath, std::regex("^.*\\.(7z)$"))) { try { - bit7z::Bit7zLibrary lib{Lamp::Core::lampConfig::getInstance().bit7zLibaryLocation}; + bit7z::Bit7zLibrary lib{Lamp::Core::lampConfig::getInstance().bit7zLibraryLocation}; bit7z::BitArchiveReader reader{lib, mod->ArchivePath, bit7z::BitFormat::SevenZip}; reader.test(); reader.extract(workingDir + "/ext/" + std::filesystem::path(mod->ArchivePath).filename().stem().string()); diff --git a/Lampray/Filesystem/lampIO.cpp b/Lampray/Filesystem/lampIO.cpp index bf45282..e4bc619 100644 --- a/Lampray/Filesystem/lampIO.cpp +++ b/Lampray/Filesystem/lampIO.cpp @@ -211,7 +211,7 @@ void Lamp::Core::FS::lampIO::fileDrop(const char *inputPath) { } } if(std::regex_match(path.filename().string(), std::regex("^.*\\.(pak)$"))){ if((std::string)Lamp::Games::getInstance().currentGame->Ident().ReadableName == "Baldur's Gate 3") { - bit7z::Bit7zLibrary lib{ Lamp::Core::lampConfig::getInstance().bit7zLibaryLocation }; + bit7z::Bit7zLibrary lib{ Lamp::Core::lampConfig::getInstance().bit7zLibraryLocation }; bit7z::BitArchiveWriter archive{ lib, bit7z::BitFormat::SevenZip }; archive.addFile(path); archive.compressTo(lampConfig::getInstance().archiveDataPath+"/"+path.filename().string()+" LMP.zip" ); diff --git a/Lampray/Filesystem/lampShare.cpp b/Lampray/Filesystem/lampShare.cpp index 350a22d..6375849 100644 --- a/Lampray/Filesystem/lampShare.cpp +++ b/Lampray/Filesystem/lampShare.cpp @@ -197,7 +197,7 @@ void Lamp::Core::FS::lampShare::importProfile() { Lamp::Core::lampControl::getInstance().inDeployment = true; Lamp::Core::lampControl::getInstance().deploymentStageTitle = "Importing Profile"; Lamp::Core::lampControl::getInstance().deplopmentTracker = {0,11}; - bit7z::Bit7zLibrary lib{Lamp::Core::lampConfig::getInstance().bit7zLibaryLocation}; + bit7z::Bit7zLibrary lib{Lamp::Core::lampConfig::getInstance().bit7zLibraryLocation}; std::filesystem::create_directories("import/"); nfdchar_t *outPath = NULL; nfdresult_t result = NFD_OpenDialog( "lampProfile", NULL, &outPath ); @@ -329,7 +329,7 @@ void Lamp::Core::FS::lampShare::exportProfile(std::string profileNameS) { Lamp::Core::lampControl::getInstance().inDeployment = true; Lamp::Core::lampControl::getInstance().deploymentStageTitle = "Creating "+profileName +".lampProfile"; Lamp::Core::lampControl::getInstance().deplopmentTracker = {0,3}; - bit7z::Bit7zLibrary lib{Lamp::Core::lampConfig::getInstance().bit7zLibaryLocation}; + bit7z::Bit7zLibrary lib{Lamp::Core::lampConfig::getInstance().bit7zLibraryLocation}; std::vector TempModList = Lamp::Core::FS::lampIO::loadModList( Lamp::Games::getInstance().currentGame->Ident().ShortHand, profileName); std::map files_map = {}; diff --git a/main.cpp b/main.cpp index d975f88..bec3555 100644 --- a/main.cpp +++ b/main.cpp @@ -129,12 +129,12 @@ int main(int, char**) Lamp::Core::FS::lampUpdate::getInstance().checkForUpdates(); } Lamp::Core::lampConfig::getInstance().lampFlags["showIntroMenu"]=(std::string)Lamp::Core::FS::lampIO::loadKeyData("showIntroMenu","LAMP CONFIG").returnReason; - Lamp::Core::lampConfig::getInstance().bit7zLibaryLocation = (std::string)Lamp::Core::FS::lampIO::loadKeyData("bit7zLibaryLocation","LAMP CONFIG").returnReason; + Lamp::Core::lampConfig::getInstance().bit7zLibraryLocation = (std::string)Lamp::Core::FS::lampIO::loadKeyData("bit7zLibraryLocation","LAMP CONFIG").returnReason; bool found7z = Lamp::Core::lampConfig::getInstance().init(); if(!found7z){ Lamp::Core::lampNotification::getInstance().pushErrorNotification(Lamp::Core::lampLang::getInstance().LS("LAMPRAY_ERROR_7Z")); } - Lamp::Core::FS::lampIO::saveKeyData("bit7zLibaryLocation", Lamp::Core::lampConfig::getInstance().bit7zLibaryLocation, "LAMP CONFIG"); + Lamp::Core::FS::lampIO::saveKeyData("bit7zLibraryLocation", Lamp::Core::lampConfig::getInstance().bit7zLibraryLocation, "LAMP CONFIG"); Lamp::Core::lampMenu Menus; // This is a very inefficent way of doing this. From e1949ad9deebea43a3eadd6373e66583330cea36 Mon Sep 17 00:00:00 2001 From: Bear Date: Mon, 30 Dec 2024 19:56:43 -0500 Subject: [PATCH 04/13] Added equality operator to lampString --- Lampray/Base/lampBase.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/Lampray/Base/lampBase.h b/Lampray/Base/lampBase.h index 153dd4c..5549fbe 100644 --- a/Lampray/Base/lampBase.h +++ b/Lampray/Base/lampBase.h @@ -134,6 +134,27 @@ namespace Lamp::Core::Base{ return data < other.data; } + + /** + * brief Custom equality operator for lampStrings + * + * @param other The lampString to compare with + * @return true if the contents of the strings are the same, false otherwise. + */ + bool operator==(const lampString& other) const { + return data == other.data; + } + + /** + * @brief Custom equality operator for C-style strings + * + * @param the string to compare to + * @return true if the contents of the strings are the same, fale otherwise. + */ + bool operator==(const char* other) const { + return data == other; + } + /** * @brief Custom operator to convert a lampString to a C-style string (const char*). * From c5838b941668dc7e21695af30beee66d89365a4c Mon Sep 17 00:00:00 2001 From: Bear Date: Mon, 30 Dec 2024 20:09:09 -0500 Subject: [PATCH 05/13] Removed unneeded explicit conversions --- Lampray/Filesystem/lampIO.cpp | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/Lampray/Filesystem/lampIO.cpp b/Lampray/Filesystem/lampIO.cpp index e4bc619..36c75f0 100644 --- a/Lampray/Filesystem/lampIO.cpp +++ b/Lampray/Filesystem/lampIO.cpp @@ -106,8 +106,8 @@ Lamp::Core::FS::lampIO::saveModList(Lamp::Core::FS::lampString game, std::vector Lamp::Core::FS::lampReturn Lamp::Core::FS::lampIO::saveKeyData(Lamp::Core::FS::lampString key, Lamp::Core::FS::lampString data, Lamp::Core::FS::lampString game) { - std::string actual = game; - if((std::string)game == "") { + lampString actual = game; + if(game == "") { actual = (std::string)Lamp::Games::getInstance().currentGame->Ident().ShortHand;; } Base::lampLog::getInstance().log("Saving " + actual + ":" + key + ":" + data); @@ -148,17 +148,13 @@ Lamp::Core::FS::lampIO::saveKeyData(Lamp::Core::FS::lampString key, Lamp::Core:: Base::lampLog::getInstance().log("Failed to save " + game + ":" + key + ":" + ":" + data, Base::lampLog::ERROR, true, Base::lampLog::LMP_KEYSAVEFAILED); return Lamp::Core::FS::lampReturn(0); - - - - } Lamp::Core::FS::lampReturn Lamp::Core::FS::lampIO::loadKeyData(Lamp::Core::FS::lampString key, Lamp::Core::FS::lampString game) { std::string actual = game; - if((std::string)game == "") { + if(game == "") { actual = (std::string)Lamp::Games::getInstance().currentGame->Ident().ShortHand;; } Base::lampLog::lampLog::getInstance().log("Loading " + actual + ":" + key); @@ -210,7 +206,7 @@ void Lamp::Core::FS::lampIO::fileDrop(const char *inputPath) { Base::lampLog::LMP_NOFILEDROP); } } if(std::regex_match(path.filename().string(), std::regex("^.*\\.(pak)$"))){ - if((std::string)Lamp::Games::getInstance().currentGame->Ident().ReadableName == "Baldur's Gate 3") { + if(Lamp::Games::getInstance().currentGame->Ident().ReadableName == "Baldur's Gate 3") { bit7z::Bit7zLibrary lib{ Lamp::Core::lampConfig::getInstance().bit7zLibraryLocation }; bit7z::BitArchiveWriter archive{ lib, bit7z::BitFormat::SevenZip }; archive.addFile(path); From 8042d485388bf5fc7876af7d76e9740fd3197a6d Mon Sep 17 00:00:00 2001 From: Bear Date: Tue, 31 Dec 2024 00:10:38 -0500 Subject: [PATCH 06/13] Added 7zip location for not pzip installation --- Lampray/Control/lampConfig.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Lampray/Control/lampConfig.cpp b/Lampray/Control/lampConfig.cpp index f9d1600..72c3c2e 100644 --- a/Lampray/Control/lampConfig.cpp +++ b/Lampray/Control/lampConfig.cpp @@ -18,6 +18,8 @@ bool Lamp::Core::lampConfig::init() { bit7zLibraryLocation = "/usr/lib64/p7zip/7z.so"; } else if (exists(std::filesystem::path{"/usr/libexec/7z.so"})) { bit7zLibraryLocation = "/usr/libexec/7z.so"; + } else if (exists(std::filesystem::path{"/usr/lib/7zip/7z.so"})) { + bit7zLibraryLocation = "/usr/lib/7zip/7z.so"; } else { Base::lampLog::getInstance().log("Fatal. Cannot locate 7z.so", Base::lampLog::ERROR, true, Base::lampLog::LMP_NO7ZP); From b5c862e9e6d99652a82f78f97cc2c5365fe3650e Mon Sep 17 00:00:00 2001 From: Bear Date: Tue, 31 Dec 2024 00:36:53 -0500 Subject: [PATCH 07/13] Fixed appData clean up code --- game-data/BG3/BG3.cpp | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/game-data/BG3/BG3.cpp b/game-data/BG3/BG3.cpp index 92125f6..39eda02 100644 --- a/game-data/BG3/BG3.cpp +++ b/game-data/BG3/BG3.cpp @@ -2,6 +2,7 @@ // Created by charles on 27/09/23. // +#include #include #include "BG3.h" #include "../../Lampray/Control/lampControl.h" @@ -232,15 +233,11 @@ Lamp::Game::lampReturn Lamp::Game::BG3::preCleanUp() { Lamp::Core::lampControl::getInstance().deplopmentTracker.first = 6; - if(std::filesystem::is_empty(keyInfo["installDirPath"])){ - // Overlay did exist, not anymore. - } - std::filesystem::path installPath(keyInfo["installDirPath"]); if (std::filesystem::exists(installPath) && std::filesystem::is_directory(installPath) && std::filesystem::exists(installPath.parent_path() / ("Lampray Managed - " + installPath.stem().string())) && std::filesystem::is_directory(installPath.parent_path() / ("Lampray Managed - " + installPath.stem().string()))) { - if(std::filesystem::is_empty(std::filesystem::path(keyInfo["installDirPath"]))){ + if(std::filesystem::is_empty(installPath)){ system(("pkexec umount \""+Lamp::Games::getInstance().currentGame->KeyInfo()["installDirPath"]+"\"").c_str()); try { std::filesystem::rename( @@ -251,28 +248,29 @@ Lamp::Game::lampReturn Lamp::Game::BG3::preCleanUp() { } skipMount = false; - }else { + } else { skipMount = true; } + } + + std::filesystem::path appPath(keyInfo["appDataPath"]); + std::filesystem::path tempAppPath(appPath.parent_path() / ("Lampray Managed - " + appPath.stem().string())); + + if(std::filesystem::exists(appPath) && std::filesystem::is_directory(appPath) + && std::filesystem::exists(tempAppPath) && std::filesystem::is_directory(tempAppPath)) { + if(std::filesystem::is_empty(std::filesystem::path(KeyInfo()["appDataPath"]+"/Mods"))){ system(("pkexec umount \""+Lamp::Games::getInstance().currentGame->KeyInfo()["appDataPath"]+"/Mods\"").c_str()); try { - std::filesystem::rename(std::filesystem::path(KeyInfo()["appDataPath"] + "/Mods").parent_path() / - ("Lampray Managed - " + - std::filesystem::path(KeyInfo()["appDataPath"] + "/Mods").stem().string()), - std::filesystem::path(KeyInfo()["appDataPath"] + "/Mods")); + std::filesystem::rename(tempAppPath / "Mods", + appPath / "Mods"); } catch (std::exception ex) { } skipMount = false; + } else { + skipMount = true; } - - std::cout << "The version directory exists in the parent path." << std::endl; - } else { - if(std::filesystem::is_empty(keyInfo["installDirPath"])){ - // panic - } - // we good } // std::string managedString = std::string("Lampray Managed - ") + gamePath.filename().string(); From 056e10a5499c12def5e0dc2d9c56df17d18cccee Mon Sep 17 00:00:00 2001 From: Bear Date: Tue, 31 Dec 2024 03:22:30 -0500 Subject: [PATCH 08/13] Removed space from header name --- CMakeLists.txt | 2 +- Lampray/Menu/{lampCustomise .h => lampCustomise.h} | 0 Lampray/Menu/lampMenu.cpp | 5 ++--- main.cpp | 2 +- 4 files changed, 4 insertions(+), 5 deletions(-) rename Lampray/Menu/{lampCustomise .h => lampCustomise.h} (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index c6f9ff6..a88221e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -39,7 +39,7 @@ add_executable(Lampray main.cpp Lampray/Filesystem/lampUpdate.cpp Lampray/Control/lampGames.h Lampray/Filesystem/lampShare.cpp - "Lampray/Menu/lampCustomise .h" + Lampray/Menu/lampCustomise.h Lampray/Filesystem/lampTrack.cpp game-data/C77/C77.cpp game-data/C77/C77.h diff --git a/Lampray/Menu/lampCustomise .h b/Lampray/Menu/lampCustomise.h similarity index 100% rename from Lampray/Menu/lampCustomise .h rename to Lampray/Menu/lampCustomise.h diff --git a/Lampray/Menu/lampMenu.cpp b/Lampray/Menu/lampMenu.cpp index 2b5e0de..e7f8722 100644 --- a/Lampray/Menu/lampMenu.cpp +++ b/Lampray/Menu/lampMenu.cpp @@ -1,10 +1,9 @@ // // Created by charles on 27/09/23. -// +#include #include "lampMenu.h" -#include "lampCustomise .h" +#include "lampCustomise.h" #include "../Lang/lampLang.h" -#include #include "../Control/lampNotification.h" void Lamp::Core::lampMenu::RunMenus() { diff --git a/main.cpp b/main.cpp index bec3555..2997f12 100644 --- a/main.cpp +++ b/main.cpp @@ -4,7 +4,7 @@ #include "Lampray/Lang/lampLang.h" #include "Lampray/Control/lampControl.h" #include "Lampray/Menu/lampMenu.h" -#include "Lampray/Menu/lampCustomise .h" +#include "Lampray/Menu/lampCustomise.h" #include #include "SDL2/SDL.h" From 4619671038672604977ec6f33b5fe1c2b8f734a6 Mon Sep 17 00:00:00 2001 From: Bear Date: Tue, 31 Dec 2024 09:11:59 -0500 Subject: [PATCH 09/13] updated docs wrt Libary -> Library --- docs/customizing-lampray.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/customizing-lampray.md b/docs/customizing-lampray.md index e08a659..59a3e02 100644 --- a/docs/customizing-lampray.md +++ b/docs/customizing-lampray.md @@ -16,7 +16,7 @@ In most cases, Lampray can find your 7-Zip installation automatically. However, First open `~/Lampray/Config/config.mdf` in your text editor, then find and replace the following line with the path to your `7z.so` utility. ```sql -/usr/lib/p7zip/7z.so +/usr/lib/p7zip/7z.so ``` ## Customizing your font From be95dcafde209400fb6a923f18731a294f1b52e9 Mon Sep 17 00:00:00 2001 From: Bear Date: Tue, 31 Dec 2024 09:15:35 -0500 Subject: [PATCH 10/13] Undid finding invalid 7z.so --- Lampray/Control/lampConfig.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/Lampray/Control/lampConfig.cpp b/Lampray/Control/lampConfig.cpp index 72c3c2e..f9d1600 100644 --- a/Lampray/Control/lampConfig.cpp +++ b/Lampray/Control/lampConfig.cpp @@ -18,8 +18,6 @@ bool Lamp::Core::lampConfig::init() { bit7zLibraryLocation = "/usr/lib64/p7zip/7z.so"; } else if (exists(std::filesystem::path{"/usr/libexec/7z.so"})) { bit7zLibraryLocation = "/usr/libexec/7z.so"; - } else if (exists(std::filesystem::path{"/usr/lib/7zip/7z.so"})) { - bit7zLibraryLocation = "/usr/lib/7zip/7z.so"; } else { Base::lampLog::getInstance().log("Fatal. Cannot locate 7z.so", Base::lampLog::ERROR, true, Base::lampLog::LMP_NO7ZP); From f1bb183a23c3a3d26176bbeadfc0ddc9b1549c5f Mon Sep 17 00:00:00 2001 From: Bear Date: Thu, 2 Jan 2025 16:21:03 -0500 Subject: [PATCH 11/13] Added whether to use XDG directories as a compile option --- CMakeLists.txt | 7 +++++-- Lampray/Control/lampConfig.h | 22 ++++++++++++++++++++-- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a88221e..9b57de6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,9 +4,9 @@ project(Lampray) set(CMAKE_CXX_STANDARD 17) +option(USE_XDG_DIRECTORY "Use XDG directory to store data instead of the working directory" ON) - -add_executable(Lampray main.cpp +add_executable(${PROJECT_NAME} main.cpp third-party/imgui/imconfig.h third-party/imgui/imgui.cpp third-party/imgui/imgui.h @@ -50,6 +50,9 @@ add_executable(Lampray main.cpp Lampray/Lang/lampLang.h ) +if(USE_XDG_DIRECTORY) + target_compile_definitions(${PROJECT_NAME} PUBLIC USE_XDG) +endif(USE_XDG_DIRECTORY) diff --git a/Lampray/Control/lampConfig.h b/Lampray/Control/lampConfig.h index 3740016..a55cd28 100644 --- a/Lampray/Control/lampConfig.h +++ b/Lampray/Control/lampConfig.h @@ -7,6 +7,7 @@ #include #include +#include #include "../../game-data/gameControl.h" #include "../Base/lampBase.h" @@ -36,8 +37,8 @@ namespace Lamp::Core { lampConfig(lampConfig const&) = delete; void operator=(lampConfig const&) = delete; - - const lampString baseDataPath = lampString(std::getenv("HOME")) + "/.lampray/"; + + const lampString baseDataPath = getBaseDataPath(); const lampString saveDataPath = baseDataPath + "Mod_Lists/"; const lampString archiveDataPath = baseDataPath + "Archives/"; const lampString ConfigDataPath = baseDataPath + "Config/"; @@ -77,6 +78,23 @@ namespace Lamp::Core { * The constructor is private to ensure that only one instance of `lampConfig` can exist. */ lampConfig(){}; + + static lampString getBaseDataPath() { + std::string ret = ""; +#ifdef USE_XDG + char *xdg_data_home = std::getenv("XDG_DATA_HOME"); + + if (!xdg_data_home) { + ret += std::getenv("HOME"); + ret += "/.local/share"; + } + + ret += "/lampray/"; +#else + ret = "Lamp_Data/"; +#endif + return lampString(ret); + } }; }; #endif //LAMP_LAMPCONFIG_H From 3081cea11b471e88a3ba1d2757051a6862190640 Mon Sep 17 00:00:00 2001 From: Bear Date: Thu, 2 Jan 2025 23:41:51 -0500 Subject: [PATCH 12/13] Moved lang files into the working directory + cleaned up logic --- Lampray/Lang/lampLang.h | 19 +++++++++++++------ main.cpp | 34 ++++++++++++++-------------------- 2 files changed, 27 insertions(+), 26 deletions(-) diff --git a/Lampray/Lang/lampLang.h b/Lampray/Lang/lampLang.h index 1bac271..49a2757 100644 --- a/Lampray/Lang/lampLang.h +++ b/Lampray/Lang/lampLang.h @@ -5,10 +5,12 @@ #ifndef LAMPRAY_LAMPLANG_H #define LAMPRAY_LAMPLANG_H +#include #include #include #include #include +#include "../Control/lampConfig.h" #include "../Base/lampBase.h" namespace Lamp { @@ -49,10 +51,10 @@ namespace Lamp { } - Base::lampTypes::lampReturn build(Base::lampTypes::lampString filePath){ + Base::lampTypes::lampReturn build(const std::filesystem::path& filePath){ if (!std::filesystem::exists(filePath)) { - return {false, "File not found: " + filePath}; + return {false, "File not found: " + filePath.string()}; } // Load the XML document @@ -68,7 +70,7 @@ namespace Lamp { if (langNode) { LanguageName = langNode.attribute("name").value(); } else { - return {false,"Failed to load language. No Name."}; + return {false, "Failed to load language. No Name."}; } for (pugi::xml_node node = langNode.child("LangNode"); node; node = node.next_sibling("LangNode")) { @@ -93,7 +95,7 @@ namespace Lamp { LanguageContainer CurrentLanguage; - void createEnglishUK(){ + std::filesystem::path createEnglishUK(){ pugi::xml_document doc; auto root = doc.append_child("LamprayLang"); root.append_attribute("name").set_value("English (UK)"); @@ -194,8 +196,13 @@ This action cannot be undone.)"); addLangNode("LAMPRAY_SELECT_PATH", "Select Path"); addLangNode("LAMPRAY_ERROR_7Z", "Failed to find 7z.so! Many actions, such as deployment, will not function correctly. See the wiki for more information."); addLangNode("LAMPRAY_WARN_GAME_PATH", " directories are not set. Deployment will not work until you have set them in the Game Configuration menu."); - std::filesystem::create_directories("Lamp_Language/"); - doc.save_file("Lamp_Language/English (UK).xml"); + + auto baseDirectory = Lamp::Core::lampConfig::getInstance().baseDataPath + "Language/"; + std::filesystem::create_directory(baseDirectory); + + std::filesystem::path path = baseDirectory + "English (UK).xml"; + doc.save_file(path.c_str()); + return path; } private: diff --git a/main.cpp b/main.cpp index 2997f12..518d576 100644 --- a/main.cpp +++ b/main.cpp @@ -1,3 +1,4 @@ +#include "Lampray/Control/lampConfig.h" #include "third-party/imgui/imgui.h" #include "third-party/imgui/imgui_impl_sdl2.h" #include "third-party/imgui/imgui_impl_sdlrenderer2.h" @@ -47,7 +48,7 @@ int main(int, char**) ImGui_ImplSDL2_InitForSDLRenderer(window, renderer); ImGui_ImplSDLRenderer2_Init(renderer); - std::filesystem::path fontFolder("Lamp_Font/"); + auto fontFolder = Lamp::Core::lampConfig::getInstance().baseDataPath + "Fonts/"; // Check if the "Font" folder exists if (std::filesystem::is_directory(fontFolder)) { @@ -61,29 +62,22 @@ int main(int, char**) ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f); - std::string languageCheck = Lamp::Core::FS::lampIO::loadKeyData("LanguagePath", "LAMP CONFIG"); - Lamp::Core::lampLang::getInstance().CurrentLanguage = Lamp::Core::lampLang::LanguageContainer(); - - if(languageCheck != ""){ - if (!std::filesystem::exists(languageCheck)) { - Lamp::Core::Base::lampLog::getInstance().log(Lamp::Core::lampLang::getInstance().CurrentLanguage.build(languageCheck).returnReason); - }else{ - if (!std::filesystem::exists("Lamp_Language/English (UK).xml")) { - Lamp::Core::lampLang::getInstance().createEnglishUK(); - } - Lamp::Core::Base::lampLog::getInstance().log(Lamp::Core::lampLang::getInstance().CurrentLanguage.build("Lamp_Language/English (UK).xml").returnReason); - } - }else{ - if (!std::filesystem::exists("Lamp_Language/English (UK).xml")) { - Lamp::Core::lampLang::getInstance().createEnglishUK(); - } - Lamp::Core::Base::lampLog::getInstance().log(Lamp::Core::lampLang::getInstance().CurrentLanguage.build("Lamp_Language/English (UK).xml").returnReason); + std::string preferredLanguage = Lamp::Core::FS::lampIO::loadKeyData("LanguagePath", "LAMP CONFIG"); + Lamp::Core::lampLang::getInstance().CurrentLanguage = Lamp::Core::lampLang::LanguageContainer(); + + auto languageLoaded = Lamp::Core::lampLang::getInstance() + .CurrentLanguage.build(preferredLanguage); + Lamp::Core::Base::lampLog::getInstance().log(languageLoaded.returnReason); + if(!languageLoaded) { + auto path = Lamp::Core::lampLang::getInstance().createEnglishUK(); + Lamp::Core::Base::lampLog::getInstance().log( + Lamp::Core::lampLang::getInstance() + .CurrentLanguage.build(path) + .returnReason); } - - Lamp::Core::lampControl::getInstance().Colour_SearchHighlight = Lamp::Core::Base::lampTypes::lampHexAlpha(Lamp::Core::lampCustomise::getInstance().defaultColours[13]); ImGui::GetStyle().Colors[ImGuiCol_Text] = Lamp::Core::Base::lampTypes::lampHexAlpha(Lamp::Core::lampCustomise::getInstance().defaultColours[0]); ImGui::GetStyle().Colors[ImGuiCol_WindowBg] = Lamp::Core::Base::lampTypes::lampHexAlpha(Lamp::Core::lampCustomise::getInstance().defaultColours[1]); From a6909a4be6763b791428a940ea81647cf7168953 Mon Sep 17 00:00:00 2001 From: Bear Date: Fri, 3 Jan 2025 13:35:46 -0500 Subject: [PATCH 13/13] Updated README.md --- README.md | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e1037fb..44f2a98 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,17 @@ Launch the Lampray application. The first time you run Lampray, the following files and directories will be created: +If the CMake option `USE_XDG_DIRECTORY` is set (default): +```bash +~ +└── $XDG_DATA_HOME + ├── Archives + ├── Config + ├── Deployment + ├── Language + └── Mod_Lists +``` +If `USE_XDG_DIRECTORY` is not set: ```bash ~ ├── imgui.ini @@ -58,11 +69,11 @@ The first time you run Lampray, the following files and directories will be crea │ ├── Archives │ ├── Config │ ├── Deployment +│ ├── Language │ └── Mod_Lists ├── lamp.log └── Lampray ``` - Now you're ready to [mod your game](./docs/managing-mods.md). ## Supported games