diff --git a/README.md b/README.md index 86eefd2..544182c 100644 --- a/README.md +++ b/README.md @@ -2,16 +2,23 @@ A small application designed to help Collective Unconscious developers submit their updates # Install required librairies -sudo apt install -y g++ qtcreator qtbase5-dev qt5-qmake cmake +sudo apt install -y git g++ qtcreator qtbase5-dev qt5-qmake cmake zip -# Build and execute -cmake -B build -S . && -cd build && -make && -./cu_submitter +# Build +``` +cd +git clone https://github.com/noahrav/cu_submitter.git +cd cu_submitter +cmake -B build +cd build +make +``` + +The executable is build/cu_submitter ## CLI ./cu_submitter --help | --usage : prints the usage\ ./cu_submitter --chgen : generates a changelog text file\ -./cu_submitter --transfer : transfers the modified files to the destination path +./cu_submitter --transfer : transfers the modified files to the destination path\ +./cu_submitter --submit [] : compress the modified files to a submission archive diff --git a/src/cu_submitter.cpp b/src/cu_submitter.cpp index 678a14c..3884af1 100644 --- a/src/cu_submitter.cpp +++ b/src/cu_submitter.cpp @@ -5,6 +5,7 @@ #include "chgen/chgen.h" #include "transfer/transfer.h" +#include "submit/submit.h" #include "utils/error.h" #include "utils/log.h" #include "utils/print.h" @@ -25,7 +26,8 @@ int main(int argc, char* argv[]) usage_message += "-----\n"; usage_message += "--help | --usage : prints this message\n"; usage_message += "--chgen : generates a changelog text file\n"; - usage_message += "--transfer : : transfers the modified files to the destination path\n"; + usage_message += "--transfer : transfers the modified files to the destination path\n"; + usage_message += "--submit [] : compress the modified files to a submission archive\n"; print(usage_message); } else if (option == "--chgen") { @@ -72,6 +74,45 @@ int main(int argc, char* argv[]) transfer::DevbuildTransferer::transfer(to); transfer::DevbuildTransferer::exportChangelog(); + } else if (option == "--submit") { + if (argc < 4) { + error("Not enough arguments"); + return 1; + } + + const std::string base = argv[2]; + const std::string modified = argv[3]; + const std::string archive = argc >= 5 ? argv[4] : ""; + + const auto changelog = submit::SubmissionBuilder::getSubmissionChangelog(base, modified); + + if (changelog == nullptr) { + error("Could not generate changelog"); + return 1; + } + + std::cout << "Changelog: \n"; + std::cout << changelog->stringify() << "\n\n"; + + std::cout << "Confirm ? (O/N) "; + char confirm; + std::cin >> confirm; + if (confirm == 'N' || confirm == 'n') { + error("Submission cancelled"); + return 8; + } + + try { + if (archive.length() > 0) { + submit::SubmissionBuilder::submit(archive); + } else { + submit::SubmissionBuilder::submit(); + } + + submit::SubmissionBuilder::compress(); + } catch (const std::exception &e) { + error(std::string(e.what())); + } } else { error("Invalid arguments"); return 1; diff --git a/src/submit/submit.cpp b/src/submit/submit.cpp index 67b0fde..bc07501 100644 --- a/src/submit/submit.cpp +++ b/src/submit/submit.cpp @@ -70,7 +70,7 @@ namespace submit { } const auto base_asset_folder = std::string(modified_path_ / fs::path(folder)); - const auto destination_asset_folder = std::string(archive_path_ / fs::path(folder)); + const auto destination_asset_folder = std::string(gameRoot() / fs::path(folder)); if (!fs::create_directory(destination_asset_folder)) { error("Could not create: " + destination_asset_folder); @@ -107,14 +107,14 @@ namespace submit { case data::Status::REMOVED: break; case data::Status::MODIFIED: - log("Moving " + std::string(origin_map) + " into " + archive_path_); + log("Moving " + std::string(origin_map) + " into " + std::string(gameRoot())); - fs::copy(origin_map, archive_path_); + fs::copy(origin_map, gameRoot()); break; case data::Status::ADDED: - log("Moving " + std::string(origin_map) + " into " + archive_path_); + log("Moving " + std::string(origin_map) + " into " + std::string(gameRoot())); - fs::copy(origin_map, archive_path_); + fs::copy(origin_map, gameRoot()); break; } } @@ -127,12 +127,13 @@ namespace submit { } try { - fs::create_directories(archive_path); - archive_path_ = archive_path; + const fs::path game_root = gameRoot(); + + fs::create_directories(game_root); - fs::copy(modified_path_ / fs::path("RPG_RT.lbd"), archive_path); - fs::copy(modified_path_ / fs::path("RPG_RT.lmt"), archive_path); + fs::copy(modified_path_ / fs::path("RPG_RT.lbd"), game_root); + fs::copy(modified_path_ / fs::path("RPG_RT.lmt"), game_root); submitMaps(); @@ -145,6 +146,10 @@ namespace submit { submitAssets(data::AssetCategory::PICTURE); submitAssets(data::AssetCategory::BATTLE_ANIMATION); + exportChangelog(); + + log("File " + archive_path + " ready for compression"); + } catch (const std::exception &e) { error(std::string(e.what())); } @@ -164,4 +169,41 @@ namespace submit { submit(output_name); } + + void SubmissionBuilder::exportChangelog() { + if (archive_path_.empty()) { + error("Archive path not defined"); + return; + } + if (!submissionChangelog_) { + error("No changelog scanned"); + return; + } + + const fs::path export_path = archive_path_; + + chgen::ChangelogGenerator::generate(submissionChangelog_, export_path); + } + + void SubmissionBuilder::compress() { + if (archive_path_.length() < 0 || !fs::exists(archive_path_)) { + error("Archive path is not defined. getSubmissionChangelog, submit and exportChangelog need to be called beforehand"); + return; + } + + log("Compressing " + archive_path_ + "..."); + + const std::string zipCommand = "zip -r " + archive_path_ + ".zip" + " " + archive_path_; + + if (std::system(zipCommand.c_str()) != 0) { + error("Could not compress " + archive_path_); + return; + } + + log("Compression successful. Archive : " + archive_path_ + ".zip"); + } + + fs::path SubmissionBuilder::gameRoot() { + return archive_path_ / fs::path("data"); + } } // submit diff --git a/src/submit/submit.h b/src/submit/submit.h index a9dc381..4873722 100644 --- a/src/submit/submit.h +++ b/src/submit/submit.h @@ -43,6 +43,11 @@ namespace submit { */ static void exportChangelog(); + /** + * Compresse archive_path_ into an archive file + */ + static void compress(); + private: /** * Moves assets into the submission folder @@ -53,6 +58,10 @@ namespace submit { * Moves .lmu map files into the submission folder */ static void submitMaps(); + /** + * @return the root of the game files + */ + static fs::path gameRoot(); static std::shared_ptr submissionChangelog_; diff --git a/src/transfer/transfer.cpp b/src/transfer/transfer.cpp index 4b7e3fc..1616018 100644 --- a/src/transfer/transfer.cpp +++ b/src/transfer/transfer.cpp @@ -423,7 +423,7 @@ namespace transfer { return; } - fs::path export_path = destination_path_; + const fs::path export_path = destination_path_; chgen::ChangelogGenerator::generate(transferChangelog_, export_path.parent_path()); }