diff --git a/MystatDesktopWpf/Languages/lang.en-US.xaml b/MystatDesktopWpf/Languages/lang.en-US.xaml index d741515..c38dc0f 100644 --- a/MystatDesktopWpf/Languages/lang.en-US.xaml +++ b/MystatDesktopWpf/Languages/lang.en-US.xaml @@ -186,4 +186,8 @@ Clearing... Calculating... Failed to clear! + + + Windows settings + Run on Windows startup diff --git a/MystatDesktopWpf/Languages/lang.ru-RU.xaml b/MystatDesktopWpf/Languages/lang.ru-RU.xaml index a8b9b78..38fec0e 100644 --- a/MystatDesktopWpf/Languages/lang.ru-RU.xaml +++ b/MystatDesktopWpf/Languages/lang.ru-RU.xaml @@ -185,4 +185,8 @@ Очистка... Вычисление... Не получилось очистить кэш! + + + Настройки Windows + Запускать при старте Windows diff --git a/MystatDesktopWpf/Languages/lang.uk-UA.xaml b/MystatDesktopWpf/Languages/lang.uk-UA.xaml index d00b759..f303c2f 100644 --- a/MystatDesktopWpf/Languages/lang.uk-UA.xaml +++ b/MystatDesktopWpf/Languages/lang.uk-UA.xaml @@ -185,4 +185,8 @@ Очистка... Розрахунок... Не вдалося очистити! + + + Налаштування Windows + Запускати під час старту Windows diff --git a/MystatDesktopWpf/MystatDesktopWpf.csproj b/MystatDesktopWpf/MystatDesktopWpf.csproj index d4ad56f..9b736ad 100644 --- a/MystatDesktopWpf/MystatDesktopWpf.csproj +++ b/MystatDesktopWpf/MystatDesktopWpf.csproj @@ -27,6 +27,18 @@ + + + tlbimp + 0 + 1 + f935dc20-1cf0-11d0-adb9-00c04fd58a0b + 0 + false + true + + + diff --git a/MystatDesktopWpf/UserControls/Menus/Settings.xaml b/MystatDesktopWpf/UserControls/Menus/Settings.xaml index 1eddb3e..9291ea4 100644 --- a/MystatDesktopWpf/UserControls/Menus/Settings.xaml +++ b/MystatDesktopWpf/UserControls/Menus/Settings.xaml @@ -15,6 +15,7 @@ + diff --git a/MystatDesktopWpf/UserControls/SettingsSections/WindowsSettings.xaml b/MystatDesktopWpf/UserControls/SettingsSections/WindowsSettings.xaml new file mode 100644 index 0000000..7586ca3 --- /dev/null +++ b/MystatDesktopWpf/UserControls/SettingsSections/WindowsSettings.xaml @@ -0,0 +1,20 @@ + + + + + + + + + + + + diff --git a/MystatDesktopWpf/UserControls/SettingsSections/WindowsSettings.xaml.cs b/MystatDesktopWpf/UserControls/SettingsSections/WindowsSettings.xaml.cs new file mode 100644 index 0000000..5cab53e --- /dev/null +++ b/MystatDesktopWpf/UserControls/SettingsSections/WindowsSettings.xaml.cs @@ -0,0 +1,61 @@ +using IWshRuntimeLibrary; +using System; +using System.Diagnostics; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Controls.Primitives; + +namespace MystatDesktopWpf.UserControls.SettingsSections +{ + /// + /// Interaction logic for WindowsSettings.xaml + /// + public partial class WindowsSettings : UserControl + { + public WindowsSettings() + { + InitializeComponent(); + StartupToggle.IsChecked = System.IO.File.Exists(Environment.GetFolderPath(Environment.SpecialFolder.Startup) + @"\Mystat Desktop.lnk"); + StartupToggle.Checked += ToggleButton_Checked; + } + + // Create shortcut to startup folder + private void ToggleButton_Checked(object sender, RoutedEventArgs e) + { + if (sender is ToggleButton toggleButton) + { + try + { + string appPath = Process.GetCurrentProcess().MainModule.FileName; + string shortcutPath = Environment.GetFolderPath(Environment.SpecialFolder.Startup) + @"\Mystat Desktop.lnk"; + + WshShell shell = new WshShell(); + IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(shortcutPath); + + shortcut.TargetPath = appPath; + shortcut.WorkingDirectory = System.IO.Path.GetDirectoryName(appPath); + shortcut.Save(); + } + catch (Exception) + { + toggleButton.IsChecked = false; + } + } + } + + private void ToggleButton_Unchecked(object sender, RoutedEventArgs e) + { + if (sender is ToggleButton toggleButton) + { + try + { + System.IO.File.Delete(Environment.GetFolderPath(Environment.SpecialFolder.Startup) + @"\Mystat Desktop.lnk"); + } + catch (Exception) + { + toggleButton.IsChecked = true; + } + } + } + } +}