0
|
1 using System;
|
|
2 using System.Drawing;
|
|
3 using System.Collections;
|
|
4 using System.ComponentModel;
|
|
5 using System.Windows.Forms;
|
|
6 using System.Data;
|
|
7 using IBBoard;
|
|
8 using IBBoard.Relic.RelicTools;
|
|
9 using IBBoard.Relic.RelicTools.Exceptions;
|
|
10 using System.Threading;
|
|
11 using System.IO;
|
|
12
|
|
13 namespace IBBoard.Relic.IChunkyViewer
|
|
14 {
|
|
15 /// <summary>
|
|
16 /// Summary description for Form1.
|
|
17 /// </summary>
|
|
18 public class Form1 : System.Windows.Forms.Form
|
|
19 {
|
|
20 private System.Windows.Forms.MainMenu mainMenu;
|
|
21 private System.Windows.Forms.MenuItem menuItem1;
|
|
22 private System.Windows.Forms.MenuItem miFile_Open;
|
|
23 private System.Windows.Forms.OpenFileDialog openFileDialog;
|
|
24 private System.ComponentModel.IContainer components;
|
|
25 private System.Windows.Forms.TreeView treeView;
|
|
26 private System.Windows.Forms.TextBox txtDetails;
|
|
27 private System.Windows.Forms.ImageList imageList;
|
|
28 private System.Windows.Forms.ContextMenu contextMenu;
|
|
29 private System.Windows.Forms.MenuItem miSaveChunk;
|
|
30 private System.Windows.Forms.SaveFileDialog saveFileDialog;
|
|
31 private System.Windows.Forms.MenuItem menuItem2;
|
|
32 private System.Windows.Forms.MenuItem menuItem3;
|
|
33 private System.Windows.Forms.MenuItem menuItem4;
|
|
34
|
|
35 private RelicChunkyFile chunkyFile;
|
|
36 private string chunkyFilePath = "";
|
|
37 private string chunkyFileNewPath = "";
|
|
38 private System.Windows.Forms.MenuItem menuItem5;
|
|
39 private System.Windows.Forms.FolderBrowserDialog folderBrowserDialog;
|
|
40 private System.Windows.Forms.StatusBar statusBar;
|
|
41 private System.Windows.Forms.Timer timer;
|
|
42
|
|
43 private System.Windows.Forms.MenuItem menuItem6;
|
|
44 private System.Windows.Forms.MenuItem menuItem8;
|
|
45 private System.Windows.Forms.MenuItem miExportChunk;
|
|
46 private System.Windows.Forms.MenuItem miImportChunk;
|
|
47 private System.Windows.Forms.SaveFileDialog exportFileDialog;
|
|
48 private System.Windows.Forms.OpenFileDialog importFileDialog;
|
|
49 private System.Windows.Forms.MenuItem miImportSiblingChunk;
|
|
50 private System.Windows.Forms.MenuItem menuItem9;
|
|
51 private System.Windows.Forms.MenuItem miSave;
|
|
52 private System.Windows.Forms.MenuItem menuItem11;
|
|
53 private System.Windows.Forms.MenuItem menuItem10;
|
|
54 private System.Windows.Forms.MenuItem miDeleteChunk;
|
|
55 private System.Windows.Forms.MenuItem miOptions;
|
|
56 private System.Windows.Forms.MenuItem menuItem7;
|
|
57 private System.Windows.Forms.MenuItem miShowValidationString;
|
|
58 private System.Windows.Forms.MenuItem menuItem16;
|
|
59 private System.Windows.Forms.MenuItem miRefreshValidations;
|
|
60
|
|
61 private ChunkyValidator[] chunkyValidators;
|
|
62 private System.Windows.Forms.MenuItem miValidateAs;
|
|
63 private System.Windows.Forms.MenuItem miNoValidators;
|
|
64 private Preferences preferences;
|
|
65
|
|
66 private Progress progress = null;
|
|
67
|
|
68 private Form1()
|
|
69 { //
|
|
70 // Required for Windows Form Designer support
|
|
71 //
|
|
72 InitializeComponent();
|
|
73 preferences = new Preferences("IChunkyViewer");
|
|
74
|
|
75 openFileDialog.InitialDirectory = preferences["DoWPath"].ToString();
|
|
76 }
|
|
77
|
|
78 public Form1(string path): this()
|
|
79 {
|
|
80 if (path!=null && path.Trim()!="")
|
|
81 {
|
|
82 chunkyFileNewPath = path;
|
|
83 Thread thr = new Thread(new ThreadStart(openChunkyFile));
|
|
84 thr.Start();
|
|
85 }
|
|
86 }
|
|
87
|
|
88 private void Form1_Load(object sender, System.EventArgs e)
|
|
89 {
|
|
90 readInValidators();
|
|
91 }
|
|
92
|
|
93 /// <summary>
|
|
94 /// Clean up any resources being used.
|
|
95 /// </summary>
|
|
96 protected override void Dispose( bool disposing )
|
|
97 {
|
|
98 if( disposing )
|
|
99 {
|
|
100 if (components != null)
|
|
101 {
|
|
102 components.Dispose();
|
|
103 }
|
|
104 }
|
|
105 base.Dispose( disposing );
|
|
106 }
|
|
107
|
|
108 #region Windows Form Designer generated code
|
|
109 /// <summary>
|
|
110 /// Required method for Designer support - do not modify
|
|
111 /// the contents of this method with the code editor.
|
|
112 /// </summary>
|
|
113 private void InitializeComponent()
|
|
114 {
|
|
115 this.components = new System.ComponentModel.Container();
|
|
116 System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));
|
|
117 this.treeView = new System.Windows.Forms.TreeView();
|
|
118 this.contextMenu = new System.Windows.Forms.ContextMenu();
|
|
119 this.miSaveChunk = new System.Windows.Forms.MenuItem();
|
|
120 this.miExportChunk = new System.Windows.Forms.MenuItem();
|
|
121 this.menuItem8 = new System.Windows.Forms.MenuItem();
|
|
122 this.miImportChunk = new System.Windows.Forms.MenuItem();
|
|
123 this.miImportSiblingChunk = new System.Windows.Forms.MenuItem();
|
|
124 this.menuItem10 = new System.Windows.Forms.MenuItem();
|
|
125 this.miDeleteChunk = new System.Windows.Forms.MenuItem();
|
|
126 this.imageList = new System.Windows.Forms.ImageList(this.components);
|
|
127 this.mainMenu = new System.Windows.Forms.MainMenu();
|
|
128 this.menuItem1 = new System.Windows.Forms.MenuItem();
|
|
129 this.miFile_Open = new System.Windows.Forms.MenuItem();
|
|
130 this.menuItem5 = new System.Windows.Forms.MenuItem();
|
|
131 this.menuItem9 = new System.Windows.Forms.MenuItem();
|
|
132 this.miSave = new System.Windows.Forms.MenuItem();
|
|
133 this.menuItem11 = new System.Windows.Forms.MenuItem();
|
|
134 this.menuItem4 = new System.Windows.Forms.MenuItem();
|
|
135 this.menuItem6 = new System.Windows.Forms.MenuItem();
|
|
136 this.miOptions = new System.Windows.Forms.MenuItem();
|
|
137 this.menuItem7 = new System.Windows.Forms.MenuItem();
|
|
138 this.miShowValidationString = new System.Windows.Forms.MenuItem();
|
|
139 this.miValidateAs = new System.Windows.Forms.MenuItem();
|
|
140 this.miNoValidators = new System.Windows.Forms.MenuItem();
|
|
141 this.menuItem16 = new System.Windows.Forms.MenuItem();
|
|
142 this.miRefreshValidations = new System.Windows.Forms.MenuItem();
|
|
143 this.menuItem2 = new System.Windows.Forms.MenuItem();
|
|
144 this.menuItem3 = new System.Windows.Forms.MenuItem();
|
|
145 this.txtDetails = new System.Windows.Forms.TextBox();
|
|
146 this.openFileDialog = new System.Windows.Forms.OpenFileDialog();
|
|
147 this.saveFileDialog = new System.Windows.Forms.SaveFileDialog();
|
|
148 this.folderBrowserDialog = new System.Windows.Forms.FolderBrowserDialog();
|
|
149 this.statusBar = new System.Windows.Forms.StatusBar();
|
|
150 this.timer = new System.Windows.Forms.Timer(this.components);
|
|
151 this.exportFileDialog = new System.Windows.Forms.SaveFileDialog();
|
|
152 this.importFileDialog = new System.Windows.Forms.OpenFileDialog();
|
|
153 this.SuspendLayout();
|
|
154 //
|
|
155 // treeView
|
|
156 //
|
|
157 this.treeView.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
|
|
158 | System.Windows.Forms.AnchorStyles.Left)));
|
|
159 this.treeView.ContextMenu = this.contextMenu;
|
|
160 this.treeView.ImageList = this.imageList;
|
|
161 this.treeView.Location = new System.Drawing.Point(0, 0);
|
|
162 this.treeView.Name = "treeView";
|
|
163 this.treeView.SelectedImageIndex = 1;
|
|
164 this.treeView.Size = new System.Drawing.Size(344, 520);
|
|
165 this.treeView.TabIndex = 0;
|
|
166 this.treeView.MouseDown += new System.Windows.Forms.MouseEventHandler(this.treeView_MouseDown);
|
|
167 this.treeView.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.treeView_AfterSelect);
|
|
168 //
|
|
169 // contextMenu
|
|
170 //
|
|
171 this.contextMenu.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
|
|
172 this.miSaveChunk,
|
|
173 this.miExportChunk,
|
|
174 this.menuItem8,
|
|
175 this.miImportChunk,
|
|
176 this.miImportSiblingChunk,
|
|
177 this.menuItem10,
|
|
178 this.miDeleteChunk});
|
|
179 this.contextMenu.Popup += new System.EventHandler(this.contextMenu_Popup);
|
|
180 //
|
|
181 // miSaveChunk
|
|
182 //
|
|
183 this.miSaveChunk.Index = 0;
|
|
184 this.miSaveChunk.Text = "&Save chunk to location";
|
|
185 this.miSaveChunk.Click += new System.EventHandler(this.miSaveChunk_Click);
|
|
186 //
|
|
187 // miExportChunk
|
|
188 //
|
|
189 this.miExportChunk.Index = 1;
|
|
190 this.miExportChunk.Text = "&Export chunk";
|
|
191 this.miExportChunk.Click += new System.EventHandler(this.miExportChunk_Click);
|
|
192 //
|
|
193 // menuItem8
|
|
194 //
|
|
195 this.menuItem8.Index = 2;
|
|
196 this.menuItem8.Text = "-";
|
|
197 //
|
|
198 // miImportChunk
|
|
199 //
|
|
200 this.miImportChunk.Index = 3;
|
|
201 this.miImportChunk.Text = "&Import child chunk";
|
|
202 this.miImportChunk.Click += new System.EventHandler(this.miImportChunk_Click);
|
|
203 //
|
|
204 // miImportSiblingChunk
|
|
205 //
|
|
206 this.miImportSiblingChunk.Index = 4;
|
|
207 this.miImportSiblingChunk.Text = "I&mport sibling chunk";
|
|
208 this.miImportSiblingChunk.Click += new System.EventHandler(this.miImportSiblingChunk_Click);
|
|
209 //
|
|
210 // menuItem10
|
|
211 //
|
|
212 this.menuItem10.Index = 5;
|
|
213 this.menuItem10.Text = "-";
|
|
214 //
|
|
215 // miDeleteChunk
|
|
216 //
|
|
217 this.miDeleteChunk.Index = 6;
|
|
218 this.miDeleteChunk.Text = "&Delete chunk";
|
|
219 this.miDeleteChunk.Click += new System.EventHandler(this.miDeleteChunk_Click);
|
|
220 //
|
|
221 // imageList
|
|
222 //
|
|
223 this.imageList.ColorDepth = System.Windows.Forms.ColorDepth.Depth32Bit;
|
|
224 this.imageList.ImageSize = new System.Drawing.Size(16, 16);
|
|
225 this.imageList.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imageList.ImageStream")));
|
|
226 this.imageList.TransparentColor = System.Drawing.Color.Transparent;
|
|
227 //
|
|
228 // mainMenu
|
|
229 //
|
|
230 this.mainMenu.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
|
|
231 this.menuItem1,
|
|
232 this.menuItem6,
|
|
233 this.menuItem7,
|
|
234 this.menuItem2});
|
|
235 //
|
|
236 // menuItem1
|
|
237 //
|
|
238 this.menuItem1.Index = 0;
|
|
239 this.menuItem1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
|
|
240 this.miFile_Open,
|
|
241 this.menuItem5,
|
|
242 this.menuItem9,
|
|
243 this.miSave,
|
|
244 this.menuItem11,
|
|
245 this.menuItem4});
|
|
246 this.menuItem1.Text = "&File";
|
|
247 //
|
|
248 // miFile_Open
|
|
249 //
|
|
250 this.miFile_Open.Index = 0;
|
|
251 this.miFile_Open.Text = "&Open";
|
|
252 this.miFile_Open.Click += new System.EventHandler(this.miFile_Open_Click);
|
|
253 //
|
|
254 // menuItem5
|
|
255 //
|
|
256 this.menuItem5.Index = 1;
|
|
257 this.menuItem5.Text = "O&pen in new window";
|
|
258 this.menuItem5.Click += new System.EventHandler(this.menuItem5_Click);
|
|
259 //
|
|
260 // menuItem9
|
|
261 //
|
|
262 this.menuItem9.Index = 2;
|
|
263 this.menuItem9.Text = "-";
|
|
264 //
|
|
265 // miSave
|
|
266 //
|
|
267 this.miSave.Enabled = false;
|
|
268 this.miSave.Index = 3;
|
|
269 this.miSave.Text = "&Save";
|
|
270 this.miSave.Click += new System.EventHandler(this.miSave_Click);
|
|
271 //
|
|
272 // menuItem11
|
|
273 //
|
|
274 this.menuItem11.Index = 4;
|
|
275 this.menuItem11.Text = "-";
|
|
276 //
|
|
277 // menuItem4
|
|
278 //
|
|
279 this.menuItem4.Index = 5;
|
|
280 this.menuItem4.Text = "&Exit";
|
|
281 this.menuItem4.Click += new System.EventHandler(this.menuItem4_Click);
|
|
282 //
|
|
283 // menuItem6
|
|
284 //
|
|
285 this.menuItem6.Index = 1;
|
|
286 this.menuItem6.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
|
|
287 this.miOptions});
|
|
288 this.menuItem6.Text = "&Edit";
|
|
289 //
|
|
290 // miOptions
|
|
291 //
|
|
292 this.miOptions.Index = 0;
|
|
293 this.miOptions.Text = "&Options";
|
|
294 this.miOptions.Click += new System.EventHandler(this.miOptions_Click);
|
|
295 //
|
|
296 // menuItem7
|
|
297 //
|
|
298 this.menuItem7.Index = 2;
|
|
299 this.menuItem7.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
|
|
300 this.miShowValidationString,
|
|
301 this.miValidateAs});
|
|
302 this.menuItem7.Text = "&Tools";
|
|
303 //
|
|
304 // miShowValidationString
|
|
305 //
|
|
306 this.miShowValidationString.Enabled = false;
|
|
307 this.miShowValidationString.Index = 0;
|
|
308 this.miShowValidationString.Text = "Vali&dation string";
|
|
309 this.miShowValidationString.Click += new System.EventHandler(this.miShowValidationString_Click);
|
|
310 //
|
|
311 // miValidateAs
|
|
312 //
|
|
313 this.miValidateAs.Enabled = false;
|
|
314 this.miValidateAs.Index = 1;
|
|
315 this.miValidateAs.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
|
|
316 this.miNoValidators,
|
|
317 this.menuItem16,
|
|
318 this.miRefreshValidations});
|
|
319 this.miValidateAs.Text = "&Validate as...";
|
|
320 //
|
|
321 // miNoValidators
|
|
322 //
|
|
323 this.miNoValidators.Enabled = false;
|
|
324 this.miNoValidators.Index = 0;
|
|
325 this.miNoValidators.Text = "No validators";
|
|
326 //
|
|
327 // menuItem16
|
|
328 //
|
|
329 this.menuItem16.Index = 1;
|
|
330 this.menuItem16.Text = "-";
|
|
331 //
|
|
332 // miRefreshValidations
|
|
333 //
|
|
334 this.miRefreshValidations.Index = 2;
|
|
335 this.miRefreshValidations.Text = "Refresh list";
|
|
336 this.miRefreshValidations.Click += new System.EventHandler(this.miRefreshValidations_Click);
|
|
337 //
|
|
338 // menuItem2
|
|
339 //
|
|
340 this.menuItem2.Index = 3;
|
|
341 this.menuItem2.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
|
|
342 this.menuItem3});
|
|
343 this.menuItem2.Text = "&Help";
|
|
344 //
|
|
345 // menuItem3
|
|
346 //
|
|
347 this.menuItem3.Index = 0;
|
|
348 this.menuItem3.Text = "&About";
|
|
349 this.menuItem3.Click += new System.EventHandler(this.menuItem3_Click);
|
|
350 //
|
|
351 // txtDetails
|
|
352 //
|
|
353 this.txtDetails.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
|
|
354 | System.Windows.Forms.AnchorStyles.Left)
|
|
355 | System.Windows.Forms.AnchorStyles.Right)));
|
|
356 this.txtDetails.Font = new System.Drawing.Font("Courier New", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
|
|
357 this.txtDetails.Location = new System.Drawing.Point(344, 0);
|
|
358 this.txtDetails.Multiline = true;
|
|
359 this.txtDetails.Name = "txtDetails";
|
|
360 this.txtDetails.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
|
|
361 this.txtDetails.Size = new System.Drawing.Size(392, 520);
|
|
362 this.txtDetails.TabIndex = 1;
|
|
363 this.txtDetails.Text = "";
|
|
364 //
|
|
365 // statusBar
|
|
366 //
|
|
367 this.statusBar.Location = new System.Drawing.Point(0, 519);
|
|
368 this.statusBar.Name = "statusBar";
|
|
369 this.statusBar.Size = new System.Drawing.Size(736, 22);
|
|
370 this.statusBar.TabIndex = 2;
|
|
371 //
|
|
372 // timer
|
|
373 //
|
|
374 this.timer.Interval = 2000;
|
|
375 this.timer.Tick += new System.EventHandler(this.timer_Tick);
|
|
376 //
|
|
377 // exportFileDialog
|
|
378 //
|
|
379 this.exportFileDialog.DefaultExt = "chunk";
|
|
380 this.exportFileDialog.Filter = "Relic Chunky Chunks (*.chunk)|*.chunk";
|
|
381 //
|
|
382 // importFileDialog
|
|
383 //
|
|
384 this.importFileDialog.Filter = "Relic Chunky Chunks (*.chunk)|*.chunk";
|
|
385 //
|
|
386 // Form1
|
|
387 //
|
|
388 this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
|
|
389 this.ClientSize = new System.Drawing.Size(736, 541);
|
|
390 this.Controls.Add(this.statusBar);
|
|
391 this.Controls.Add(this.txtDetails);
|
|
392 this.Controls.Add(this.treeView);
|
|
393 this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
|
|
394 this.Menu = this.mainMenu;
|
|
395 this.Name = "Form1";
|
|
396 this.Text = "IChunky Viewer";
|
|
397 this.Load += new System.EventHandler(this.Form1_Load);
|
|
398 this.ResumeLayout(false);
|
|
399
|
|
400 }
|
|
401 #endregion
|
|
402
|
|
403 /// <summary>
|
|
404 /// The main entry point for the application.
|
|
405 /// </summary>
|
|
406 [STAThread]
|
|
407 static void Main(string[] args)
|
|
408 {
|
|
409 if (args.Length==0)
|
|
410 {
|
|
411 Application.EnableVisualStyles();
|
|
412 Application.DoEvents();
|
|
413 Application.Run(new Form1(""));
|
|
414 }
|
|
415 else if (args.Length==1 && File.Exists(args[0]))
|
|
416 {
|
|
417 Application.EnableVisualStyles();
|
|
418 Application.DoEvents();
|
|
419 Application.Run(new Form1(args[0]));
|
|
420 }
|
|
421 else
|
|
422 {
|
|
423 MessageBox.Show(null, "The file path specified was invalid. Please try again with a correct path.", "Invalid path", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
424 }
|
|
425 }
|
|
426
|
|
427 private delegate void NoParamDelegate();
|
|
428 private delegate int TreeNodeAddDelegate(TreeNode node);
|
|
429 private delegate void TreeNodeAddRangeDelegate(TreeNode[] nodes);
|
|
430
|
|
431 private void openChunkyFile()
|
|
432 {
|
|
433 if (chunkyFileNewPath=="")
|
|
434 {
|
|
435 return;
|
|
436 }
|
|
437
|
|
438 Thread progressThread = null;
|
|
439
|
|
440 //if (new FileInfo(chunkyFileNewPath).Length>102400)
|
|
441 //{
|
|
442 // progressThread = new Thread(new ThreadStart(showProgress));
|
|
443 // progressThread.Start();
|
|
444 //}
|
|
445
|
|
446 Thread.Sleep(100);
|
|
447
|
|
448 try{
|
|
449 RelicChunkyFile newChunkyFile = RelicChunkyReader.ReadChunkyFile(chunkyFileNewPath);
|
|
450 chunkyFile = newChunkyFile; // make sure we don't trash the old value if it fails
|
|
451 }
|
|
452 catch(InvalidFileException)
|
|
453 {
|
|
454 if (OnChunkyOpenFailed!=null)
|
|
455 {
|
|
456 OnChunkyOpenFailed();
|
|
457 }
|
|
458
|
|
459 MessageBox.Show(this, "The file '"+chunkyFileNewPath+"' was not a valid Relic Chunky file", "Invalid Chunky File", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
460
|
|
461 if (!(progressThread.ThreadState==ThreadState.Aborted || progressThread.ThreadState==ThreadState.AbortRequested
|
|
462 || progressThread.ThreadState==ThreadState.Stopped || progressThread.ThreadState==ThreadState.StopRequested))
|
|
463 {
|
|
464 try
|
|
465 {
|
|
466 progressThread.Abort();
|
|
467 }
|
|
468 catch{}
|
|
469 }
|
|
470
|
|
471 return;
|
|
472 }
|
|
473 catch(InvalidChunkException)
|
|
474 {
|
|
475 if (OnChunkyOpenFailed!=null)
|
|
476 {
|
|
477 OnChunkyOpenFailed();
|
|
478 }
|
|
479
|
|
480 MessageBox.Show(this, "The file '"+chunkyFileNewPath+"' was not a valid Relic Chunky file", "Invalid Chunky Chunk in file", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
481
|
|
482 if (!(progressThread.ThreadState==ThreadState.Aborted || progressThread.ThreadState==ThreadState.AbortRequested
|
|
483 || progressThread.ThreadState==ThreadState.Stopped || progressThread.ThreadState==ThreadState.StopRequested))
|
|
484 {
|
|
485 try
|
|
486 {
|
|
487 progressThread.Abort();
|
|
488 }
|
|
489 catch{}
|
|
490 }
|
|
491
|
|
492 return;
|
|
493 }
|
|
494
|
|
495 chunkyFilePath = chunkyFileNewPath;
|
|
496 chunkyFileNewPath = "";
|
|
497
|
|
498 if (OnChunkyOpened!=null)
|
|
499 {
|
|
500 OnChunkyOpened(chunkyFilePath);
|
|
501 }
|
|
502
|
|
503 treeView.Invoke(new NoParamDelegate(treeView.Nodes.Clear));
|
|
504 txtDetails.Invoke(new NoParamDelegate(txtDetails.Clear));
|
|
505
|
|
506 foreach (RelicChunkyStructure strct in chunkyFile.ChunkyStructures)
|
|
507 {
|
|
508 int count = strct.RootChunks.Count;
|
|
509 TreeNode node = null;
|
|
510 ChunkyFolder fold;
|
|
511 TreeNode[] nodes = new TreeNode[count];
|
|
512
|
|
513 int children = strct.RootChunks.Count;
|
|
514
|
|
515 for(int i = 0; i<count; i++)
|
|
516 {
|
|
517 if (strct.RootChunks[i] is ChunkyData)
|
|
518 {
|
|
519 children+=1;
|
|
520 }
|
|
521 else if (strct.RootChunks[i] is ChunkyFolder)
|
|
522 {
|
|
523 children += ((ChunkyFolder)strct.RootChunks[i]).Children.Count;
|
|
524 }
|
|
525 }
|
|
526
|
|
527 if (OnChunkyNodesCounted!=null)
|
|
528 {
|
|
529 OnChunkyNodesCounted(children);
|
|
530 }
|
|
531
|
|
532 for(int i = 0; i<count; i++)
|
|
533 {
|
|
534 node = new TreeNode();
|
|
535 setNodeName(node, strct.RootChunks[i]);
|
|
536 node.Tag = strct.RootChunks[i];
|
|
537
|
|
538 if (strct.RootChunks[i] is ChunkyFolder)
|
|
539 {
|
|
540 fold = (ChunkyFolder)strct.RootChunks[i];
|
|
541
|
|
542 foreach(ChunkyChunk chunk in fold.Children)
|
|
543 {
|
|
544 addTreeNode(chunk, node);
|
|
545 }
|
|
546 }
|
|
547 else
|
|
548 {
|
|
549 node.ImageIndex = 2;
|
|
550 node.SelectedImageIndex = 2;
|
|
551 }
|
|
552
|
|
553 nodes[i] = node;
|
|
554
|
|
555 if (OnChunkyNodeAdded!=null)
|
|
556 {
|
|
557 OnChunkyNodeAdded(strct.RootChunks[i]);
|
|
558 }
|
|
559 }
|
|
560
|
|
561 if (OnChunkyNodesAdded!=null)
|
|
562 {
|
|
563 OnChunkyNodesAdded(false);
|
|
564 }
|
|
565
|
|
566 treeView.Invoke(new TreeNodeAddRangeDelegate(treeView.Nodes.AddRange), new object[]{nodes});
|
|
567
|
|
568 if (OnChunkyNodesAdded!=null)
|
|
569 {
|
|
570 OnChunkyNodesAdded(true);
|
|
571 }
|
|
572 }
|
|
573
|
|
574 this.Invoke(new SetStringDelegate(SetTitle), new object[]{"IChunky Viewer - "+chunkyFile.Name});
|
|
575
|
|
576 System.Console.Write(chunkyFilePath.Substring(0, chunkyFilePath.LastIndexOf(Constants.DirectoryChar)));
|
|
577 folderBrowserDialog.SelectedPath = chunkyFilePath.Substring(0, chunkyFilePath.LastIndexOf(Constants.DirectoryChar));
|
|
578 openFileDialog.InitialDirectory = chunkyFilePath.Substring(0, chunkyFilePath.LastIndexOf(Constants.DirectoryChar));
|
|
579 miSave.Enabled = true;
|
|
580 miShowValidationString.Enabled = true;
|
|
581 miValidateAs.Enabled = true;
|
|
582 }
|
|
583
|
|
584 private delegate void SetStringDelegate(string val);
|
|
585
|
|
586 private void SetTitle(string title)
|
|
587 {
|
|
588 this.Text = title;
|
|
589 }
|
|
590
|
|
591 private void addTreeNode(ChunkyChunk chunk, TreeNode parent)
|
|
592 {
|
|
593 if (chunk is ChunkyData)
|
|
594 {
|
|
595 addTreeNode((ChunkyData)chunk, parent);
|
|
596 }
|
|
597 else
|
|
598 {
|
|
599 addTreeNode((ChunkyFolder)chunk, parent);
|
|
600 }
|
|
601 }
|
|
602
|
|
603 private void addTreeNode(ChunkyData chunk, TreeNode parent)
|
|
604 {
|
|
605 TreeNode temp = new TreeNode("", 2, 2);
|
|
606 setNodeName(temp, chunk);
|
|
607 temp.Tag = chunk;
|
|
608 parent.Nodes.Add(temp);
|
|
609
|
|
610 if (OnChunkyNodeAdded!=null)
|
|
611 {
|
|
612 OnChunkyNodeAdded(chunk);
|
|
613 }
|
|
614 }
|
|
615
|
|
616 private void addTreeNode(ChunkyFolder fld, TreeNode parent)
|
|
617 {
|
|
618 TreeNode node = new TreeNode("", 0, 1);
|
|
619 setNodeName(node, fld);
|
|
620 node.Tag = fld;
|
|
621
|
|
622 foreach(ChunkyChunk chunk in fld.Children)
|
|
623 {
|
|
624 addTreeNode(chunk, node);
|
|
625 }
|
|
626
|
|
627 parent.Nodes.Add(node);
|
|
628
|
|
629 if (OnChunkyNodeAdded!=null)
|
|
630 {
|
|
631 OnChunkyNodeAdded(fld);
|
|
632 }
|
|
633 }
|
|
634
|
|
635 private void miFile_Open_Click(object sender, System.EventArgs e)
|
|
636 {
|
|
637 DialogResult dr = openFileDialog.ShowDialog(this);
|
|
638
|
|
639 if (dr == DialogResult.OK)
|
|
640 {
|
|
641 chunkyFileNewPath = openFileDialog.FileName;
|
|
642 Thread thr = new Thread(new ThreadStart(openChunkyFile));
|
|
643 thr.Start();
|
|
644 }
|
|
645 }
|
|
646
|
|
647 private void treeView_AfterSelect(object sender, System.Windows.Forms.TreeViewEventArgs e)
|
|
648 {
|
|
649 txtDetails.Text = ((ChunkyChunk)e.Node.Tag).GetDisplayDetails();
|
|
650 }
|
|
651
|
|
652 private void miSaveChunk_Click(object sender, System.EventArgs e)
|
|
653 {
|
|
654 if (treeView.SelectedNode!=null)
|
|
655 {
|
|
656 DialogResult dr = folderBrowserDialog.ShowDialog();
|
|
657
|
|
658 if (dr == DialogResult.OK)
|
|
659 {
|
|
660 statusBar.Text = "Saving chunk...";
|
|
661
|
|
662 if(treeView.SelectedNode.Tag is ChunkyData)
|
|
663 {
|
|
664 if (((ChunkyData)treeView.SelectedNode.Tag).Save(folderBrowserDialog.SelectedPath))
|
|
665 {
|
|
666 statusBar.Text+= "Saved";
|
|
667 timer.Enabled = true;
|
|
668 }
|
|
669 }
|
|
670 else
|
|
671 {
|
|
672 int saves = ((ChunkyFolder)treeView.SelectedNode.Tag).Save(folderBrowserDialog.SelectedPath);
|
|
673
|
|
674 if (saves != 1)
|
|
675 {
|
|
676 statusBar.Text+= saves+" items saved";
|
|
677 }
|
|
678 else
|
|
679 {
|
|
680 statusBar.Text+= "1 item saved";
|
|
681 }
|
|
682
|
|
683 timer.Enabled = true;
|
|
684 }
|
|
685 }
|
|
686 }
|
|
687 }
|
|
688
|
|
689 private void treeView_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
|
|
690 {
|
|
691 if (e.Button == MouseButtons.Right)
|
|
692 {
|
|
693 TreeNode tn = treeView.GetNodeAt(e.X, e.Y);
|
|
694
|
|
695 if (tn!=null)
|
|
696 {
|
|
697 treeView.SelectedNode = tn;
|
|
698 }
|
|
699 else
|
|
700 {
|
|
701 treeView.SelectedNode = null;
|
|
702 }
|
|
703 }
|
|
704 }
|
|
705
|
|
706 private void contextMenu_Popup(object sender, System.EventArgs e)
|
|
707 {
|
|
708 if (treeView.SelectedNode!=null)
|
|
709 {
|
|
710 foreach(MenuItem item in contextMenu.MenuItems)
|
|
711 {
|
|
712 item.Visible = true;
|
|
713 }
|
|
714
|
|
715 ChunkyChunk chunk = ((ChunkyChunk)treeView.SelectedNode.Tag);
|
|
716 miSaveChunk.Enabled = chunk.Savable;
|
|
717
|
|
718 miDeleteChunk.Enabled = (treeView.SelectedNode!=treeView.Nodes[0] || treeView.Nodes.Count>1);
|
|
719 }
|
|
720 else
|
|
721 {
|
|
722 foreach(MenuItem item in contextMenu.MenuItems)
|
|
723 {
|
|
724 item.Visible = false;
|
|
725 }
|
|
726 }
|
|
727 }
|
|
728
|
|
729 private void menuItem3_Click(object sender, System.EventArgs e)
|
|
730 {
|
|
731 AboutChunkyViewer frm = new AboutChunkyViewer();
|
|
732 frm.ShowDialog(this);
|
|
733 frm.Dispose();
|
|
734 }
|
|
735
|
|
736 private void menuItem4_Click(object sender, System.EventArgs e)
|
|
737 {
|
|
738 this.Close();
|
|
739 }
|
|
740
|
|
741 private void showProgress()
|
|
742 {
|
|
743 try
|
|
744 {
|
|
745 progress = new Progress(this);
|
|
746 progress.ShowDialog(this);
|
|
747 }
|
|
748 catch{}
|
|
749 }
|
|
750
|
|
751 private void menuItem5_Click(object sender, System.EventArgs e)
|
|
752 {
|
|
753 DialogResult dr = openFileDialog.ShowDialog(this);
|
|
754
|
|
755 if (dr == DialogResult.OK)
|
|
756 {
|
|
757 System.Diagnostics.Process proc = new System.Diagnostics.Process();
|
|
758 proc.EnableRaisingEvents = false;
|
|
759 proc.StartInfo.FileName = Application.ExecutablePath;
|
|
760 proc.StartInfo.Arguments = "\""+openFileDialog.FileName+"\"";
|
|
761 proc.Start();
|
|
762 }
|
|
763 }
|
|
764
|
|
765 private void timer_Tick(object sender, System.EventArgs e)
|
|
766 {
|
|
767 statusBar.Text = "";
|
|
768 timer.Enabled = false;
|
|
769 }
|
|
770
|
|
771 private void miExportChunk_Click(object sender, System.EventArgs e)
|
|
772 {
|
|
773 if (treeView.SelectedNode!=null)
|
|
774 {
|
|
775 DialogResult dr = exportFileDialog.ShowDialog(this);
|
|
776
|
|
777 if (dr == DialogResult.OK)
|
|
778 {
|
|
779 statusBar.Text = "Exporting...";
|
|
780 if (((ChunkyChunk)treeView.SelectedNode.Tag).Export(exportFileDialog.FileName))
|
|
781 {
|
|
782 statusBar.Text+= "Exported";
|
|
783 timer.Enabled = true;
|
|
784 }
|
|
785 else
|
|
786 {
|
|
787 statusBar.Text = "Export failed";
|
|
788 }
|
|
789 }
|
|
790 }
|
|
791 }
|
|
792
|
|
793 private void miImportChunk_Click(object sender, System.EventArgs e)
|
|
794 {
|
|
795 if (treeView.SelectedNode!=null && treeView.SelectedNode.Tag is ChunkyFolder)
|
|
796 {
|
|
797 DialogResult dr = importFileDialog.ShowDialog(this);
|
|
798
|
|
799 if (dr == DialogResult.OK)
|
|
800 {
|
|
801 FileStream str = new FileStream(importFileDialog.FileName, FileMode.Open);
|
|
802 byte[] bytes = new byte[str.Length];
|
|
803 str.Read(bytes, 0, (int)str.Length);
|
|
804 str.Close();
|
|
805 ChunkyChunk chunk = RelicChunkReader.ReadChunkyChunk(bytes);
|
|
806 ChunkyFolder folder = (ChunkyFolder)treeView.SelectedNode.Tag;
|
|
807 folder.Children.Add(chunk);
|
|
808 addTreeNode(chunk, treeView.SelectedNode);
|
|
809 cascadeRefreshUp(treeView.SelectedNode);
|
|
810 txtDetails.Text = ((ChunkyChunk)treeView.SelectedNode.Tag).GetDisplayDetails();
|
|
811 }
|
|
812 }
|
|
813 }
|
|
814
|
|
815 private void cascadeRefreshUp(TreeNode node)
|
|
816 {
|
|
817 setNodeName(node, (ChunkyChunk)node.Tag);
|
|
818
|
|
819 if (node.Parent!=null)
|
|
820 {
|
|
821 cascadeRefreshUp(node.Parent);
|
|
822 }
|
|
823 }
|
|
824
|
|
825 private void cascadeRefreshDown(TreeNode node)
|
|
826 {
|
|
827 setNodeName(node, (ChunkyChunk)node.Tag);
|
|
828
|
|
829 foreach (TreeNode childNode in node.Nodes)
|
|
830 {
|
|
831 cascadeRefreshDown(childNode);
|
|
832 }
|
|
833 }
|
|
834
|
|
835 private void setNodeName(TreeNode node, ChunkyChunk chunk)
|
|
836 {
|
|
837 int showSizes = (int)preferences["ShowChunkSizes"];
|
|
838
|
|
839 if (showSizes == 1)
|
|
840 {
|
|
841 node.Text = chunk.ID+" ("+chunk.DataLength+")";
|
|
842 }
|
|
843 else if (showSizes == 2)
|
|
844 {
|
|
845 node.Text = chunk.ID+" ("+chunk.Length+")";
|
|
846 }
|
|
847 else
|
|
848 {
|
|
849 node.Text = chunk.ID;
|
|
850 }
|
|
851 }
|
|
852
|
|
853 private void miImportSiblingChunk_Click(object sender, System.EventArgs e)
|
|
854 {
|
|
855 if (treeView.SelectedNode!=null)
|
|
856 {
|
|
857 DialogResult dr = importFileDialog.ShowDialog(this);
|
|
858
|
|
859 if (dr == DialogResult.OK)
|
|
860 {
|
|
861 FileStream str = new FileStream(importFileDialog.FileName, FileMode.Open);
|
|
862 byte[] bytes = new byte[str.Length];
|
|
863 str.Read(bytes, 0, (int)str.Length);
|
|
864 str.Close();
|
|
865 ChunkyChunk chunk = RelicChunkReader.ReadChunkyChunk(bytes);
|
|
866
|
|
867 if (treeView.SelectedNode.Parent!=null)
|
|
868 {
|
|
869 ChunkyFolder folder = (ChunkyFolder)((ChunkyChunk)treeView.SelectedNode.Tag).Parent;
|
|
870 folder.Children.Add(chunk);
|
|
871 addTreeNode(chunk, treeView.SelectedNode.Parent);
|
|
872 cascadeRefreshUp(treeView.SelectedNode.Parent);
|
|
873 }
|
|
874 else
|
|
875 {
|
|
876 RelicChunkyFile file = ((ChunkyChunk)treeView.SelectedNode.Tag).ParentFile;
|
|
877 file.ChunkyStructures[0].RootChunks.Add(chunk);
|
|
878 TreeNode node = new TreeNode();
|
|
879 setNodeName(node, chunk);
|
|
880 node.Tag = chunk;
|
|
881
|
|
882 if (chunk is ChunkyFolder)
|
|
883 {
|
|
884 ChunkyFolder fold = (ChunkyFolder)chunk;
|
|
885
|
|
886 foreach(ChunkyChunk childChunk in fold.Children)
|
|
887 {
|
|
888 addTreeNode(childChunk, node);
|
|
889 }
|
|
890 }
|
|
891 else
|
|
892 {
|
|
893 node.ImageIndex = 2;
|
|
894 node.SelectedImageIndex = 2;
|
|
895 }
|
|
896
|
|
897 treeView.Nodes.Add(node);
|
|
898
|
|
899 if (OnChunkyNodeAdded!=null)
|
|
900 {
|
|
901 OnChunkyNodeAdded(chunk);
|
|
902 }
|
|
903 }
|
|
904 }
|
|
905 }
|
|
906 }
|
|
907
|
|
908 private void miSave_Click(object sender, System.EventArgs e)
|
|
909 {
|
|
910 if (chunkyFile!=null)
|
|
911 {
|
|
912 statusBar.Text = "Saving...";
|
|
913 chunkyFile.Save(new DirectoryInfo(chunkyFilePath.Substring(0, chunkyFilePath.LastIndexOf(Constants.DirectoryChar))));
|
|
914 statusBar.Text+= "Saved";
|
|
915 timer.Enabled = true;
|
|
916 }
|
|
917 }
|
|
918
|
|
919 private void miDeleteChunk_Click(object sender, System.EventArgs e)
|
|
920 {
|
|
921 if (treeView.SelectedNode!=null)
|
|
922 {
|
|
923 TreeNode node = treeView.SelectedNode;
|
|
924 ChunkyChunk chunk = (ChunkyChunk)node.Tag;
|
|
925
|
|
926 if (chunk.Parent!=null)
|
|
927 {
|
|
928 chunk.Parent.Children.Remove(chunk);
|
|
929 TreeNode parent = node.Parent;
|
|
930 node.Parent.Nodes.Remove(node);
|
|
931 cascadeRefreshUp(parent);
|
|
932 }
|
|
933 else
|
|
934 {
|
|
935 chunk.ParentFile.ChunkyStructures[0].RootChunks.Remove(chunk);
|
|
936 treeView.Nodes.Remove(node);
|
|
937 }
|
|
938 }
|
|
939 }
|
|
940
|
|
941 private void miOptions_Click(object sender, System.EventArgs e)
|
|
942 {
|
|
943 FrmConfig frm = new FrmConfig(preferences);
|
|
944 DialogResult dr = frm.ShowDialog(this);
|
|
945
|
|
946 if (dr == DialogResult.OK)
|
|
947 {
|
|
948 foreach (TreeNode node in treeView.Nodes)
|
|
949 {
|
|
950 cascadeRefreshDown(node);
|
|
951 }
|
|
952 }
|
|
953 }
|
|
954
|
|
955 private void miShowValidationString_Click(object sender, System.EventArgs e)
|
|
956 {
|
|
957 if (chunkyFile!=null)
|
|
958 {
|
|
959 FrmValidationString val = new FrmValidationString(chunkyFile);
|
|
960 val.ShowDialog(this);
|
|
961 }
|
|
962 }
|
|
963
|
|
964 private void readInValidators()
|
|
965 {
|
|
966 statusBar.Text = "Reading validators...";
|
|
967 DirectoryInfo dir = new DirectoryInfo(preferences["DoWPath"].ToString() + Constants.DirectoryString + "IChunkyValidators");
|
|
968
|
|
969 miValidateAs.MenuItems.Clear();
|
|
970
|
|
971 if (dir.Exists)
|
|
972 {
|
|
973 FileInfo[] validators = dir.GetFiles("*.validator");
|
|
974
|
|
975 if (validators.Length>0)
|
|
976 {
|
|
977 //chunkyValidators = new ChunkyValidator[validators.Length];
|
|
978 //MenuItem[] items = new MenuItem[validators.Length];
|
|
979 ArrayList chunkyValidatorsTemp = new ArrayList();
|
|
980 ArrayList menuitems = new ArrayList();
|
|
981 EventHandler handler = new EventHandler(miValidate_Click);
|
|
982 ChunkyValidator validator;
|
|
983
|
|
984 for (int i = 0; i<validators.Length; i++)
|
|
985 {
|
|
986 try
|
|
987 {
|
|
988 validator = new ChunkyValidator(validators[i]);
|
|
989 chunkyValidatorsTemp.Add(validator);
|
|
990 menuitems.Add(new MenuItem(validator.FileType, handler));
|
|
991 }
|
|
992 catch (InvalidOperationException){}//invalid validator file
|
|
993 }
|
|
994
|
|
995 chunkyValidators = (ChunkyValidator[])chunkyValidatorsTemp.ToArray(typeof(ChunkyValidator));
|
|
996 miValidateAs.MenuItems.AddRange((MenuItem[])menuitems.ToArray(typeof(MenuItem)));
|
|
997 miValidateAs.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {this.menuItem16,
|
|
998 this.miRefreshValidations});
|
|
999
|
|
1000 statusBar.Text = "Refreshed";
|
|
1001 timer.Enabled = true;
|
|
1002 }
|
|
1003 else
|
|
1004 {
|
|
1005 statusBar.Text = "No validators found";
|
|
1006 timer.Enabled = true;
|
|
1007 miValidateAs.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {this.miNoValidators,
|
|
1008 this.menuItem16,
|
|
1009 this.miRefreshValidations});
|
|
1010 }
|
|
1011 }
|
|
1012 else
|
|
1013 {
|
|
1014 statusBar.Text = "ERROR: Could not find validators";
|
|
1015 timer.Enabled = true;
|
|
1016 MessageBox.Show(this, "IChunkyViewer could not find a folder of Chunky file validators at "+dir.FullName, "Could not find validators", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
|
1017
|
|
1018 miValidateAs.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {this.miNoValidators,
|
|
1019 this.menuItem16,
|
|
1020 this.miRefreshValidations});
|
|
1021 }
|
|
1022 }
|
|
1023
|
|
1024 private void miValidate_Click(object sender, System.EventArgs e)
|
|
1025 {
|
|
1026 if (sender is MenuItem && chunkyFile!=null)
|
|
1027 {
|
|
1028 ChunkyValidator validator = chunkyValidators[((MenuItem)sender).Index];
|
|
1029 if (validator.Validate(chunkyFile.GetValidationString()))
|
|
1030 {
|
|
1031 MessageBox.Show(this, chunkyFile.Name+" is a valid "+validator.FileType+" file", "Validation successful", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
1032 }
|
|
1033 else
|
|
1034 {
|
|
1035 MessageBox.Show(this, chunkyFile.Name+" is not a valid "+validator.FileType+" file", "Validation failed", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
|
1036 }
|
|
1037 }
|
|
1038 }
|
|
1039
|
|
1040 private void miRefreshValidations_Click(object sender, System.EventArgs e)
|
|
1041 {
|
|
1042 readInValidators();
|
|
1043 }
|
|
1044
|
|
1045 public delegate void ChunkyOpenedDelegate(string path);
|
|
1046 public event ChunkyOpenedDelegate OnChunkyOpened;
|
|
1047 public delegate void ChunkyNodesCountedDelegate(int nodes);
|
|
1048 public event ChunkyNodesCountedDelegate OnChunkyNodesCounted;
|
|
1049 public delegate void ChunkyNodeAddedDelegate(ChunkyChunk chunk);
|
|
1050 public event ChunkyNodeAddedDelegate OnChunkyNodeAdded;
|
|
1051 public delegate void ChunkyNodesAddedDelegate(bool rendered);
|
|
1052 public event ChunkyNodesAddedDelegate OnChunkyNodesAdded;
|
|
1053 public delegate void ChunkyOpenFailedDelegate();
|
|
1054 public event ChunkyOpenFailedDelegate OnChunkyOpenFailed;
|
|
1055 }
|
|
1056 }
|