Skip to content

Commit

Permalink
Added timers and another feature
Browse files Browse the repository at this point in the history
  • Loading branch information
jss2a98aj committed Apr 6, 2022
1 parent 37583cf commit cf803e1
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 13 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
6 changes: 5 additions & 1 deletion json_intermediary_writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 3 additions & 1 deletion json_patch_writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
7 changes: 5 additions & 2 deletions parse_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"];
Expand Down
1 change: 1 addition & 0 deletions parse_settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
29 changes: 23 additions & 6 deletions starbound_patch_helper.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <chrono>
#include <fstream>
#include <iostream>
#include <sstream>
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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()
Expand All @@ -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)) {
Expand Down Expand Up @@ -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;
Expand All @@ -198,8 +209,9 @@ void parseAssets(MasterSettings & masterSettings, const fs::path sourceAssetPath
}
}

auto duration = std::chrono::duration_cast<std::chrono::seconds>(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;
}

Expand All @@ -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()
Expand All @@ -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);
Expand Down Expand Up @@ -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;
Expand All @@ -279,7 +295,8 @@ void makePatches(MasterSettings & masterSettings, const fs::path sourceAssetPath
}
}

auto duration = std::chrono::duration_cast<std::chrono::seconds>(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;
}

0 comments on commit cf803e1

Please sign in to comment.