mirror of
https://github.com/ckaczor/FeedCenter.git
synced 2026-02-17 02:51:37 -05:00
Reorganize auto-start and default feed reader settings
This commit is contained in:
@@ -4,30 +4,19 @@ using Common.IO;
|
|||||||
using Common.Settings;
|
using Common.Settings;
|
||||||
using Common.Wpf.Extensions;
|
using Common.Wpf.Extensions;
|
||||||
using FeedCenter.Properties;
|
using FeedCenter.Properties;
|
||||||
using Microsoft.Win32;
|
|
||||||
using System;
|
using System;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.IO;
|
|
||||||
using System.Reflection;
|
|
||||||
|
|
||||||
namespace FeedCenter
|
namespace FeedCenter
|
||||||
{
|
{
|
||||||
public partial class App
|
public partial class App
|
||||||
{
|
{
|
||||||
#region Debug properties
|
|
||||||
|
|
||||||
private static bool _useDebugPath;
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Main function
|
#region Main function
|
||||||
|
|
||||||
[STAThread]
|
[STAThread]
|
||||||
public static void Main()
|
public static void Main()
|
||||||
{
|
{
|
||||||
_useDebugPath = Environment.CommandLine.IndexOf("/debugPath", StringComparison.InvariantCultureIgnoreCase) != -1;
|
|
||||||
|
|
||||||
// Create and initialize the app object
|
// Create and initialize the app object
|
||||||
var app = new App();
|
var app = new App();
|
||||||
app.InitializeComponent();
|
app.InitializeComponent();
|
||||||
@@ -46,10 +35,7 @@ namespace FeedCenter
|
|||||||
using (isolationHandle)
|
using (isolationHandle)
|
||||||
{
|
{
|
||||||
// Set the data directory based on debug or not
|
// Set the data directory based on debug or not
|
||||||
AppDomain.CurrentDomain.SetData("DataDirectory",
|
AppDomain.CurrentDomain.SetData("DataDirectory", SystemConfiguration.DataDirectory);
|
||||||
_useDebugPath
|
|
||||||
? Path.GetDirectoryName(Assembly.GetEntryAssembly().Location)
|
|
||||||
: UserSettingsPath);
|
|
||||||
|
|
||||||
// Get the generic provider
|
// Get the generic provider
|
||||||
var genericProvider = (GenericSettingsProvider) Settings.Default.Providers[typeof(GenericSettingsProvider).Name];
|
var genericProvider = (GenericSettingsProvider) Settings.Default.Providers[typeof(GenericSettingsProvider).Name];
|
||||||
@@ -67,7 +53,7 @@ namespace FeedCenter
|
|||||||
genericProvider.DeleteOldVersionsOnUpgrade = false;
|
genericProvider.DeleteOldVersionsOnUpgrade = false;
|
||||||
|
|
||||||
// Initialize the tracer with the current process ID
|
// Initialize the tracer with the current process ID
|
||||||
Tracer.Initialize(UserSettingsPath, FeedCenter.Properties.Resources.ApplicationName, Process.GetCurrentProcess().Id.ToString(CultureInfo.InvariantCulture), false);
|
Tracer.Initialize(SystemConfiguration.UserSettingsPath, FeedCenter.Properties.Resources.ApplicationName, Process.GetCurrentProcess().Id.ToString(CultureInfo.InvariantCulture), false);
|
||||||
|
|
||||||
Current.DispatcherUnhandledException += HandleCurrentDispatcherUnhandledException;
|
Current.DispatcherUnhandledException += HandleCurrentDispatcherUnhandledException;
|
||||||
AppDomain.CurrentDomain.UnhandledException += HandleCurrentDomainUnhandledException;
|
AppDomain.CurrentDomain.UnhandledException += HandleCurrentDomainUnhandledException;
|
||||||
@@ -87,9 +73,11 @@ namespace FeedCenter
|
|||||||
var splashWindow = new SplashWindow();
|
var splashWindow = new SplashWindow();
|
||||||
splashWindow.ShowDialog();
|
splashWindow.ShowDialog();
|
||||||
|
|
||||||
// Update the registry settings
|
// Set whether we should auto-start
|
||||||
SetStartWithWindows(Settings.Default.StartWithWindows);
|
Current.SetStartWithWindows(Settings.Default.StartWithWindows);
|
||||||
SetDefaultFeedReader(Settings.Default.RegisterAsDefaultFeedReader);
|
|
||||||
|
// Set whether we should be the default feed reader
|
||||||
|
SystemConfiguration.SetDefaultFeedReader(Settings.Default.RegisterAsDefaultFeedReader);
|
||||||
|
|
||||||
// Initialize the window
|
// Initialize the window
|
||||||
mainWindow.Initialize();
|
mainWindow.Initialize();
|
||||||
@@ -115,94 +103,5 @@ namespace FeedCenter
|
|||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Helpers
|
|
||||||
|
|
||||||
public static string UserSettingsPath
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
// If we're running in debug mode then use a local path for the database and logs
|
|
||||||
if (_useDebugPath)
|
|
||||||
return Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
|
|
||||||
|
|
||||||
// Get the path to the local application data directory
|
|
||||||
var path = Path.Combine(
|
|
||||||
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
|
|
||||||
FeedCenter.Properties.Resources.ApplicationName);
|
|
||||||
|
|
||||||
// Make sure it exists - create it if needed
|
|
||||||
if (!Directory.Exists(path))
|
|
||||||
Directory.CreateDirectory(path);
|
|
||||||
|
|
||||||
return path;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void SetStartWithWindows(bool value)
|
|
||||||
{
|
|
||||||
// Get the application name
|
|
||||||
var applicationName = FeedCenter.Properties.Resources.ApplicationDisplayName;
|
|
||||||
|
|
||||||
// Get application details
|
|
||||||
var publisherName = applicationName;
|
|
||||||
var productName = applicationName;
|
|
||||||
var allProgramsPath = Environment.GetFolderPath(Environment.SpecialFolder.Programs);
|
|
||||||
var shortcutPath = Path.Combine(allProgramsPath, publisherName);
|
|
||||||
|
|
||||||
// Build the auto start path
|
|
||||||
shortcutPath = "\"" + Path.Combine(shortcutPath, productName) + ".appref-ms\"";
|
|
||||||
|
|
||||||
// Set auto start
|
|
||||||
Current.SetStartWithWindows(applicationName, shortcutPath, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void SetDefaultFeedReader(bool value)
|
|
||||||
{
|
|
||||||
// Get the location of the assembly
|
|
||||||
var assemblyLocation = Assembly.GetEntryAssembly().Location;
|
|
||||||
|
|
||||||
// Open the registry key (creating if needed)
|
|
||||||
using (var registryKey = Registry.CurrentUser.CreateSubKey("Software\\Classes\\feed", RegistryKeyPermissionCheck.ReadWriteSubTree))
|
|
||||||
{
|
|
||||||
if (registryKey == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
// Write the handler settings
|
|
||||||
registryKey.SetValue(string.Empty, "URL:Feed Handler");
|
|
||||||
registryKey.SetValue("URL Protocol", string.Empty);
|
|
||||||
|
|
||||||
// Open the icon subkey (creating if needed)
|
|
||||||
using (var subKey = registryKey.CreateSubKey("DefaultIcon", RegistryKeyPermissionCheck.ReadWriteSubTree))
|
|
||||||
{
|
|
||||||
if (subKey != null)
|
|
||||||
{
|
|
||||||
// Write the assembly location
|
|
||||||
subKey.SetValue(string.Empty, assemblyLocation);
|
|
||||||
|
|
||||||
// Close the subkey
|
|
||||||
subKey.Close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Open the subkey for the command (creating if needed)
|
|
||||||
using (var subKey = registryKey.CreateSubKey("shell\\open\\command", RegistryKeyPermissionCheck.ReadWriteSubTree))
|
|
||||||
{
|
|
||||||
if (subKey != null)
|
|
||||||
{
|
|
||||||
// Write the assembly location and parameter
|
|
||||||
subKey.SetValue(string.Empty, string.Format("\"{0}\" %1", assemblyLocation));
|
|
||||||
|
|
||||||
// Close the subkey
|
|
||||||
subKey.Close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Close the registry key
|
|
||||||
registryKey.Close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -183,6 +183,7 @@
|
|||||||
<Reference Include="PresentationFramework" />
|
<Reference Include="PresentationFramework" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Compile Include="SystemConfiguration.cs" />
|
||||||
<Page Include="App.xaml">
|
<Page Include="App.xaml">
|
||||||
<Generator>MSBuild:Compile</Generator>
|
<Generator>MSBuild:Compile</Generator>
|
||||||
<SubType>Designer</SubType>
|
<SubType>Designer</SubType>
|
||||||
|
|||||||
@@ -1,4 +1,7 @@
|
|||||||
namespace FeedCenter.Options
|
using System.Windows;
|
||||||
|
using Common.Wpf.Extensions;
|
||||||
|
|
||||||
|
namespace FeedCenter.Options
|
||||||
{
|
{
|
||||||
public partial class GeneralOptionsPanel
|
public partial class GeneralOptionsPanel
|
||||||
{
|
{
|
||||||
@@ -32,8 +35,8 @@
|
|||||||
if (registerAsDefaultFeedReaderCheckBox.IsChecked.HasValue && settings.RegisterAsDefaultFeedReader != registerAsDefaultFeedReaderCheckBox.IsChecked.Value)
|
if (registerAsDefaultFeedReaderCheckBox.IsChecked.HasValue && settings.RegisterAsDefaultFeedReader != registerAsDefaultFeedReaderCheckBox.IsChecked.Value)
|
||||||
settings.RegisterAsDefaultFeedReader = registerAsDefaultFeedReaderCheckBox.IsChecked.Value;
|
settings.RegisterAsDefaultFeedReader = registerAsDefaultFeedReaderCheckBox.IsChecked.Value;
|
||||||
|
|
||||||
App.SetStartWithWindows(settings.StartWithWindows);
|
Application.Current.SetStartWithWindows(settings.StartWithWindows);
|
||||||
App.SetDefaultFeedReader(settings.RegisterAsDefaultFeedReader);
|
SystemConfiguration.SetDefaultFeedReader(settings.RegisterAsDefaultFeedReader);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string CategoryName
|
public override string CategoryName
|
||||||
|
|||||||
95
Application/SystemConfiguration.cs
Normal file
95
Application/SystemConfiguration.cs
Normal file
@@ -0,0 +1,95 @@
|
|||||||
|
using Common.Wpf.Extensions;
|
||||||
|
using Microsoft.Win32;
|
||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
using System.Reflection;
|
||||||
|
using System.Windows;
|
||||||
|
|
||||||
|
namespace FeedCenter
|
||||||
|
{
|
||||||
|
public static class SystemConfiguration
|
||||||
|
{
|
||||||
|
public static void SetDefaultFeedReader(bool value)
|
||||||
|
{
|
||||||
|
// Get the location of the assembly
|
||||||
|
var assemblyLocation = Assembly.GetEntryAssembly().Location;
|
||||||
|
|
||||||
|
// Open the registry key (creating if needed)
|
||||||
|
using (var registryKey = Registry.CurrentUser.CreateSubKey("Software\\Classes\\feed", RegistryKeyPermissionCheck.ReadWriteSubTree))
|
||||||
|
{
|
||||||
|
if (registryKey == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
// Write the handler settings
|
||||||
|
registryKey.SetValue(string.Empty, "URL:Feed Handler");
|
||||||
|
registryKey.SetValue("URL Protocol", string.Empty);
|
||||||
|
|
||||||
|
// Open the icon subkey (creating if needed)
|
||||||
|
using (var subKey = registryKey.CreateSubKey("DefaultIcon", RegistryKeyPermissionCheck.ReadWriteSubTree))
|
||||||
|
{
|
||||||
|
if (subKey != null)
|
||||||
|
{
|
||||||
|
// Write the assembly location
|
||||||
|
subKey.SetValue(string.Empty, assemblyLocation);
|
||||||
|
|
||||||
|
// Close the subkey
|
||||||
|
subKey.Close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Open the subkey for the command (creating if needed)
|
||||||
|
using (var subKey = registryKey.CreateSubKey("shell\\open\\command", RegistryKeyPermissionCheck.ReadWriteSubTree))
|
||||||
|
{
|
||||||
|
if (subKey != null)
|
||||||
|
{
|
||||||
|
// Write the assembly location and parameter
|
||||||
|
subKey.SetValue(string.Empty, string.Format("\"{0}\" %1", assemblyLocation));
|
||||||
|
|
||||||
|
// Close the subkey
|
||||||
|
subKey.Close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Close the registry key
|
||||||
|
registryKey.Close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool UseDebugPath
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return Environment.CommandLine.IndexOf("/debugPath", StringComparison.InvariantCultureIgnoreCase) != -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static string DataDirectory
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return UseDebugPath ? Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) : UserSettingsPath;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static string UserSettingsPath
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
// If we're running in debug mode then use a local path for the database and logs
|
||||||
|
if (UseDebugPath)
|
||||||
|
return Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
|
||||||
|
|
||||||
|
// Get the path to the local application data directory
|
||||||
|
var path = Path.Combine(
|
||||||
|
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
|
||||||
|
Properties.Resources.ApplicationName);
|
||||||
|
|
||||||
|
// Make sure it exists - create it if needed
|
||||||
|
if (!Directory.Exists(path))
|
||||||
|
Directory.CreateDirectory(path);
|
||||||
|
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user