-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.c
81 lines (68 loc) · 2.18 KB
/
main.c
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
#include "sha256sum.h"
#define MAJOR_VERSION 2
#define MINOR_VERSION 0
#define PATCH_VERSION 4
int run(int argc, LPWSTR argv[])
{
Args args = { 0 };
ErrorCode parse_result = ParseArgs(&args, argc, argv);
// error handling from argument parsing
switch (parse_result)
{
case PARSE_ARGS_MISSING_PARAMETER:
case PARSE_ARGS_MISSING_SHASUMS_FILE:
case PARSE_ARGS_ALLOCATE_ERROR:
return parse_result;
}
// show application version
if (args.showVersion)
{
wprintf(L"%ls version %d.%d.%d\n", argv[0], MAJOR_VERSION, MINOR_VERSION, PATCH_VERSION);
return SUCCESS;
}
// since WinAPI only reads binary we don't support text mode
if (args.textMode)
{
wprintf(L"%ls only supports binary mode\n", argv[0]);
return SUCCESS;
}
// run check on checksum file
if (args.sumFile != NULL)
{
return VerifyChecksums(&args);
}
// handle all FILE parameters
if (args.files != NULL)
{
FileList* current = args.files;
while (current != NULL)
{
WIN32_FIND_DATA findFileData;
HANDLE hFind = FindFirstFile(current->file, &findFileData);
if (hFind == INVALID_HANDLE_VALUE)
{
wchar_t msg[MAX_PATH + 100];
wsprintfW(msg, L"failed to find files for argument '%ls' with error %lu\n", current->file, GetLastError());
WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE), msg, lstrlenW(msg), NULL, NULL);
return MAIN_FAILED_TO_FIND_FILES;
}
do
{
ErrorCode printHashStatus = PrintHash(&args, current->file, findFileData.cFileName);
if (printHashStatus != SUCCESS)
{
FindClose(hFind);
return printHashStatus;
}
} while (FindNextFile(hFind, &findFileData) != 0);
FindClose(hFind);
current = current->next;
}
return SUCCESS;
}
return SUCCESS;
}
int wmain(int argc, LPWSTR argv[])
{
return run(argc, argv);
}