Commit 793f2e4f authored by GitLab CI's avatar GitLab CI

Merge remote-tracking branch 'upstream/master' into master-build

* upstream/master:
  WinGui: Add missing .ass extension to subtitle import
  WinGui: Clean-up the preset archive code.  New filename format for archive files is presets.json.version.archive to make it easier to identify what preset version it came from. i.e.  presets.json.36_0_0.archive
  WinGui: Improvements for #2090 - Support upgrading presets from 1.2.2 and later. Preset importer required some fixes to allow this to operate. - Changed Import Presets function to ignore built-in presets when the user tries to import the presets.json file. Cuts down on the volume of errors they'll get doing so.
parents 41264c86 176e1efa
Pipeline #60948059 passed with stages
in 64 minutes and 9 seconds
......@@ -25,8 +25,8 @@ namespace HandBrakeWPF.Model.Filters
public FilterPreset(HBPresetTune presetTune)
{
this.DisplayName = presetTune.Name;
this.Key = presetTune.ShortName;
this.DisplayName = presetTune?.Name;
this.Key = presetTune?.ShortName;
}
public string DisplayName { get; set; }
......
......@@ -25,8 +25,8 @@ namespace HandBrakeWPF.Model.Filters
public FilterTune(HBPresetTune presetTune)
{
this.DisplayName = presetTune.Name;
this.Key = presetTune.ShortName;
this.DisplayName = presetTune?.Name;
this.Key = presetTune?.ShortName;
}
public string DisplayName { get; set; }
......
......@@ -3737,6 +3737,17 @@ namespace HandBrakeWPF.Properties {
}
}
/// <summary>
/// Looks up a localized string similar to Your presets file contained built-in presets. The import function does not support importing these. Please use &apos;Presets Menu -&gt; Reset Built In-Presets&apos; to restore the standard presets.
///
///Where supported, any user presets will have been imported..
/// </summary>
public static string PresetService_ImportingBuiltInWarning {
get {
return ResourceManager.GetString("PresetService_ImportingBuiltInWarning", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Unable to load presets..
/// </summary>
......
......@@ -1991,4 +1991,9 @@ Non-Live Options: {date} {time} {creation-date} {creation-time} {quality} {bitra
<data name="Queue_RecoveryPossible" xml:space="preserve">
<value>Queue Recovery Possible</value>
</data>
<data name="PresetService_ImportingBuiltInWarning" xml:space="preserve">
<value>Your presets file contained built-in presets. The import function does not support importing these. Please use 'Presets Menu -&gt; Reset Built In-Presets' to restore the standard presets.
Where supported, any user presets will have been imported.</value>
</data>
</root>
\ No newline at end of file
......@@ -103,8 +103,24 @@ namespace HandBrakeWPF.Services.Presets.Factories
/* Filter Settings */
preset.Task.Grayscale = importedPreset.VideoGrayScale;
preset.Task.DeblockPreset = new FilterPreset(HandBrakeFilterHelpers.GetFilterPresets((int)hb_filter_ids.HB_FILTER_DEBLOCK).FirstOrDefault(s => s.ShortName == importedPreset.PictureDeblockPreset));
preset.Task.DeblockTune = new FilterTune(HandBrakeFilterHelpers.GetFilterTunes((int)hb_filter_ids.HB_FILTER_DEBLOCK).FirstOrDefault(s => s.ShortName == importedPreset.PictureDeblockTune));
if (!string.IsNullOrEmpty(importedPreset.PictureDeblockPreset))
{
preset.Task.DeblockPreset = new FilterPreset(HandBrakeFilterHelpers.GetFilterPresets((int)hb_filter_ids.HB_FILTER_DEBLOCK).FirstOrDefault(s => s.ShortName == importedPreset.PictureDeblockPreset));
}
else
{
preset.Task.DeblockPreset = new FilterPreset("Off", "off");
}
if (!string.IsNullOrEmpty(importedPreset.PictureDeblockTune))
{
preset.Task.DeblockTune = new FilterTune(HandBrakeFilterHelpers.GetFilterTunes((int)hb_filter_ids.HB_FILTER_DEBLOCK).FirstOrDefault(s => s.ShortName == importedPreset.PictureDeblockTune));
}
else
{
preset.Task.DeblockTune = new FilterTune("Off", "off");
}
preset.Task.CustomDeblock = importedPreset.PictureDeblockCustom;
if (importedPreset.PictureSharpenFilter != null)
......
......@@ -192,6 +192,7 @@ namespace HandBrakeWPF.Services.Presets
// HBPreset Handling
if (container.PresetList != null)
{
bool containsBuildInPreset = false;
foreach (var objectPreset in container.PresetList)
{
PresetCategory category = JsonConvert.DeserializeObject<PresetCategory>(objectPreset.ToString());
......@@ -200,10 +201,14 @@ namespace HandBrakeWPF.Services.Presets
foreach (HBPreset hbPreset in category.ChildrenArray)
{
Preset preset = this.ConvertHbPreset(hbPreset);
if (preset != null)
if (preset != null && !preset.IsBuildIn)
{
this.AddOrUpdateImportedPreset(preset);
}
else
{
containsBuildInPreset = true;
}
}
}
else
......@@ -212,13 +217,26 @@ namespace HandBrakeWPF.Services.Presets
if (hbPreset != null)
{
Preset preset = this.ConvertHbPreset(hbPreset);
if (preset != null)
if (preset != null && !preset.IsBuildIn)
{
this.AddOrUpdateImportedPreset(preset);
}
else
{
containsBuildInPreset = true;
}
}
}
}
if (containsBuildInPreset)
{
this.errorService.ShowMessageBox(
Properties.Resources.PresetService_ImportingBuiltInWarning,
Properties.Resources.Warning,
MessageBoxButton.OK,
MessageBoxImage.Warning);
}
}
}
}
......@@ -601,62 +619,47 @@ namespace HandBrakeWPF.Services.Presets
}
/// <summary>
/// Recover from a corrupted preset file
/// Add .old to the current filename, and delete the current file.
/// Archive the presets file without deleting it.
/// </summary>
/// <param name="file">
/// The broken presets file.
/// The filename to archive
/// </param>
/// <param name="delete">
/// True will delete the current presets file.
/// </param>
/// <returns>
/// The <see cref="string"/>.
/// The archived filename
/// </returns>
private string RecoverFromCorruptedPresetFile(string file)
private string ArchivePresetFile(string file, bool delete)
{
try
{
// Recover from Error.
string disabledFile = string.Format("{0}.{1}", file, GeneralUtilities.ProcessId);
PresetVersion version = HandBrakePresetService.GetCurrentPresetVersion();
string archiveFile = string.Format("{0}.{1}_{2}_{3}.archive", file, version.Major, version.Minor, version.Micro);
if (File.Exists(file))
{
File.Move(file, disabledFile);
if (File.Exists(file))
int counter = 0;
while (File.Exists(archiveFile))
{
File.Delete(file);
counter = counter + 1;
string appendedNumber = string.Format("({0})", counter);
archiveFile = string.Format("{0}.{1}_{2}_{3} {4}.archive", file, version.Major, version.Minor, version.Micro, appendedNumber);
}
}
return disabledFile;
}
catch (IOException e)
{
this.ServiceLogMessage(e.ToString());
// Give up
}
return "Sorry, the archiving failed.";
}
/// <summary>
/// Archive the presets file without deleting it.
/// </summary>
/// <param name="file">The filename to archive</param>
/// <returns>The archived filename</returns>
private string ArchivePresetFile(string file)
{
try
{
// Recover from Error.
string archiveFile = string.Format("{0}.{1}", file, GeneralUtilities.ProcessId);
if (File.Exists(file))
{
File.Copy(file, archiveFile);
if (delete)
{
File.Delete(file);
}
}
return archiveFile;
}
catch (IOException)
catch (IOException e)
{
// Give up
this.ServiceLogMessage(e.ToString());
}
return "Sorry, the archiving failed.";
......@@ -695,7 +698,7 @@ namespace HandBrakeWPF.Services.Presets
if (container?.PresetList == null)
{
this.ServiceLogMessage("Attempting Preset Recovery ...");
string filename = this.RecoverFromCorruptedPresetFile(this.presetFile);
string filename = this.ArchivePresetFile(this.presetFile, true);
this.errorService.ShowMessageBox(
Resources.PresetService_UnableToLoadPresets + filename,
Resources.PresetService_UnableToLoad,
......@@ -712,7 +715,7 @@ namespace HandBrakeWPF.Services.Presets
{
this.userSettingService.SetUserSetting(UserSettingConstants.ForcePresetReset, ForcePresetReset);
string fileName = this.ArchivePresetFile(this.presetFile);
string fileName = this.ArchivePresetFile(this.presetFile, true);
this.errorService.ShowMessageBox(
Resources.Presets_PresetForceReset
+ Environment.NewLine + Environment.NewLine + Resources.PresetService_ArchiveFile + fileName,
......@@ -728,7 +731,7 @@ namespace HandBrakeWPF.Services.Presets
catch (Exception ex)
{
this.ServiceLogMessage(ex.ToString());
this.RecoverFromCorruptedPresetFile(this.presetFile);
this.ArchivePresetFile(this.presetFile, true);
this.UpdateBuiltInPresets();
}
}
......
......@@ -254,7 +254,7 @@ namespace HandBrakeWPF.ViewModels
{
OpenFileDialog dialog = new OpenFileDialog
{
Filter = "Subtitle files (*.srt, *.ssa)|*.srt;*.ssa",
Filter = "Subtitle files (*.srt, *.ssa, *.ass)|*.srt;*.ssa;*.ass",
CheckFileExists = true,
Multiselect = true
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment