-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathMainWindow.xaml.cs
163 lines (146 loc) · 6.12 KB
/
MainWindow.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Forms;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using PakExplorer.Es.Models;
using PakExplorer.Pak;
using PakExplorer.Tree;
using PakExplorer.Tree.Files;
using PakExplorer.Tree.Items;
using PakExplorer.Tree.Items.Es;
using PakExplorer.Tree.Items.Es.Child;
using Cursors = System.Windows.Input.Cursors;
using MessageBox = System.Windows.MessageBox;
using OpenFileDialog = Microsoft.Win32.OpenFileDialog;
using Path = System.IO.Path;
namespace PakExplorer {
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window {
private bool ParseScripts = false;
private readonly ObservableCollection<ITreeItem> PakList = new();
private readonly ObservableCollection<ITreeItem> ScriptList = new();
private PakTreeItem? CurrentPak { get; set; }
private FileBase? SelectedEntry { get; set; }
public MainWindow() {
InitializeComponent();
PakView.ItemsSource = PakList;
}
private void OpenFile(object sender, ExecutedRoutedEventArgs e) {
var dlg = new OpenFileDialog();
dlg.Title = "Load PAK archive";
dlg.DefaultExt = ".pak";
dlg.Filter = "PAK File|*.pak|Preview BI Files|*.pak";
dlg.Multiselect = true;
if (dlg.ShowDialog() == true) {
LoadPAK(dlg.FileName);
}
}
private void ExtractAll(object sender, RoutedEventArgs e) {
var dialog = new FolderBrowserDialog();
dialog.Description = "Extract To...";
dialog.UseDescriptionForTitle = true;
dialog.ShowDialog();
ExtractAllToFolder(dialog.SelectedPath);
}
private void ExtractAllToFolder(string dialogSelectedPath) {
foreach (PakTreeItem pak in PakList) {
var currentExtractPath = Path.Combine(dialogSelectedPath,
Path.GetFileNameWithoutExtension(pak.PakFile.FileName));
foreach (var entry in pak.PakFile.PakEntries) {
var extractPath = Path.Combine(currentExtractPath, entry.Name);
if (!Directory.Exists(Directory.GetParent(extractPath)?.FullName)) {
Directory.CreateDirectory(Directory.GetParent(extractPath).FullName);
}
File.WriteAllBytesAsync(extractPath, entry.EntryData);
}
}
}
public void LoadPAK(string path) {
var pak = new PakTreeItem(new Pak.Pak(path));
PakList.Add(pak);
if (!ParseScripts) return;
if (MessageBox.Show("It looks like you have Parse Scripts enabled, this can impact pak load time and in extreme cases cause freezing." +
" Do you want to disable script parsing for this pak?", "Disable Parsing?", MessageBoxButton.YesNo,
MessageBoxImage.Warning) == MessageBoxResult.No) {
ScriptList.Add(new ScriptPakTreeItem(pak));
}
}
private void ShowPakEntry(object sender, RoutedPropertyChangedEventArgs<object> e) {
ResetView();
Cursor = Cursors.Wait;
switch (e.NewValue) {
case FileBase entry:
SelectedEntry = entry;
Show(entry);
break;
case PakDirectoryTreeItem directory:
break;
}
Cursor = Cursors.Arrow;
}
private void ResetView() {
TextPreview.Visibility = Visibility.Hidden;
TextPreview.Text = string.Empty;
SelectedEntry = null;
CurrentPak = null;
}
private void Show(FileBase entry) {
ResetView();
TextPreview.Text = Encoding.UTF8.GetString(entry.EntryData);
TextPreview.Visibility = Visibility.Visible;
}
private void ShowPakScript(object sender, RoutedPropertyChangedEventArgs<object> e) {
switch (e.NewValue) {
case EnforceScriptTreeItem esItem:
ResetView();
TextPreview.Text = esItem.Scope.ToString();
TextPreview.Visibility = Visibility.Visible;
break;
case EnforceClassTreeItem esClassItem:
ResetView();
TextPreview.Text = esClassItem.EsClazz.ToString();
TextPreview.Visibility = Visibility.Visible;
break;
case EnforceFunctionTreeItem esFunctionItem:
ResetView();
TextPreview.Text = esFunctionItem.EsFunction.ToString();
TextPreview.Visibility = Visibility.Visible;
break;
case EnforceVariableTreeItem esVariableItem:
ResetView();
TextPreview.Text = esVariableItem.EsVariable.ToString() + ';';
TextPreview.Visibility = Visibility.Visible;
break;
}
}
private void EnableScriptParsing_Click(object sender, RoutedEventArgs e) {
ParseScripts = true;
ScriptsTab.Visibility = Visibility.Visible;
ScriptView.ItemsSource = ScriptList;
foreach (var pak in PakList) ScriptList.Add(new ScriptPakTreeItem((PakTreeItem) pak));
}
private void DisableScriptParsing_Click(object sender, RoutedEventArgs e) {
ParseScripts = false;
ScriptView.ItemsSource = null;
ScriptsTab.Visibility = Visibility.Hidden;
ScriptList.Clear();
}
}
}