Skip to content

Commit

Permalink
Add notes autosave and better play error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
segabl committed Jun 10, 2021
1 parent 5c74c6f commit ecd6f61
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
27 changes: 21 additions & 6 deletions MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using System.Net;
using System.Reflection;
using System.Text.RegularExpressions;
using System.Timers;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
Expand All @@ -35,6 +36,7 @@ public partial class MainWindow : AdonisWindow {
private Button playingButton;
private bool converterAvailable;
private CollectionViewSource soundBankViewSource = new CollectionViewSource();
private Timer autosaveNotesTimer;

public bool UpdateCheckEnabled { get => appSettings.checkForUpdates; set => appSettings.checkForUpdates = value; }

Expand Down Expand Up @@ -74,6 +76,14 @@ public MainWindow() {
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;
}

Expand Down Expand Up @@ -210,20 +220,25 @@ private void OnPlayButtonClick(object sender, RoutedEventArgs e) {

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) {
MessageBox.Show($"Can't play file:\n{ex.Message}", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
MessageBox.Show($"{debugStr}:\n{ex.Message}", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
return;
} finally {
File.Delete(fileName);
}
}
mediaPlayer.Open(new Uri(convertedFileName));
mediaPlayer.Play();
SetPlayButtonState(button, null);

if (File.Exists(convertedFileName)) {
mediaPlayer.Open(new Uri(convertedFileName));
mediaPlayer.Play();
SetPlayButtonState(button, null);
}
}

private void OnRecentFileClick(object sender, RoutedEventArgs e) {
Expand Down
2 changes: 1 addition & 1 deletion PD2SoundBankEditor.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<UseWPF>true</UseWPF>
<StartupObject></StartupObject>
<AssemblyName>PD2SoundBankEditor</AssemblyName>
<Version>1.0.2</Version>
<Version>1.0.3</Version>
<AssemblyVersion>1.0.0.0</AssemblyVersion>
<FileVersion>1.0.0.0</FileVersion>
<NeutralLanguage>en</NeutralLanguage>
Expand Down

0 comments on commit ecd6f61

Please sign in to comment.