Skip to content

Commit

Permalink
[tool] add Advance Form
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinZonda committed Nov 4, 2020
1 parent 0484da8 commit 25a5e82
Show file tree
Hide file tree
Showing 10 changed files with 1,403 additions and 8 deletions.
3 changes: 3 additions & 0 deletions .idea/.idea.NaiveSharp/.idea/contentModel.xml

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

2 changes: 2 additions & 0 deletions NaiveSharp/ConstText/Msg.cs
Expand Up @@ -5,5 +5,7 @@ public static class Msg
public const string RUNNING_UNDER_BGD = "Hi there! Naive# is still running under background!";

public const string TIP_TITLE = "Naive# Tip";

public const string ASK_CHANGES_NEED_APP_RESTART = "Reopening Naive# is required to apply changes.\nDo you want to reopen Naive# immediately?";
}
}
1 change: 1 addition & 0 deletions NaiveSharp/ConstText/Path/Config.cs
Expand Up @@ -3,6 +3,7 @@
public static partial class PATH
{
public const string CONFIG = @"config";
public const string CONFIG_DEBUG = @"config\debug";
public const string CONFIG_INI = @"config\config.ini";
public const string CONFIG_FORM = @"config\form.ns";
public const string CONFIG_NODE_NS = @"config\node.ns";
Expand Down
9 changes: 9 additions & 0 deletions NaiveSharp/NaiveSharp.csproj
Expand Up @@ -138,6 +138,12 @@
<Compile Include="View\About.Designer.cs">
<DependentUpon>About.cs</DependentUpon>
</Compile>
<Compile Include="View\AdvanceWindow.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="View\AdvanceWindow.Designer.cs">
<DependentUpon>AdvanceWindow.cs</DependentUpon>
</Compile>
<Compile Include="View\MainWindow.cs">
<SubType>Form</SubType>
</Compile>
Expand Down Expand Up @@ -166,6 +172,9 @@
<EmbeddedResource Include="View\About.resx">
<DependentUpon>About.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="View\AdvanceWindow.resx">
<DependentUpon>AdvanceWindow.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="View\MainWindow.resx">
<DependentUpon>MainWindow.cs</DependentUpon>
</EmbeddedResource>
Expand Down
5 changes: 3 additions & 2 deletions NaiveSharp/Program.cs
Expand Up @@ -2,6 +2,7 @@

using System;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Windows.Forms;
Expand All @@ -11,12 +12,12 @@ namespace NaiveSharp
static class Program
{
[STAThread]
static void Main()
static void Main(string[] args)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Process instance = RunningInstance();
if (instance == null)
if (instance == null || args.Contains("--no-check-running"))
{
Application.Run(new MainWindow());
}
Expand Down
132 changes: 132 additions & 0 deletions NaiveSharp/View/AdvanceWindow.Designer.cs

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

94 changes: 94 additions & 0 deletions NaiveSharp/View/AdvanceWindow.cs
@@ -0,0 +1,94 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Windows.Forms;

using NaiveSharp.ConstText;
using NaiveSharp.Controller;

namespace NaiveSharp.View
{
public partial class AdvanceWindow : Form
{
public AdvanceWindow()
{
InitializeComponent();
}

private static bool IsDebug()
=> File.Exists(PATH.CONFIG_DEBUG);

private static void SetDebugStatus(bool status)
{
if (status)
{
Create(PATH.CONFIG_DEBUG);
}
else
{
Delete(PATH.CONFIG_DEBUG);
}
}

private static void ResetFormSize()
=> Delete(PATH.CONFIG_FORM);

private static void Delete(string path)
{
if (File.Exists(path))
{
File.Delete(path);
}
}

private static void Create(string path)
{
if (!File.Exists(path))
{
File.Create(path).Close();
}

}

private void AdvanceWindow_Load(object sender, System.EventArgs e)
=> btnDebug.Text = IsDebug() ? "Turn Off" : "Turn On";

private void btnResetFormSize_Click(object sender, System.EventArgs e)
{
ResetFormSize();
RequestRestart();
}

private void btnDebug_Click(object sender, System.EventArgs e)
{
if (btnDebug.Text.EndsWith("On"))
{
SetDebugStatus(true);
btnDebug.Text = "Turn Off";
}
else
{
SetDebugStatus(false);
btnDebug.Text = "Turn On";
}
RequestRestart();
}

private static void RequestRestart()
{
if (MessageBox.Show(Msg.ASK_CHANGES_NEED_APP_RESTART, "Info", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk)
== DialogResult.Yes)
{
Operation.Stop();

Process.Start(new ProcessStartInfo
{
FileName = Application.ExecutablePath,
Arguments = "--no-check-running",
WindowStyle = ProcessWindowStyle.Normal
});
Environment.Exit(0);
}
}
}
}

0 comments on commit 25a5e82

Please sign in to comment.