Skip to content

Tomato #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 28, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
startup
  • Loading branch information
dimojang committed Mar 28, 2021
commit fadfb47bbea2e31b30a503ec5e8ef087cbd64a28
2 changes: 1 addition & 1 deletion Frogy.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<PropertyGroup>
<TargetZone>LocalIntranet</TargetZone>
<TargetZone>Internet</TargetZone>
</PropertyGroup>
<PropertyGroup>
<GenerateManifests>false</GenerateManifests>
Expand Down
46 changes: 45 additions & 1 deletion Methods/MyDeviceHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
Expand Down Expand Up @@ -110,7 +111,6 @@ private struct LARGE_INTEGER //此结构体在C++中使用的为union结构,
readonly long QuadPart;
}


/// <summary>
/// 读取设备状态
/// 0 代表锁定
Expand Down Expand Up @@ -138,5 +138,49 @@ public static int DeviceState
return dwFlags;
}
}

public static void RegisterStartup()
{
try
{
RegistryKey key = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true) ??
Registry.CurrentUser.CreateSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run");

Assembly curAssembly = Assembly.GetExecutingAssembly();
key.SetValue(curAssembly.GetName().Name, curAssembly.Location);
}
catch { }
}

public static void DeregisterStartup()
{
try
{
RegistryKey key = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true) ??
Registry.CurrentUser.CreateSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run");

Assembly curAssembly = Assembly.GetExecutingAssembly();
key.DeleteValue(curAssembly.GetName().Name);
}
catch { }
}

public static bool GetStartupStatus()
{
bool result = false;
try
{
RegistryKey key = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true) ??
Registry.CurrentUser.CreateSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run");

Assembly curAssembly = Assembly.GetExecutingAssembly();

string[] values = key.GetValueNames();
foreach(string s in values) if (s == curAssembly.GetName().Name) result = true;
}
catch { }

return result;
}
}
}
4 changes: 2 additions & 2 deletions Properties/app.manifest
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
Remove this element if your application requires this virtualization for backwards
compatibility.
-->
<requestedExecutionLevel level="highestAvailable" uiAccess="false" />
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
</requestedPrivileges>
<applicationRequestMinimum>
<defaultAssemblyRequest permissionSetReference="Custom" />
<PermissionSet class="System.Security.PermissionSet" version="1" ID="Custom" SameSite="site" Unrestricted="true" />
<PermissionSet class="System.Security.PermissionSet" version="1" ID="Custom" SameSite="site" />
</applicationRequestMinimum>
</security>
</trustInfo>
Expand Down
2 changes: 2 additions & 0 deletions Resources/Language/en-US.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,7 @@
<system:String x:Key="Option_ThemeTitle">Theme</system:String>
<system:String x:Key="Option_ThemeDefault">Default</system:String>
<system:String x:Key="Option_ThemeNight">Night</system:String>
<system:String x:Key="Option_SystemTitle">System</system:String>
<system:String x:Key="Option_Startup">Start with windows</system:String>

</ResourceDictionary>
2 changes: 2 additions & 0 deletions Resources/Language/zh-CN.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,7 @@
<system:String x:Key="Option_ThemeTitle">主题</system:String>
<system:String x:Key="Option_ThemeDefault">默认</system:String>
<system:String x:Key="Option_ThemeNight">夜晚</system:String>
<system:String x:Key="Option_SystemTitle">系统</system:String>
<system:String x:Key="Option_Startup">开机自启</system:String>

</ResourceDictionary>
17 changes: 17 additions & 0 deletions ViewModels/OptionViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,23 @@ public int ThemeListSelectedIndex
}
#endregion

#region
private bool startupStatus = MyDeviceHelper.GetStartupStatus();
public bool StartupStatus
{
get { return startupStatus; }
set
{
if (value)
MyDeviceHelper.RegisterStartup();
else
MyDeviceHelper.DeregisterStartup();

startupStatus = value;
}
}
#endregion

#region INotifyPropertyChanged
public event PropertyChangedEventHandler PropertyChanged = delegate { };
public void OnPropertyChanged([CallerMemberName] string propertyName = null)
Expand Down
12 changes: 12 additions & 0 deletions Views/OptionView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,18 @@
</ComboBox>
</StackPanel>

<Separator/>

<TextBlock Style="{StaticResource TextBlockSubTitleBold}"
Text="{DynamicResource Option_SystemTitle}"
Margin="10,10,10,0"
HorizontalAlignment="Left"/>
<StackPanel Margin="10"
HorizontalAlignment="Left">
<CheckBox Content="{DynamicResource Option_Startup}"
IsChecked="{Binding Path=StartupStatus}"/>
</StackPanel>

<Separator/>

<TextBlock Style="{StaticResource TextBlockSubTitleBold}"
Expand Down