-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMainWindow.xaml.cs
More file actions
1861 lines (1645 loc) · 66.9 KB
/
MainWindow.xaml.cs
File metadata and controls
1861 lines (1645 loc) · 66.9 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
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
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#nullable disable
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Globalization;
using System.IO;
using System.Text;
using System.Text.Json;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using CsvHelper;
using CsvHelper.Configuration;
using Microsoft.Win32;
namespace DSTSModTool;
public class AppSettings
{
public string GamePath { get; set; } = "";
}
public class Mod : INotifyPropertyChanged
{
private bool _isSelected;
public string Name { get; set; } = "";
public string Type { get; set; } = "";
public bool IsSelected
{
get => _isSelected;
set
{
_isSelected = value;
OnPropertyChanged(nameof(IsSelected));
}
}
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window, INotifyPropertyChanged
{
private bool _isGamePathSelected;
private string _gamePath = string.Empty;
public bool IsGamePathSelected
{
get => _isGamePathSelected;
set
{
_isGamePathSelected = value;
OnPropertyChanged(nameof(IsGamePathSelected));
}
}
public ObservableCollection<Mod> ModList { get; set; } = new ObservableCollection<Mod>();
public bool HasSelectedMods => ModList.Any(m => m.IsSelected);
private readonly string settingsFile = "settings.json";
public MainWindow()
{
InitializeComponent();
DataContext = this;
ModListBox.ItemsSource = ModList;
LoadSettings();
LoadMods();
// Listen to mod selection changes
ModList.CollectionChanged += (s, e) =>
{
if (e.NewItems != null)
{
foreach (Mod mod in e.NewItems)
{
mod.PropertyChanged += Mod_PropertyChanged;
}
}
if (e.OldItems != null)
{
foreach (Mod mod in e.OldItems)
{
mod.PropertyChanged -= Mod_PropertyChanged;
}
}
};
// Load banner image
string bannerPath = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "banner.png");
if (System.IO.File.Exists(bannerPath))
{
try
{
var bitmap = new BitmapImage(new Uri(bannerPath));
BannerImage.Source = bitmap;
}
catch
{
// Ignore if image cannot be loaded
}
}
}
private void Mod_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == nameof(Mod.IsSelected))
{
OnPropertyChanged(nameof(HasSelectedMods));
}
}
private void LoadMods()
{
ModList.Clear();
string modsDir = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Mods");
if (Directory.Exists(modsDir))
{
foreach (var dir in Directory.GetDirectories(modsDir))
{
string modName = System.IO.Path.GetFileName(dir);
string modType = "Unknown";
if (Directory.Exists(System.IO.Path.Combine(dir, "data")))
{
modType = "Data Mod";
}
else if (Directory.Exists(System.IO.Path.Combine(dir, "message")))
{
modType = "Text Mod";
}
var mod = new Mod { Name = modName, Type = modType };
mod.PropertyChanged += Mod_PropertyChanged;
ModList.Add(mod);
}
}
}
private void LoadSettings()
{
if (File.Exists(settingsFile))
{
try
{
string json = File.ReadAllText(settingsFile);
var settings = JsonSerializer.Deserialize<AppSettings>(json);
if (settings != null && !string.IsNullOrEmpty(settings.GamePath))
{
_gamePath = settings.GamePath;
GamePathTextBox.Text = _gamePath;
IsGamePathSelected = true;
}
}
catch
{
// Ignore errors
}
}
}
private void SaveSettings()
{
try
{
var settings = new AppSettings { GamePath = _gamePath };
string json = JsonSerializer.Serialize(settings);
File.WriteAllText(settingsFile, json);
}
catch
{
// Ignore errors
}
}
private void BrowseButton_Click(object sender, RoutedEventArgs e)
{
var dialog = new OpenFolderDialog();
dialog.Title = "Select Digimon Story: Time Stranger game folder";
if (dialog.ShowDialog() == true)
{
_gamePath = dialog.FolderName;
GamePathTextBox.Text = _gamePath;
IsGamePathSelected = true;
SaveSettings();
}
}
private void ModListBox_Drop(object sender, System.Windows.DragEventArgs e)
{
// Drag drop disabled for now
}
private void ModListBox_KeyDown(object sender, System.Windows.Input.KeyEventArgs e)
{
if (e.Key == System.Windows.Input.Key.Delete)
{
var selectedMods = ModList.Where(m => m.IsSelected).ToList();
if (selectedMods.Count > 0)
{
var result = System.Windows.MessageBox.Show("Are you sure you want to delete the selected mods?", "Confirm", MessageBoxButton.YesNo);
if (result == MessageBoxResult.Yes)
{
foreach (var mod in selectedMods)
{
string modDir = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Mods", mod.Name);
if (Directory.Exists(modDir))
{
Directory.Delete(modDir, true);
}
ModList.Remove(mod);
}
}
}
}
}
private void CreateModButton_Click(object sender, RoutedEventArgs e)
{
// Show create mod dialog
var createWindow = new Window
{
Title = "Create New Mod",
Width = 400,
Height = 250,
ResizeMode = ResizeMode.NoResize,
WindowStartupLocation = WindowStartupLocation.CenterOwner,
Owner = this
};
var stackPanel = new StackPanel { Margin = new Thickness(20) };
var nameLabel = new TextBlock { Text = "Mod Name:", Margin = new Thickness(0, 0, 0, 5) };
var nameTextBox = new TextBox { Margin = new Thickness(0, 0, 0, 10) };
var typeLabel = new TextBlock { Text = "Mod Type:", Margin = new Thickness(0, 0, 0, 5) };
var typeComboBox = new ComboBox { ItemsSource = new[] { "Data Mod", "Text Mod" }, SelectedIndex = 0, Margin = new Thickness(0, 0, 0, 20) };
var createButton = new Button
{
Content = "Create Mod",
Style = (Style)FindResource("ModernButton"),
HorizontalAlignment = HorizontalAlignment.Right
};
createButton.Click += (s, args) =>
{
string modName = nameTextBox.Text.Trim();
if (string.IsNullOrEmpty(modName))
{
System.Windows.MessageBox.Show("Please enter a mod name.");
return;
}
string modType = typeComboBox.SelectedItem.ToString();
string modsDir = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Mods");
Directory.CreateDirectory(modsDir);
string modDir = System.IO.Path.Combine(modsDir, modName);
if (Directory.Exists(modDir))
{
System.Windows.MessageBox.Show("Mod with this name already exists.");
return;
}
Directory.CreateDirectory(modDir);
if (modType == "Data Mod")
{
Directory.CreateDirectory(System.IO.Path.Combine(modDir, "data"));
Directory.CreateDirectory(System.IO.Path.Combine(modDir, "font"));
Directory.CreateDirectory(System.IO.Path.Combine(modDir, "images"));
Directory.CreateDirectory(System.IO.Path.Combine(modDir, "lua"));
Directory.CreateDirectory(System.IO.Path.Combine(modDir, "shaders"));
}
else if (modType == "Text Mod")
{
Directory.CreateDirectory(System.IO.Path.Combine(modDir, "font"));
Directory.CreateDirectory(System.IO.Path.Combine(modDir, "images"));
Directory.CreateDirectory(System.IO.Path.Combine(modDir, "message"));
Directory.CreateDirectory(System.IO.Path.Combine(modDir, "text"));
}
System.Windows.MessageBox.Show($"Mod '{modName}' created successfully.");
LoadMods();
createWindow.Close();
};
stackPanel.Children.Add(nameLabel);
stackPanel.Children.Add(nameTextBox);
stackPanel.Children.Add(typeLabel);
stackPanel.Children.Add(typeComboBox);
stackPanel.Children.Add(createButton);
createWindow.Content = stackPanel;
createWindow.ShowDialog();
}
private void AddModButton_Click(object sender, RoutedEventArgs e)
{
var openDialog = new Microsoft.Win32.OpenFileDialog();
openDialog.Filter = "ZIP Files (*.zip)|*.zip";
openDialog.Title = "Select mod ZIP file";
if (openDialog.ShowDialog() == true)
{
string zipFile = openDialog.FileName;
string modName = System.IO.Path.GetFileNameWithoutExtension(zipFile);
string modsDir = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Mods");
Directory.CreateDirectory(modsDir);
string modDir = System.IO.Path.Combine(modsDir, modName);
if (Directory.Exists(modDir))
{
System.Windows.MessageBox.Show("Mod with this name already exists.");
return;
}
try
{
System.IO.Compression.ZipFile.ExtractToDirectory(zipFile, modDir);
LoadMods(); // Refresh list
System.Windows.MessageBox.Show($"Mod '{modName}' added successfully.");
}
catch (Exception ex)
{
System.Windows.MessageBox.Show($"Error adding mod: {ex.Message}");
}
}
}
private void InstallModButton_Click(object sender, RoutedEventArgs e)
{
var selectedMods = ModList.Where(m => m.IsSelected).ToList();
if (selectedMods.Count == 0)
{
System.Windows.MessageBox.Show("Please select a mod to install.");
return;
}
if (selectedMods.Count > 1)
{
System.Windows.MessageBox.Show("Please select only one mod to install.");
return;
}
var selectedMod = selectedMods[0];
string modDir = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Mods", selectedMod.Name);
// Get gamedata directory
string gamedataDir = System.IO.Path.Combine(_gamePath, "gamedata");
if (!Directory.Exists(gamedataDir))
{
System.Windows.MessageBox.Show("Gamedata directory not found in game path.");
return;
}
// Determine target file based on mod type
string targetFile;
if (selectedMod.Type == "Data Mod")
{
targetFile = System.IO.Path.Combine(gamedataDir, "patch_0.dx11.mvgl");
}
else if (selectedMod.Type == "Text Mod")
{
// Show language selection dialog
var languageWindow = new Window
{
Title = "Select Language",
Width = 300,
Height = 200,
ResizeMode = ResizeMode.NoResize,
WindowStartupLocation = WindowStartupLocation.CenterOwner,
Owner = this
};
var stackPanel = new StackPanel { Margin = new Thickness(20) };
var label = new TextBlock { Text = "Select language:", Margin = new Thickness(0, 0, 0, 10) };
var comboBox = new ComboBox { Margin = new Thickness(0, 0, 0, 20) };
// Load languages from hardcoded list (code, name)
var languages = new (string Code, string Name)[]
{
("00", "Japanese"),
("01", "English"),
("02", "Français"),
("03", "Español"),
("04", "Deutsch"),
("05", "Italiano"),
("07", "Brasil (Portuguès)"),
("09", "Korean"),
("10", "Chinese (Traditional)"),
("11", "Chinese (Simplified)"),
("30", "Latinoamérica (Español)")
};
foreach (var lang in languages)
{
comboBox.Items.Add(lang.Name);
}
comboBox.SelectedIndex = 1; // Default to English
var selectButton = new Button
{
Content = "Select",
Style = (Style)FindResource("ModernButton"),
HorizontalAlignment = HorizontalAlignment.Right
};
string selectedLanguageCode = "";
selectButton.Click += (s, args) =>
{
if (comboBox.SelectedIndex >= 0)
{
selectedLanguageCode = languages[comboBox.SelectedIndex].Code;
}
languageWindow.Close();
};
stackPanel.Children.Add(label);
stackPanel.Children.Add(comboBox);
stackPanel.Children.Add(selectButton);
languageWindow.Content = stackPanel;
languageWindow.ShowDialog();
if (string.IsNullOrEmpty(selectedLanguageCode))
{
return; // Cancelled
}
targetFile = System.IO.Path.Combine(gamedataDir, $"patch_text{selectedLanguageCode}.dx11.mvgl");
}
else
{
System.Windows.MessageBox.Show("Unknown mod type.");
return;
}
// Run DSCSToolsCLI --pack
string cliPath = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Tools", "DSCSTools", "DSCSToolsCLI.exe");
if (!System.IO.File.Exists(cliPath))
{
System.Windows.MessageBox.Show("DSCSToolsCLI.exe not found.");
return;
}
var process = new System.Diagnostics.Process
{
StartInfo = new System.Diagnostics.ProcessStartInfo
{
FileName = cliPath,
Arguments = $"--pack \"{modDir}\" \"{targetFile}\"",
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardError = true,
CreateNoWindow = true
}
};
process.Start();
string output = process.StandardOutput.ReadToEnd();
string error = process.StandardError.ReadToEnd();
process.WaitForExit();
if (process.ExitCode == 0)
{
System.Windows.MessageBox.Show($"Mod installed successfully. Patched file: {targetFile}");
}
else
{
System.Windows.MessageBox.Show($"Error installing mod: {error}");
}
}
private void UninstallModButton_Click(object sender, RoutedEventArgs e)
{
// Get gamedata directory
string gamedataDir = System.IO.Path.Combine(_gamePath, "gamedata");
if (!Directory.Exists(gamedataDir))
{
System.Windows.MessageBox.Show("Gamedata directory not found in game path.");
return;
}
var patchFiles = Directory.GetFiles(gamedataDir, "patch_*.mvgl", SearchOption.AllDirectories);
if (patchFiles.Length == 0)
{
System.Windows.MessageBox.Show("No patch files found in gamedata.");
return;
}
// Show file selection dialog
var selectWindow = new Window
{
Title = "Select Patch File to Uninstall",
Width = 400,
Height = 350,
ResizeMode = ResizeMode.NoResize,
WindowStartupLocation = WindowStartupLocation.CenterOwner,
Owner = this
};
var listBox = new ListBox { Margin = new Thickness(10), Height = 200 };
foreach (var file in patchFiles)
{
listBox.Items.Add(System.IO.Path.GetFileName(file));
}
var selectButton = new Button
{
Content = "Uninstall Mod",
Style = (Style)FindResource("ModernButton"),
HorizontalAlignment = HorizontalAlignment.Right
};
selectButton.Click += (s, args) =>
{
if (listBox.SelectedItem != null)
{
string selectedFileName = listBox.SelectedItem.ToString();
string filePath = patchFiles[listBox.SelectedIndex];
var result = System.Windows.MessageBox.Show($"Are you sure you want to delete {selectedFileName}?", "Confirm Uninstall", MessageBoxButton.YesNo);
if (result == MessageBoxResult.Yes)
{
try
{
System.IO.File.Delete(filePath);
System.Windows.MessageBox.Show("Mod uninstalled successfully.");
}
catch (Exception ex)
{
System.Windows.MessageBox.Show($"Error uninstalling mod: {ex.Message}");
}
}
}
selectWindow.Close();
};
var stackPanel = new StackPanel();
stackPanel.Children.Add(new TextBlock { Text = "Select patch file to uninstall:", Margin = new Thickness(10, 10, 10, 5) });
stackPanel.Children.Add(listBox);
stackPanel.Children.Add(selectButton);
selectWindow.Content = stackPanel;
selectWindow.ShowDialog();
}
// Tool buttons
private void MVGLExtactButton_Click(object sender, RoutedEventArgs e)
{
if (string.IsNullOrEmpty(_gamePath))
{
System.Windows.MessageBox.Show("Please select game path first.");
return;
}
string gamedataPath = System.IO.Path.Combine(_gamePath, "gamedata");
if (!Directory.Exists(gamedataPath))
{
System.Windows.MessageBox.Show("Gamedata folder not found.");
return;
}
var mvglFiles = Directory.GetFiles(gamedataPath, "*.mvgl", SearchOption.AllDirectories);
if (mvglFiles.Length == 0)
{
System.Windows.MessageBox.Show("No .mvgl files found.");
return;
}
// Show file selection dialog
var selectWindow = new Window
{
Title = "Select MVGL File",
Width = 400,
Height = 350,
ResizeMode = ResizeMode.NoResize,
WindowStartupLocation = WindowStartupLocation.CenterOwner,
Owner = this
};
var listBox = new ListBox { Margin = new Thickness(10), Height = 200 };
foreach (var file in mvglFiles)
{
listBox.Items.Add(System.IO.Path.GetFileName(file));
}
var progressBar = new ProgressBar
{
Margin = new Thickness(10),
IsIndeterminate = false,
Visibility = Visibility.Collapsed
};
var selectButton = new Button
{
Content = "Extract",
Style = (Style)FindResource("ModernButton"),
HorizontalAlignment = HorizontalAlignment.Right
};
selectButton.Click += async (s, args) =>
{
if (listBox.SelectedItem != null)
{
selectButton.IsEnabled = false;
progressBar.Visibility = Visibility.Visible;
string selectedFile = mvglFiles[listBox.SelectedIndex];
string fileName = System.IO.Path.GetFileNameWithoutExtension(selectedFile);
string extractedDir = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Extracted", fileName);
Directory.CreateDirectory(extractedDir);
// Use indeterminate progress for all files
progressBar.IsIndeterminate = true;
await RunDSCSToolsCLIAsync($"--extract \"{selectedFile}\" \"{extractedDir}\"");
progressBar.Visibility = Visibility.Collapsed;
selectButton.IsEnabled = true;
}
selectWindow.Close();
};
var stackPanel = new StackPanel();
stackPanel.Children.Add(listBox);
stackPanel.Children.Add(progressBar);
stackPanel.Children.Add(selectButton);
selectWindow.Content = stackPanel;
selectWindow.ShowDialog();
}
private void MVGLHelpButton_Click(object sender, RoutedEventArgs e)
{
string helpText = "MVGL Tool Help:\n\n" +
"This tool extracts MVGL model files from the Digimon Story: Time Stranger game data.\n\n" +
"Instructions:\n" +
"1. Ensure the game path is set correctly.\n" +
"2. Click 'Extract' to view available .mvgl files in the gamedata folder.\n" +
"3. Select a file from the list.\n" +
"4. Click 'Extract' in the dialog to unpack the file.\n" +
"5. Files will be extracted to the 'Extracted' folder in the application directory.\n\n" +
"Note: Large files like app_0.dx11.mvgl may take several minutes to extract.";
System.Windows.MessageBox.Show(helpText, "MVGL Tool Help", MessageBoxButton.OK, MessageBoxImage.Information);
}
private void CPKExtractButton_Click(object sender, RoutedEventArgs e)
{
if (string.IsNullOrEmpty(_gamePath))
{
System.Windows.MessageBox.Show("Please select game path first.");
return;
}
string gamedataPath = System.IO.Path.Combine(_gamePath, "gamedata");
if (!Directory.Exists(gamedataPath))
{
System.Windows.MessageBox.Show("Gamedata folder not found.");
return;
}
var cpkFiles = Directory.GetFiles(gamedataPath, "*.cpk", SearchOption.AllDirectories);
if (cpkFiles.Length == 0)
{
System.Windows.MessageBox.Show("No .cpk files found.");
return;
}
// Show file selection dialog
var selectWindow = new Window
{
Title = "Select CPK File",
Width = 400,
Height = 350,
ResizeMode = ResizeMode.NoResize,
WindowStartupLocation = WindowStartupLocation.CenterOwner,
Owner = this
};
var listBox = new ListBox { Margin = new Thickness(10), Height = 200 };
foreach (var file in cpkFiles)
{
listBox.Items.Add(System.IO.Path.GetFileName(file));
}
var progressBar = new ProgressBar
{
Margin = new Thickness(10),
IsIndeterminate = true,
Visibility = Visibility.Collapsed
};
var selectButton = new Button
{
Content = "Extract",
Style = (Style)FindResource("ModernButton"),
HorizontalAlignment = HorizontalAlignment.Right
};
selectButton.Click += async (s, args) =>
{
if (listBox.SelectedItem != null)
{
selectButton.IsEnabled = false;
progressBar.Visibility = Visibility.Visible;
string selectedFile = cpkFiles[listBox.SelectedIndex];
string fileName = System.IO.Path.GetFileNameWithoutExtension(selectedFile);
string extractedDir = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "CPKExtracted", fileName);
Directory.CreateDirectory(extractedDir);
await RunYACpkToolAsync($"\"{selectedFile}\" \"{extractedDir}\"");
progressBar.Visibility = Visibility.Collapsed;
selectButton.IsEnabled = true;
}
selectWindow.Close();
};
var stackPanel = new StackPanel();
stackPanel.Children.Add(listBox);
stackPanel.Children.Add(progressBar);
stackPanel.Children.Add(selectButton);
selectWindow.Content = stackPanel;
selectWindow.ShowDialog();
}
private void CPKRepackButton_Click(object sender, RoutedEventArgs e)
{
string extractedDir = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "CPKExtracted");
if (!Directory.Exists(extractedDir))
{
System.Windows.MessageBox.Show("CPKExtracted folder not found. Extract some CPK files first.");
return;
}
var subDirs = Directory.GetDirectories(extractedDir);
if (subDirs.Length == 0)
{
System.Windows.MessageBox.Show("No extracted folders found.");
return;
}
// Show folder selection dialog
var selectWindow = new Window
{
Title = "Select Folder to Repack",
Width = 400,
Height = 350,
ResizeMode = ResizeMode.NoResize,
WindowStartupLocation = WindowStartupLocation.CenterOwner,
Owner = this
};
var listBox = new ListBox { Margin = new Thickness(10), Height = 200 };
foreach (var dir in subDirs)
{
listBox.Items.Add(System.IO.Path.GetFileName(dir));
}
var progressBar = new ProgressBar
{
Margin = new Thickness(10),
IsIndeterminate = true,
Visibility = Visibility.Collapsed
};
var selectButton = new Button
{
Content = "Repack",
Style = (Style)FindResource("ModernButton"),
HorizontalAlignment = HorizontalAlignment.Right
};
selectButton.Click += async (s, args) =>
{
if (listBox.SelectedItem != null)
{
selectButton.IsEnabled = false;
progressBar.Visibility = Visibility.Visible;
string selectedDir = subDirs[listBox.SelectedIndex];
string dirName = System.IO.Path.GetFileName(selectedDir);
string packedDir = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "CPKPacked");
Directory.CreateDirectory(packedDir);
string outputCpk = System.IO.Path.Combine(packedDir, dirName + ".cpk");
await RunYACpkToolAsync($"\"{selectedDir}\" \"{outputCpk}\"");
progressBar.Visibility = Visibility.Collapsed;
selectButton.IsEnabled = true;
}
selectWindow.Close();
};
var stackPanel = new StackPanel();
stackPanel.Children.Add(listBox);
stackPanel.Children.Add(progressBar);
stackPanel.Children.Add(selectButton);
selectWindow.Content = stackPanel;
selectWindow.ShowDialog();
}
private void CPKHelpButton_Click(object sender, RoutedEventArgs e)
{
string helpText = "CPK Tool Help:\n\n" +
"This tool extracts and repacks CPK archive files from the Digimon Story: Time Stranger game data.\n\n" +
"Extract Instructions:\n" +
"1. Ensure the game path is set correctly.\n" +
"2. Click 'Extract' to view available .cpk files in the gamedata folder.\n" +
"3. Select a file from the list.\n" +
"4. Click 'Extract' in the dialog to unpack the file.\n" +
"5. Files will be extracted to the 'Extracted' folder in the application directory.\n\n" +
"Repack Instructions:\n" +
"1. Click 'Repack' to view extracted folders in the 'Extracted' directory.\n" +
"2. Select a folder from the list.\n" +
"3. Click 'Repack' in the dialog to pack the folder into a .cpk file.\n" +
"4. The packed file will be saved to the 'CPKPacked' folder in the application directory.";
System.Windows.MessageBox.Show(helpText, "CPK Tool Help", MessageBoxButton.OK, MessageBoxImage.Information);
}
private void MBEExtractButton_Click(object sender, RoutedEventArgs e)
{
string extractedDir = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Extracted");
if (!Directory.Exists(extractedDir))
{
System.Windows.MessageBox.Show("Extracted folder not found. Extract some files first.");
return;
}
var subDirs = Directory.GetDirectories(extractedDir);
if (subDirs.Length == 0)
{
System.Windows.MessageBox.Show("No extracted folders found.");
return;
}
// Show folder selection dialog
var selectWindow = new Window
{
Title = "Select Extracted Folder",
Width = 400,
Height = 350,
ResizeMode = ResizeMode.NoResize,
WindowStartupLocation = WindowStartupLocation.CenterOwner,
Owner = this
};
var listBox = new ListBox { Margin = new Thickness(10), Height = 150 };
foreach (var dir in subDirs)
{
listBox.Items.Add(System.IO.Path.GetFileName(dir));
}
var typeComboBox = new ComboBox { Margin = new Thickness(10), ItemsSource = new[] { "message", "text" } };
typeComboBox.SelectedIndex = 0;
var progressBar = new ProgressBar
{
Margin = new Thickness(10),
IsIndeterminate = true,
Visibility = Visibility.Collapsed
};
var selectButton = new Button
{
Content = "Extract MBE",
Style = (Style)FindResource("ModernButton"),
HorizontalAlignment = HorizontalAlignment.Right
};
selectButton.Click += async (s, args) =>
{
if (listBox.SelectedItem != null && typeComboBox.SelectedItem != null)
{
selectButton.IsEnabled = false;
progressBar.Visibility = Visibility.Visible;
string selectedDir = subDirs[listBox.SelectedIndex];
string type = typeComboBox.SelectedItem.ToString();
string typeDir = System.IO.Path.Combine(selectedDir, type);
if (!Directory.Exists(typeDir))
{
System.Windows.MessageBox.Show($"{type} folder not found in {System.IO.Path.GetFileName(selectedDir)}.");
selectButton.IsEnabled = true;
progressBar.Visibility = Visibility.Collapsed;
return;
}
var mbeFiles = Directory.GetFiles(typeDir, "*.mbe");
if (mbeFiles.Length == 0)
{
System.Windows.MessageBox.Show($"No .mbe files found in {type} folder.");
selectButton.IsEnabled = true;
progressBar.Visibility = Visibility.Collapsed;
return;
}
string outputDir = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "MBEExtracted", type);
Directory.CreateDirectory(outputDir);
foreach (var mbeFile in mbeFiles)
{
await RunPythonScriptAsync("MBE_Parser.py", $"\"{mbeFile}\"", outputDir);
}
if (mbeFiles.Length > 0)
{
System.Windows.MessageBox.Show($"Extracted {mbeFiles.Length} .mbe files to {outputDir}.");
}
progressBar.Visibility = Visibility.Collapsed;
selectButton.IsEnabled = true;
}
selectWindow.Close();
};
var stackPanel = new StackPanel();
stackPanel.Children.Add(new TextBlock { Text = "Select extracted folder:", Margin = new Thickness(10, 10, 10, 5) });
stackPanel.Children.Add(listBox);
stackPanel.Children.Add(new TextBlock { Text = "Select type:", Margin = new Thickness(10, 10, 10, 5) });
stackPanel.Children.Add(typeComboBox);
stackPanel.Children.Add(progressBar);
stackPanel.Children.Add(selectButton);
selectWindow.Content = stackPanel;
selectWindow.ShowDialog();
}
private void MBERepackButton_Click(object sender, RoutedEventArgs e)
{
string mbeExtractDir = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "MBEExtracted");
if (!Directory.Exists(mbeExtractDir))
{
System.Windows.MessageBox.Show("MBEExtracted folder not found. Extract some MBE files first.");
return;
}
var subDirs = Directory.GetDirectories(mbeExtractDir);
if (subDirs.Length == 0)
{
System.Windows.MessageBox.Show("No MBE extracted folders found.");
return;
}
// Show folder selection dialog
var selectWindow = new Window
{
Title = "Select MBE Folder to Repack",
Width = 400,
Height = 350,
ResizeMode = ResizeMode.NoResize,
WindowStartupLocation = WindowStartupLocation.CenterOwner,
Owner = this
};
var listBox = new ListBox { Margin = new Thickness(10), Height = 200 };
foreach (var dir in subDirs)
{
listBox.Items.Add(System.IO.Path.GetFileName(dir));
}
var progressBar = new ProgressBar
{
Margin = new Thickness(10),
IsIndeterminate = true,
Visibility = Visibility.Collapsed
};
var selectButton = new Button
{
Content = "Repack MBE",
Style = (Style)FindResource("ModernButton"),
HorizontalAlignment = HorizontalAlignment.Right
};
selectButton.Click += async (s, args) =>
{
if (listBox.SelectedItem != null)
{
selectButton.IsEnabled = false;
progressBar.Visibility = Visibility.Visible;
string selectedDir = subDirs[listBox.SelectedIndex];
string selectedName = System.IO.Path.GetFileName(selectedDir);
string packedDir = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "MBEPacked", selectedName);
Directory.CreateDirectory(packedDir);
// Get subfolders in selectedDir (e.g., message\analyse)
var subFolders = Directory.GetDirectories(selectedDir);
foreach (var subFolder in subFolders)
{
await RunPythonScriptAsync("MBE_Repacker.py", $"\"{subFolder}\"");
// Script creates file in the same directory as subFolder
string subName = System.IO.Path.GetFileName(subFolder);
string subDir = System.IO.Path.GetDirectoryName(subFolder);
string mbeFile = System.IO.Path.Combine(subDir, subName + ".mbe");