-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
141 lines (120 loc) · 5.16 KB
/
Program.cs
File metadata and controls
141 lines (120 loc) · 5.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
using System;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Text.RegularExpressions;
using System.Threading;
using System.Windows.Forms;
using NovelArm.Modules;
using NovelArm.Modules.Systems;
namespace NovelArm
{
static class Program
{
#region Properties
internal static readonly string APP_NAME = Application.ProductName;
internal static readonly string PATH = Application.StartupPath;
internal static readonly string EXE_PATH = Application.ExecutablePath;
internal static string VERSION = Application.ProductVersion;
internal static bool UPDATED = false;
internal static bool HIDE_WINDOW = false;
internal static readonly Process thisProcess = Process.GetCurrentProcess();
internal static readonly IntPtr minWorkingSet = thisProcess.MinWorkingSet;
internal static readonly IntPtr maxWorkingSet = thisProcess.MaxWorkingSet;
internal static readonly Size SCREEN = Screen.PrimaryScreen.Bounds.Size;
internal static ConfigForm configForm;
#endregion
internal static void EmptyMyWorkingSet()
{
NativeMethods.EmptyWorkingSet(thisProcess.Handle);
}
internal static void SetForegroundThis()
{
configForm.Invoke((MethodInvoker)delegate ()
{
NativeMethods.SetForegroundWindow(configForm.Handle);
});
}
/// <summary>
/// 특정 폼이 화면에 정해진 퍼센트만큼 보이는지의 여부를 반환합니다. 0%이면 폼이 화면에 아예 담겨있지 않은 경우입니다.
/// </summary>
/// <param name="formLoc"></param>
/// <param name="formSize"></param>
/// <param name="MinPercentOnScreen"></param>
/// <returns></returns>
internal static bool IsOnScreen(Point formLoc, Size formSize, double MinPercentOnScreen = 0.2)
{
double PixelsVisible = 0;
Rectangle Rec = new Rectangle(formLoc, formSize);
foreach (Screen Scrn in Screen.AllScreens)
{
Rectangle r = Rectangle.Intersect(Rec, Scrn.WorkingArea);
if (r.Width != 0 & r.Height != 0)
{
PixelsVisible += (r.Width * r.Height);
}
}
// double percent = PixelsVisible / (Rec.Width * Rec.Height);
return PixelsVisible >= (Rec.Width * Rec.Height) * MinPercentOnScreen;
}
/// <summary>
/// 해당 애플리케이션의 주 진입점입니다.
/// </summary>
[STAThread]
static void Main(string[] args)
{
// Arguments 처리
string action = null;
switch (args.Length)
{
// 창 숨기기
case 1:
action = args[0].ToLower();
if (action.EndsWith("hidewindow"))
{
HIDE_WINDOW = true;
}
break;
// 재시작 | 설정 초기화
case 2:
action = args[0].ToLower();
if (action.EndsWith("restart") || action.EndsWith("reset"))
{
int.TryParse(args[1], out int oldPid);
ProcessExt.WaitForClose(oldPid, maxWaitMilliseconds: 10000, terminate: false);
}
break;
// 업데이트
case 4:
action = args[0].ToLower();
string oldPidStr = args[1];
string oldFile = args[2];
string numberForFun = args[3];
if (action.EndsWith("update"))
{
int.TryParse(oldPidStr, out int oldPid);
ProcessExt.WaitForClose(oldPid, maxWaitMilliseconds: 10000, terminate: true);
UPDATED = true;
NativeMethods.SetForegroundWindow(Process.GetCurrentProcess().Handle);
MessageBox.Show($"{numberForFun}번 지구에서 성공적으로 {APP_NAME} {VERSION}을(를) 훔쳐왔어요!\n뒷일은 저에게 맡기시고 작가님께서 잘 활용하시길 바랄게요!", "상태창", 0, MessageBoxIcon.Information);
}
break;
default:
break;
}
// 프로그램 중복실행 방지
Mutex mutex = new Mutex(true, APP_NAME, out bool isNotDuplicated);
bool isDuplicated = !isNotDuplicated;
if (isDuplicated)
{
MessageBox.Show("프로그램이 이미 실행중입니다.\n\nWindows 작업 표시줄의 트레이 메뉴에서 확인해보세요.", APP_NAME, 0, MessageBoxIcon.Error);
return;
}
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
configForm = new ConfigForm();
Application.Run(configForm);
mutex.ReleaseMutex();
}
}
}