-
Notifications
You must be signed in to change notification settings - Fork 1
/
MainWindow.xaml.cs
572 lines (503 loc) · 20.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
using AdonisUI.Controls;
using Microsoft.Win32;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net;
using System.Reflection;
using System.Text.RegularExpressions;
using System.Timers;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Media;
using MessageBox = AdonisUI.Controls.MessageBox;
using MessageBoxButton = AdonisUI.Controls.MessageBoxButton;
using MessageBoxImage = AdonisUI.Controls.MessageBoxImage;
using MessageBoxResult = AdonisUI.Controls.MessageBoxResult;
namespace PD2SoundBankEditor {
public partial class MainWindow : AdonisWindow {
static readonly string CONVERTER_NAME = "wwise_ima_adpcm.exe";
static readonly string CONVERTER_PATH = Path.Join(AppDomain.CurrentDomain.BaseDirectory, CONVERTER_NAME);
static readonly string SETTINGS_PATH = Path.Join(AppDomain.CurrentDomain.BaseDirectory, "settings.json");
static readonly string TEMPORARY_PATH = Path.Join(AppDomain.CurrentDomain.BaseDirectory, "tmp");
static readonly string LOG_PATH = Path.Join(AppDomain.CurrentDomain.BaseDirectory, "log.txt");
private ApplicationSettings appSettings = new ApplicationSettings();
private MediaPlayer mediaPlayer = new MediaPlayer();
private SoundBank soundBank;
private Button playingButton;
private bool converterAvailable;
private CollectionViewSource soundBankViewSource = new CollectionViewSource();
private Timer autosaveNotesTimer;
private Regex viewFilterRegex = null;
public bool UpdateCheckEnabled { get => appSettings.checkForUpdates; set => appSettings.checkForUpdates = value; }
public bool SuppressErrorsEnabled { get => appSettings.suppressErrors; set => appSettings.suppressErrors = value; }
public bool HideUnreferencedEnabled { get => appSettings.hideUnreferenced; set => appSettings.hideUnreferenced = value; }
public MainWindow() {
InitializeComponent();
DataContext = this;
if (File.Exists(SETTINGS_PATH)) {
try {
appSettings = JsonConvert.DeserializeObject<ApplicationSettings>(File.ReadAllText(SETTINGS_PATH));
} catch (Exception ex) {
Trace.WriteLine(ex.Message);
File.AppendAllText(LOG_PATH, ex.Message);
}
}
converterAvailable = File.Exists(CONVERTER_PATH);
if (!converterAvailable) {
MessageBox.Show($"The sound converter could not be found, you will not be able to play, convert or replace stream files! Please place {CONVERTER_NAME} in the directory of this application!", "Information", MessageBoxButton.OK, MessageBoxImage.Warning);
}
if (appSettings.checkForUpdates && (DateTime.Now - appSettings.lastUpdateCheck).TotalHours > 1) {
try {
var client = new WebClient();
client.Headers.Add("User-Agent:PD2SoundbankEditor");
client.DownloadStringAsync(new Uri("https://api.github.com/repos/segabl/pd2-soundbank-editor/releases"));
client.DownloadStringCompleted += OnReleaseDataFetched;
appSettings.lastUpdateCheck = DateTime.Now;
} catch (Exception ex) {
Trace.WriteLine(ex.Message);
File.AppendAllText(LOG_PATH, ex.Message);
}
}
recentFilesList.ItemsSource = appSettings.recentlyOpenedFiles;
recentFilesList.IsEnabled = appSettings.recentlyOpenedFiles.Count > 0;
autosaveNotesTimer = new Timer(60000) {
AutoReset = true,
Enabled = true
};
autosaveNotesTimer.Elapsed += (object source, ElapsedEventArgs e) => {
soundBank?.SaveNotes();
};
mediaPlayer.MediaEnded += SetPlayButtonState;
}
private void OnReleaseDataFetched(object sender, DownloadStringCompletedEventArgs e) {
if (e.Error != null || e.Cancelled) {
return;
}
GitHubRelease latestRelease = null;
try {
var allReleases = JsonConvert.DeserializeObject<List<GitHubRelease>>(e.Result);
latestRelease = allReleases.FirstOrDefault(r => !r.draft && !r.prerelease);
} catch (Exception ex) {
Trace.WriteLine(ex.Message);
File.AppendAllText(LOG_PATH, ex.Message);
}
if (latestRelease == null) {
return;
}
var latestVersion = latestRelease.tag_name[1..];
var productVersion = FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location).ProductVersion;
if (CompareVersionStrings(latestVersion, productVersion) > 0) {
var result = MessageBox.Show($"There's a newer release ({latestRelease.tag_name}) of this application available. Do you want to go to the release page to download it now?", "Information", MessageBoxButton.YesNo, MessageBoxImage.Information);
if (result == MessageBoxResult.Yes) {
Process.Start(new ProcessStartInfo(latestRelease.html_url) { UseShellExecute = true });
}
}
}
private void CommandSaveCanExecute(object sender, System.Windows.Input.CanExecuteRoutedEventArgs e) {
e.CanExecute = soundBank != null && soundBank.IsDirty;
}
private void CommandSaveExecuted(object sender, System.Windows.Input.ExecutedRoutedEventArgs e) {
soundBank.Save(soundBank.FilePath);
UpdateWindowTitle();
}
private void CommandSaveAsCanExecute(object sender, System.Windows.Input.CanExecuteRoutedEventArgs e) {
e.CanExecute = soundBank != null;
}
private void CommandSaveAsExecuted(object sender, System.Windows.Input.ExecutedRoutedEventArgs e) {
var diag = new SaveFileDialog {
Filter = "Soundbanks (*.bnk)|*.bnk",
FileName = Path.GetFileName(soundBank.FilePath),
AddExtension = true
};
if (diag.ShowDialog() != true) {
return;
}
soundBank.Save(diag.FileName);
UpdateWindowTitle();
}
private void OnOpenButtonClick(object sender, RoutedEventArgs e) {
var diag = new OpenFileDialog {
Filter = "Soundbanks (*.bnk)|*.bnk"
};
if (diag.ShowDialog() != true) {
return;
}
soundBank?.SaveNotes();
DoGenericProcessing(false, LoadSoundBank, OnSoundBankLoaded, diag.FileName);
}
private void OnExitButtonClick(object sender, RoutedEventArgs e) {
Close();
}
private void OnAboutButtonClick(object sender, RoutedEventArgs e) {
MessageBox.Show($"PD2 Soundbank Editor v{FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location).ProductVersion}\nMade by Hoppip", "About", MessageBoxButton.OK, MessageBoxImage.Information);
}
private void OnExtractButtonClick(object sender, RoutedEventArgs e) {
DoGenericProcessing(true, ExtractStreams, OnExtractStreamsFinished, ((Button)sender) == extractAllButton ? soundBank.StreamInfos : dataGrid.SelectedItems.Cast<StreamInfo>());
}
private void OnReplaceButtonClick(object sender, RoutedEventArgs e) {
var diag = new OpenFileDialog {
Filter = "Wave audio files (*.wav)|*.wav"
};
if (diag.ShowDialog() != true) {
return;
}
if (!Directory.Exists(TEMPORARY_PATH)) {
Directory.CreateDirectory(TEMPORARY_PATH);
}
var fileNameNoExt = Path.GetFileNameWithoutExtension(diag.FileName);
var fileName = Path.Combine(TEMPORARY_PATH, fileNameNoExt + ".stream");
try {
StartConverterProcess($"-e \"{diag.FileName}\" \"{fileName}\"");
} catch (Exception ex) {
MessageBox.Show($"An error occured while trying to convert {diag.FileName}:\n{ex.Message}", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
return;
}
var data = File.ReadAllBytes(fileName);
foreach (var info in dataGrid.SelectedItems.Cast<StreamInfo>()) {
info.Data = data;
info.ReplacementFile = fileNameNoExt + ".wav";
var tmpFile = Path.Combine(TEMPORARY_PATH, info.Id + ".wav");
if (File.Exists(tmpFile)) {
File.Delete(tmpFile);
}
}
soundBank.IsDirty = true;
UpdateWindowTitle();
}
private void OnReplaceByNamesButtonClick(object sender, RoutedEventArgs e) {
var diag = new OpenFileDialog {
Filter = "Wave audio files (*.wav)|*.wav",
Multiselect = true
};
if (diag.ShowDialog() != true) {
return;
}
if (!Directory.Exists(TEMPORARY_PATH)) {
Directory.CreateDirectory(TEMPORARY_PATH);
}
var notfound = new List<string>();
var mappings = new Dictionary<string, StreamInfo>();
foreach (var file in diag.FileNames) {
var fileNameNoExt = Path.GetFileNameWithoutExtension(file);
var fileName = Path.Combine(TEMPORARY_PATH, fileNameNoExt + ".stream");
if (!uint.TryParse(fileNameNoExt, out var targetStreamId)) {
notfound.Add(fileNameNoExt + ".wav");
continue;
}
var targetStreamInfo = soundBank.StreamInfos.FirstOrDefault(info => info.Id == targetStreamId);
if (targetStreamInfo == null) {
notfound.Add(fileNameNoExt + ".wav");
continue;
}
mappings[file] = targetStreamInfo;
}
if (notfound.Count > 0) {
MessageBox.Show($"{notfound.Count} files could not be matched to any ID in this soundbank:\n{string.Join(", ", notfound)}", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
}
if (mappings.Count > 0) {
DoGenericProcessing(true, ReplaceStreams, OnReplaceStreamsFinished, mappings);
}
}
private void OnFilterChanged(object sender, RoutedEventArgs e) {
var view = soundBankViewSource.View;
if (view == null || filterTextBox == null) {
return;
}
viewFilterRegex = null;
if (filterTextBox.Text.Length > 0) {
try {
viewFilterRegex = new Regex(filterTextBox.Text, RegexOptions.Compiled);
} catch (Exception) { }
}
view.Refresh();
}
private void OnPlayButtonClick(object sender, RoutedEventArgs e) {
if (!converterAvailable) {
return;
}
var button = (Button)sender;
var info = (StreamInfo)button.DataContext;
var sameButton = playingButton == button;
SetPlayButtonState(null, null);
if (sameButton) {
return;
}
if (!Directory.Exists(TEMPORARY_PATH)) {
Directory.CreateDirectory(TEMPORARY_PATH);
}
var fileName = Path.Combine(TEMPORARY_PATH, $"{info.Id}.stream");
var convertedFileName = Path.ChangeExtension(fileName, "wav");
var debugStr = "";
if (!File.Exists(convertedFileName)) {
try {
debugStr = "Failed at saving stream";
info.Save(fileName);
debugStr = "Failed at converting stream";
StartConverterProcess($"-d \"{fileName}\" \"{convertedFileName}\"");
File.Delete(fileName);
} catch (Exception ex) {
if (!SuppressErrorsEnabled) {
MessageBox.Show($"{debugStr}:\n{ex.Message}", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
}
return;
}
}
if (File.Exists(convertedFileName)) {
mediaPlayer.Open(new Uri(convertedFileName));
mediaPlayer.Play();
SetPlayButtonState(button, null);
}
}
private void OnRecentFileClick(object sender, RoutedEventArgs e) {
var menuItem = (MenuItem)sender;
var file = (string)menuItem.DataContext;
soundBank?.SaveNotes();
DoGenericProcessing(false, LoadSoundBank, OnSoundBankLoaded, file);
if (!File.Exists(file)) {
appSettings.recentlyOpenedFiles.Remove(file);
recentFilesList.ItemsSource = null; //too lazy for proper notify
recentFilesList.ItemsSource = appSettings.recentlyOpenedFiles;
}
}
private void OnConvertLooseFilesClick(object sender, RoutedEventArgs e) {
var diag = new OpenFileDialog {
Filter = "Stream audio files (*.stream)|*.stream|Wave audio files (*.wav)|*.wav",
Multiselect = true,
};
if (diag.ShowDialog() != true) {
return;
}
DoGenericProcessing(true, ConvertLooseFiles, OnConvertLooseFilesFinished, diag.FileNames);
}
private void OnSetAudioPropertiesClick(object sender, RoutedEventArgs e) {
var paramsWindow = new ParamsWindow(soundBank) { Owner = this };
paramsWindow.ShowDialog();
}
private void OnDataGridSelectionChanged(object sender, SelectionChangedEventArgs e) {
replaceSelectedButton.IsEnabled = converterAvailable && dataGrid.SelectedItems.Count > 0;
extractSelectedButton.IsEnabled = converterAvailable && dataGrid.SelectedItems.Count > 0;
}
private void OnWindowClosed(object sender, EventArgs e) {
soundBank?.SaveNotes();
if (Directory.Exists(TEMPORARY_PATH)) {
Directory.Delete(TEMPORARY_PATH, true);
}
File.WriteAllText(SETTINGS_PATH, JsonConvert.SerializeObject(appSettings));
}
private void StartConverterProcess(string args) {
var convertProcess = new Process();
convertProcess.StartInfo.UseShellExecute = false;
convertProcess.StartInfo.CreateNoWindow = true;
convertProcess.StartInfo.RedirectStandardOutput = true;
convertProcess.StartInfo.FileName = CONVERTER_PATH;
convertProcess.StartInfo.Arguments = args;
convertProcess.Start();
var output = convertProcess.StandardOutput.ReadToEnd();
convertProcess.WaitForExit();
if (output != "") {
throw new FileFormatException(output);
}
}
public void DoGenericProcessing(bool reportProgress, Action<object, DoWorkEventArgs> work, Action<object, RunWorkerCompletedEventArgs> workFinished = null, object argument = null) {
mainGrid.IsEnabled = false;
BackgroundWorker worker = new BackgroundWorker {
WorkerReportsProgress = reportProgress
};
worker.DoWork += (sender, e) => work(sender, e);
if (reportProgress) {
worker.ProgressChanged += OnGenericProcessingProgress;
} else {
progressBar.IsIndeterminate = true;
}
worker.RunWorkerCompleted += OnGenericProcessingFinished;
if (workFinished != null) {
worker.RunWorkerCompleted += (sender, e) => workFinished(sender, e);
}
worker.RunWorkerAsync(argument);
}
private void OnGenericProcessingProgress(object sender, ProgressChangedEventArgs e) {
progressBar.Value = e.ProgressPercentage;
}
private void OnGenericProcessingFinished(object sender, RunWorkerCompletedEventArgs e) {
progressBar.IsIndeterminate = false;
progressBar.Value = 0;
mainGrid.IsEnabled = true;
}
public void LoadSoundBank(object sender, DoWorkEventArgs e) {
try {
soundBank = new SoundBank(e.Argument as string);
} catch (Exception ex) {
e.Result = ex.Message;
}
}
public void OnSoundBankLoaded(object sender, RunWorkerCompletedEventArgs e) {
if (e.Result != null) {
MessageBox.Show($"Can't open soundbank:\n{e.Result}", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
return;
}
soundBankViewSource.Source = soundBank.StreamInfos;
soundBankViewSource.View.Filter = new Predicate<object>(info => {
if (HideUnreferencedEnabled && !(info as StreamInfo).HasReferences) {
return false;
} else if (viewFilterRegex == null) {
return (info as StreamInfo).Note.Contains(filterTextBox.Text) || (info as StreamInfo).Id.ToString().Contains(filterTextBox.Text);
} else {
return viewFilterRegex.Match((info as StreamInfo).Note).Success || viewFilterRegex.Match((info as StreamInfo).Id.ToString()).Success;
}
});
dataGrid.ItemsSource = soundBankViewSource.View;
dataGrid.DataContext = soundBankViewSource.View;
if (appSettings.recentlyOpenedFiles.Contains(soundBank.FilePath)) {
appSettings.recentlyOpenedFiles.Remove(soundBank.FilePath);
}
appSettings.recentlyOpenedFiles.Insert(0, soundBank.FilePath);
if (appSettings.recentlyOpenedFiles.Count > 10) {
appSettings.recentlyOpenedFiles.RemoveRange(10, appSettings.recentlyOpenedFiles.Count - 10);
}
recentFilesList.ItemsSource = null; //too lazy for proper notify
recentFilesList.ItemsSource = appSettings.recentlyOpenedFiles;
UpdateWindowTitle();
extractAllButton.IsEnabled = converterAvailable && soundBank.StreamInfos.Count > 0;
replaceByNamesButton.IsEnabled = converterAvailable && soundBank.StreamInfos.Count > 0;
setAudioPropertiedMenuItem.IsEnabled = ((HircSection)soundBank.Sections.Find(x => x.Name == "HIRC"))?.SoundObjects.Count > 0;
if (!soundBank.StreamInfos.Any(info => info.HasReferences)) {
MessageBox.Show($"This soundbank does not contain any referenced embedded streams. Unreferenced embedded data is usually garbage data.", "Information", MessageBoxButton.OK, MessageBoxImage.Warning);
}
}
public void UpdateWindowTitle() {
Title = $"PD2 Soundbank Editor - {Path.GetFileName(soundBank.FilePath)}{(soundBank.IsDirty ? "*" : "")}";
}
private void ExtractStreams(object sender, DoWorkEventArgs e) {
var streamDescriptions = (IEnumerable<StreamInfo>)e.Argument;
var soundBankName = soundBank.FilePath;
var savePath = Path.Join(Path.GetDirectoryName(soundBankName), Path.GetFileNameWithoutExtension(soundBankName));
if (!Directory.Exists(savePath)) {
Directory.CreateDirectory(savePath);
}
var n = 0;
var errors = new List<string>();
foreach (var info in streamDescriptions) {
var file = Path.Join(savePath, $"{info.Id}.stream");
var convertedFileName = Path.ChangeExtension(file, "wav");
try {
info.Save(file);
StartConverterProcess($"-d \"{file}\" \"{convertedFileName}\"");
} catch (Exception ex) {
errors.Add(ex.Message);
}
(sender as BackgroundWorker).ReportProgress((int)(++n / (float)streamDescriptions.Count() * 100));
}
e.Result = errors;
}
void OnExtractStreamsFinished(object sender, RunWorkerCompletedEventArgs e) {
var errors = (List<string>)e.Result;
if (errors.Count > 0) {
MessageBox.Show($"Extraction finished with {errors.Count} error(s)!", "Information", MessageBoxButton.OK, MessageBoxImage.Warning);
File.AppendAllLines(LOG_PATH, errors);
} else {
MessageBox.Show("Extraction complete!", "Information", MessageBoxButton.OK, MessageBoxImage.Information);
}
}
private void ReplaceStreams(object sender, DoWorkEventArgs e) {
var fileMappings = (Dictionary<string, StreamInfo>)e.Argument;
var n = 0;
var errors = new List<string>();
if (!Directory.Exists(TEMPORARY_PATH)) {
Directory.CreateDirectory(TEMPORARY_PATH);
}
foreach (var mapping in fileMappings) {
var file = mapping.Key;
var targetStreamInfo = mapping.Value;
var fileNameNoExt = Path.GetFileNameWithoutExtension(file);
var fileName = Path.Combine(TEMPORARY_PATH, fileNameNoExt + ".stream");
try {
StartConverterProcess($"-e \"{file}\" \"{fileName}\"");
} catch (Exception ex) {
errors.Add(ex.Message);
}
targetStreamInfo.Data = File.ReadAllBytes(fileName);
targetStreamInfo.ReplacementFile = fileNameNoExt + ".wav";
var tmpFile = Path.Combine(TEMPORARY_PATH, targetStreamInfo.Id + ".wav");
if (File.Exists(tmpFile)) {
File.Delete(tmpFile);
}
(sender as BackgroundWorker).ReportProgress((int)(++n / (float)fileMappings.Count * 100));
soundBank.IsDirty = true;
}
e.Result = errors;
}
void OnReplaceStreamsFinished(object sender, RunWorkerCompletedEventArgs e) {
var errors = (List<string>)e.Result;
if (errors.Count > 0) {
MessageBox.Show($"Sound replacement finished with {errors.Count} error(s)!", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
File.AppendAllLines(LOG_PATH, errors);
} else {
MessageBox.Show($"Sound replacement finished successfully!", "Information", MessageBoxButton.OK, MessageBoxImage.Information);
}
UpdateWindowTitle();
}
private void ConvertLooseFiles(object sender, DoWorkEventArgs e) {
var files = (string[])e.Argument;
var n = 0;
var errors = new List<string>();
foreach (var file in files) {
var fileExt = Path.GetExtension(file);
var fileNameNoExt = Path.GetFileNameWithoutExtension(file);
var fileDir = Path.GetDirectoryName(file);
var fileName = Path.Combine(fileDir, fileNameNoExt + (fileExt == ".wav" ? ".stream" : ".wav"));
try {
StartConverterProcess($"-{(fileExt == ".wav" ? "e" : "d")} \"{file}\" \"{fileName}\"");
} catch (Exception ex) {
errors.Add(ex.Message);
}
(sender as BackgroundWorker).ReportProgress((int)(++n / (float)files.Length * 100));
}
e.Result = errors;
}
void OnConvertLooseFilesFinished(object sender, RunWorkerCompletedEventArgs e) {
var errors = (List<string>)e.Result;
if (errors.Count > 0) {
MessageBox.Show($"Conversion finished with {errors.Count} error(s)!", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
File.AppendAllLines(LOG_PATH, errors);
} else {
MessageBox.Show($"Conversion finished successfully!", "Information", MessageBoxButton.OK, MessageBoxImage.Information);
}
}
private void SetPlayButtonState(object sender, EventArgs e) {
if (sender == mediaPlayer || sender == null) {
mediaPlayer.Stop();
mediaPlayer.Close();
if (playingButton != null) {
playingButton.Content = "▶";
}
playingButton = null;
} else {
playingButton = (Button)sender;
playingButton.Content = "■";
}
}
private int CompareVersionStrings(string v1, string v2) {
try {
var nums1 = v1.Split(".").Select(int.Parse).ToArray();
var nums2 = v2.Split(".").Select(int.Parse).ToArray();
for (var i = 0; i < nums1.Length && i < nums2.Length; i++) {
if (nums1[i] == nums2[i]) {
continue;
} else {
return Math.Sign(nums1[i] - nums2[i]);
}
}
return Math.Sign(nums1.Length - nums2.Length);
} catch (Exception ex) {
File.AppendAllText(LOG_PATH, ex.Message);
return 0;
}
}
}
}