-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainForm.cs
More file actions
196 lines (171 loc) · 6.67 KB
/
Copy pathMainForm.cs
File metadata and controls
196 lines (171 loc) · 6.67 KB
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
using FSB5BankParser.Forms;
using SimpleRIFF.RIFF_Objects;
using System.Reflection;
#pragma warning disable CS8602
#pragma warning disable CS8714
/*
Main TODO things
- Find where/how Sound GUIDs and Sound Names are linked in binary
^THISSSSSSSS
- Finish FSPRO decompilation system
- Do more research with already known and unknown chunks
*/
namespace FSB5BankParser
{
public partial class MainForm : Form
{
public MainForm()
{
InitializeComponent();
Console.WriteLine($"FSB5BankParser v{BuildVersion}" +
$"\n\tby burnedpopcorn180" +
$"\n\nNo Bank files Loaded" +
$"\nPlease select a folder to load all bank files\n");
}
public readonly static string BuildVersion =
$"{Assembly.GetExecutingAssembly().GetName().Version}";
public static string FSPROVersion = "Studio.02.02.00"; // For XML, could be changed
public string BankFolder = string.Empty;
public List<string> BankFiles = [];
public Dictionary<string, RIFFObject?> RIFFObjects = [];
// Construct entire FMOD system
public SystemConstructor FMODSystem = new();
// really dont want to do this
// but its kinda the only easy way i can think of to make everything more modular
private string? cCode = null;
private RIFFGenericDataObject? ItemAsObj = null;
private RIFFListObject? ItemAsList = null;
private TreeNode? latestNode = null;
// Settings
private bool ShowEmptyChunks = false;
#region UI/Dropdown Buttons
private void aboutToolStripMenuItem_Click(object sender, EventArgs e) {
new AboutForm(BuildVersion).ShowDialog();
}
private void button1_Click(object sender, EventArgs e) {
LoadFSB5Files();
}
private void openFileToolStripMenuItem_Click(object sender, EventArgs e) {
LoadFSB5Files();
}
private void unloadFileToolStripMenuItem_Click(object sender, EventArgs e) {
UnloadFSB5Files();
}
private void showEmptyChunksToolStripMenuItem_Click(object sender, EventArgs e)
{
// update this
ShowEmptyChunks = !ShowEmptyChunks;
showEmptyChunksToolStripMenuItem.Text = !ShowEmptyChunks ? "Show Empty Chunks" : "Hide Empty Chunks";
// update treenode (don't need to unload it because load does it for me lol)
LoadTreeView();
}
#endregion
#region Tools
private void extractBankAsFolderToolStripMenuItem_Click(object sender, EventArgs e)
{
if (BankFiles.Count == 0)
{
MessageBox.Show("No bank files loaded\nPlease load bank files and try again", "Error");
return;
}
// TEMP
MessageBox.Show("Note that this feature is currently UNFINISHED, and will NOT result in a functional output" +
"\n\nPlease do not report this to Github Issues", "NOTICE");
InputForm input = new();
input.ShowDialog();
if (input.AcceptedClose)
InitFSPROExport(input.InputText);
else
MessageBox.Show("Operation Cancelled\nPlease try again", "Error");
GC.Collect();
}
private void extractallsoundsToolStripMenuItem_Click(object sender, EventArgs e)
{
using FolderBrowserDialog dialog = new();
dialog.Description = "Select Folder to Export Sound Files";
dialog.UseDescriptionForTitle = true;
if (dialog.ShowDialog() == DialogResult.OK && !string.IsNullOrWhiteSpace(dialog.SelectedPath))
ExtractSoundEntries(dialog.SelectedPath);
}
private void exportSelectedChunkToolStripMenuItem_Click(object sender, EventArgs e) {
ExportSelectedChunk();
}
#endregion
#region Context Menu
private void exportToolStripMenuItem_Click(object sender, EventArgs e) {
ExportSelectedChunk();
}
private void viewHexToolStripMenuItem_Click(object sender, EventArgs e)
{
if (bankTreeView.SelectedNode.Tag is RIFFGenericDataObject item)
new HexViewerForm(item.Data).Show();
}
private void bankTreeView_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
{
if (e.Button == MouseButtons.Left || e.Button == MouseButtons.Right)
bankTreeView.SelectedNode = e.Node;
}
#endregion
#region Search Box
private void SearchTextBox_TextChanged(object sender, EventArgs e)
{
// if text changes during countdown, restart it again
searchTimer.Stop();
searchTimer.Start();
}
private void SearchTimer_Tick(object sender, EventArgs e)
{
// once countdown finishes, stop it and search
searchTimer.Stop();
bankTreeView.BeginUpdate();
string searchText = searchTextBox.Text.Trim();
// if empty, then reset everything
if (string.IsNullOrWhiteSpace(searchText)) {
ResetTree(bankTreeView.Nodes);
}
// if not, search nodes
else
{
foreach (TreeNode node in bankTreeView.Nodes)
SearchNodes(node, searchText);
}
bankTreeView.EndUpdate();
}
#region Recursive Search Funcs
private static bool SearchNodes(TreeNode currentNode, string searchText)
{
bool isMatch = currentNode.Text.Contains(searchText, StringComparison.OrdinalIgnoreCase);
bool childMatched = false;
foreach (TreeNode child in currentNode.Nodes)
{
if (SearchNodes(child, searchText))
childMatched = true;
}
if (isMatch || childMatched)
{
currentNode.BackColor = isMatch ? Color.Yellow : Color.White;
currentNode.Expand();
if (isMatch)
currentNode.EnsureVisible();
return true;
}
else
{
currentNode.BackColor = Color.White;
currentNode.Collapse();
return false;
}
}
private static void ResetTree(TreeNodeCollection nodes)
{
foreach (TreeNode node in nodes)
{
node.BackColor = Color.White;
node.Collapse();
ResetTree(node.Nodes);
}
}
#endregion
#endregion
}
}