Skip to content

Commit

Permalink
Check if file exists before playing
Browse files Browse the repository at this point in the history
  • Loading branch information
segabl committed May 31, 2021
1 parent a62e080 commit 5c74c6f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
14 changes: 7 additions & 7 deletions MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,9 @@ private void OnReplaceButtonClick(object sender, RoutedEventArgs e) {
foreach (var info in dataGrid.SelectedItems.Cast<StreamInfo>()) {
info.Data = data;
info.ReplacementFile = fileNameNoExt + ".wav";
info.ConvertedFilePath = null;
var tmpFile = Path.Combine(TEMPORARY_PATH, info.Id + ".wav");
if (File.Exists(tmpFile))
File.Delete(tmpFile);
}
soundBank.IsDirty = true;
Title = $"PD2 Soundbank Editor - {Path.GetFileName(soundBank.FilePath)}*";
Expand Down Expand Up @@ -206,21 +208,20 @@ private void OnPlayButtonClick(object sender, RoutedEventArgs e) {
return;
}

if (info.ConvertedFilePath == null) {
var fileName = Path.Combine(TEMPORARY_PATH, $"{info.Id}.stream");
var convertedFileName = Path.ChangeExtension(fileName, "wav");
var fileName = Path.Combine(TEMPORARY_PATH, $"{info.Id}.stream");
var convertedFileName = Path.ChangeExtension(fileName, "wav");
if (!File.Exists(convertedFileName)) {
try {
info.Save(fileName);
StartConverterProcess($"-d \"{fileName}\" \"{convertedFileName}\"");
info.ConvertedFilePath = convertedFileName;
} catch (Exception ex) {
MessageBox.Show($"Can't play file:\n{ex.Message}", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
return;
} finally {
File.Delete(fileName);
}
}
mediaPlayer.Open(new Uri(info.ConvertedFilePath));
mediaPlayer.Open(new Uri(convertedFileName));
mediaPlayer.Play();
SetPlayButtonState(button, null);
}
Expand Down Expand Up @@ -349,7 +350,6 @@ private void ExtractStreams(object sender, DoWorkEventArgs e) {
try {
info.Save(fileName);
StartConverterProcess($"-d \"{fileName}\" \"{convertedFileName}\"");
info.ConvertedFilePath = convertedFileName;
} catch (Exception) {
errors++;
}
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.1</Version>
<Version>1.0.2</Version>
<AssemblyVersion>1.0.0.0</AssemblyVersion>
<FileVersion>1.0.0.0</FileVersion>
<NeutralLanguage>en</NeutralLanguage>
Expand Down
1 change: 0 additions & 1 deletion SoundBank.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ public byte[] Data {
}
}
public double Size { get => data.Length / 1024f; }
public string ConvertedFilePath { get; set; }
public string ReplacementFile {
get => replacementFile;
set {
Expand Down

0 comments on commit 5c74c6f

Please sign in to comment.