diff options
author | sr55 <[email protected]> | 2012-10-13 19:48:12 +0000 |
---|---|---|
committer | sr55 <[email protected]> | 2012-10-13 19:48:12 +0000 |
commit | 029c9b1db2fbf86fc8ded15580cd8023e4b180fc (patch) | |
tree | 227743486b489e989f0b1c67234ebefa4316b10c /win/CS/HandBrakeWPF | |
parent | 2a18d05b52ea084b4bb968f3622872a8a08d83fa (diff) |
WinGui: Refactor multi-instance support to use Process ID. Fix old log file cleanup function.
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@5016 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'win/CS/HandBrakeWPF')
-rw-r--r-- | win/CS/HandBrakeWPF/Helpers/QueueRecoveryHelper.cs | 45 | ||||
-rw-r--r-- | win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs | 11 | ||||
-rw-r--r-- | win/CS/HandBrakeWPF/Views/OptionsView.xaml | 5 |
3 files changed, 48 insertions, 13 deletions
diff --git a/win/CS/HandBrakeWPF/Helpers/QueueRecoveryHelper.cs b/win/CS/HandBrakeWPF/Helpers/QueueRecoveryHelper.cs index f37fae656..b434fc0b9 100644 --- a/win/CS/HandBrakeWPF/Helpers/QueueRecoveryHelper.cs +++ b/win/CS/HandBrakeWPF/Helpers/QueueRecoveryHelper.cs @@ -11,8 +11,11 @@ namespace HandBrakeWPF.Helpers {
using System;
using System.Collections.Generic;
+ using System.Diagnostics;
+ using System.Globalization;
using System.IO;
using System.Linq;
+ using System.Text.RegularExpressions;
using System.Windows;
using System.Xml.Serialization;
@@ -68,12 +71,19 @@ namespace HandBrakeWPF.Helpers }
// Cleanup old/unused queue files for now.
- if (!GeneralUtilities.IsMultiInstance)
+ foreach (string file in removeFiles)
{
- foreach (string file in removeFiles)
+ Match m = Regex.Match(file, @"([0-9]+).xml");
+ if (m.Success)
{
- File.Delete(file);
+ int processId = int.Parse(m.Groups[1].ToString());
+ if (GeneralUtilities.IsPidACurrentHandBrakeInstance(processId))
+ {
+ continue;
+ }
}
+
+ File.Delete(file);
}
return queueFiles;
@@ -116,16 +126,41 @@ namespace HandBrakeWPF.Helpers foreach (string file in queueFiles)
{
encodeQueue.RestoreQueue(appDataPath + file); // Start Recovery
+ if (!file.Contains(GeneralUtilities.ProcessId.ToString(CultureInfo.InvariantCulture)))
+ {
+ try
+ {
+ // Once we load it in, remove it as we no longer need it.
+ File.Delete(file);
+ }
+ catch (Exception)
+ {
+ // Keep quite, nothing much we can do if there are problems.
+ // We will continue processing files.
+ }
+ }
}
}
else
{
- if (GeneralUtilities.IsMultiInstance) return; // Don't tamper with the files if we are multi instance
-
foreach (string file in queueFiles)
{
if (File.Exists(Path.Combine(appDataPath, file)))
+ {
+ // Check that the file doesn't belong to another running instance.
+ Match m = Regex.Match(file, @"[([0-9]+)].xml");
+ if (m.Success)
+ {
+ int processId = int.Parse(m.Groups[1].ToString());
+ if (GeneralUtilities.IsPidACurrentHandBrakeInstance(processId))
+ {
+ continue;
+ }
+ }
+
+ // Delete it if it doesn't
File.Delete(Path.Combine(appDataPath, file));
+ }
}
}
}
diff --git a/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs index 70f62c435..4b90e8feb 100644 --- a/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs +++ b/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs @@ -15,6 +15,7 @@ namespace HandBrakeWPF.ViewModels using System.Globalization;
using System.IO;
using System.Linq;
+ using System.Threading;
using System.Windows;
using System.Windows.Media.Imaging;
@@ -196,8 +197,6 @@ namespace HandBrakeWPF.ViewModels public MainViewModel(IUserSettingService userSettingService, IScanServiceWrapper scanService, IEncodeServiceWrapper encodeService, IPresetService presetService,
IErrorService errorService, IShellViewModel shellViewModel, IUpdateService updateService, IDriveDetectService driveDetectService, INotificationService notificationService)
{
- GeneralUtilities.SetInstanceId();
-
this.scanService = scanService;
this.encodeService = encodeService;
this.presetService = presetService;
@@ -207,7 +206,6 @@ namespace HandBrakeWPF.ViewModels this.driveDetectService = driveDetectService;
this.userSettingService = userSettingService;
this.queueProcessor = IoC.Get<IQueueProcessor>();
- this.queueProcessor.ResetInstanceId();
// Setup Properties
this.WindowTitle = "HandBrake";
@@ -825,6 +823,13 @@ namespace HandBrakeWPF.ViewModels this.SourceMenu = this.GenerateSourceMenu();
this.driveDetectService.StartDetection(this.DriveTrayChanged);
+
+ // Log Cleaning
+ if (userSettingService.GetUserSetting<bool>(UserSettingConstants.ClearOldLogs))
+ {
+ Thread clearLog = new Thread(() => GeneralUtilities.ClearLogFiles(30));
+ clearLog.Start();
+ }
}
/// <summary>
diff --git a/win/CS/HandBrakeWPF/Views/OptionsView.xaml b/win/CS/HandBrakeWPF/Views/OptionsView.xaml index 88f2fae61..3e883a7ff 100644 --- a/win/CS/HandBrakeWPF/Views/OptionsView.xaml +++ b/win/CS/HandBrakeWPF/Views/OptionsView.xaml @@ -24,11 +24,6 @@ <Style TargetType="ListBoxItem">
<Setter Property="Padding" Value="8,4" />
- <!--<Style.Triggers>
- <DataTrigger Binding="{Binding IsBuildIn}" Value="True">
- <Setter Property="Foreground" Value="DarkBlue" />
- </DataTrigger>
- </Style.Triggers>-->
</Style>
<Options:OptionsTabConverter x:Key="tabConverter" />
|