From e383dcfd43355ebd9754acc9f4d01e5a0cb27ecf Mon Sep 17 00:00:00 2001 From: louve Date: Tue, 1 Oct 2024 16:15:15 +0200 Subject: [PATCH] Filter out unnecessary files --- src/Components/Modules/Download.cpp | 50 ++++++++++++++++++++++++++++- src/Components/Modules/Download.hpp | 3 ++ 2 files changed, 52 insertions(+), 1 deletion(-) diff --git a/src/Components/Modules/Download.cpp b/src/Components/Modules/Download.cpp index 0123504e..51de1891 100644 --- a/src/Components/Modules/Download.cpp +++ b/src/Components/Modules/Download.cpp @@ -116,8 +116,9 @@ namespace Components fileEntry.name = name; fileEntry.hash = hash; fileEntry.size = size; + fileEntry.isMap = download->isMap_; - if (!fileEntry.name.empty()) + if (!fileEntry.name.empty() && fileEntry.allowed()) { download->files_.push_back(fileEntry); download->totalBytes_ += fileEntry.size; @@ -139,6 +140,8 @@ namespace Components auto file = download->files_[index]; + assert(file.allowed()); + auto path = download->mod_ + "/" + file.name; if (download->isMap_) { @@ -884,4 +887,49 @@ namespace Components CLDownload.clear(); } } + + bool Download::ClientDownload::File::allowed() const + { + if (name.contains("..") || name.contains(":")) + { + return false; + } + + if (name.contains("\\") || name.contains("/")) + { + return false; + } + + if (isMap) + { + if (name.ends_with(".arena")) + { + return true; + } + + if (name.ends_with(".iwd")) + { + return true; + } + + if (name.ends_with(".ff")) + { + return true; + } + } + else + { + // Plain and simple + if (name == "mod.ff") + { + return true; + } + if (name.ends_with(".iwd")) + { + return true; + } + } + + return false; + } } diff --git a/src/Components/Modules/Download.hpp b/src/Components/Modules/Download.hpp index 09b5702e..a7724bd7 100644 --- a/src/Components/Modules/Download.hpp +++ b/src/Components/Modules/Download.hpp @@ -55,6 +55,9 @@ namespace Components std::string name; std::string hash; std::size_t size; + bool isMap; + + bool allowed() const; }; std::vector files_;