-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7cb6095
commit d11e838
Showing
7 changed files
with
106 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
MystatDesktopWpf/UserControls/SettingsSections/WindowsSettings.xaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<UserControl x:Class="MystatDesktopWpf.UserControls.SettingsSections.WindowsSettings" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:local="clr-namespace:MystatDesktopWpf.UserControls.SettingsSections" | ||
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes" | ||
mc:Ignorable="d" | ||
d:DesignHeight="450" d:DesignWidth="800"> | ||
<materialDesign:Card Padding="8"> | ||
<StackPanel Margin="8 0 0 0"> | ||
<TextBlock Text="{DynamicResource m_WindowsSettings}" HorizontalAlignment="Left" Style="{DynamicResource MaterialDesignBody1TextBlock}"/> | ||
<StackPanel Orientation="Horizontal" Margin="0 8"> | ||
<ToggleButton x:Name="StartupToggle" Unchecked="ToggleButton_Unchecked" /> | ||
<TextBlock Text="{DynamicResource m_RunOnWindowsStartup}" Margin="8 0 0 0"/> | ||
</StackPanel> | ||
</StackPanel> | ||
|
||
</materialDesign:Card> | ||
</UserControl> |
61 changes: 61 additions & 0 deletions
61
MystatDesktopWpf/UserControls/SettingsSections/WindowsSettings.xaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
{ | ||
/// <summary> | ||
/// Interaction logic for WindowsSettings.xaml | ||
/// </summary> | ||
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; | ||
} | ||
} | ||
} | ||
} | ||
} |