Post installation settings initialization

Fixed: Issue where it is impossible to delete a conversion preset define
in default settings.
Fixed: Issue where the windows context menu does not contains user
preset after an application upgrade.
This commit is contained in:
Tichau committed 2016-01-13 20:17:55 +01:00
1 parent efed37b4dc
commit e8a01c91f2
3 files changed
+107 -113

No files matched your search

+32 -21
View File
@@ -156,16 +156,6 @@ namespace FileConverter
{
Diagnostics.Debug.Log("The number of processors on this computer is {0}. Set the default number of conversion threads to {0}", Environment.ProcessorCount);
this.numberOfConversionThread = Environment.ProcessorCount;
// Load settigns.
Debug.Log("Load settings...");
this.Settings = Settings.Load();
if (this.Settings == null)
{
Diagnostics.Debug.LogError("The application will now shutdown. If you want to fix the problem yourself please edit or delete the file: C:\\Users\\UserName\\AppData\\Local\\FileConverter\\Settings.user.xml.");
Dispatcher.BeginInvoke((Action)(() => Application.Current.Shutdown()));
return;
}
// Retrieve arguments.
Debug.Log("Retrieve arguments...");
@@ -198,6 +188,7 @@ namespace FileConverter
}
#endif
// Log arguments.
for (int index = 0; index < args.Length; index++)
{
string argument = args[index];
@@ -215,10 +206,9 @@ namespace FileConverter
return;
}
ConversionPreset conversionPreset = null;
List<string> filePaths = new List<string>();
// Parse arguments.
List<string> filePaths = new List<string>();
string conversionPresetName = null;
for (int index = 1; index < args.Length; index++)
{
string argument = args[index];
@@ -229,6 +219,11 @@ namespace FileConverter
switch (parameterTitle)
{
case "post-install-init":
Settings.PostInstallationInitialization();
Dispatcher.BeginInvoke((Action)(() => Application.Current.Shutdown()));
return;
case "version":
Console.Write(ApplicationVersion.ToString());
Dispatcher.BeginInvoke((Action)(() => Application.Current.Shutdown()));
@@ -252,14 +247,7 @@ namespace FileConverter
return;
}
conversionPreset = this.Settings.GetPresetFromName(args[index + 1]);
if (conversionPreset == null)
{
Debug.LogError("Invalid conversion preset '{0}'. (code 0x02)", args[index + 1]);
Dispatcher.BeginInvoke((Action)(() => Application.Current.Shutdown()));
return;
}
conversionPresetName = args[index + 1];
index++;
continue;
@@ -281,6 +269,17 @@ namespace FileConverter
}
}
// Load settigns.
Debug.Log("Load settings...");
this.Settings = Settings.Load();
if (this.Settings == null)
{
Diagnostics.Debug.LogError("The application will now shutdown. If you want to fix the problem yourself please edit or delete the file: C:\\Users\\UserName\\AppData\\Local\\FileConverter\\Settings.user.xml.");
Dispatcher.BeginInvoke((Action)(() => Application.Current.Shutdown()));
return;
}
// Check upgrade.
if (this.Settings.CheckUpgradeAtStartup)
{
long fileTime = Registry.GetValue<long>(Registry.Keys.LastUpdateCheckDate);
@@ -293,6 +292,18 @@ namespace FileConverter
}
}
ConversionPreset conversionPreset = null;
if (!string.IsNullOrEmpty(conversionPresetName))
{
conversionPreset = this.Settings.GetPresetFromName(conversionPresetName);
if (conversionPreset == null)
{
Debug.LogError("Invalid conversion preset '{0}'. (code 0x02)", conversionPresetName);
Dispatcher.BeginInvoke((Action)(() => Application.Current.Shutdown()));
return;
}
}
if (conversionPreset != null)
{
// Create convertion jobs.
+59 -5
View File
@@ -93,7 +93,7 @@ namespace FileConverter
}
}
public static Settings Load()
public static void PostInstallationInitialization()
{
Settings defaultSettings = null;
@@ -115,6 +115,7 @@ namespace FileConverter
Diagnostics.Debug.LogError("Default settings not found at path {0}. You should try to reinstall the application.", defaultFilePath);
}
// Load user settings if exists.
Settings userSettings = null;
string userFilePath = Settings.GetUserSettingsFilePath();
if (File.Exists(userFilePath))
@@ -125,7 +126,37 @@ namespace FileConverter
}
catch (Exception)
{
MessageBoxResult messageBoxResult = MessageBox.Show("Can't load file converter user settings. Do you want to fall back to default settings ?", "Error", MessageBoxButton.YesNo, MessageBoxImage.Exclamation);
System.IO.File.Delete(userFilePath);
}
if (userSettings != null && userSettings.SerializationVersion != Version)
{
Diagnostics.Debug.Log("File converter settings has been imported from version {0} to version {1}.", userSettings.SerializationVersion, Version);
}
}
Settings settings = userSettings != null ? userSettings.Merge(defaultSettings) : defaultSettings;
settings.Save();
}
public static Settings Load()
{
Settings settings = null;
string userFilePath = Settings.GetUserSettingsFilePath();
if (File.Exists(userFilePath))
{
Settings userSettings = null;
try
{
XmlHelpers.LoadFromFile<Settings>("Settings", userFilePath, out userSettings);
settings = userSettings;
}
catch (Exception)
{
MessageBoxResult messageBoxResult =
MessageBox.Show(
"Can't load file converter user settings. Do you want to fall back to default settings ?",
"Error", MessageBoxButton.YesNo, MessageBoxImage.Exclamation);
if (messageBoxResult == MessageBoxResult.Yes)
{
System.IO.File.Delete(userFilePath);
@@ -139,11 +170,34 @@ namespace FileConverter
if (userSettings != null && userSettings.SerializationVersion != Version)
{
Diagnostics.Debug.Log("File converter settings has been imported from version {0} to version {1}.", userSettings.SerializationVersion, Version);
Diagnostics.Debug.Log("File converter settings has been imported from version {0} to version {1}.",
userSettings.SerializationVersion, Version);
}
}
else
{
// Load the default settings.
string defaultFilePath = Settings.GetDefaultSettingsFilePath();
if (File.Exists(defaultFilePath))
{
Settings defaultSettings = null;
try
{
XmlHelpers.LoadFromFile<Settings>("Settings", defaultFilePath, out defaultSettings);
settings = defaultSettings;
}
catch (Exception exception)
{
Diagnostics.Debug.LogError("Fail to load file converter default settings. {0}", exception.Message);
}
}
else
{
Diagnostics.Debug.LogError("Default settings not found at path {0}. You should try to reinstall the application.", defaultFilePath);
}
}
return userSettings != null ? userSettings.Merge(defaultSettings) : defaultSettings;
return settings;
}
public ConversionPreset GetPresetFromName(string presetName)
@@ -170,7 +224,7 @@ namespace FileConverter
// Write the settings in registry.
if (Settings.IsInAdmininstratorPrivileges)
{
// We are in admin mode, write reigstry ...
// We are in admin mode, write registry ...
bool succeed = Settings.ApplyRegistryModifications(registryEntries);
if (succeed)
{
+16 -87
View File
@@ -29,6 +29,11 @@
<Feature Id="ShellExtensionFeature" Title="ShellExtension" Level="1" AllowAdvertise="no">
<ComponentRef Id="FileConverterExtension.dll" />
</Feature>
<CustomAction Id='LaunchFile' FileKey='FileConverter.exe' ExeCommand='--post-install-init' Return='asyncNoWait' />
<InstallExecuteSequence>
<Custom Action="LaunchFile" After="InstallFinalize">NOT Installed</Custom>
</InstallExecuteSequence>
<UIRef Id="WixUI_InstallDir" />
<Property Id="WIXUI_INSTALLDIR" Value="INSTALLFOLDER" />
@@ -53,17 +58,23 @@
<Fragment>
<ComponentGroup Id="ProductComponents" Directory="INSTALLFOLDER">
<!-- Resources -->
<Component Guid="{AA5EA6F7-C443-488B-8E48-7CF000B9AD2A}" Win64="$(var.Win64)">
<File Id="FileConverter.exe" Source="$(var.FileConverter.TargetPath)" KeyPath="yes" />
</Component>
<Component Guid="{1790B82E-86BC-4B95-AA1D-9859FF3B6CA4}" Win64="$(var.Win64)">
<File Source="..\Middleware\ffmpeg.exe" KeyPath="yes" />
</Component>
<Component Guid="{9BF0AC45-A586-41C9-BA93-6048B46DA65F}" Win64="$(var.Win64)">
<File Id="SharpShell.dll" KeyPath="yes" Source="..\Middleware\SharpShell\SharpShell.dll" />
</Component>
<Component Guid="{E1B1C09C-B089-40D8-859B-0E55F640CAE1}" Win64="$(var.Win64)">
<File Id="Markdown.Xaml.dll" KeyPath="yes" Source="..\Middleware\Markdown.Xaml.dll" />
</Component>
<Component Guid="{AA5EA6F7-C443-488B-8E48-7CF000B9AD2A}" Win64="$(var.Win64)">
<File Source="$(var.FileConverter.TargetPath)" KeyPath="yes" />
<Component Guid="{55CD0B47-D5B0-4F0C-A54E-3E11DF345B48}" Win64="$(var.Win64)">
<File Id="Ripper.dll" KeyPath="yes" Source="..\Middleware\Ripper.dll" />
</Component>
<Component Guid="{1790B82E-86BC-4B95-AA1D-9859FF3B6CA4}" Win64="$(var.Win64)">
<File Source="..\Middleware\ffmpeg.exe" KeyPath="yes" />
<Component Guid="{3CE6CF1B-431C-41FD-8381-3F73EDAF7B8A}" Win64="$(var.Win64)">
<File Id="yeti.mmedia.dll" KeyPath="yes" Source="..\Middleware\yeti.mmedia.dll" />
</Component>
<Component Guid="{86AEF5B3-C25B-4662-BAEF-20969D1821A5}" Win64="$(var.Win64)">
<File Source="..\Application\FileConverter\Settings.default.xml" KeyPath="yes" />
@@ -77,95 +88,13 @@
<Component Guid="{6378238B-E44F-414B-A7AE-7E72CFA8616D}" Win64="$(var.Win64)">
<File Source="..\LICENSE.md" KeyPath="yes" />
</Component>
<Component Guid="{55CD0B47-D5B0-4F0C-A54E-3E11DF345B48}" Win64="$(var.Win64)">
<File Id="Ripper.dll" KeyPath="yes" Source="..\Middleware\Ripper.dll" />
</Component>
<Component Guid="{3CE6CF1B-431C-41FD-8381-3F73EDAF7B8A}" Win64="$(var.Win64)">
<File Id="yeti.mmedia.dll" KeyPath="yes" Source="..\Middleware\yeti.mmedia.dll" />
</Component>
<!-- Registry entries -->
<Component Id="RegistryEntries" Guid="{C3EF3D67-0206-4DBD-B2EA-78FF2E290093}">
<RegistryKey Root="HKCU" Key="Software\FileConverter">
<RegistryKey Root="HKCU" Key="Software\FileConverter" Action="createAndRemoveOnUninstall">
<RegistryValue Name="Path" Type="string" Value="[INSTALLFOLDER]FileConverter.exe"/>
<RegistryValue Name="CompatibleInputExtensions" Type="string" Value="3gp;aac;aiff;ape;avi;bik;bmp;cda;flac;flv;ico;jpg;jpeg;m4a;mkv;mov;mp3;mp4;ogg;png;tiff;wav;webm;wma;wmv"/>
</RegistryKey>
<RegistryKey Root="HKCU" Key="Software\FileConverter\3gp">
<RegistryValue Name="Presets" Type="string" Value="To Mkv;To Mkv (low quality);To Avi;To Ogg;To Flac;To Wav;To Mp3;To Aac"/>
</RegistryKey>
<RegistryKey Root="HKCU" Key="Software\FileConverter\aac">
<RegistryValue Name="Presets" Type="string" Value="To Ogg;To Wav;To Mp3"/>
</RegistryKey>
<RegistryKey Root="HKCU" Key="Software\FileConverter\aiff">
<RegistryValue Name="Presets" Type="string" Value="To Ogg;To Wav;To Mp3;To Aac"/>
</RegistryKey>
<RegistryKey Root="HKCU" Key="Software\FileConverter\ape">
<RegistryValue Name="Presets" Type="string" Value="To Ogg;To Flac;To Wav;To Mp3;To Aac"/>
</RegistryKey>
<RegistryKey Root="HKCU" Key="Software\FileConverter\avi">
<RegistryValue Name="Presets" Type="string" Value="To Mkv;To Mkv (low quality);To Avi;To Ogg;To Flac;To Wav;To Mp3;To Aac"/>
</RegistryKey>
<RegistryKey Root="HKCU" Key="Software\FileConverter\bik">
<RegistryValue Name="Presets" Type="string" Value="To Mkv;To Mkv (low quality);To Avi;To Ogg;To Flac;To Wav;To Mp3;To Aac"/>
</RegistryKey>
<RegistryKey Root="HKCU" Key="Software\FileConverter\bmp">
<RegistryValue Name="Presets" Type="string" Value="To Png;To Jpg;To Ico (max 256x256);To small Png"/>
</RegistryKey>
<RegistryKey Root="HKCU" Key="Software\FileConverter\cda">
<RegistryValue Name="Presets" Type="string" Value="Extract CDA to Flac;Extract CDA to Ogg;Extract CDA to Mp3"/>
</RegistryKey>
<RegistryKey Root="HKCU" Key="Software\FileConverter\flac">
<RegistryValue Name="Presets" Type="string" Value="To Ogg;To Wav;To Mp3;To Aac"/>
</RegistryKey>
<RegistryKey Root="HKCU" Key="Software\FileConverter\flv">
<RegistryValue Name="Presets" Type="string" Value="To Mkv;To Mkv (low quality);To Avi;To Ogg;To Flac;To Wav;To Mp3;To Aac"/>
</RegistryKey>
<RegistryKey Root="HKCU" Key="Software\FileConverter\ico">
<RegistryValue Name="Presets" Type="string" Value="To Png;To Jpg"/>
</RegistryKey>
<RegistryKey Root="HKCU" Key="Software\FileConverter\jpeg">
<RegistryValue Name="Presets" Type="string" Value="To Png;To Ico (max 256x256);To small Png"/>
</RegistryKey>
<RegistryKey Root="HKCU" Key="Software\FileConverter\jpg">
<RegistryValue Name="Presets" Type="string" Value="To Png;To Ico (max 256x256);To small Png"/>
</RegistryKey>
<RegistryKey Root="HKCU" Key="Software\FileConverter\m4a">
<RegistryValue Name="Presets" Type="string" Value="To Ogg;To Wav;To Mp3;To Aac"/>
</RegistryKey>
<RegistryKey Root="HKCU" Key="Software\FileConverter\mkv">
<RegistryValue Name="Presets" Type="string" Value="To Mkv;To Mkv (low quality);To Avi;To Ogg;To Flac;To Wav;To Mp3;To Aac"/>
</RegistryKey>
<RegistryKey Root="HKCU" Key="Software\FileConverter\mov">
<RegistryValue Name="Presets" Type="string" Value="To Mkv;To Mkv (low quality);To Avi;To Ogg;To Flac;To Wav;To Mp3;To Aac"/>
</RegistryKey>
<RegistryKey Root="HKCU" Key="Software\FileConverter\mp3">
<RegistryValue Name="Presets" Type="string" Value="To Ogg;To Wav;To Aac"/>
</RegistryKey>
<RegistryKey Root="HKCU" Key="Software\FileConverter\mp4">
<RegistryValue Name="Presets" Type="string" Value="To Mkv;To Mkv (low quality);To Avi;To Ogg;To Flac;To Wav;To Mp3;To Aac"/>
</RegistryKey>
<RegistryKey Root="HKCU" Key="Software\FileConverter\ogg">
<RegistryValue Name="Presets" Type="string" Value="To Wav;To Mp3;To Aac"/>
</RegistryKey>
<RegistryKey Root="HKCU" Key="Software\FileConverter\png">
<RegistryValue Name="Presets" Type="string" Value="To Jpg;To Ico (max 256x256);To small Png"/>
</RegistryKey>
<RegistryKey Root="HKCU" Key="Software\FileConverter\tiff">
<RegistryValue Name="Presets" Type="string" Value="To Png;To Jpg;To Ico (max 256x256);To small Png"/>
</RegistryKey>
<RegistryKey Root="HKCU" Key="Software\FileConverter\wav">
<RegistryValue Name="Presets" Type="string" Value="To Ogg;To Flac;To Mp3;To Aac"/>
</RegistryKey>
<RegistryKey Root="HKCU" Key="Software\FileConverter\webm">
<RegistryValue Name="Presets" Type="string" Value="To Mkv;To Mkv (low quality);To Avi;To Ogg;To Flac;To Wav;To Mp3;To Aac"/>
</RegistryKey>
<RegistryKey Root="HKCU" Key="Software\FileConverter\wma">
<RegistryValue Name="Presets" Type="string" Value="To Ogg;To Wav;To Mp3;To Aac"/>
</RegistryKey>
<RegistryKey Root="HKCU" Key="Software\FileConverter\wmv">
<RegistryValue Name="Presets" Type="string" Value="To Mkv;To Mkv (low quality);To Avi;To Ogg;To Flac;To Wav;To Mp3;To Aac"/>
</RegistryKey>
</Component>
</ComponentGroup>
</Fragment>