-
Notifications
You must be signed in to change notification settings - Fork 14
/
MainWindow.xaml.cs
741 lines (623 loc) · 28.6 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
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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
// Copyright © 2019 Rafael Gonzalez - All Rights Reserved
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
using AutoUpdaterDotNET;
using FFXIV_TexTools.Helpers;
using FFXIV_TexTools.Models;
using FFXIV_TexTools.Properties;
using FFXIV_TexTools.Resources;
using FFXIV_TexTools.ViewModels;
using FFXIV_TexTools.Views;
using MahApps.Metro;
using MahApps.Metro.Controls.Dialogs;
using System;
using System.Diagnostics;
using System.IO;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Data;
using System.Windows.Forms;
using xivModdingFramework.General.Enums;
using xivModdingFramework.Helpers;
using xivModdingFramework.Items.Interfaces;
using xivModdingFramework.Mods;
using xivModdingFramework.Mods.FileTypes;
using xivModdingFramework.SqPack.FileTypes;
using Application = System.Windows.Application;
using SysTimer = System.Timers;
namespace FFXIV_TexTools
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow
{
private SysTimer.Timer searchTimer = new SysTimer.Timer(300);
private string _startupArgs;
public MainWindow(string[] args)
{
CheckForUpdates();
CheckForSettingsUpdate();
var fileVersion = FileVersionInfo.GetVersionInfo(System.Reflection.Assembly.GetExecutingAssembly().Location).FileVersion;
if (args != null && args.Length > 0)
{
_startupArgs = args[0];
OnlyImport();
}
try
{
InitializeComponent();
}
catch(Exception e)
{
System.Windows.MessageBox.Show(
"TexTools was unable to locate dependency files.\nPlease make sure you are running TexTools in the folder it came in.\n\nIf you continue to receive this error," +
$"\nPlease make sure your Anti-Virus is not blocking TexTools.\n\nError: {e.Message}\n\n Exception:{e.InnerException}",
"Dependencies Error v" + fileVersion);
Environment.Exit(-1);
return;
}
ItemSearchTextBox.Focus();
var mainViewModel = new MainViewModel(this);
this.DataContext = mainViewModel;
if (searchTimer == null)
{
searchTimer = new SysTimer.Timer(300);
}
searchTimer.Enabled = true;
searchTimer.AutoReset = false;
searchTimer.Elapsed += SearchTimerOnElapsed;
}
private void CheckForUpdates()
{
AutoUpdater.Start("https://raw.githubusercontent.com/liinko/FFXIVTexToolsWeb/master/updater.xml");
}
private void CheckForSettingsUpdate()
{
if (Settings.Default.UpgradeRequired)
{
Settings.Default.Upgrade();
Settings.Default.UpgradeRequired = false;
Settings.Default.Save();
}
}
private async void OnlyImport()
{
var gameDirectory = new DirectoryInfo(Settings.Default.FFXIV_Directory);
var index = new Index(gameDirectory);
if (index.IsIndexLocked(XivDataFile._0A_Exd))
{
FlexibleMessageBox.Show("Error Accessing Index File\n\n" +
"Please exit the game before proceeding.\n" +
"-----------------------------------------------------\n\n",
"Index Access Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
var modPackDirectory = new DirectoryInfo(Settings.Default.ModPack_Directory);
await ImportModpack(new DirectoryInfo(_startupArgs), modPackDirectory, false, true);
}
Application.Current.Shutdown();
}
/// <summary>
/// Event handler for the language button clicked
/// </summary>
private void LanguageButton_Click(object sender, RoutedEventArgs e)
{
RightFlyout.Content = new LanguageOptionsView();
RightFlyout.IsOpen = true;
}
/// <summary>
/// Event handler for the light theme clicked
/// </summary>
private void MenuLightTheme_Click(object sender, RoutedEventArgs e)
{
var appStyle = ThemeManager.DetectAppStyle(Application.Current);
ThemeManager.ChangeAppStyle(Application.Current, ThemeManager.GetAccent(appStyle.Item2.Name), ThemeManager.GetAppTheme("BaseLight"));
Settings.Default.Application_Theme = "BaseLight";
Settings.Default.Save();
}
/// <summary>
/// Event handler for the dark theme clicked
/// </summary>
private void MenuDarkTheme_Click(object sender, RoutedEventArgs e)
{
var appStyle = ThemeManager.DetectAppStyle(Application.Current);
ThemeManager.ChangeAppStyle(Application.Current, ThemeManager.GetAccent(appStyle.Item2.Name), ThemeManager.GetAppTheme("BaseDark"));
Settings.Default.Application_Theme = "BaseDark";
Settings.Default.Save();
}
/// <summary>
/// Event handler for the treeview selected item changed
/// </summary>
private void TreeView_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
{
UpdateViews(e.NewValue as Category);
}
/// <summary>
/// Updates the texture and model views with the selected item
/// </summary>
/// <param name="selectedItem">The selected item</param>
private void UpdateViews(Category selectedItem)
{
if (selectedItem?.Item != null)
{
var textureView = TextureTabItem.Content as TextureView;
var textureViewModel = textureView.DataContext as TextureViewModel;
textureViewModel.UpdateTexture(selectedItem.Item);
if (selectedItem.Item.Category.Equals(XivStrings.UI) ||
selectedItem.Item.ItemCategory.Equals(XivStrings.Face_Paint) ||
selectedItem.Item.ItemCategory.Equals(XivStrings.Equip_Decals))
{
if (TabsControl.SelectedIndex == 1)
{
TabsControl.SelectedIndex = 0;
}
ModelTabItem.IsEnabled = false;
}
else
{
ModelTabItem.IsEnabled = true;
var modelView = ModelTabItem.Content as ModelView;
var modelViewModel = modelView.DataContext as ModelViewModel;
modelViewModel.UpdateModel(selectedItem.Item as IItemModel);
}
}
}
/// <summary>
/// Event handler for the model id search clicked
/// </summary>
private void Menu_ModelIDSearch_Click(object sender, RoutedEventArgs e)
{
var modelSearchView = new ModelSearchView(this) {Owner = this};
modelSearchView.Show();
}
/// <summary>
/// Event handler for the icon id search clicked
/// </summary>
private void Menu_IconIDSearch_Click(object sender, RoutedEventArgs e)
{
var iconSearchView = new IconSearchView(this) {Owner = this};
iconSearchView.Show();
}
/// <summary>
/// Event handler for the about menu item clicked
/// </summary>
private void Menu_About_Click(object sender, RoutedEventArgs e)
{
var about = new AboutView {Owner = this};
about.Show();
}
/// <summary>
/// Event handler for the PK Emporium site
/// </summary>
private void PKEmporium_Click(object sender, RoutedEventArgs e)
{
Process.Start(WebUrl.PKEmporium_Website);
}
/// <summary>
/// Event handler for the Xiv Mod Archive site
/// </summary>
private void XivModArchive_Click(object sender, RoutedEventArgs e)
{
Process.Start(WebUrl.XivModArchive_Website);
}
/// <summary>
/// Event handler for the Nexus Mods site
/// </summary>
private void NexusMods_Click(object sender, RoutedEventArgs e)
{
Process.Start(WebUrl.NexusMods_Website);
}
/// <summary>
/// Event handler for the Discord Invite
/// </summary>
private void DiscordButton_Click(object sender, RoutedEventArgs e)
{
Process.Start(WebUrl.Discord_Invite);
}
/// <summary>
/// Event handler for the BugReport site
/// </summary>
private void Menu_BugReport_Click(object sender, RoutedEventArgs e)
{
Process.Start(WebUrl.BugReport_Website);
}
/// <summary>
/// Event handler for the Tutorials site
/// </summary>
private void Menu_Tutorials_Click(object sender, RoutedEventArgs e)
{
Process.Start(WebUrl.Tutorials_Website);
}
/// <summary>
/// Event handler for the mod list menu item clicked
/// </summary>
private void Menu_ModList_Click(object sender, RoutedEventArgs e)
{
var modListView = new ModListView {Owner = this};
modListView.Show();
}
/// <summary>
/// Event handler for the problem check menu item clicked
/// </summary>
private void Menu_ProblemCheck_Click(object sender, RoutedEventArgs e)
{
var problemCheckView = new ProblemCheckView {Owner = this};
problemCheckView.Show();
}
/// <summary>
/// Event handler for the customize menu item clicked
/// </summary>
private void Customize_Click(object sender, RoutedEventArgs e)
{
var customize = new CustomizeSettingsView {Owner = this};
customize.Show();
}
/// <summary>
/// Event handler for the mod pack wizard menu item clicked
/// </summary>
private async void Menu_MakeModpackWizard_Click(object sender, RoutedEventArgs e)
{
var wizard = new ModPackWizard {Owner = this};
var result = wizard.ShowDialog();
if (result == true)
{
if (wizard.ModPackFileName.Equals("NoData"))
{
await this.ShowMessageAsync("Error: Mod Pack Creation Failed", "No mods were detected in the options list.");
}
else
{
await this.ShowMessageAsync("Mod Pack Creation Complete", $"The ModPack ({wizard.ModPackFileName}.ttmp2) has been successfully Created.");
}
}
}
/// <summary>
/// Event handler for the import mod pack menu item clicked
/// </summary>
private async void Menu_ImportModpack_Click(object sender, RoutedEventArgs e)
{
var modPackDirectory = new DirectoryInfo(Settings.Default.ModPack_Directory);
var openFileDialog = new OpenFileDialog {InitialDirectory = modPackDirectory.FullName, Filter = "TexToolsModPack TTMP (*.ttmp;*.ttmp2)|*.ttmp;*.ttmp2", Multiselect = true};
if (openFileDialog.ShowDialog() != System.Windows.Forms.DialogResult.OK)
return;
var importMultiple = openFileDialog.FileNames.Length > 1;
var modsImported = 0;
foreach (var fileName in openFileDialog.FileNames)
{
var fileInfo = new FileInfo(fileName);
if (fileInfo.Length == 0)
{
FlexibleMessageBox.Show($"TTMP file [ {Path.GetFileNameWithoutExtension(fileName)} ] is empty.\n\nImporting Canceled.", $"Import Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
continue;
}
modsImported += await ImportModpack(new DirectoryInfo(fileName), modPackDirectory, importMultiple);
}
if (modsImported > 0)
{
await this.ShowMessageAsync("Import Complete",
$"{modsImported} mod(s) successfully imported.");
}
}
/// <summary>
/// This method opens the modpack import wizard or imports a modpack silently
/// </summary>
/// <param name="path">The path to the modpack</param>
/// <param name="silent">If the modpack wizard should be shown or the modpack should just be imported without any user interaction</param>
/// <returns></returns>
private async Task<int> ImportModpack(DirectoryInfo path, DirectoryInfo modPackDirectory, bool silent = false, bool messageInImport = false)
{
var importError = false;
try
{
var ttmp = new TTMP(modPackDirectory, XivStrings.TexTools);
var ttmpData = ttmp.GetModPackJsonData(path);
if (ttmpData.ModPackJson.TTMPVersion.Contains("w"))
{
var gameDirectory = new DirectoryInfo(Settings.Default.FFXIV_Directory);
var index = new Index(gameDirectory);
if (index.IsIndexLocked(XivDataFile._0A_Exd))
{
FlexibleMessageBox.Show("Error Accessing Index File\n\n" +
"Please exit the game before proceeding.\n" +
"-----------------------------------------------------\n\n",
"Index Access Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return 0;
}
try
{
var importWizard = new ImportModPackWizard(ttmpData.ModPackJson, ttmpData.ImageDictionary,
path, messageInImport);
if (messageInImport)
{
importWizard.WindowStartupLocation = WindowStartupLocation.CenterScreen;
}
else
{
importWizard.Owner = this;
}
var result = importWizard.ShowDialog();
if (result == true)
{
return importWizard.TotalModsImported;
}
}
catch
{
importError = true;
}
}
else if(ttmpData.ModPackJson.TTMPVersion.Contains("s"))
{
try
{
var simpleImport = new SimpleModPackImporter(path,
ttmpData.ModPackJson, silent, messageInImport);
if (messageInImport)
{
simpleImport.WindowStartupLocation = WindowStartupLocation.CenterScreen;
}
else
{
simpleImport.Owner = this;
}
var result = simpleImport.ShowDialog();
if (result == true)
{
return simpleImport.TotalModsImported;
}
}
catch
{
importError = true;
}
}
}
catch (Exception ex)
{
if (!importError)
{
var simpleImport = new SimpleModPackImporter(path, null, silent, messageInImport);
if (messageInImport)
{
simpleImport.WindowStartupLocation = WindowStartupLocation.CenterScreen;
}
else
{
simpleImport.Owner = this;
}
var result = simpleImport.ShowDialog();
if (result == true)
{
return simpleImport.TotalModsImported;
}
}
else
{
FlexibleMessageBox.Show($"There was an error importing the mod pack at {path.FullName}\n\nMessage: {ex.Message}", $"ModPack Import Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return 0;
}
}
return 0;
}
/// <summary>
/// Event handler for the simple mod pack menu item clicked
/// </summary>
private async void Menu_MakeSimpleModpack_Click(object sender, RoutedEventArgs e)
{
var simpleCreator = new SimpleModPackCreator{Owner = this};
var result = simpleCreator.ShowDialog();
if (result == true)
{
await this.ShowMessageAsync("Mod Pack Creation Complete", $"The ModPack ({simpleCreator.ModPackFileName}.ttmp2) has been successfully Created.");
}
}
/// <summary>
/// Event handler for the start over menu item clicked
/// </summary>
private async void Menu_StartOver_Click(object sender, RoutedEventArgs e)
{
var gameDirectory = new DirectoryInfo(Settings.Default.FFXIV_Directory);
var index = new Index(gameDirectory);
var outdated = false;
if (index.IsIndexLocked(XivDataFile._0A_Exd))
{
FlexibleMessageBox.Show("Error Accessing Index File\n\n" +
"Please exit the game before proceeding.\n" +
"-----------------------------------------------------\n\n",
"Index Access Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
var result = FlexibleMessageBox.Show("Starting over will:\n\n" +
"Restore index files to their original state.\n" +
"Delete all mod dat files from game folder.\n" +
"Delete all mod list file entries.\n\n" +
"Do you want to start over?", "Start Over", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
if (result == System.Windows.Forms.DialogResult.Yes)
{
var indexBackupsDirectory = new DirectoryInfo(Settings.Default.Backup_Directory);
if (!Directory.Exists(indexBackupsDirectory.FullName))
{
FlexibleMessageBox.Show("Error Accessing Index Backups Folder\n\n" +
"Please set your Index Backups directory in Options > Customize and try again.\n",
"Index Backups Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
var filesToCheck = new XivDataFile[] { XivDataFile._01_Bgcommon, XivDataFile._04_Chara, XivDataFile._06_Ui };
var problemChecker = new ProblemChecker(gameDirectory);
foreach (var xivDataFile in filesToCheck)
{
var backupFile = new DirectoryInfo($"{indexBackupsDirectory.FullName}\\{xivDataFile.GetDataFileName()}.win32.index");
if(!File.Exists(backupFile.FullName)) continue;
var outdatedCheck = problemChecker.CheckForOutdatedBackups(xivDataFile, indexBackupsDirectory);
if (!outdatedCheck)
{
outdated = FlexibleMessageBox.Show("Index Backups may be outdated.\n\n" +
"Click OK only if you are sure that your index backups are up to date\n\n" +
"Clicking Cancel will attempt to Start Over without using backups.",
"Index Backups Error", MessageBoxButtons.OKCancel, MessageBoxIcon.Error) == System.Windows.Forms.DialogResult.Cancel;
}
}
var task = Task.Run((() =>
{
var modding = new Modding(gameDirectory);
var dat = new Dat(gameDirectory);
var modListDirectory = new DirectoryInfo(Path.Combine(gameDirectory.Parent.Parent.FullName, XivStrings.ModlistFilePath));
var backupFiles = Directory.GetFiles(indexBackupsDirectory.FullName);
// Make sure backups exist
if (backupFiles.Length == 0)
{
FlexibleMessageBox.Show($"No backup files found in the following directory:\n{indexBackupsDirectory.FullName}\n\n" +
$"Index entries will be put back to original offsets instead.\n" +
"-----------------------------------------------------\n\n",
"Backup Files Missing", MessageBoxButtons.OK, MessageBoxIcon.Warning);
// Toggle off all mods
modding.ToggleAllMods(false);
}
else if (outdated)
{
// Toggle off all mods
modding.ToggleAllMods(false);
}
else
{
// Copy backups to ffxiv folder
foreach (var backupFile in backupFiles)
{
if (backupFile.Contains(".win32.index"))
{
File.Copy(backupFile, $"{gameDirectory}/{Path.GetFileName(backupFile)}", true);
}
}
}
// Delete modded dat files
foreach (var xivDataFile in (XivDataFile[])Enum.GetValues(typeof(XivDataFile)))
{
var datFiles = dat.GetModdedDatList(xivDataFile);
foreach (var datFile in datFiles)
{
File.Delete(datFile);
}
if (datFiles.Count > 0)
{
problemChecker.RepairIndexDatCounts(xivDataFile);
}
}
// Delete mod list
File.Delete(modListDirectory.FullName);
modding.CreateModlist();
}));
task.Wait();
UpdateViews(ItemTreeView.SelectedItem as Category);
await this.ShowMessageAsync("Start Over Complete", "The start over process has been completed.");
}
}
private void Menu_Donate_Click(object sender, RoutedEventArgs e)
{
System.Diagnostics.Process.Start(WebUrl.FFXIV_Donate);
}
private async void Menu_Backup_Click(object sender, RoutedEventArgs e)
{
var result = FlexibleMessageBox.Show("This will create a backup of the index files TexTools can modify (01, 04, 06)\n\n" +
"Do you want to Backup Now?" +
"\n\nWarning:\nIn order to create a clean backup, all active modifications will be set to disabled, they will have to be re-enabled manually.",
"Backup Index Files", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
if (result == System.Windows.Forms.DialogResult.Yes)
{
var gameDirectory = new DirectoryInfo(Settings.Default.FFXIV_Directory);
var backupDirectory = new DirectoryInfo(Properties.Settings.Default.Backup_Directory);
var indexFiles = new XivDataFile[] { XivDataFile._04_Chara, XivDataFile._06_Ui, XivDataFile._01_Bgcommon };
var index = new Index(gameDirectory);
var modding = new Modding(gameDirectory);
if (index.IsIndexLocked(XivDataFile._0A_Exd))
{
FlexibleMessageBox.Show("Unable to create backup while game is running.", $"Backup Creation Failed", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
try
{
// Toggle off all mods
modding.ToggleAllMods(false);
}
catch (Exception ex)
{
FlexibleMessageBox.Show($"Unable to create backup files.\n\nError Message:\n{ex.Message}", $"Backup Creation Failed", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
foreach (var xivDataFile in indexFiles)
{
try
{
File.Copy($"{gameDirectory.FullName}\\{xivDataFile.GetDataFileName()}.win32.index",
$"{backupDirectory}\\{xivDataFile.GetDataFileName()}.win32.index", true);
File.Copy($"{gameDirectory.FullName}\\{xivDataFile.GetDataFileName()}.win32.index2",
$"{backupDirectory}\\{xivDataFile.GetDataFileName()}.win32.index2", true);
}
catch (Exception ex)
{
FlexibleMessageBox.Show($"Unable to create backups.\n\nError: {ex.Message}", $"Backup Creation Failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
await this.ShowMessageAsync("Backup Complete", "The index files have been successfully backed up");
}
}
private void ItemTreeView_Loaded(object sender, RoutedEventArgs e)
{
var view = (CollectionView) CollectionViewSource.GetDefaultView(ItemTreeView.ItemsSource);
view.Filter = SearchFilter;
}
private bool SearchFilter(object item)
{
if (((Category)item).Categories != null)
{
var subItems = (CollectionView)CollectionViewSource.GetDefaultView(((Category)item).Categories);
subItems.Filter = SearchFilter;
((Category)item).IsExpanded = !string.IsNullOrEmpty(ItemSearchTextBox.Text);
return !subItems.IsEmpty;
}
return ((Category)item).Name.ToLower().Contains(ItemSearchTextBox.Text.ToLower());
}
private void ItemSearchTextBox_TextChanged(object sender, System.Windows.Controls.TextChangedEventArgs e)
{
searchTimer.Stop();
searchTimer.Start();
}
private void SearchTimerOnElapsed(object sender, SysTimer.ElapsedEventArgs e)
{
Dispatcher.Invoke(UpdateFilter);
}
private void UpdateFilter()
{
CollectionViewSource.GetDefaultView(ItemTreeView.ItemsSource).Refresh();
}
private void MetroWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
if (searchTimer != null)
{
searchTimer.Elapsed -= SearchTimerOnElapsed;
searchTimer.Dispose();
}
}
private void MetroWindow_Loaded(object sender, RoutedEventArgs e)
{
var fileVersion = FileVersionInfo.GetVersionInfo(System.Reflection.Assembly.GetExecutingAssembly().Location).FileVersion;
Title += $" {fileVersion.Substring(0, fileVersion.LastIndexOf("."))}";
}
private void GithubButton_Click(object sender, RoutedEventArgs e)
{
Process.Start(WebUrl.Github_Website);
}
}
}