IFiltersViewModel filtersViewModel, IAudioViewModel audioViewModel, ISubtitlesViewModel subtitlesViewModel,\r
IX264ViewModel advancedViewModel, IChaptersViewModel chaptersViewModel, IStaticPreviewViewModel staticPreviewViewModel,\r
IQueueViewModel queueViewModel, IMetaDataViewModel metaDataViewModel, INotifyIconService notifyIconService)\r
+ : base(userSettingService)\r
{\r
this.scanService = scanService;\r
this.presetService = presetService;\r
public void FileScan()\r
{\r
OpenFileDialog dialog = new OpenFileDialog { Filter = "All files (*.*)|*.*" };\r
+\r
+ string mruDir = this.GetMru(Constants.FileScanMru);\r
+ if (!string.IsNullOrEmpty(mruDir))\r
+ {\r
+ dialog.InitialDirectory = mruDir;\r
+ }\r
+\r
bool? dialogResult = dialog.ShowDialog();\r
\r
if (dialogResult.HasValue && dialogResult.Value)\r
{\r
+ this.SetMru(Constants.FileScanMru, Path.GetDirectoryName(dialog.FileName));\r
+\r
this.StartScan(dialog.FileName, this.TitleSpecificScan);\r
}\r
}\r
\r
// StartScan is not synchronous, so for now we don't support adding both srt and video file at the same time. \r
string[] subtitleFiles = fileNames.Where(f => Path.GetExtension(f)?.ToLower() == ".srt").ToArray();\r
- if (this.SelectedTab != 5 && subtitleFiles.Any())\r
+ if (subtitleFiles.Any())\r
{\r
this.SwitchTab(5);\r
this.SubtitleViewModel.Import(subtitleFiles);\r
? (extension == ".mp4" || extension == ".m4v" ? 1 : 2)\r
: (this.CurrentTask.OutputFormat == OutputFormat.Mkv ? 2 : 0);\r
\r
+ string mruDir = this.GetMru(Constants.FileSaveMru);\r
+ if (!string.IsNullOrEmpty(mruDir))\r
+ {\r
+ saveFileDialog.InitialDirectory = mruDir;\r
+ }\r
+\r
+ // If we have a current directory, override the MRU.\r
if (this.CurrentTask != null && !string.IsNullOrEmpty(this.CurrentTask.Destination))\r
{\r
if (Directory.Exists(Path.GetDirectoryName(this.CurrentTask.Destination)))\r
bool? result = saveFileDialog.ShowDialog();\r
if (result.HasValue && result.Value)\r
{\r
+ this.SetMru(Constants.FileSaveMru, Path.GetDirectoryName(saveFileDialog.FileName));\r
+\r
if (saveFileDialog.FileName == this.ScannedSource.ScanPath)\r
{\r
this.errorService.ShowMessageBox(Resources.Main_SourceDestinationMatchError, Resources.Error, MessageBoxButton.OK, MessageBoxImage.Error);\r
this.NotifyOfPropertyChange(() => this.ShowAdvancedTab);\r
}\r
}\r
-\r
#endregion\r
}\r
}
\ No newline at end of file
\r
namespace HandBrakeWPF.ViewModels\r
{\r
+ using System;\r
+ using System.IO;\r
+\r
using Caliburn.Micro;\r
\r
+ using HandBrakeWPF.Services.Interfaces;\r
using HandBrakeWPF.ViewModels.Interfaces;\r
\r
/// <summary>\r
/// </summary>\r
public class ViewModelBase : Screen, IViewModelBase\r
{\r
- #region Constants and Fields\r
+ private readonly IUserSettingService userSettingService;\r
\r
- /// <summary>\r
- /// Backing Field to prevent the Load method being called more than once.\r
- /// </summary>\r
private bool hasLoaded;\r
-\r
- /// <summary>\r
- /// The title.\r
- /// </summary>\r
private string title;\r
\r
- #endregion\r
-\r
- #region Constructors and Destructors\r
-\r
- /// <summary>\r
- /// Initializes a new instance of the <see cref="ViewModelBase"/> class.\r
- /// </summary>\r
public ViewModelBase()\r
{\r
}\r
\r
- #endregion\r
+ public ViewModelBase(IUserSettingService userSettingService)\r
+ {\r
+ this.userSettingService = userSettingService;\r
+ }\r
\r
#region Properties\r
\r
set\r
{\r
this.title = value;\r
- this.NotifyOfPropertyChange("Title");\r
+ this.NotifyOfPropertyChange();\r
}\r
}\r
\r
// Implement in the ViewModel to perform viewmodel specific code.\r
}\r
\r
+ public string GetMru(string key)\r
+ {\r
+ if (this.userSettingService == null)\r
+ {\r
+ throw new NotImplementedException("You must use the constructor with UserSettingService to use this function.");\r
+ }\r
+\r
+ string filePath = this.userSettingService.GetUserSetting<string>("mru" + key);\r
+ if (!string.IsNullOrEmpty(filePath) && Directory.Exists(filePath))\r
+ {\r
+ return filePath;\r
+ }\r
+\r
+ return null;\r
+ }\r
+\r
+ public void SetMru(string key, string value)\r
+ {\r
+ if (this.userSettingService == null)\r
+ {\r
+ throw new NotImplementedException("You must use the constructor with UserSettingService to use this function.");\r
+ }\r
+\r
+ if (string.IsNullOrEmpty(value) || !Directory.Exists(value))\r
+ {\r
+ this.userSettingService.SetUserSetting("mru" + key, string.Empty);\r
+ return;\r
+ }\r
+\r
+ this.userSettingService.SetUserSetting("mru" + key, value);\r
+ }\r
+\r
#endregion\r
}\r
}
\ No newline at end of file