public void ParseSuggestedBindingRedirectsMetadata() { var parameter = ItemGroupParser.ParsePropertyOrItemList(@"Output Item(s): SuggestedBindingRedirects= Microsoft.Build, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a MaxVersion=15.1.0.0 Microsoft.VisualStudio.Validation, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a MaxVersion=15.3.0.0", MessageProcessor.OutputItemsMessagePrefix, new StringCache()) as Parameter; Assert.True(parameter != null); Assert.True(parameter.Children.Count == 2); var item = parameter.FirstChild as Item; Assert.True(item != null); var metadata = item.FirstChild as Metadata; Assert.True(metadata != null); Assert.Equal("SuggestedBindingRedirects", parameter.Name); Assert.Equal("Microsoft.Build, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", item.Text); Assert.Equal("MaxVersion", metadata.Name); Assert.Equal("15.1.0.0", metadata.Value); }
public void AddItemWithMultilineMetadata() { var result = ItemGroupParser.ParsePropertyOrItemList(@"Added Item(s): Link= tmp AcceptableNonZeroExitCodes= AdditionalDependencies=kernel32.lib;user32.lib; ;", MessageProcessor.OutputItemsMessagePrefix, new StringCache()); }
public void ParseMultilineMetadata() { var parameter = ItemGroupParser.ParsePropertyOrItemList(@"Added Item(s): _ProjectsFiles= Project1 AdditionalProperties= AutoParameterizationWebConfigConnectionStrings=false; _PackageTempDir=Out\Dir; Project2 AdditionalProperties= AutoParameterizationWebConfigConnectionStrings=false; _PackageTempDir=Out\Dir; Project3 AdditionalProperties= AutoParameterizationWebConfigConnectionStrings=false; _PackageTempDir=Out\Dir; ", MessageProcessor.ItemGroupIncludeMessagePrefix, new StringCache()) as Parameter; //Assert.Equal(3, parameter.Children.Count); }
public void ParseThereWasAConflictMultiline() { var message = @" References which depend on ""System.IO.Compression.FileSystem, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"" [C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Ref\3.1.0\ref\netcoreapp3.1\System.IO.Compression.FileSystem.dll]. C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Ref\3.1.0\ref\netcoreapp3.1\System.IO.Compression.FileSystem.dll Project file item includes which caused reference ""C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Ref\3.1.0\ref\netcoreapp3.1\System.IO.Compression.FileSystem.dll"". C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Ref\3.1.0\ref\netcoreapp3.1\System.IO.Compression.FileSystem.dll References which depend on ""System.IO.Compression.FileSystem"" []. Unresolved primary reference with an item include of ""System.IO.Compression.FileSystem"".".NormalizeLineBreaks(); var stringCache = new StringCache(); var parameter = new Parameter(); ItemGroupParser.ParseThereWasAConflict(parameter, message, stringCache); var text = StringWriter.GetString(parameter).NormalizeLineBreaks(); var expected = @" References which depend on ""System.IO.Compression.FileSystem, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"" [C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Ref\3.1.0\ref\netcoreapp3.1\System.IO.Compression.FileSystem.dll]. C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Ref\3.1.0\ref\netcoreapp3.1\System.IO.Compression.FileSystem.dll Project file item includes which caused reference ""C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Ref\3.1.0\ref\netcoreapp3.1\System.IO.Compression.FileSystem.dll"". C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Ref\3.1.0\ref\netcoreapp3.1\System.IO.Compression.FileSystem.dll References which depend on ""System.IO.Compression.FileSystem"" []. Unresolved primary reference with an item include of ""System.IO.Compression.FileSystem"". ".NormalizeLineBreaks(); Assert.Equal(expected, text); }
public static void Writer2 <TKey>(ReadableTuple <TKey> item, ServerType destServer, StringBuilder builder, BaseDb db, List <string> aegisNames, List <string> names) { var itemCopy = new ReadableTuple <TKey>(item.GetKey <TKey>(), item.Attributes); itemCopy.Copy(item); item = itemCopy; int key = item.GetKey <int>(); if (destServer == ServerType.RAthena) { var itemDb = db.GetMeta <int>(ServerDbs.Items); ServerType source = DbPathLocator.GetServerType(); if (source == ServerType.Hercules) { List <string> constantsList = Constants.Keys.ToList(); Table <int, ReadableTuple <int> > table = db.GetMeta <int>(ServerDbs.Items); var tuple = item; var res2 = table.TryGetTuple(key); if (res2 != null) { string name = res2.GetValue(ServerItemAttributes.AegisName).ToString(); int low = Int32.MaxValue; int index = -1; for (int j = 0; j < Constants.Count; j++) { int dist = Methods.LevenshteinDistance(name, constantsList[j]); if (dist < low) { low = dist; index = j; } } string closestString = constantsList[index]; int groupId = Constants[closestString]; tuple.SetRawValue(0, groupId); } } Dictionary <int, ReadableTuple <int> > dico = (Dictionary <int, ReadableTuple <int> >)item.GetRawValue(1); key = item.GetKey <int>(); foreach (var pair in dico.OrderBy(p => p.Key)) { var dbTuple = itemDb.TryGetTuple(pair.Key); List <string> items = ServerItemGroupSubAttributes.AttributeList.Attributes.Select(p => pair.Value.GetValue <string>(p)).ToList(); RemoveDefaultValues(items); builder.AppendLine(key + "," + string.Join(",", items.ToArray()) + (dbTuple == null ? "" : "\t// " + dbTuple.GetValue(ServerItemAttributes.Name))); } builder.AppendLine(); } else if (destServer == ServerType.Hercules) { builder.AppendLine(ItemGroupParser.ToHerculesDbEntry(db, item.GetKey <int>(), aegisNames, names)); builder.AppendLine(); } }
public static void Writer(DbDebugItem <int> debug, AbstractDb <int> db) { try { if (debug.FileType == FileType.Txt) { // Do not care about the loaded IDs, just write them where they belong _idToGroupName.Clear(); var itemDb = db.GetMeta <int>(ServerDbs.Items); AbstractDb <string> constantDb = db.GetDb <string>(ServerDbs.Constants); var affectedGroups = new HashSet <int>(); var nonNullGroups = new HashSet <int> { 1, 2, 3, 4, 6, 44, 28, 29, 30, 31, 34, 43 }; if (debug.DbSource == ServerDbs.ItemGroupsBlueBox) { affectedGroups = new HashSet <int> { 1 }; } else if (debug.DbSource == ServerDbs.ItemGroupsVioletBox) { affectedGroups = new HashSet <int> { 2 }; } else if (debug.DbSource == ServerDbs.ItemGroupsCardalbum) { affectedGroups = new HashSet <int> { 3, 44 }; } else if (debug.DbSource == ServerDbs.ItemGroupsFindingore) { affectedGroups = new HashSet <int> { 6 }; } else if (debug.DbSource == ServerDbs.ItemGroupsGiftBox) { affectedGroups = new HashSet <int> { 4, 28, 29, 30, 31, 34, 43 }; } else if (debug.DbSource == ServerDbs.ItemGroupsMisc) { affectedGroups = null; } else if (debug.DbSource == ServerDbs.ItemGroupsPackages) { affectedGroups = null; } if (affectedGroups != null) { while (true) { bool isModified = false; // Check if the group was modified or not foreach (var tuple in db.Table.FastItems.Where(p => affectedGroups.Contains(p.Key))) { if (!tuple.Normal) { isModified = true; break; } } if (isModified) { break; } // Check if the file has more groups than what it's supposed to HashSet <int> loadedIds = ((Utilities.Extension.Tuple <ServerDbs, HashSet <int> >)db.Attached[debug.DbSource]).Item2; foreach (var id in loadedIds) { if (!affectedGroups.Contains(id)) { isModified = true; break; } } if (isModified) { break; } foreach (var id in affectedGroups) { if (!loadedIds.Contains(id)) { isModified = true; break; } } if (isModified) { break; } return; } } else { while (true) { bool isModified = false; // Check if the group was modified or not foreach (var tuple in db.Table.FastItems.Where(p => !nonNullGroups.Contains(p.Key))) { bool isPackage = _isPackage((Dictionary <int, ReadableTuple <int> >)tuple.GetRawValue(1)); if (debug.DbSource == ServerDbs.ItemGroupsMisc && isPackage) { continue; } if (debug.DbSource == ServerDbs.ItemGroupsPackages && !isPackage) { continue; } if (!tuple.Normal) { isModified = true; break; } } if (isModified) { break; } return; } } using (StreamWriter writer = new StreamWriter(debug.FilePath)) { foreach (ReadableTuple <int> tup in db.Table.FastItems.OrderBy(p => p.Key)) { Dictionary <int, ReadableTuple <int> > dico = (Dictionary <int, ReadableTuple <int> >)tup.GetRawValue(1); int key = tup.GetKey <int>(); bool isPackage = _isPackage(dico); if ((affectedGroups != null && affectedGroups.Contains(key)) || (affectedGroups == null && debug.DbSource == ServerDbs.ItemGroupsGiftBox && isPackage == false) || (affectedGroups == null && debug.DbSource == ServerDbs.ItemGroupsPackages && isPackage == true)) { foreach (var pair in dico.OrderBy(p => p.Key)) { var dbTuple = itemDb.TryGetTuple(pair.Key); List <string> items = ServerItemGroupSubAttributes.AttributeList.Attributes.Select(p => pair.Value.GetValue <string>(p)).ToList(); RemoveDefaultValues(items); writer.WriteLine(_getWriterGroupName(key, constantDb) + "," + string.Join(",", items.ToArray()) + (dbTuple == null ? "" : "\t// " + dbTuple.GetValue(ServerItemAttributes.Name))); } writer.WriteLine(); } } } } else if (debug.FileType == FileType.Conf) { StringBuilder builder = new StringBuilder(); var dbItems = db.GetMeta <int>(ServerDbs.Items); List <string> aegisNames = dbItems.FastItems.Select(p => p.GetStringValue(ServerItemAttributes.AegisName.Index)).ToList(); List <string> names = dbItems.FastItems.Select(p => p.GetStringValue(ServerItemAttributes.Name.Index)).ToList(); foreach (int id in db.Table.FastItems.Select(p => p.Key).OrderBy(p => p)) { //bool isPackage = _isPackage((Dictionary<int, ReadableTuple<int>>)db.Table[id].GetRawValue(1)); // //if (debug.DbSource == ServerDbs.ItemGroupsMisc && isPackage) // continue; // //if (debug.DbSource == ServerDbs.ItemGroupsPackages && !isPackage) // continue; builder.AppendLine(ItemGroupParser.ToHerculesDbEntry(db, id, aegisNames, names)); builder.AppendLine(); } IOHelper.WriteAllText(debug.FilePath, builder.ToString()); } } catch (Exception err) { debug.ReportException(err); } }
public static void DbItemGroups <TKey>(DbDebugItem <TKey> debug, AbstractDb <TKey> db) { foreach (DbAttribute attribute in ServerItemGroupSubAttributes.AttributeList.Attributes) { db.Attached[attribute.DisplayName] = false; } if (debug.FileType == FileType.Txt) { if (db.Attached["FromUserRawInput"] != null && (bool)db.Attached["FromUserRawInput"]) { _loadItemsGroupdDb(db, debug.FilePath); return; } using (StreamReader reader = new StreamReader(File.OpenRead(debug.FilePath))) { string line; while (!reader.EndOfStream) { line = reader.ReadLine(); if (line != null && line.StartsWith("import: ")) { string dbPath = AllLoaders.DetectPathAll(line.Replace("import: ", "")); if (dbPath == null) { ErrorHandler.HandleException("Couldn't find the file '" + line.Replace("import: ", "") + "'."); } else { db.Attached[dbPath] = new Tuple <string, HashSet <int> >(line.Replace("import: ", ""), new HashSet <int>()); _loadItemsGroupdDb(db, dbPath); } } } } } else if (debug.FileType == FileType.Conf) { ItemGroupParser itemHelper = new ItemGroupParser(); Table <int, ReadableTuple <int> > itemsDb = db.GetMeta <int>(ServerDbs.Items); int index = ServerItemAttributes.AegisName.Index; var table = db.Table; var items = itemsDb.FastItems; // The reverse table is used for an optimization (~3 seconds to ~50 ms) // All the items are stored in a dictionary by their name instead of their ID TkDictionary <string, int> reverseTable = new TkDictionary <string, int>(); foreach (var item in items) { reverseTable[item.GetStringValue(index).ToLowerInvariant()] = item.GetKey <int>(); } #if SDE_DEBUG Z.StopAndRemoveWithoutDisplay(-1); Z.StopAndRemoveWithoutDisplay(-2); Z.StopAndRemoveWithoutDisplay(-3); CLHelper.CR(-2); #endif foreach (string elements in TextFileHelper.GetElementsByParenthesis(File.ReadAllBytes(debug.FilePath))) { #if SDE_DEBUG CLHelper.CS(-2); CLHelper.CR(-1); CLHelper.CR(-3); #endif if (!itemHelper.Init(debug, elements)) { return; } #if SDE_DEBUG CLHelper.CS(-3); #endif try { Tuple tupleItem = itemsDb.TryGetTuple(reverseTable[itemHelper.Id.ToLowerInvariant()]); if (tupleItem == null) { if (itemHelper.Id.StartsWith("ID")) { int ival; if (Int32.TryParse(itemHelper.Id.Substring(2), out ival)) { tupleItem = itemsDb.TryGetTuple(ival); } if (tupleItem == null) { debug.ReportIdException("Item ID '" + ival + "' couldn't be found.", itemHelper.Id, ErrorLevel.Critical); continue; } } if (tupleItem == null) { debug.ReportIdException("Item ID '" + itemHelper.Id + "' couldn't be found.", itemHelper.Id, ErrorLevel.Critical); continue; } } TKey itemId = tupleItem.GetKey <TKey>(); if (!table.ContainsKey(itemId)) { ReadableTuple <TKey> tuple = new ReadableTuple <TKey>(itemId, db.AttributeList); tuple.SetRawValue(ServerItemGroupAttributes.Table, new Dictionary <int, ReadableTuple <int> >()); table.Add(itemId, tuple); } for (int i = 0; i < itemHelper.Quantities.Count; i++) { string onameId = itemHelper.Quantities[i].Item1; string orate = itemHelper.Quantities[i].Item2; int id = 0; int rate; tupleItem = itemsDb.TryGetTuple(reverseTable[onameId.ToLowerInvariant()]); if (tupleItem == null) { if (onameId.StartsWith("ID")) { if (!Int32.TryParse(onameId.Substring(2), out id)) { debug.ReportIdException("Item ID '" + itemHelper.Quantities[i].Item1 + "' couldn't be found in group '" + itemHelper.Id + "'.", itemHelper.Id, ErrorLevel.Critical); continue; } } else { debug.ReportIdException("Item ID '" + itemHelper.Quantities[i].Item1 + "' couldn't be found in group '" + itemHelper.Id + "'.", itemHelper.Id, ErrorLevel.Critical); continue; } } int nameId = tupleItem == null ? id : tupleItem.GetKey <int>(); Int32.TryParse(orate, out rate); Dictionary <int, ReadableTuple <int> > dico = (Dictionary <int, ReadableTuple <int> >)table.GetRaw(itemId, ServerItemGroupAttributes.Table); ReadableTuple <int> tuple = new ReadableTuple <int>(nameId, ServerItemGroupSubAttributes.AttributeList); tuple.SetRawValue(ServerItemGroupSubAttributes.Rate, rate); dico[nameId] = tuple; } } catch { if (!debug.ReportIdException(itemHelper.Id)) { return; } } #if SDE_DEBUG CLHelper.CS(-1); CLHelper.CR(-2); #endif } #if SDE_DEBUG CLHelper.CS(-2); CLHelper.CS(-3); CLHelper.WA = ", method core : " + CLHelper.CD(-1) + "ms, loop getter : " + CLHelper.CD(-2) + "ms, internal parser : " + CLHelper.CD(-3); #endif } }
public static void DbItemGroupWriter <TKey>(DbDebugItem <TKey> debug, AbstractDb <TKey> db) { try { if (debug.FileType == FileType.Txt) { string currentDirectory = Path.GetDirectoryName(debug.FilePath); string parentDirectory = Path.GetDirectoryName(currentDirectory); var itemDb = db.GetMeta <int>(ServerDbs.Items); ServerType source = AllLoaders.GetServerType(); using (StreamWriter writerPrimary = new StreamWriter(debug.FilePath)) { // currentDirectory = something\db\pre-re // parentDirectory = something\db // outmostDirectory = something if (source == ServerType.Hercules) { // This means we read the file from Hercules db.Attached["0"] = new Tuple <string, HashSet <int> >("db/" + debug.SubPath + "/item_bluebox.txt", new HashSet <int> { 1 }); db.Attached["1"] = new Tuple <string, HashSet <int> >("db/" + debug.SubPath + "/item_violetbox.txt", new HashSet <int> { 2 }); db.Attached["2"] = new Tuple <string, HashSet <int> >("db/" + debug.SubPath + "/item_cardalbum.txt", new HashSet <int> { 3, 44 }); db.Attached["3"] = new Tuple <string, HashSet <int> >("db/item_findingore.txt", new HashSet <int> { 6 }); db.Attached["4"] = new Tuple <string, HashSet <int> >("db/" + debug.SubPath + "/item_giftbox.txt", new HashSet <int> { 4, 28, 29, 30, 31, 34, 43 }); db.Attached["5"] = new Tuple <string, HashSet <int> >("db/" + debug.SubPath + "/item_misc.txt", new HashSet <int> { 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17 }); } List <Tuple <string, HashSet <int> > > loadedItems = db.Attached.Values.OfType <Tuple <string, HashSet <int> > >().OrderBy(p => p.Item2.Count).ToList(); List <ReadableTuple <TKey> > allTuples; if (source == ServerType.Hercules) { allTuples = db.Table.FastItems.Select(p => db.Table.Copy(p.GetKey <TKey>())).ToList(); List <string> constantsList = Constants.Keys.ToList(); Dictionary <int, int> matches = new Dictionary <int, int>(); Table <int, ReadableTuple <int> > table = db.GetMeta <int>(ServerDbs.Items); for (int i = 0; i < allTuples.Count; i++) { var tuple = allTuples[i]; int key = tuple.GetKey <int>(); if (matches.ContainsKey(key)) { tuple.SetRawValue(0, matches[key]); continue; } var res2 = table.TryGetTuple(key); if (res2 != null) { string name = res2.GetValue(ServerItemAttributes.AegisName).ToString(); string closestString = Methods.ClosestString(name, constantsList); int groupId = Constants[closestString]; matches[key] = groupId; tuple.SetRawValue(0, matches[key]); } else { debug.ReportException("Key not found : " + key); } } } else { allTuples = db.Table.FastItems; } for (int i = 0; i < loadedItems.Count; i++) { var tuple = loadedItems[i]; string importPath = tuple.Item1.Trim(' ', '\t'); string temp = Path.GetDirectoryName(importPath); string outputPath = ""; var set = tuple.Item2; int level = 0; while (!string.IsNullOrEmpty(temp)) { temp = Path.GetDirectoryName(temp); level++; } string internalPath = ""; if (level == 2) { outputPath = "db/" + debug.SubPath + "/" + Path.GetFileName(importPath); internalPath = debug.SubPath + "/" + Path.GetFileName(importPath); } else if (level == 1) { outputPath = "db/" + Path.GetFileName(importPath); internalPath = Path.GetFileName(importPath); } string filePath = GrfPath.Combine(parentDirectory, internalPath); GrfPath.CreateDirectoryFromFile(filePath); List <ReadableTuple <TKey> > tuples; if (i == loadedItems.Count - 1) { //outputeverything tuples = allTuples; } else { tuples = allTuples.Where(p => set.Contains(p.GetKey <int>())).ToList(); for (int j = 0; j < tuples.Count; j++) { allTuples.Remove(tuples[j]); } } using (StreamWriter writer = new StreamWriter(filePath)) { foreach (ReadableTuple <TKey> tup in tuples.OrderBy(p => p.GetKey <TKey>())) { Dictionary <int, ReadableTuple <int> > dico = (Dictionary <int, ReadableTuple <int> >)tup.GetRawValue(1); int key = tup.GetKey <int>(); foreach (var pair in dico.OrderBy(p => p.Key)) { var dbTuple = itemDb.TryGetTuple(pair.Key); List <string> items = ServerItemGroupSubAttributes.AttributeList.Attributes.Select(p => pair.Value.GetValue <string>(p)).ToList(); RemoveDefaultValues(items); writer.WriteLine(key + "," + string.Join(",", items.ToArray()) + (dbTuple == null ? "" : "\t// " + dbTuple.GetValue(ServerItemAttributes.Name))); } writer.WriteLine(); } } writerPrimary.WriteLine("import: " + outputPath); } } } else if (debug.FileType == FileType.Conf) { StringBuilder builder = new StringBuilder(); var dbItems = db.GetMeta <int>(ServerDbs.Items); List <string> aegisNames = dbItems.FastItems.Select(p => p.GetStringValue(ServerItemAttributes.AegisName.Index)).ToList(); List <string> names = dbItems.FastItems.Select(p => p.GetStringValue(ServerItemAttributes.Name.Index)).ToList(); foreach (int id in db.Table.FastItems.Select(p => p.GetKey <int>()).OrderBy(p => p)) { builder.AppendLine(ItemGroupParser.ToHerculesDbEntry(db, id, aegisNames, names)); builder.AppendLine(); } File.WriteAllText(debug.FilePath, builder.ToString(), Encoding.Default); } } catch (Exception err) { debug.ReportException(err); } }