Skip to content

Commit

Permalink
Merge pull request #4 from Cp0204/master
Browse files Browse the repository at this point in the history
关键操作确认/同目录不允许多开
  • Loading branch information
codemonkey-m authored Jun 24, 2020
2 parents c70accd + e5f586e commit f33c7b9
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
6 changes: 4 additions & 2 deletions FrpClient-Win/AddItemDlg.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,10 @@ public void InitShow(string strSectionName = null)

private void DeleteItem_Click(object sender, System.EventArgs e)
{
DB.Instance().DelItem(cNewItemInfo.strSectionName);
Close();
if(MessageBox.Show("确定要删除吗?", "删除条目", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.OK) {
DB.Instance().DelItem(cNewItemInfo.strSectionName);
Close();
}
}

private void InputAddLoaclIP_DoubleClick(object sender, EventArgs e) {
Expand Down
27 changes: 24 additions & 3 deletions FrpClient-Win/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ private void OnMainFormLoad(object sender, EventArgs e)
{
System.IO.Directory.SetCurrentDirectory(System.Windows.Forms.Application.StartupPath);

// 检查同目录多开
if(IsDuplicateInstance()){
MessageBox.Show("本程序已经在运行!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
Application.Exit();
}

InitList(true);
UpdateStartButton();
//notifyIcon.Icon = this.Icon;
Expand All @@ -53,6 +59,17 @@ private void OnMainFormLoad(object sender, EventArgs e)
}
}

// 检查是否多开
private static bool IsDuplicateInstance() {
bool bCreatedNew;
// 允许不同目录实例
string name = System.Windows.Forms.Application.StartupPath;
name = name.Replace("\\", "/");
//创建Mutex互斥对象
System.Threading.Mutex newMutex = new System.Threading.Mutex(true, name, out bCreatedNew);
return !bCreatedNew;
}

private void InitList(bool bReadConfig = false)
{
if(bReadConfig)
Expand Down Expand Up @@ -111,7 +128,7 @@ private void RestartService_Click(object sender, EventArgs e)
private void MyProcOutputHandler(object sendingProcess,DataReceivedEventArgs outLine)
{
if(!String.IsNullOrEmpty(outLine.Data)) {
ProcOutput.Text += outLine.Data.ToString()+"\r\n";
ProcOutput.AppendText(outLine.Data.ToString() + "\r\n");
ProcOutput.SelectionStart = ProcOutput.Text.Length;
ProcOutput.ScrollToCaret();
}
Expand Down Expand Up @@ -173,11 +190,15 @@ private void NotifyIcon_MouseClick(object sender, MouseEventArgs e) {
this.Show();
this.Activate();
this.ShowInTaskbar = true;
ProcOutput.ScrollToCaret();
}
}

private void Exit_toolStripMenuItem_Click(object sender, EventArgs e) {
CloseFrp();
Application.Exit();
if(MessageBox.Show("确定要退出吗?", "退出程序", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.OK){
CloseFrp();
Application.Exit();
}
}

private void AutoRun_Click(object sender, EventArgs e)
Expand Down

0 comments on commit f33c7b9

Please sign in to comment.