diff --git a/.contrib/Source Code/Parser/DB/Types/ItemModifiedAppearance.cs b/.contrib/Source Code/Parser/DB/Types/ItemModifiedAppearance.cs index 5f311db5a38..92aea020394 100644 --- a/.contrib/Source Code/Parser/DB/Types/ItemModifiedAppearance.cs +++ b/.contrib/Source Code/Parser/DB/Types/ItemModifiedAppearance.cs @@ -1,5 +1,4 @@ using System.Collections.Generic; -using System.Runtime.Remoting.Channels; namespace ATT.DB.Types { diff --git a/.contrib/Source Code/Parser/DB/WagoData.cs b/.contrib/Source Code/Parser/DB/WagoData.cs index b338c59dce4..8f9a0700015 100644 --- a/.contrib/Source Code/Parser/DB/WagoData.cs +++ b/.contrib/Source Code/Parser/DB/WagoData.cs @@ -1,9 +1,11 @@ using ATT.DB.Types; -using Csv; +using CsvHelper; using System; using System.Collections; using System.Collections.Concurrent; using System.Collections.Generic; +using System.Diagnostics; +using System.Globalization; using System.IO; using System.Linq; using System.Reflection; @@ -140,12 +142,14 @@ public static Dictionary GetExportableData(T o) where T : IDB /// The path of the CSV file. public static void LoadFromCSV(string path) { - Framework.LogDebug($"Wago.LoadFromCSV: {path}"); + Trace.WriteLine($"Wago.LoadFromCSV: {path}"); // Parse the filename for the database type and locale, if specified. - var filename = path.Substring(path.LastIndexOf('\\') + 1); + var filename = path.Substring(path.LastIndexOf(Path.DirectorySeparatorChar) + 1); var segments = filename.Split('.', '-', '_'); // Example: Item_enUS.1.15.7.60277 + Trace.WriteLine($"filename: {filename}"); + // The Type is always listed first, followed by the locale (Default: enUS) string type = segments[0]; string locale = segments[1]; @@ -1070,13 +1074,6 @@ public static void StoreLocalizedData(IDictionary db, string locale } #endregion #region Cache Helper - /// - /// The default CSV Options to use for Wago Data Modules. - /// - private static readonly CsvOptions DEFAULT_CSV_OPTIONS = new CsvOptions - { - AllowNewLineInEnclosedFieldValues = true - }; /// /// The Cache class retains useful Type-specific data to ensure that the fastest parsing and data storage methods are utilized. @@ -1180,24 +1177,36 @@ public static Dictionary GetExportableData(T o) /// public static void LoadFromCSV(string content, string locale) { - foreach (var line in CsvReader.ReadFromText(content, DEFAULT_CSV_OPTIONS)) + using var reader = new StringReader(content); + using var csv = new CsvReader(reader, CultureInfo.InvariantCulture); + + var records = csv.GetRecords(); + + foreach (var record in records) { T obj = (T)Activator.CreateInstance(ParseType); - foreach (var header in line.Headers) + + // Convert dynamic record to dictionary for easier header/property access + var recordDict = (IDictionary)record; + + foreach (var kvp in recordDict) { + var header = kvp.Key; + var valueObj = kvp.Value?.ToString() ?? ""; + if (AllPropertiesByName.TryGetValue(header, out var property)) { - if (line.HasColumn(header)) + try { - var value = line[header]; - try - { - property.SetValue(obj, Convert.ChangeType(value, property.PropertyType, System.Globalization.CultureInfo.InvariantCulture)); - } - catch (Exception ex) - { - throw new InvalidProgramException($"Failed converting property {ParseType.Name}.{property.Name} [{property.PropertyType.Name}] from: '{value}' [{value.GetType().Name}]", ex); - } + // Convert to property type + var convertedValue = Convert.ChangeType(valueObj, property.PropertyType, CultureInfo.InvariantCulture); + property.SetValue(obj, convertedValue); + } + catch (Exception ex) + { + throw new InvalidProgramException( + $"Failed converting property {ParseType.Name}.{property.Name} [{property.PropertyType.Name}] from: '{valueObj}' [{valueObj.GetType().Name}]", + ex); } } /* @@ -1207,6 +1216,8 @@ public static void LoadFromCSV(string content, string locale) } */ } + + // Add to cache if (CachedData.TryAdd(obj.ID, obj)) { //Framework.LogWarn($"WagoData.Load.{ParseType.Name}.Add: {obj.ID}", line.Values); @@ -1215,6 +1226,7 @@ public static void LoadFromCSV(string content, string locale) { //Framework.LogWarn($"WagoData.Load.{ParseType.Name}.Skip: {obj.ID}", line.Values); } + StoreLocalizedData(obj, locale); } diff --git a/.contrib/Source Code/Parser/Framework/Framework.cs b/.contrib/Source Code/Parser/Framework/Framework.cs index 8b50a0b1fb8..864ff65d77e 100644 --- a/.contrib/Source Code/Parser/Framework/Framework.cs +++ b/.contrib/Source Code/Parser/Framework/Framework.cs @@ -776,13 +776,19 @@ public static void InitConfigSettings(string filepath, bool replaceConfig = fals { Log($"Using config: {filepath}"); Config = new CustomConfiguration(filepath); - Console.Title = $"ATT Parser: {filepath}"; + if (OperatingSystem.IsWindows()) + { + Console.Title = $"ATT Parser: {filepath}"; + } } else { Log($"Added config: {filepath}"); Config.ApplyFile(filepath); - Console.Title += $" + {filepath}"; + if (OperatingSystem.IsWindows()) + { + Console.Title += $" + {filepath}"; + } } } diff --git a/.contrib/Source Code/Parser/Parser.csproj b/.contrib/Source Code/Parser/Parser.csproj index 699da3f8ccd..d904b84745a 100644 --- a/.contrib/Source Code/Parser/Parser.csproj +++ b/.contrib/Source Code/Parser/Parser.csproj @@ -1,188 +1,22 @@ - - - - - Debug - AnyCPU - {47D83200-8E21-487B-8F44-B08C7A1CBC82} - Exe - ATT - Parser - v4.8 - 512 - true - - false - publish\ - true - Disk - false - Foreground - 7 - Days - false - false - true - 0 - 1.0.0.%2a - false - true - - - lib\att_logo_128_new_jrX_icon.ico - - - true - ..\..\Parser\ - TRACE;RETAIL;TWW - full - x64 - prompt - MinimumRecommendedRules.ruleset - true - false - true - - - true - ..\..\Parser\ - TRACE;DEBUG;RETAIL;TWW - false - full - x64 - 7.3 - prompt - MinimumRecommendedRules.ruleset - true - - - ATT.Program - - - - packages\Csv.2.0.93\lib\net40\Csv.dll - - - False - lib\KeraLua.dll - - - - False - lib\NLua.dll - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - False - .NET Framework 3.5 SP1 - false - - - - - \ No newline at end of file + + + false + Exe + net8.0 + enable + enable + + + + + + + + + + + + + + + diff --git a/.contrib/Source Code/Parser/Program.cs b/.contrib/Source Code/Parser/Program.cs index a2229bccddf..dc2ad722956 100644 --- a/.contrib/Source Code/Parser/Program.cs +++ b/.contrib/Source Code/Parser/Program.cs @@ -236,6 +236,8 @@ static void ImportAchievementCategoryData(AchievementCategory achievementCategor static int Main(string[] args) { + string exePath = Assembly.GetExecutingAssembly().Location; + Console.WriteLine(exePath); // Setup tracing to the console. Tracer.OnWrite += Console.Write; AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(UnhandledExceptionHandler); @@ -425,10 +427,10 @@ static int Main(string[] args) string content = ""; try { - var mainFileName = $"{databaseRootFolder}\\..\\_main.lua"; + var mainFileName = $"{databaseRootFolder}{Path.DirectorySeparatorChar}..{Path.DirectorySeparatorChar}_main.lua"; if (!File.Exists(mainFileName)) { - Trace.WriteLine("Could not find the '_main.lua' header file."); + Trace.WriteLine($"Could not find the {mainFileName} header file."); Trace.WriteLine("Operation cannot continue without it."); Framework.WaitForUser("Press any key to close..."); return ErrorCode; @@ -832,9 +834,9 @@ static void ProcessInitialCommandBlock(StringBuilder builder, string content, re { // Attempt to parse a command that initiates a command block. int newLineIndex = content.IndexOf('\n', index += 4); - var command = content.Substring(index, (newLineIndex > 0 ? newLineIndex : length) - index).Trim().ToUpper().Split(' '); + var command = content.Substring(index, (newLineIndex > 0 ? newLineIndex : length) - index).Trim().Split(' '); index = newLineIndex; - switch (command[0]) + switch (command[0].ToUpper()) { case "IF": PreProcessorNestLevel = 0; @@ -944,7 +946,7 @@ static void ProcessImportCommand(string[] command, StringBuilder builder, string builder.Append("-- ").Append(shortname).AppendLine(); // Are we already using the Retail DB? - string filename = ".\\DATAS\\" + shortname; + string filename = $".{Path.DirectorySeparatorChar}DATAS{Path.DirectorySeparatorChar}" + shortname.Replace('\\', Path.DirectorySeparatorChar); if (Directory.Exists(filename)) { int fileCount = 0;