mirror of
https://github.com/BeamMP/BeamMP-Launcher.git
synced 2025-07-03 08:26:01 +00:00
Implement DeleteDuplicateMods option
This commit is contained in:
parent
8d641f326d
commit
2529146d5a
@ -30,6 +30,7 @@ extern uint64_t UDPSock;
|
|||||||
extern uint64_t TCPSock;
|
extern uint64_t TCPSock;
|
||||||
extern std::string Branch;
|
extern std::string Branch;
|
||||||
extern std::string CachingDirectory;
|
extern std::string CachingDirectory;
|
||||||
|
extern bool deleteDuplicateMods;
|
||||||
extern bool TCPTerminate;
|
extern bool TCPTerminate;
|
||||||
extern std::string LastIP;
|
extern std::string LastIP;
|
||||||
extern std::string MStatus;
|
extern std::string MStatus;
|
||||||
|
@ -15,6 +15,7 @@ namespace fs = std::filesystem;
|
|||||||
|
|
||||||
std::string Branch;
|
std::string Branch;
|
||||||
std::string CachingDirectory = "./Resources";
|
std::string CachingDirectory = "./Resources";
|
||||||
|
bool deleteDuplicateMods = false;
|
||||||
|
|
||||||
void ParseConfig(const nlohmann::json& d) {
|
void ParseConfig(const nlohmann::json& d) {
|
||||||
if (d["Port"].is_number()) {
|
if (d["Port"].is_number()) {
|
||||||
@ -42,6 +43,11 @@ void ParseConfig(const nlohmann::json& d) {
|
|||||||
options.no_launch = dev;
|
options.no_launch = dev;
|
||||||
options.no_update = dev;
|
options.no_update = dev;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (d.contains(("DeleteDuplicateMods")) && d["DeleteDuplicateMods"].is_boolean()) {
|
||||||
|
deleteDuplicateMods = d["DeleteDuplicateMods"].get<bool>();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConfigInit() {
|
void ConfigInit() {
|
||||||
|
@ -475,10 +475,28 @@ void NewSyncResources(SOCKET Sock, const std::string& Mods, const std::vector<Mo
|
|||||||
|
|
||||||
info("Syncing...");
|
info("Syncing...");
|
||||||
|
|
||||||
|
std::vector<std::pair<std::string, std::filesystem::path>> CachedMods = {};
|
||||||
|
if (deleteDuplicateMods) {
|
||||||
|
for (const auto& entry : fs::directory_iterator(CachingDirectory)) {
|
||||||
|
if (entry.is_regular_file() && entry.path().extension() == ".zip" && entry.path().filename().string().length() > 10) {
|
||||||
|
CachedMods.push_back(std::make_pair(entry.path().filename().string().substr(0, entry.path().filename().string().length() - 13) + ".zip", entry.path()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int ModNo = 0;
|
int ModNo = 0;
|
||||||
int TotalMods = ModInfos.size();
|
int TotalMods = ModInfos.size();
|
||||||
for (auto ModInfoIter = ModInfos.begin(), AlsoModInfoIter = ModInfos.begin(); ModInfoIter != ModInfos.end() && !Terminate; ++ModInfoIter, ++AlsoModInfoIter) {
|
for (auto ModInfoIter = ModInfos.begin(), AlsoModInfoIter = ModInfos.begin(); ModInfoIter != ModInfos.end() && !Terminate; ++ModInfoIter, ++AlsoModInfoIter) {
|
||||||
++ModNo;
|
++ModNo;
|
||||||
|
if (deleteDuplicateMods) {
|
||||||
|
for (auto& CachedMod : CachedMods) {
|
||||||
|
if (CachedMod.first == ModInfoIter->FileName && CachedMod.second.stem().string() + ".zip" != std::filesystem::path(ModInfoIter->FileName).stem().string() + "-" + ModInfoIter->Hash.substr(0, 8) + ".zip") {
|
||||||
|
debug("Found duplicate mod '" + CachedMod.second.stem().string() + ".zip" + "' in cache, removing it");
|
||||||
|
std::filesystem::remove(CachedMod.second);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
if (ModInfoIter->Hash.length() < 8 || ModInfoIter->HashAlgorithm != "sha256") {
|
if (ModInfoIter->Hash.length() < 8 || ModInfoIter->HashAlgorithm != "sha256") {
|
||||||
error("Unsupported hash algorithm or invalid hash for '" + ModInfoIter->FileName + "'");
|
error("Unsupported hash algorithm or invalid hash for '" + ModInfoIter->FileName + "'");
|
||||||
Terminate = true;
|
Terminate = true;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user