-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFile Manager
More file actions
294 lines (263 loc) · 9.7 KB
/
Copy pathFile Manager
File metadata and controls
294 lines (263 loc) · 9.7 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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
/* Windows File Manager V1 By Uranium-239 */
/* Delete, Open, MD5 */
#include <windows.h>
#include <strings.h>
#include <fstream>
#include <wincrypt.h>
using namespace std;
#define OPEN_OBJECT 0x01
#define SHIFT_BACK 0x02
#define MD5 0x03
#define DEL 0x04
static HWND filelist = 0;
char directory[500]="C:\\";
void DeleteMyFile(char buffer[]){
char file[600];
strcpy(file,directory);
strcat(file,buffer);
if(MessageBox(0,file,"Delete this file?",MB_YESNO)==IDYES){
DeleteFile(file);
}
}
void MD5Hash(BYTE hash[],int sz,char sec[]){
HCRYPTPROV hProv = 0,hHash = 0;
BYTE rgbHash[16];
DWORD cbHash = 0;
char file[MAX_PATH],dig[] = "0123456789abcdef";
int l=0;
CryptAcquireContext(&hProv,NULL,NULL,PROV_RSA_FULL,CRYPT_VERIFYCONTEXT);
CryptCreateHash(hProv,CALG_MD5,0,0,&hHash);
CryptHashData(hHash,hash,sz,0);
cbHash = 16;
CryptGetHashParam(hHash, HP_HASHVAL, rgbHash, &cbHash, 0);
for(DWORD i=0;i<cbHash;i++){
sec[l]=dig[rgbHash[i]>>4];
l++;
sec[l]=dig[rgbHash[i] & 0xf];
l++;
}
for(l=32;l<strlen(sec);l++)sec[l]=0;
CryptDestroyHash(hHash);
CryptReleaseContext(hProv, 0);
}
int MessageBoxFileHashSum(char buffer[]){
char file[600];
strcpy(file,directory);
strcat(file,buffer);
ifstream read(file,ios::binary);
read.seekg(0,ios::end);
int l = read.tellg();
read.seekg(0,ios::beg);
char * buf = 0;
if((buf = (char*)malloc(l)) == NULL){
MessageBox(0,"Directorys cannot be summed",0,0);
return 0;
}
read.read(buf,l);
if(read.fail()){
free(buf);
MessageBox(NULL,"Error Opening File","Uranium-239",MB_OK);
return 0;
}
read.close();
char hash[32];
MD5Hash((BYTE*)buf,l,hash);
free(buf);
MessageBox(NULL,hash,"File Checksum:",MB_OK);
}
void UpdateList(){
char path[500];
strcpy(path,directory);
strcat(path,"*.*");
WIN32_FIND_DATA data;
HANDLE hFile = FindFirstFileA(path, &data);
SendMessage(filelist, LB_RESETCONTENT, 0, 0);
while(FindNextFile(hFile,&data)!=0)
{
SendMessage(filelist, LB_INSERTSTRING, (WPARAM) -1, (LPARAM)data.cFileName);
}
FindClose(hFile);
}
void RemoveLastDirectory(){
int i[3];
i[3]=strlen(directory);
for(i[0]=0;i[0]<i[3];i[0]++){
if(directory[i[0]]=='\\'){
i[2]=i[1];
i[1]=i[0];
}
}
for(i[2]++;i[2]<i[3];i[2]++)directory[i[2]]=0;
}
/* Declare Windows procedure */
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
/* Make the class name into a global variable */
char szClassName[ ] = "FileViewer";
int WINAPI WinMain (HINSTANCE hThisInstance,
HINSTANCE hPrevInstance,
LPSTR lpszArgument,
int nFunsterStil)
{
HWND hwnd; /* This is the handle for our window */
MSG messages; /* Here messages to the application are saved */
WNDCLASSEX wincl; /* Data structure for the windowclass */
/* The Window structure */
wincl.hInstance = hThisInstance;
wincl.lpszClassName = szClassName;
wincl.lpfnWndProc = WindowProcedure; /* This function is called by windows */
wincl.style = CS_DBLCLKS; /* Catch double-clicks */
wincl.cbSize = sizeof (WNDCLASSEX);
/* Use default icon and mouse-pointer */
wincl.hIcon = LoadCursor (NULL, IDC_ARROW);
wincl.hIconSm = LoadCursor (NULL, IDC_ARROW);
wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
wincl.lpszMenuName = NULL; /* No menu */
wincl.cbClsExtra = 0; /* No extra bytes after the window class */
wincl.cbWndExtra = 0; /* structure or the window instance */
/* Use Windows's default color as the background of the window */
wincl.hbrBackground = (HBRUSH) CreateSolidBrush(RGB(1,1,1));
/* Register the window class, and if it fails quit the program */
if (!RegisterClassEx (&wincl))
return 0;
/* The class is registered, let's create the program*/
hwnd = CreateWindowEx (
0, /* Extended possibilites for variation */
szClassName, /* Classname */
"File Manager", /* Title Text */
WS_OVERLAPPEDWINDOW, /* default window */
100, /* Windows decides the position */
50, /* where the window ends up on the screen */
412, /* The programs width */
460, /* and height in pixels */
HWND_DESKTOP, /* The window is a child-window to desktop */
NULL, /* No menu */
hThisInstance, /* Program Instance handler */
NULL /* No Window Creation data */
);
/* Make the window visible on the screen */
ShowWindow (hwnd, nFunsterStil);
/* Run the message loop. It will run until GetMessage() returns 0 */
while (GetMessage (&messages, NULL, 0, 0))
{
/* Translate virtual-key messages into character messages */
TranslateMessage(&messages);
/* Send message to WindowProcedure */
DispatchMessage(&messages);
}
/* The program return-value is 0 - The value that PostQuitMessage() gave */
return messages.wParam;
}
/* This function is called by the Windows function DispatchMessage() */
LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
static HWND open = 0;
static HWND back = 0;
static HWND md5 = 0;
static HWND del = 0;
char buffer[500];
switch (message) /* handle the messages */
{
case WM_DESTROY:
PostQuitMessage (0); /* send a WM_QUIT to the message queue */
break;
case WM_CREATE:
filelist=CreateWindow(
"ListBox",
0,
WS_CHILD | LBS_MULTICOLUMN | WS_VISIBLE | WS_BORDER | WS_VSCROLL | WS_HSCROLL | LBS_DISABLENOSCROLL,
2,2,400,400,
hwnd,
(HMENU)1,
((LPCREATESTRUCT) lParam)->hInstance,
NULL
);
SendMessage(filelist,LB_SETCOLUMNWIDTH,(WPARAM)200,0);
open = CreateWindow(
"BUTTON",
"Open",
WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
2,390,100,30,
hwnd,
(HMENU)OPEN_OBJECT,
((LPCREATESTRUCT) lParam)->hInstance,
NULL
);
back = CreateWindow(
"BUTTON",
"Back",
WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
100,390,100,30,
hwnd,
(HMENU)SHIFT_BACK,
((LPCREATESTRUCT) lParam)->hInstance,
NULL
);
md5 = CreateWindow(
"BUTTON",
"MD5 Sum",
WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
200,390,100,30,
hwnd,
(HMENU)MD5,
((LPCREATESTRUCT) lParam)->hInstance,
NULL
);
del = CreateWindow(
"BUTTON",
"Delete",
WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
300,390,100,30,
hwnd,
(HMENU)DEL,
((LPCREATESTRUCT) lParam)->hInstance,
NULL
);
UpdateList();
case WM_COMMAND:
if (HIWORD(wParam) == BN_CLICKED)
{
int c;
switch(LOWORD(wParam)){
case DEL:
c = SendMessage(filelist, LB_GETCURSEL, 0, 0);
SendMessage(filelist,LB_GETTEXT,(WPARAM)c,(LPARAM)buffer);
DeleteMyFile(buffer);
UpdateList();
break;
case MD5:
c = SendMessage(filelist, LB_GETCURSEL, 0, 0);
SendMessage(filelist,LB_GETTEXT,(WPARAM)c,(LPARAM)buffer);
MessageBoxFileHashSum(buffer);
break;
case SHIFT_BACK:
RemoveLastDirectory();
UpdateList();
break;
case OPEN_OBJECT:
BOOL file;
c = SendMessage(filelist, LB_GETCURSEL, 0, 0);
SendMessage(filelist,LB_GETTEXT,(WPARAM)c,(LPARAM)buffer);
if(strcmp(buffer,"..")==0){
RemoveLastDirectory();
}else{
if(strstr(buffer,".")!=NULL)file=TRUE;
else file=FALSE;
if(file==FALSE){
strcat(buffer,"\\");
strcat(directory,buffer);
}else{
char p_b[500];
strcpy(p_b,directory);
strcat(p_b,buffer);
ShellExecute(0,"open",p_b,0,0,SW_SHOW);
}
}
UpdateList();
break;
}
}
default: /* for messages that we don't deal with */
return DefWindowProc (hwnd, message, wParam, lParam);
}
return 0;
}