Skip to content

Commit

Permalink
Parser: Consolidated some DB file merging logic
Browse files Browse the repository at this point in the history
Parser: Consolidated some conditional file export logic
  • Loading branch information
ImUnicke committed Aug 12, 2024
1 parent 98caf5c commit db2ffe7
Show file tree
Hide file tree
Showing 8 changed files with 91 additions and 160 deletions.
Binary file modified .contrib/Parser/DATAS/00 - DB/Wago/Release/net8.0/CSVCleaner.dll
Binary file not shown.
Binary file modified .contrib/Parser/DATAS/00 - DB/Wago/Release/net8.0/CSVCleaner.exe
Binary file not shown.
Binary file modified .contrib/Parser/Item DB Compiler.exe
Binary file not shown.
Binary file modified .contrib/Parser/Item DB Compiler.pdb
Binary file not shown.
Binary file modified .contrib/Parser/Parser.exe
Binary file not shown.
203 changes: 66 additions & 137 deletions .contrib/Source Code/Parser/Framework/Framework.Merge.cs

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions .contrib/Source Code/Parser/Framework/Framework.Objects.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1034,7 +1034,7 @@ public static void Export(string directory)
var filename = Path.Combine(directory, "Categories.lua");
var content = ATT.Export.ExportCompressedLuaCategories(AllContainerClones).ToString().Replace("\r\n", "\n").Trim();
if (!string.IsNullOrEmpty(DATA_REQUIREMENTS)) content = $"if not ({DATA_REQUIREMENTS}) then return; end \n{content}";
if (!File.Exists(filename) || File.ReadAllText(filename, Encoding.UTF8).Replace("\r\n", "\n").Trim() != content) File.WriteAllText(filename, content, Encoding.UTF8);
WriteIfDifferent(filename, content);
}

public static void ExportAutoLocale(string filename)
Expand Down Expand Up @@ -1066,7 +1066,7 @@ public static void ExportAutoLocale(string filename)

string content = locale.ToString();
if (!string.IsNullOrEmpty(DATA_REQUIREMENTS)) content = $"if not ({DATA_REQUIREMENTS}) then return; end \n{content}";
if (!File.Exists(filename) || File.ReadAllText(filename, Encoding.UTF8) != content) File.WriteAllText(filename, content, Encoding.UTF8);
WriteIfDifferent(filename, content);
}
}

Expand All @@ -1093,7 +1093,7 @@ public static void ExportAutoItemSources(string directory)

string content = data.ToString();
if (!string.IsNullOrEmpty(DATA_REQUIREMENTS)) content = $"if not ({DATA_REQUIREMENTS}) then return; end \n{content}";
if (!File.Exists(filename) || File.ReadAllText(filename, Encoding.UTF8) != content) File.WriteAllText(filename, content, Encoding.UTF8);
WriteIfDifferent(filename, content);
}
}
#endregion
Expand Down
42 changes: 22 additions & 20 deletions .contrib/Source Code/Parser/Framework/Framework.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,15 +138,15 @@ public static partial class Framework

private static readonly Dictionary<string, Dictionary<long, bool>> REFERENCED =
new Dictionary<string, Dictionary<long, bool>>
{
//{ "itemID", new Dictionary<long, bool>() },
//{ "headerID", new Dictionary<long, bool>() },
//{ "factionID", new Dictionary<long, bool>() },
//{ "flightPathID", new Dictionary<long, bool>() },
//{ "npcID", new Dictionary<long, bool>() },
//{ "objectID", new Dictionary<long, bool>() },
//{ "questID", new Dictionary<long, bool>() },
};
{
//{ "itemID", new Dictionary<long, bool>() },
//{ "headerID", new Dictionary<long, bool>() },
//{ "factionID", new Dictionary<long, bool>() },
//{ "flightPathID", new Dictionary<long, bool>() },
//{ "npcID", new Dictionary<long, bool>() },
//{ "objectID", new Dictionary<long, bool>() },
//{ "questID", new Dictionary<long, bool>() },
};

private static readonly Dictionary<string, Dictionary<long, List<IDictionary<string, object>>>> SOURCED =
new Dictionary<string, Dictionary<long, List<IDictionary<string, object>>>>
Expand Down Expand Up @@ -1935,8 +1935,7 @@ public static void Export()
}
keys.Sort(new Comparison<long>((i1, i2) => i2.CompareTo(i1)));

// Check to make sure the content is different since Diff tools are dumb as hell.
File.WriteAllText(Path.Combine(debugFolder.FullName, "Custom Headers.lua"), builder.ToString().Replace("\r\n", "\n").Trim(), Encoding.UTF8);
WriteIfDifferent(Path.Combine(debugFolder.FullName, "Custom Headers.lua"), builder.ToString());
}

// Export the FilterDB file.
Expand Down Expand Up @@ -2355,14 +2354,12 @@ public static void Export()
}
var headerIDsByKey = ExportRawLua(CustomHeaderIDsByKey);
var dynamicHeaderIDsFileName = $"{addonRootFolder}/.contrib/Parser/lib/Functions/Dynamic Header IDs.lua";
string existingDynamicHeaders = File.Exists(dynamicHeaderIDsFileName) ? File.ReadAllText(dynamicHeaderIDsFileName) : null;
var debugFolder = Directory.CreateDirectory(Path.GetDirectoryName(dynamicHeaderIDsFileName));
string newDynamicHeaders = headerIDsByKey
headerIDsByKey
.Insert(0, "\nHeaderAssignments = ")
.Insert(0, "-- DO NOT REFERENCE THE IDS IN THIS FILE, SHOULD IT GET DELETED (which it will eventually), THE ASSIGNMENTS WILL BE REASSIGNED!")
.Insert(0, "-- This file is dynamically generated by Parser! DO NOT MODIFIY IT MANUALLY!\n").AppendLine(";")
.Append("NextHeaderID = ").Append(minHeaderID - 1).Append(";").ToString();
if (existingDynamicHeaders != newDynamicHeaders) File.WriteAllText(dynamicHeaderIDsFileName, newDynamicHeaders, Encoding.UTF8);
.Append("NextHeaderID = ").Append(minHeaderID - 1).Append(";");
WriteIfDifferent(dynamicHeaderIDsFileName, headerIDsByKey.ToString());
}

// Now export it based on what we know.
Expand Down Expand Up @@ -3139,10 +3136,7 @@ public static void Export()
// Check to make sure the content is different since Diff tools are dumb as hell.
var filename = Path.Combine(addonRootFolder, $"db/{dbRootFolder}LocalizationDB.lua");
var localizationDatabaseContent = localizationDatabase.ToString().Replace("\r\n", "\n").Trim();
if (!File.Exists(filename) || File.ReadAllText(filename, Encoding.UTF8).Replace("\r\n", "\n").Trim() != localizationDatabaseContent)
{
File.WriteAllText(filename, localizationDatabaseContent, Encoding.UTF8);
}
WriteIfDifferent(filename, localizationDatabaseContent);

CurrentParseStage = ParseStage.ExportAddonData;
IncludeRawNewlines = false;
Expand Down Expand Up @@ -3176,5 +3170,13 @@ public static void Export()
ObjectHarvester.ExportDirtyObjectsToFilePath(dirtyObjectsFilePath);
}
}

public static void WriteIfDifferent(string filename, string content)
{
if (!File.Exists(filename) || File.ReadAllText(filename, Encoding.UTF8).Replace("\r\n", "\n").Trim() != content)
{
File.WriteAllText(filename, content, Encoding.UTF8);
}
}
}
}

0 comments on commit db2ffe7

Please sign in to comment.