Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: changed directory for where data is stored to be fixed (+ some code fixes) #164

Merged
merged 13 commits into from
Jan 12, 2025
Merged
9 changes: 6 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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)



Expand Down
21 changes: 21 additions & 0 deletions Lampray/Base/lampBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -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*).
*
Expand Down
10 changes: 5 additions & 5 deletions Lampray/Control/lampConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
27 changes: 22 additions & 5 deletions Lampray/Control/lampConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include <list>
#include <filesystem>
#include <variant>
#include "../../game-data/gameControl.h"
#include "../Base/lampBase.h"

Expand Down Expand Up @@ -35,17 +36,16 @@ namespace Lamp::Core {
}

lampConfig(lampConfig const&) = delete;
void operator=(lampConfig const&) = delete;

//((std::string)std::getenv("HOME")) + "/.lamp/
const lampString baseDataPath = "Lamp_Data/";
void operator=(lampConfig const&) = delete;

const lampString baseDataPath = getBaseDataPath();
const lampString saveDataPath = baseDataPath + "Mod_Lists/";
const lampString archiveDataPath = baseDataPath + "Archives/";
const lampString ConfigDataPath = baseDataPath + "Config/";
const lampString DeploymentDataPath = baseDataPath + "Deployment/";
const lampString workingPaths = baseDataPath + "WorkingDirectories/";

lampString bit7zLibaryLocation = "";
lampString bit7zLibraryLocation = "";

const bool defaultCheckForUpdateAtStart = true;
bool checkForUpdatesAtStartup = true;
Expand Down Expand Up @@ -78,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
8 changes: 4 additions & 4 deletions Lampray/Filesystem/lampExtract.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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());
Expand All @@ -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());
Expand Down
14 changes: 5 additions & 9 deletions Lampray/Filesystem/lampIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -210,8 +206,8 @@ 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") {
bit7z::Bit7zLibrary lib{ Lamp::Core::lampConfig::getInstance().bit7zLibaryLocation };
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);
archive.compressTo(lampConfig::getInstance().archiveDataPath+"/"+path.filename().string()+" LMP.zip" );
Expand Down
4 changes: 2 additions & 2 deletions Lampray/Filesystem/lampShare.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down Expand Up @@ -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<Lamp::Core::Base::lampMod::Mod *> TempModList = Lamp::Core::FS::lampIO::loadModList(
Lamp::Games::getInstance().currentGame->Ident().ShortHand, profileName);
std::map<std::string, std::string> files_map = {};
Expand Down
19 changes: 13 additions & 6 deletions Lampray/Lang/lampLang.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
#ifndef LAMPRAY_LAMPLANG_H
#define LAMPRAY_LAMPLANG_H

#include <filesystem>
#include <string>
#include <map>
#include <pugixml.hpp>
#include <unordered_set>
#include "../Control/lampConfig.h"
#include "../Base/lampBase.h"

namespace Lamp {
Expand Down Expand Up @@ -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
Expand All @@ -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")) {
Expand All @@ -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)");
Expand Down Expand Up @@ -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:
Expand Down
File renamed without changes.
5 changes: 2 additions & 3 deletions Lampray/Menu/lampMenu.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
//
// Created by charles on 27/09/23.
//
#include <cstdlib>
#include "lampMenu.h"
#include "lampCustomise .h"
#include "lampCustomise.h"
#include "../Lang/lampLang.h"
#include <cstdlib>
#include "../Control/lampNotification.h"

void Lamp::Core::lampMenu::RunMenus() {
Expand Down
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,29 @@ 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
├── Lamp_Data
│ ├── Archives
│ ├── Config
│ ├── Deployment
│ ├── Language
│ └── Mod_Lists
├── lamp.log
└── Lampray
```

Now you're ready to [mod your game](./docs/managing-mods.md).

## Supported games
Expand Down
2 changes: 1 addition & 1 deletion docs/customizing-lampray.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
<bit7zLibaryLocation>/usr/lib/p7zip/7z.so</bit7zLibaryLocation>
<bit7zLibraryLocation>/usr/lib/p7zip/7z.so</bit7zLibraryLocation>
```

## Customizing your font
Expand Down
Loading
Loading