Skip to content

Commit

Permalink
refactor: refactoring some code
Browse files Browse the repository at this point in the history
  • Loading branch information
ShrBox committed Aug 4, 2024
1 parent 9ee412c commit c5fb903
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
"type": "native",
"description": "LLMoney, but adapted to LeviLamina",
"author": "LiteLDev",
"version": "0.8.2"
"version": "0.8.3"
}
21 changes: 11 additions & 10 deletions src/API.cpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
#include "Event.h"
#include "LLMoney.h"
#include "LegacyMoney.h"
#include "Settings.h"
#include "ll/api/Logger.h"
#include "ll/api/service/PlayerInfo.h"
#include "sqlitecpp/SQLiteCpp.h"
#include <memory>
#include <vector>


static std::unique_ptr<SQLite::Database> db;
ll::Logger moneylog("LLMoney");
#undef snprintf

struct cleanSTMT {
Expand Down Expand Up @@ -52,7 +51,7 @@ bool initDB() {
Time COLLATE BINARY COLLATE BINARY DESC \
); ");
} catch (std::exception const& e) {
moneylog.error("Database error: {}", e.what());
legacy_money::LegacyMoney::getInstance().getSelf().getLogger().error("Database error: {}", e.what());
return false;
}
ConvertData();
Expand Down Expand Up @@ -81,7 +80,7 @@ long long LLMoney_Get(std::string xuid) {
}
return rv;
} catch (std::exception const& e) {
moneylog.error("Database error: {}\n", e.what());
legacy_money::LegacyMoney::getInstance().getSelf().getLogger().error("Database error: {}\n", e.what());
return -1;
}
}
Expand Down Expand Up @@ -156,7 +155,7 @@ bool LLMoney_Trans(std::string from, std::string to, long long val, std::string
return true;
} catch (std::exception const& e) {
db->exec("rollback");
moneylog.error("Database error: {}\n", e.what());
legacy_money::LegacyMoney::getInstance().getSelf().getLogger().error("Database error: {}\n", e.what());
return false;
}
}
Expand Down Expand Up @@ -214,7 +213,7 @@ std::vector<std::pair<std::string, long long>> LLMoney_Ranking(unsigned short nu
get.clearBindings();
return mapTemp;
} catch (std::exception const& e) {
moneylog.error("Database error: {}\n", e.what());
legacy_money::LegacyMoney::getInstance().getSelf().getLogger().error("Database error: {}\n", e.what());
return {};
}
}
Expand Down Expand Up @@ -249,7 +248,7 @@ std::string LLMoney_GetHist(std::string xuid, int timediff) {
get.clearBindings();
return rv;
} catch (std::exception const& e) {
moneylog.error("Database error: {}\n", e.what());
legacy_money::LegacyMoney::getInstance().getSelf().getLogger().error("Database error: {}\n", e.what());
return "failed";
}
}
Expand All @@ -262,7 +261,9 @@ void LLMoney_ClearHist(int difftime) {

void ConvertData() {
if (std::filesystem::exists("plugins\\LLMoney\\money.db")) {
moneylog.info("Old money data detected, try to convert old data to new data");
legacy_money::LegacyMoney::getInstance().getSelf().getLogger().info(
"Old money data detected, try to convert old data to new data"
);
try {
std::unique_ptr<SQLite::Database> db2 = std::make_unique<SQLite::Database>(
"plugins\\LLMoney\\money.db",
Expand All @@ -285,10 +286,10 @@ void ConvertData() {
}
get.reset();
} catch (std::exception& e) {
moneylog.error("{}", e.what());
legacy_money::LegacyMoney::getInstance().getSelf().getLogger().error("{}", e.what());
}
std::filesystem::rename("plugins\\LLMoney\\money.db", "plugins\\LLMoney\\money_old.db");
moneylog.info("Conversion completed");
legacy_money::LegacyMoney::getInstance().getSelf().getLogger().info("Conversion completed");
}
}
// #include <RemoteCallAPI.h>
Expand Down
2 changes: 1 addition & 1 deletion src/LLMoney.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include "ll/api/service/PlayerInfo.h"
#include <vector>

#ifdef LLMONEY_EXPORTS
#define LLMONEY_API __declspec(dllexport)
Expand Down
3 changes: 1 addition & 2 deletions src/LegacyMoney.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,7 @@ bool initDB();

bool cmp(std::pair<std::string, long long> a, std::pair<std::string, long long> b) { return a.second > b.second; }


using ll::i18n_literals::operator""_tr;
using namespace ll::i18n_literals;

void loadCfg() {
// config
Expand Down
4 changes: 2 additions & 2 deletions tooth.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"format_version": 2,
"tooth": "github.com/LiteLDev/LegacyMoney",
"version": "0.8.2",
"version": "0.8.3",
"info": {
"name": "LegacyMoney",
"description": "LLMoney, but adapted to LeviLamina",
Expand All @@ -13,7 +13,7 @@
"economy"
]
},
"asset_url": "https://github.com/LiteLDev/LegacyMoney/releases/download/v0.8.2/LegacyMoney-windows-x64.zip",
"asset_url": "https://github.com/LiteLDev/LegacyMoney/releases/download/v0.8.3/LegacyMoney-windows-x64.zip",
"prerequisites": {
"github.com/LiteLDev/LeviLamina": ">=0.13.4 <0.14.0"
},
Expand Down

0 comments on commit c5fb903

Please sign in to comment.