Skip to content

Commit

Permalink
feat: submit complete
Browse files Browse the repository at this point in the history
  • Loading branch information
noahrav committed Nov 30, 2023
1 parent 2100bce commit 34fdea8
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 18 deletions.
21 changes: 14 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <base_path> <modified_path> : generates a changelog text file\
./cu_submitter --transfer <unmodified_copy_path> <modified_copy_path> <destination_path> : transfers the modified files to the destination path
./cu_submitter --transfer <unmodified_copy_path> <modified_copy_path> <destination_path> : transfers the modified files to the destination path\
./cu_submitter --submit <unmodified_copy_path> <modified_copy_path> [<archive_path>] : compress the modified files to a submission archive
43 changes: 42 additions & 1 deletion src/cu_submitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -25,7 +26,8 @@ int main(int argc, char* argv[])
usage_message += "-----\n";
usage_message += "--help | --usage : prints this message\n";
usage_message += "--chgen <base_path> <modified_path> : generates a changelog text file\n";
usage_message += "--transfer <unmodified_copy_path> <modified_copy_path> <destination_path>: : transfers the modified files to the destination path\n";
usage_message += "--transfer <unmodified_copy_path> <modified_copy_path> <destination_path> : transfers the modified files to the destination path\n";
usage_message += "--submit <unmodified_copy_path> <modified_copy_path> [<archive_path>] : compress the modified files to a submission archive\n";

print(usage_message);
} else if (option == "--chgen") {
Expand Down Expand Up @@ -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;
Expand Down
60 changes: 51 additions & 9 deletions src/submit/submit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
}
Expand All @@ -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();

Expand All @@ -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()));
}
Expand All @@ -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
9 changes: 9 additions & 0 deletions src/submit/submit.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<data::Changelog> submissionChangelog_;

Expand Down
2 changes: 1 addition & 1 deletion src/transfer/transfer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down

0 comments on commit 34fdea8

Please sign in to comment.