/// <summary> /// Opens file dialog to open a package /// </summary> private void OpenFileClick(object sender, RoutedEventArgs e) { ViewModel.Assets.ClearAssets(); ActivePackage?.Dispose(); ActivePackage = null; GC.Collect(); var dialog = new OpenFileDialog() { Title = "Tyrant | Open File", Filter = "Package files (*.pak)|*.pak|All files (*.*)|*.*" }; if (dialog.ShowDialog() == true) { if (Path.GetExtension(dialog.FileName).ToLower() == ".pak") { LoadPackage(dialog.FileName); } } }
/// <summary> /// Handles cleaning up on close /// </summary> private void MainWindowClosing(object sender, CancelEventArgs e) { ActivePackage?.Dispose(); Settings.Save("Settings.tcfg"); }
/// <summary> /// Loads a Package /// </summary> public void LoadPackage(string path) { try { ViewModel.Assets.ClearAssets(); ActivePackage?.Dispose(); ActivePackage = new Package(path); List <Asset> results = new List <Asset>(ActivePackage.Entries.Count); foreach (var entry in ActivePackage.Entries) { if (Cache.Entries.TryGetValue(entry.Key, out var name)) { string type = "Unknown"; if (name.Contains(".tex.")) { if (Settings["ShowTextures", "Yes"] == "Yes") { type = "Texture"; } else { continue; } } else if (name.Contains(".mesh.")) { if (Settings["ShowModels", "Yes"] == "Yes") { type = "Mesh"; } else { continue; } } else if (name.Contains(".motlist.")) { if (Settings["ShowAnims", "Yes"] == "Yes") { type = "MotionList"; } else { continue; } } else if (name.Contains(".mot.")) { if (Settings["ShowAnims", "Yes"] == "Yes") { type = "Motion"; } else { continue; } } //else if (name.Contains(".bnk.") && Settings["ShowSounds", "Yes"] == "Yes") // type = "SoundBank"; else if (Settings["ShowAll", "No"] == "Yes") { type = "Unknown"; } else { continue; } results.Add(new Asset(name, type, entry.Value)); } else if (Settings["ShowAll", "No"] == "Yes") { results.Add(new Asset("asset_" + entry.Key.ToString("x"), "Unknown", entry.Value)); } } ViewModel.Assets.AddAssets(results.OrderBy(x => x.Name).OrderBy(x => x.Type)); } catch (Exception e) { ActivePackage?.Dispose(); ActivePackage = null; MessageBox.Show(string.Format("An error occured while loading the package:\n\n{0}", e), "Tryant | Error", MessageBoxButton.OK, MessageBoxImage.Error); } }