Skip to content

Commit

Permalink
修改设置后自动静默重启以应用设置和释放内存
Browse files Browse the repository at this point in the history
  • Loading branch information
kagurazakayashi committed Mar 3, 2021
1 parent ed983da commit e46ea95
Show file tree
Hide file tree
Showing 8 changed files with 120 additions and 60 deletions.
87 changes: 49 additions & 38 deletions MFAScreenLock/MFAScreenLockApp/Form1.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 30 additions & 12 deletions MFAScreenLock/MFAScreenLockApp/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,25 +31,22 @@ private void Form1_Load(object sender, EventArgs e)
}));
版本ToolStripMenuItem.Text = "版本:" + System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
string programname = System.Diagnostics.Process.GetCurrentProcess().ProcessName;
System.Diagnostics.Process[] myProcesses = System.Diagnostics.Process.GetProcessesByName(programname);//获取指定的进程名
Thread.Sleep(500);
if (myProcesses.Length > 1) //如果可以获取到知道的进程名则说明已经启动
System.Diagnostics.Process[] myProcesses = System.Diagnostics.Process.GetProcessesByName(programname);//获取指定的进程名
wallPaperBmp = ShareClass.gWallPaperBmp();
args = Environment.GetCommandLineArgs();
if (loadConfig() && myProcesses.Length > 1) //如果可以获取到知道的进程名则说明已经启动
{
MessageBox.Show("程序已经启动,请查看任务栏中的图标。\n在图标上点击右键可以打开菜单。\n如果不需要验证后驻留后台,请添加 -e 参数。","程序已在运行",MessageBoxButtons.OK,MessageBoxIcon.Error);
notifyIcon1.Visible = false;
Application.Exit();
}

wallPaperBmp = ShareClass.gWallPaperBmp();
args = Environment.GetCommandLineArgs();
loadConfig();
if (Settings.Default.Timeout >= 60)
{
timer_lock.Enabled = true;
}
}

private void loadConfig()
private bool loadConfig()
{
if (args.Length > 2 && args[1] == "-r" && args[2] == Settings.Default.RecoveryCode)
{
Expand Down Expand Up @@ -84,11 +81,17 @@ private void loadConfig()
}
formuser.ws = 0;
timer_lock.Enabled = true;
}
else if (args.Length > 1 && args[1] == "--restart")
{

}
else
{
locknow();
return true;
}
return false;
}

private void locknow()
Expand Down Expand Up @@ -166,17 +169,25 @@ private void openconfig(Int16 tabindex = 0)
lockallscreen(true, wallPaperBmp);
timer_lock.Enabled = false;
FormLock formlock = new FormLock();
formlock.lbl_info.Text = "正在修改绑定设置";
formlock.lbl_info.Text = "正在修改设置";
formlock.setBackgroundImage(wallPaperBmp);
formlock.ShowDialog();
lockallscreen(false, wallPaperBmp);
if (formlock.ws == 1)
{
timer_lock.Enabled = false;
FormUser formuser = new FormUser();
formuser.tabControl1.SelectedIndex = tabindex;
formuser.ShowDialog();
if (tabindex == 2)
{
formuser.displayPreview = true;
}
else
{
formuser.tabControl1.SelectedIndex = tabindex;
}
formuser.ws = 0;
formuser.ShowDialog();
Restart("--restart");
}
timer_lock.Enabled = true;
formlock.ws = 0;
Expand Down Expand Up @@ -207,10 +218,12 @@ private void 退出EToolStripMenuItem_Click(object sender, EventArgs e)
timer_lock.Enabled = true;
}

private void Restart()
private void Restart(string arguments = "")
{
notifyIcon1.Visible = false;
Process ps = new Process();
ps.StartInfo.FileName = Application.ExecutablePath.ToString();
ps.StartInfo.Arguments = arguments;
ps.Start();
Application.Exit();
}
Expand Down Expand Up @@ -243,5 +256,10 @@ private void 帮助和关于HToolStripMenuItem_Click(object sender, EventArgs e)
System.Diagnostics.Process.Start("https://github.com/kagurazakayashi/MFAScreenLock");
}
}

private void 个性化ToolStripMenuItem_Click(object sender, EventArgs e)
{
openconfig(2);
}
}
}
10 changes: 10 additions & 0 deletions MFAScreenLock/MFAScreenLockApp/FormLock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@ public FormLock()
//tableLayoutPanel2.BackColor = Color.FromArgb(0, tableLayoutPanel2.BackColor);
}

protected override CreateParams CreateParams
{
get
{
CreateParams paras = base.CreateParams;
paras.ExStyle |= 0x02000000;
return paras;
}
}

public void setBackgroundImage(Bitmap wallPaperBmp)
{
this.wallPaperBmp = wallPaperBmp;
Expand Down
11 changes: 9 additions & 2 deletions MFAScreenLock/MFAScreenLockApp/FormUser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public partial class FormUser : Form
private int selectFontItem = -1;
private bool loadOK = false;
public int ws = 0;
public bool displayPreview = false;

public FormUser()
{
Expand Down Expand Up @@ -91,10 +92,11 @@ private void btn_bind_Click(object sender, EventArgs e)
btn_bind.Enabled = true;
}

private void Restart()
private void Restart(string arguments = "")
{
Process ps = new Process();
ps.StartInfo.FileName = Application.ExecutablePath.ToString();
ps.StartInfo.Arguments = arguments;
ps.Start();
Application.Exit();
}
Expand Down Expand Up @@ -173,7 +175,7 @@ private void autoStart(bool isAuto)
}
catch (Exception)
{
MessageBox.Show("请将本程序退出,然后右键选择「以管理员方式运行」,再修改此设置。", "访问被拒绝",MessageBoxButtons.OK,MessageBoxIcon.Error);
MessageBox.Show("请将本程序退出,然后右键选择「以管理员方式运行」,再修改此设置。", "访问被拒绝", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}

Expand All @@ -184,6 +186,11 @@ private void checkBox1_CheckedChanged(object sender, EventArgs e)

private void timer1_Tick(object sender, EventArgs e)
{
if (displayPreview)
{
tabControl1.SelectedIndex = 2;
displayPreview = false;
}
double idles = SysLink.GetIdleTime();
lbl_timeout.Text = (idles / 1000.0).ToString();
if (idles <= prog_timeout.Maximum)
Expand Down
1 change: 1 addition & 0 deletions MFAScreenLock/MFAScreenLockApp/MFAScreenLockApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@
</ItemGroup>
<ItemGroup>
<Content Include="icon0.ico" />
<None Include="Resources\baseline_brush_black_24dp.png" />
<None Include="Resources\ic_settings_2x.png" />
</ItemGroup>
<ItemGroup>
Expand Down
10 changes: 10 additions & 0 deletions MFAScreenLock/MFAScreenLockApp/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 11 additions & 8 deletions MFAScreenLock/MFAScreenLockApp/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -124,21 +124,24 @@
<data name="ic_assignment_ind_2x" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\ic_assignment_ind_2x.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="ic_perm_identity_2x" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\ic_perm_identity_2x.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="ic_account_circle_black_48dp" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\ic_account_circle_black_48dp.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="icon0-128px" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\icon0-128px.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="ic_settings_2x" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\ic_settings_2x.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="ic_account_circle_white_48dp" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\ic_account_circle_white_48dp.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="ic_account_circle_white_2x" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\ic_account_circle_white_2x.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="icon0-128px" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\icon0-128px.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="ic_perm_identity_2x" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\ic_perm_identity_2x.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="ic_blur_on_2x" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\ic_blur_on_2x.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
Expand All @@ -148,7 +151,7 @@
<data name="ic_close_2x" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\ic_close_2x.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="ic_settings_2x" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\ic_settings_2x.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
<data name="baseline_brush_black_24dp" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\baseline_brush_black_24dp.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
</root>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit e46ea95

Please sign in to comment.