private void Window_Loaded(object sender, RoutedEventArgs e) { Properties.Settings.Default.Reload(); Title = _defaultTitle; if (Settings.Default.FilterHistory == null) { Settings.Default.FilterHistory = new System.Collections.Specialized.StringCollection(); } if (Settings.Default.FileHistory == null) { Settings.Default.FileHistory = new System.Collections.Specialized.StringCollection(); } filterText.ItemsSource = Settings.Default.FilterHistory; Settings.Default.FileHistory.Remove("<none>"); Dictionary <string, string> friendlyNames = null; if (File.Exists(Properties.Settings.Default.ListCfgFile)) { friendlyNames = GDStash.GetFriendlyNames(Properties.Settings.Default.ListCfgFile); } BuildUrlCache(Path.Combine(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location), "ItemLinks.csv")); BuildMruMenu(friendlyNames); string[] args = Environment.GetCommandLineArgs(); if (args != null && args.Length > 1) { //1st arg is self, so skip first OpenStashFiles(args.Skip(1).Take(args.Length - 1)); } }
private void OpenStashFiles(IEnumerable <string> filenames, bool includePlayerCharacters = false) { Cursor = Cursors.Wait; bool showErrors = true; Stopwatch sw = Stopwatch.StartNew(); string extractBaseFolder; if (string.IsNullOrEmpty(Properties.Settings.Default.ExtractedRootFolder)) { extractBaseFolder = Path.Combine(Environment.CurrentDirectory, @"\Extracted\"); } else { extractBaseFolder = Properties.Settings.Default.ExtractedRootFolder; } if (!File.Exists(Path.Combine(extractBaseFolder, @"records\items\gearweapons\axe1h\a01_axe000.dbr"))) { MessageBox.Show("Please Configure Settings to point to a valid root folder where the GD game database is Extracted", "Error", MessageBoxButton.OK, MessageBoxImage.Error); Cursor = Cursors.Arrow; return; } string resourceFolder; if (string.IsNullOrEmpty(Properties.Settings.Default.ExtractedRootFolder)) { resourceFolder = Path.Combine(Environment.CurrentDirectory, @"\Extracted\"); } else { resourceFolder = Properties.Settings.Default.ResourceFolder; } if (!File.Exists(Path.Combine(resourceFolder, @"tags_items.txt"))) { MessageBox.Show("Please Configure Settings to point to a valid Resource folder containing 'tag*.txt' files", "Error", MessageBoxButton.OK, MessageBoxImage.Error); Cursor = Cursors.Arrow; return; } string title = _defaultTitle; ConcurrentBag <GDStash> stashes = new ConcurrentBag <GDStash>(); _stashes = new List <GDStash>(filenames.Count()); Dictionary <string, string> friendlyNames = null; if (File.Exists(Settings.Default.ListCfgFile)) { friendlyNames = GDStash.GetFriendlyNames(Settings.Default.ListCfgFile); } //Parallel.ForEach(filenames, _parallelOptions, filename => foreach (string filename in filenames) { if (File.Exists(filename)) { GDStash stash = new GDStash(); stash.Open(filename); stash.UpdateItems(extractBaseFolder, resourceFolder, Settings.Default.ListCfgFile, Settings.Default.ShouldResolveAffixes, Settings.Default.UseAlternateAffixFormat); stashes.Add(stash); } else { if (showErrors) { showErrors = MessageBox.Show("Stash File Not Found: " + filename + "\n\nDo you wish to be notified of other files not found?", "File Not Found", MessageBoxButton.YesNo, MessageBoxImage.Error) == MessageBoxResult.Yes; } } } //); _stashes = stashes.ToList(); List <GDStashItem> itemList = new List <GDStashItem>(); foreach (GDStash stash in _stashes) { string filename = stash.FileName; string key = Path.GetFileName(filename); itemList.AddRange(stash.Items); AddFilesToMru(filename); if (friendlyNames != null && friendlyNames.ContainsKey(key)) { title += string.Format(" {0}-{1}", friendlyNames[key], filename); } else { title += " " + filename; } } Title = title; BuildMruMenu(friendlyNames); ConcurrentDictionary <string, bool> dontExportDict = ReadDontExportItemsList(); Parallel.ForEach(itemList, _parallelOptions, item => //foreach(var item in itemList) { if (!string.IsNullOrEmpty(item.Name)) { int key = item.EmpoweredName.ToLower().GetHashCode(); int number; if (_urlCache.ContainsKey(key)) { number = _urlCache[key]; item.Url = string.Format("http://www.grimtools.com/db/items/{0}", number); } else if (item.Tag == "tagMedalD002") //Badge of Mastery edge case, key wont be in dict if affixes are resolved { item.Url = "http://www.grimtools.com/db/items/794"; } string key2 = item.Tag + item.seed; if (dontExportDict != null && dontExportDict.ContainsKey(key2)) { item.DontExport = dontExportDict[key2]; } } } ); if (Settings.Default.IncludePlayerCharacters) { //TODO: Major Cleanup string savedGamesFolder = GDPlayer.GetSavedGamesDir(); string charsFolder = Path.Combine(savedGamesFolder, @"Grim Dawn\save\main\"); string errorMessage = string.Empty; if (Directory.Exists(charsFolder)) { foreach (string folder in Directory.EnumerateDirectories(charsFolder)) { GDPlayer player = new GDPlayer(); string filename = Path.Combine(folder, @"player.gdc"); try { player.read(filename); } catch (Exception) { errorMessage += filename + "\r\n"; } GDStash stash = new GDStash { FriendlyName = player.hdr.name + " (Inventory)", FileName = filename, Bags = new List <GDStashBag>(player.inv.Bags.Count) }; stash.Bags.AddRange(player.inv.Bags); stash.UpdateItems(extractBaseFolder, resourceFolder, Settings.Default.ListCfgFile, Settings.Default.ShouldResolveAffixes, Settings.Default.UseAlternateAffixFormat); itemList.AddRange(stash.Items); stash = new GDStash { FriendlyName = player.hdr.name + " (Stash)", FileName = filename, Bags = new List <GDStashBag>(player.stash.Bags.Count) }; stash.Bags.AddRange(player.stash.Bags); stash.UpdateItems(extractBaseFolder, resourceFolder, Settings.Default.ListCfgFile, Settings.Default.ShouldResolveAffixes, Settings.Default.UseAlternateAffixFormat); itemList.AddRange(stash.Items); stash = new GDStash { FriendlyName = player.hdr.name + " (Equipped)", FileName = filename, Bags = new List <GDStashBag>(1) }; stash.Bags.Add(new GDStashBag()); stash.Bags[0].Items = new List <GDStashItem>(player.inv.equipment.Where(i => i.baseName != null)); stash.UpdateItems(extractBaseFolder, resourceFolder, Settings.Default.ListCfgFile, Settings.Default.ShouldResolveAffixes, Settings.Default.UseAlternateAffixFormat); itemList.AddRange(stash.Items); //stash.Items.AddRange(player.inv.Items); //stash.Bags.AddRange(player.stash.Bags); //stash.Items.AddRange(player.stash.Items); } } if (!string.IsNullOrEmpty(errorMessage)) { MessageBox.Show("Error Reading Character File(s) :\r\n" + errorMessage + "The file(s) may be in the old format, try Loading the character(s) in the game and exit before trying again.\r\n Program will continue", "Error Reading Character File(s)", MessageBoxButton.OK, MessageBoxImage.Warning); } } itemList.Sort((item1, item2) => { return(item1.Name.CompareTo(item2.Name)); }); _collectionViewSource = new CollectionViewSource { Source = itemList }; _dataGrid.ItemsSource = _collectionViewSource.View; RefreshColumnLayout(); sw.Stop(); TextBlock tb = new TextBlock { Text = string.Format("{0} Stash File(s) Opened at {1}. Elapsed Time: {2} seconds.", _stashes.Count, DateTime.Now.ToLocalTime().ToShortTimeString(), Math.Round(sw.Elapsed.TotalSeconds, 2)) }; //tb.ToolTip = String.Join(" , ",_stashes.Select(s => s.FileName)); StatusText.Content = tb; Cursor = Cursors.Arrow; }