From cf803e15213236af59feaaecdf0d20012b1fdc45 Mon Sep 17 00:00:00 2001 From: jss2a98aj Date: Wed, 6 Apr 2022 15:27:21 -0400 Subject: [PATCH] Added timers and another feature --- README.md | 6 +++--- json_intermediary_writer.cpp | 6 +++++- json_patch_writer.cpp | 4 +++- parse_settings.cpp | 7 +++++-- parse_settings.h | 1 + starbound_patch_helper.cpp | 29 +++++++++++++++++++++++------ 6 files changed, 40 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 0eb7cd5..ee4cdb3 100644 --- a/README.md +++ b/README.md @@ -24,9 +24,9 @@ All of this was done without altering the underlying JSON parser. All of it can # Future plans -- Build binaries for Linux. -- Build binaries for Mac. I don't have a Mac. It will require cross compiling. +- Pre-built binaries for Linux. +- Pre-built binaries for Mac. I don't have a Mac. It will require cross compiling. +- More configuration options. - More detailed crashes, including printing the path of a read file when parsing fails. -- Display the time taken to run each command. - Support for settings paths other than the default relative ones when running from the command line. - Better documentation. diff --git a/json_intermediary_writer.cpp b/json_intermediary_writer.cpp index ea61283..f0ea497 100644 --- a/json_intermediary_writer.cpp +++ b/json_intermediary_writer.cpp @@ -41,10 +41,14 @@ bool JsonIntermediaryWriter::writePointerValuePair(std::stringstream & intermedi convertNewlineBreakoutsToNewline(sourceJsonText); intermediaryText << '"' << sourceJsonText << '"'; } else { - intermediaryText << sourceJson[valuePointer]; + intermediaryText << sourceJson[valuePointer]; } //Continue iteration. return true; + //Value should only be placeholder. + } else if (pointerSettings.reference) { + //Stop iteration. + return false; //Value missing, use placeholder if possible. } else if (pointerSettings.intermediaryPlaceholderCondition == whenPossible) { writePointerValueStart(intermediaryText, pointerSettings); diff --git a/json_patch_writer.cpp b/json_patch_writer.cpp index e36005f..ffe1ce2 100644 --- a/json_patch_writer.cpp +++ b/json_patch_writer.cpp @@ -29,7 +29,9 @@ int JsonPatchWriter::writePatchFile(std::stringstream & patchText, FileSettings //TODO: if only one op set in a patch skip set brackets (configurable) //Write operation sets for (const PointerSettings & pointerSettings : fileSettings.getAllPointerSettings()) { - writeRecursiveOperationSet(patchText, pointerSettings, sourceJson, intermediaryJson); + if (!pointerSettings.reference) { + writeRecursiveOperationSet(patchText, pointerSettings, sourceJson, intermediaryJson); + } } //New line after the last operation set closer. diff --git a/parse_settings.cpp b/parse_settings.cpp index 7699995..6fc4685 100644 --- a/parse_settings.cpp +++ b/parse_settings.cpp @@ -28,11 +28,14 @@ FileSettings::FileSettings(fs::path settingsPath) { if (valuesJson.contains("path")) { pointerSettings.path = valuesJson["path"]; + if (valuesJson.contains("from")) { + pointerSettings.from = valuesJson["from"]; + } if (valuesJson.contains("numericIteratorMarker")) { pointerSettings.numericIteratorMarker = valuesJson["numericIteratorMarker"]; } - if (valuesJson.contains("from")) { - pointerSettings.from = valuesJson["from"]; + if (valuesJson.contains("reference")) { + pointerSettings.reference = valuesJson["reference"]; } if (valuesJson.contains("convertBreakoutNewlines")) { pointerSettings.convertBreakoutNewlines = valuesJson["convertBreakoutNewlines"]; diff --git a/parse_settings.h b/parse_settings.h index 2e154ec..09cf21a 100644 --- a/parse_settings.h +++ b/parse_settings.h @@ -19,6 +19,7 @@ struct PointerSettings { std::string path = ""; std::string from = ""; std::string numericIteratorMarker = ""; + bool reference = false; bool convertBreakoutNewlines = false; //Intermediary. placeholderCondition intermediaryPlaceholderCondition = never; diff --git a/starbound_patch_helper.cpp b/starbound_patch_helper.cpp index e70db98..e0c2673 100644 --- a/starbound_patch_helper.cpp +++ b/starbound_patch_helper.cpp @@ -1,3 +1,4 @@ +#include #include #include #include @@ -111,6 +112,7 @@ int main(int argc, char * argv[]) { if (requestBoolean("An intermediary asset folder already exists.\nShould it be replaced?")) { std::cout << "Deleting old intermediary asset folder.\n"; fs::remove_all(intermediaryAssetPath); + std::cout << "Old intermediary asset folder deleted.\n"; } else { std::cout << "Aborting parse.\n"; break; @@ -122,8 +124,9 @@ int main(int argc, char * argv[]) { //If a patch asset folder exists prompt the user before deleteing it. if (fs::exists(patchOutputPath)) { if (requestBoolean("A patch folder already exists.\nShould it be replaced?")) { - std::cout << "Deleting old patch folder.\n"; + std::cout << "Deleting old patch output folder.\n"; fs::remove_all(patchOutputPath); + std::cout << "Old patch patch output folder deleted.\n"; } else { std::cout << "Aborting make patches.\n"; break; @@ -151,8 +154,9 @@ void parseAssets(MasterSettings & masterSettings, const fs::path sourceAssetPath //Stop if the intermediary asset folder exists unless in overwrite mode. if (fs::exists(intermediaryAssetPath)) { if (masterSettings.getOverwriteFiles()) { - std::cout << "Clearing old intermediary asset folder.\n"; + std::cout << "Deleting old intermediary asset folder.\n"; fs::remove_all(intermediaryAssetPath); + std::cout << "Old intermediary asset folder deleted.\n"; } else { std::cout << "Intermediary asset folder already exists at:" << intermediaryAssetPath.string() @@ -162,6 +166,10 @@ void parseAssets(MasterSettings & masterSettings, const fs::path sourceAssetPath } } + std::cout << "Making intermediary files.\n"; + + auto startTime = std::chrono::high_resolution_clock::now(); + int totalIntermediaryFilesMade = 0; JsonIntermediaryWriter intermediaryWriter = JsonIntermediaryWriter(); //Iteratively parse source assets. for (const auto & directory : fs::recursive_directory_iterator(sourceAssetPath)) { @@ -189,7 +197,10 @@ void parseAssets(MasterSettings & masterSettings, const fs::path sourceAssetPath if (!writeStringStreamToPath(intermediaryText, intermediaryPath)) { std::cout << "Failed to write intermediary file to:\n" << intermediaryPath.string() << std::endl; + } + + totalIntermediaryFilesMade++; } //There can only be one match. break; @@ -198,8 +209,9 @@ void parseAssets(MasterSettings & masterSettings, const fs::path sourceAssetPath } } + auto duration = std::chrono::duration_cast(std::chrono::high_resolution_clock::now() - startTime); //Finished parse notification - std::cout << "Parsed intermediary assets at:\n" + std::cout << totalIntermediaryFilesMade << " intermediary files created in " << duration.count() << "s at:\n" << intermediaryAssetPath.string() << std::endl; } @@ -212,8 +224,9 @@ void makePatches(MasterSettings & masterSettings, const fs::path sourceAssetPath //Stop if the patch output folder exists unless in overwrite mode. if (fs::exists(patchOutputPath)) { if (masterSettings.getOverwriteFiles()) { - std::cout << "Clearing old patch output folder.\n"; + std::cout << "Deleting old patch output folder.\n"; fs::remove_all(patchOutputPath); + std::cout << "Old patch output folder deleted.\n"; } else { std::cout << "Patch output folder already exists at:" << patchOutputPath.string() @@ -223,6 +236,9 @@ void makePatches(MasterSettings & masterSettings, const fs::path sourceAssetPath } } + std::cout << "Making patches.\n"; + + auto startTime = std::chrono::high_resolution_clock::now(); int totalPatchesMade = 0; int totalValuesAltered = 0; JsonPatchWriter patchWriter = JsonPatchWriter(masterSettings); @@ -263,7 +279,7 @@ void makePatches(MasterSettings & masterSettings, const fs::path sourceAssetPath patchFilePath += pathFragment; patchFilePath += ".patch"; - //Create the patch file. + //Creating the patch file. if(!writeStringStreamToPath(patchText, patchFilePath)) { std::cout << "Failed to write patch file to:\n" << patchFilePath.string() << std::endl; @@ -279,7 +295,8 @@ void makePatches(MasterSettings & masterSettings, const fs::path sourceAssetPath } } + auto duration = std::chrono::duration_cast(std::chrono::high_resolution_clock::now() - startTime); //Finished patch output notification - std::cout << totalPatchesMade << " patches altering " << totalValuesAltered << " values created at:\n" + std::cout << totalPatchesMade << " patches containing " << totalValuesAltered << " operation sets created in " << duration.count() << "s at:\n" << patchOutputPath.string() << std::endl; }