diff options
Diffstat (limited to 'win')
-rw-r--r-- | win/CS/HandBrake.ApplicationServices/Services/PresetService.cs | 50 | ||||
-rw-r--r-- | win/CS/HandBrakeWPF/ViewModels/ShellViewModel.cs | 13 | ||||
-rw-r--r-- | win/CS/HandBrakeWPF/Views/ShellView.xaml.cs | 11 |
3 files changed, 35 insertions, 39 deletions
diff --git a/win/CS/HandBrake.ApplicationServices/Services/PresetService.cs b/win/CS/HandBrake.ApplicationServices/Services/PresetService.cs index 9e31173ae..5edfb4e1e 100644 --- a/win/CS/HandBrake.ApplicationServices/Services/PresetService.cs +++ b/win/CS/HandBrake.ApplicationServices/Services/PresetService.cs @@ -19,8 +19,6 @@ namespace HandBrake.ApplicationServices.Services using System.Text.RegularExpressions;
using System.Xml.Serialization;
- using Caliburn.Micro;
-
using HandBrake.ApplicationServices.Exceptions;
using HandBrake.ApplicationServices.Model;
using HandBrake.ApplicationServices.Services.Interfaces;
@@ -32,13 +30,6 @@ namespace HandBrake.ApplicationServices.Services /// </summary>
public class PresetService : IPresetService
{
- /**
- * TODO:
- * - Wire this into the Forms and WPF UI's
- * - Note: This is untested so far. It'll likely need fixes before it can be used.
- * - Maybe change the collection to a dictionary to allow easier lookups?
- **/
-
#region Private Variables
/// <summary>
@@ -143,14 +134,10 @@ namespace HandBrake.ApplicationServices.Services // Update the presets file
this.UpdatePresetFiles();
return true;
- }
- else
- {
- this.Update(preset);
- return true;
}
-
- return false;
+
+ this.Update(preset);
+ return true;
}
/// <summary>
@@ -447,15 +434,16 @@ namespace HandBrake.ApplicationServices.Services {
if (File.Exists(this.builtInPresetFile))
{
- StreamReader reader = new StreamReader(this.builtInPresetFile);
- List<Preset> list = (List<Preset>)Ser.Deserialize(reader);
- foreach (Preset preset in list)
+ using (StreamReader reader = new StreamReader(this.builtInPresetFile))
{
- preset.IsBuildIn = true; // Older versions did not have this flag so explicitly make sure it is set.
- this.presets.Add(preset);
+ List<Preset> list = (List<Preset>)Ser.Deserialize(reader);
+ foreach (Preset preset in list)
+ {
+ preset.IsBuildIn = true;
+ // Older versions did not have this flag so explicitly make sure it is set.
+ this.presets.Add(preset);
+ }
}
-
- reader.Close();
}
}
catch (Exception exc)
@@ -470,14 +458,14 @@ namespace HandBrake.ApplicationServices.Services {
if (File.Exists(this.userPresetFile))
{
- StreamReader reader = new StreamReader(this.userPresetFile);
- List<Preset> list = (List<Preset>)Ser.Deserialize(reader);
- foreach (Preset preset in list)
+ using (StreamReader reader = new StreamReader(this.userPresetFile))
{
- this.presets.Add(preset);
+ List<Preset> list = (List<Preset>)Ser.Deserialize(reader);
+ foreach (Preset preset in list)
+ {
+ this.presets.Add(preset);
+ }
}
-
- reader.Close();
}
}
catch (Exception exc)
@@ -503,15 +491,11 @@ namespace HandBrake.ApplicationServices.Services using (FileStream strm = new FileStream(this.builtInPresetFile, FileMode.Create, FileAccess.Write))
{
Ser.Serialize(strm, this.presets.Where(p => p.IsBuildIn).ToList());
- strm.Close();
- strm.Dispose();
}
using (FileStream strm = new FileStream(this.userPresetFile, FileMode.Create, FileAccess.Write))
{
Ser.Serialize(strm, this.presets.Where(p => p.IsBuildIn == false).ToList());
- strm.Close();
- strm.Dispose();
}
}
catch (Exception exc)
diff --git a/win/CS/HandBrakeWPF/ViewModels/ShellViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/ShellViewModel.cs index 2633b5885..a64378a49 100644 --- a/win/CS/HandBrakeWPF/ViewModels/ShellViewModel.cs +++ b/win/CS/HandBrakeWPF/ViewModels/ShellViewModel.cs @@ -147,7 +147,7 @@ namespace HandBrakeWPF.ViewModels public bool CanClose()
{
IQueueProcessor processor = IoC.Get<IQueueProcessor>();
- if (processor.EncodeService.IsEncoding)
+ if (processor != null && processor.EncodeService.IsEncoding)
{
MessageBoxResult result =
errorService.ShowMessageBox(
@@ -160,13 +160,20 @@ namespace HandBrakeWPF.ViewModels {
processor.Pause();
processor.EncodeService.Stop();
- this.MainViewModel.Shutdown();
+ if (this.MainViewModel != null)
+ {
+ this.MainViewModel.Shutdown();
+ }
+
return true;
}
return false;
}
- this.MainViewModel.Shutdown();
+ if (this.MainViewModel != null)
+ {
+ this.MainViewModel.Shutdown();
+ }
return true;
}
}
diff --git a/win/CS/HandBrakeWPF/Views/ShellView.xaml.cs b/win/CS/HandBrakeWPF/Views/ShellView.xaml.cs index 77b0d858c..8a086ea09 100644 --- a/win/CS/HandBrakeWPF/Views/ShellView.xaml.cs +++ b/win/CS/HandBrakeWPF/Views/ShellView.xaml.cs @@ -60,10 +60,15 @@ namespace HandBrakeWPF.Views /// </param>
protected override void OnClosing(System.ComponentModel.CancelEventArgs e)
{
- bool canClose = ((IShellViewModel)this.DataContext).CanClose();
- if (!canClose)
+ IShellViewModel shellViewModel = this.DataContext as IShellViewModel;
+
+ if (shellViewModel != null)
{
- e.Cancel = true;
+ bool canClose = shellViewModel.CanClose();
+ if (!canClose)
+ {
+ e.Cancel = true;
+ }
}
base.OnClosing(e);
|