Skip to content

Commit cede98f

Browse files
committed
Cleaning mess
1 parent e3b775c commit cede98f

File tree

19 files changed

+885
-0
lines changed

19 files changed

+885
-0
lines changed

Abort_src/Abort.cmd

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
::[Bat To Exe Converter]
2+
::
3+
::YAwzoRdxOk+EWAjk
4+
::fBw5plQjdCmDJH2L91c9LRVAXzihdyCGIoYU/fz/4P2JnhxNBLIDSKPn/oeGNfQX5VLqO58u2Ro=
5+
::YAwzuBVtJxjWCl3EqQJgSA==
6+
::ZR4luwNxJguZRRnk
7+
::Yhs/ulQjdF+5
8+
::cxAkpRVqdFKZSTk=
9+
::cBs/ulQjdF+5
10+
::ZR41oxFsdFKZSDk=
11+
::eBoioBt6dFKZSDk=
12+
::cRo6pxp7LAbNWATEpCI=
13+
::egkzugNsPRvcWATEpCI=
14+
::dAsiuh18IRvcCxnZtBJQ
15+
::cRYluBh/LU+EWAnk
16+
::YxY4rhs+aU+IeA==
17+
::cxY6rQJ7JhzQF1fEqQJhZksaHErQXA==
18+
::ZQ05rAF9IBncCkqN+0xwdVsFAlTMbCXqZg==
19+
::ZQ05rAF9IAHYFVzEqQIUGxNBWACNK2Xa
20+
::eg0/rx1wNQPfEVWB+kM9LVsJDCWAM3muSLAE7Yg=
21+
::fBEirQZwNQPfEVWB+kM9LVsJDGQ=
22+
::cRolqwZ3JBvQF1fEqQJQ
23+
::dhA7uBVwLU+EWDk=
24+
::YQ03rBFzNR3SWATElA==
25+
::dhAmsQZ3MwfNWATElA==
26+
::ZQ0/vhVqMQ3MEVWAtB9wSA==
27+
::Zg8zqx1/OA3MEVWAtB9wSA==
28+
::dhA7pRFwIByZRRnk
29+
::Zh4grVQjdCmDJH2L91c9LRVAXzihdyCGIoYU/fz/4P2JnhxNBLIDSKPn+7aBMvRd713hFQ==
30+
::YB416Ek+ZG8=
31+
::
32+
::
33+
::978f952a14a936cc963da21a135fa983
34+
@echo off
35+
tskill DShutdown
36+
shutdown -a
37+
erase /F /Q %TMP%\DSTime.DShutdown
38+
erase /F /Q %TEMP%\DSTime.DShutdown

DShutdown_src/lang.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
char* SET = "SET";
2+
char* CLOSE = "CLOSE";
3+
char* ABORT_SCHEDULED_SHUTDOWN = "ABORT SCHEDULED SHUTDOWN";
4+
char* SHOW_WARNINGS = "Show warnings about shutdown";
5+
char* MAIN_TEXT = "Enter time, after which the computer should turn off (in minutes):";
6+
char* TO_SHUTDOWN = "To shutdown:";
7+
char* HOURS = "hours";
8+
char* AND = "and";
9+
char* MINUTES = "minutes";
10+
char* SHUTDOWN_SCHEDULED = "Shutdown scheduled.";
11+
char* TO_SHUTDOWN30 = "To shutdown: 30 minut.";
12+
char* TO_SHUTDOWN5 = "To shutdown: 5 minut.";
13+
char* INSERT_CORRECT = "Enter correct value.";
14+
char* INCORRECT_VALUE = "Incorrect value.";

DShutdown_src/main.cpp

Lines changed: 275 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,275 @@
1+
#include <windowsx.h>
2+
#include <windows.h>
3+
#include <winuser.h>
4+
#include <ctime>
5+
#include "main.h"
6+
#include "lang.h"
7+
8+
LPSTR ClassName = "Window Class";
9+
MSG Message;
10+
11+
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
12+
13+
#define ID_EKRAN 500
14+
HWND hEkran;
15+
#define ID_OK 501
16+
#define ID_CLOSE 502
17+
#define ID_CHECKBOX 503
18+
#define ID_ABORT 504
19+
20+
int mtime;
21+
int mtimetoshutdown;
22+
int hcount;
23+
int mcount;
24+
bool CheckboxState;
25+
bool AbortMode;
26+
char TempPath[MAX_PATH] = { 0 };
27+
char DSTimePath[512];
28+
char Text2[100];
29+
time_t currenttime;
30+
31+
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
32+
{
33+
34+
// FILLING STRUCTURE
35+
WNDCLASSEX wc;
36+
37+
wc.cbSize = sizeof(WNDCLASSEX);
38+
wc.style = 0;
39+
wc.lpfnWndProc = WndProc;
40+
wc.cbClsExtra = 0;
41+
wc.cbWndExtra = 0;
42+
wc.hInstance = hInstance;
43+
wc.hIcon = (HICON)LoadImage(
44+
hInstance, MAKEINTRESOURCE(2000), IMAGE_ICON, 48, 48, LR_LOADTRANSPARENT);
45+
wc.hIconSm = (HICON)LoadImage(
46+
hInstance, MAKEINTRESOURCE(2000), IMAGE_ICON, 48, 48, LR_LOADTRANSPARENT);
47+
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
48+
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW);
49+
wc.lpszMenuName = NULL;
50+
wc.lpszClassName = ClassName;
51+
52+
// REGISTERING WINDOW CLASS
53+
if (!RegisterClassEx(&wc)) {
54+
MessageBox(
55+
NULL, "Couldn't register window!", "Error!", MB_ICONERROR | MB_TASKMODAL | MB_OK);
56+
PostQuitMessage(0);
57+
return 1;
58+
}
59+
60+
// CREATING WINDOW
61+
HWND hwnd;
62+
63+
hwnd = CreateWindowEx(WS_EX_CLIENTEDGE, ClassName, "DShutdown 1.0.0", WS_OVERLAPPEDWINDOW,
64+
CW_USEDEFAULT, CW_USEDEFAULT, 330, 265, NULL, NULL, hInstance, NULL);
65+
66+
if (hwnd == NULL) {
67+
MessageBox(NULL, "Couldn't create window!", "Error!", MB_ICONERROR | MB_TASKMODAL | MB_OK);
68+
PostQuitMessage(0);
69+
return 1;
70+
}
71+
72+
// CHECKING IF SHUTDOWN ARLEADY SCHEDULED
73+
GetTempPathA(MAX_PATH, TempPath);
74+
std::snprintf(DSTimePath, sizeof(DSTimePath), "%s\DSTime.DShutdown", TempPath);
75+
int stimefromfile = atoi(ReadFromFile(DSTimePath));
76+
if (stimefromfile != NULL) {
77+
AbortMode = true;
78+
}
79+
80+
//****************************************************************************************//
81+
// CONTROLS //
82+
//****************************************************************************************//
83+
84+
// BUTTONS
85+
HWND
86+
hButton1 = CreateWindowEx(WS_EX_CLIENTEDGE, "BUTTON", SET, WS_CHILD | WS_VISIBLE | WS_BORDER,
87+
220, 100, 80, 40, hwnd, (HMENU)ID_OK, hInstance, NULL),
88+
hButton2 = CreateWindowEx(WS_EX_CLIENTEDGE, "BUTTON", CLOSE, WS_CHILD | WS_VISIBLE | WS_BORDER,
89+
10, 100, 80, 40, hwnd, (HMENU)ID_CLOSE, hInstance, NULL),
90+
hButton3 = CreateWindowEx(WS_EX_CLIENTEDGE, "BUTTON", ABORT_SCHEDULED_SHUTDOWN, WS_CHILD | WS_VISIBLE | WS_BORDER,
91+
10, 165, 290, 40, hwnd, (HMENU)ID_ABORT, hInstance, NULL),
92+
hCheckbox1 = CreateWindowEx(0, "BUTTON", SHOW_WARNINGS, WS_CHILD | WS_VISIBLE | BS_CHECKBOX,
93+
22, 143, 270, 20, hwnd, (HMENU)ID_CHECKBOX, hInstance, NULL),
94+
// INPUT
95+
hTime = CreateWindowEx(WS_EX_CLIENTEDGE, "EDIT", NULL, WS_CHILD | WS_VISIBLE | WS_BORDER | ES_NUMBER,
96+
100, 100, 110, 40, hwnd, NULL, hInstance, NULL),
97+
// TEXTS
98+
hText1 = CreateWindowEx(0, "STATIC", NULL, WS_CHILD | WS_VISIBLE | SS_CENTER,
99+
10, 10, 290, 20, hwnd, NULL, hInstance, NULL),
100+
hText2 = CreateWindowEx(0, "STATIC", NULL, WS_CHILD | WS_VISIBLE | SS_CENTER,
101+
10, 40, 290, 50, hwnd, NULL, hInstance, NULL);
102+
SetWindowText(hText1, "DShutdown 1.0.0");
103+
SetWindowText(hText2, MAIN_TEXT);
104+
105+
// SIGN
106+
HWND hSign = CreateWindowEx(0, "STATIC", NULL, WS_CHILD | WS_VISIBLE | SS_CENTER,
107+
225, 208, 85, 12, hwnd, NULL, hInstance, NULL);
108+
SetWindowText(hSign, "Made by Distaff");
109+
110+
// FONTS
111+
HFONT fSign;
112+
fSign = CreateFont(12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, PROOF_QUALITY, 0, "Arial");
113+
HFONT fTime;
114+
fTime = CreateFont(30, 0, 0, 0, 600, 0, 0, 0, 0, 0, 0, 0, 0, "Consolas");
115+
HFONT fText1;
116+
fText1 = CreateFont(18, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, PROOF_QUALITY, 0, "Lucida Console");
117+
SendMessage(hSign, WM_SETFONT, WPARAM(fSign), TRUE);
118+
SendMessage(hTime, WM_SETFONT, WPARAM(fTime), TRUE);
119+
SendMessage(hText1, WM_SETFONT, WPARAM(fText1), TRUE);
120+
121+
if (AbortMode == true) {
122+
Button_Enable(hButton1, false);
123+
Button_Enable(hButton2, false);
124+
Button_Enable(hButton3, true);
125+
Button_Enable(hCheckbox1, false);
126+
Button_Enable(hTime, false);
127+
currenttime = time(NULL);
128+
mtimetoshutdown = (stimefromfile - currenttime) / 60 + 1;
129+
hcount = mtimetoshutdown / 60;
130+
mcount = mtimetoshutdown - hcount * 60;
131+
std::snprintf(Text2, sizeof(Text2), "%s %d %s %s %d %s.", TO_SHUTDOWN, hcount, HOURS, AND, mcount, MINUTES);
132+
SetWindowText(hText2, Text2);
133+
}
134+
135+
else {
136+
Button_Enable(hButton1, true);
137+
Button_Enable(hButton2, true);
138+
Button_Enable(hButton3, false);
139+
Button_Enable(hCheckbox1, true);
140+
Button_Enable(hTime, true);
141+
}
142+
143+
//***********************************************************************************************//
144+
// END OF CONTROLS //
145+
//***********************************************************************************************//
146+
147+
ShowWindow(hwnd, nCmdShow);
148+
UpdateWindow(hwnd);
149+
150+
// MSG LOOP
151+
while (GetMessage(&Message, NULL, 0, 0)) {
152+
// COUNTDOWN
153+
if (AbortMode == true) {
154+
currenttime = time(NULL);
155+
mtimetoshutdown = (stimefromfile - currenttime) / 60 + 1;
156+
hcount = mtimetoshutdown / 60;
157+
int lstmcount = mcount;
158+
mcount = mtimetoshutdown - hcount * 60;
159+
std::snprintf(Text2, sizeof(Text2), "%s %d %s %s %d %s.", TO_SHUTDOWN, hcount, HOURS, AND, mcount, MINUTES);
160+
if (lstmcount != mcount) {
161+
SetWindowText(hText2, Text2);
162+
}
163+
}
164+
else {
165+
DWORD dlugosc = GetWindowTextLength(hTime);
166+
LPSTR Bufor = (LPSTR)GlobalAlloc(GPTR, dlugosc + 1);
167+
GetWindowText(hTime, Bufor, dlugosc + 1);
168+
mtime = atoi(Bufor);
169+
}
170+
171+
TranslateMessage(&Message);
172+
DispatchMessage(&Message);
173+
}
174+
return Message.wParam;
175+
}
176+
177+
//**********************************************************************************************//
178+
// EVENT HANDLING //
179+
//**********************************************************************************************//
180+
181+
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
182+
{
183+
switch (msg) {
184+
case WM_COMMAND:
185+
switch (wParam) {
186+
187+
case ID_OK: {
188+
char filetime[100];
189+
int filestime = time(NULL);
190+
filestime = filestime + mtime * 60;
191+
std::snprintf(filetime, sizeof(filetime), "%d", filestime);
192+
WriteToFile(DSTimePath, filetime);
193+
if (mtime > 0) {
194+
// IF "SHOW WARNINGS" TICKED
195+
if (CheckboxState == true) {
196+
char buff[128];
197+
hcount = mtime / 60;
198+
mcount = mtime - hcount * 60;
199+
std::snprintf(buff, sizeof(buff), "%s %d %s %s %d %s.", TO_SHUTDOWN, hcount, HOURS, AND, mcount, MINUTES);
200+
ShowWindow(hwnd, SW_HIDE);
201+
MessageBox(NULL, buff, SHUTDOWN_SCHEDULED, MB_OKCANCEL | MB_ICONWARNING | MB_DEFBUTTON1 | MB_TASKMODAL);
202+
if (mtime > 5) {
203+
if (mtime > 30) {
204+
Sleep((mtime - 30) * 60000);
205+
MessageBox(NULL, TO_SHUTDOWN30, SHUTDOWN_SCHEDULED, MB_OKCANCEL | MB_ICONWARNING | MB_DEFBUTTON1);
206+
Sleep(1500000);
207+
MessageBox(NULL, TO_SHUTDOWN5, SHUTDOWN_SCHEDULED, MB_OKCANCEL | MB_ICONWARNING | MB_DEFBUTTON1);
208+
Sleep(300000);
209+
system("shutdown /s /f");
210+
}
211+
else {
212+
Sleep((mtime - 5) * 60000);
213+
MessageBox(NULL, TO_SHUTDOWN5, SHUTDOWN_SCHEDULED, MB_OKCANCEL | MB_ICONWARNING | MB_DEFBUTTON1);
214+
Sleep(300000);
215+
system("shutdown /s /f");
216+
};
217+
}
218+
else {
219+
Sleep(mtime * 60000);
220+
system("shutdown /s /f");
221+
};
222+
DestroyWindow(hwnd);
223+
PostQuitMessage(0);
224+
}
225+
else {
226+
DestroyWindow(hwnd);
227+
Sleep(mtime * 60000);
228+
system("shutdown /s /f");
229+
PostQuitMessage(0);
230+
};
231+
}
232+
else {
233+
MessageBox(hwnd, INSERT_CORRECT, INCORRECT_VALUE, MB_ICONWARNING | MB_OK);
234+
};
235+
} break;
236+
237+
case ID_CLOSE: {
238+
DestroyWindow(hwnd);
239+
PostQuitMessage(0);
240+
} break;
241+
242+
case ID_CHECKBOX: {
243+
CheckboxState = (IsDlgButtonChecked(hwnd, ID_CHECKBOX) == BST_CHECKED);
244+
if (CheckboxState == true) {
245+
CheckDlgButton(hwnd, ID_CHECKBOX, BST_UNCHECKED);
246+
}
247+
else {
248+
CheckDlgButton(hwnd, ID_CHECKBOX, BST_CHECKED);
249+
};
250+
CheckboxState = (IsDlgButtonChecked(hwnd, ID_CHECKBOX) == BST_CHECKED);
251+
} break;
252+
253+
case ID_ABORT: {
254+
system("start Abort.exe");
255+
} break;
256+
257+
default:
258+
break;
259+
}
260+
break;
261+
262+
case WM_CLOSE:
263+
DestroyWindow(hwnd);
264+
break;
265+
266+
case WM_DESTROY:
267+
PostQuitMessage(0);
268+
break;
269+
270+
default:
271+
return DefWindowProc(hwnd, msg, wParam, lParam);
272+
}
273+
274+
return 0;
275+
}

DShutdown_src/main.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#include <iostream>
2+
#include <fstream>
3+
#include <string>
4+
5+
void WriteToFile(char* filename, char* val)
6+
{
7+
std::ofstream file( filename );
8+
file << val;
9+
file.close();
10+
}
11+
12+
char* ReadFromFile(char* filename)
13+
{
14+
std::ifstream file(filename);
15+
std::string line;
16+
std::getline(file, line);
17+
char *val = &line[0u];
18+
file.close();
19+
return val;
20+
}

DShutdown_src/rescources.rc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
2000 ICON "..\..\icon\DShutdown.ico"

0 commit comments

Comments
 (0)