-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
66 lines (45 loc) · 1.77 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
#include "main.h"
int main(int iArgc, char *iArgv[]) {
char *command = malloc(6 * sizeof(char));
char *lastPartOfFile= malloc(100 * sizeof(char));
if (validationIsGood(iArgc, iArgv, command)) {
strcpy(command, iArgv[1]);
char *filename = malloc(sizeof(iArgv[2]));
strcpy(filename, iArgv[2]);
BYTE *hash;
hash = calculateMD5Checksum(filename);
getLast32CharsOfFile(filename, lastPartOfFile);
if (strcmp(command, "-add") == 0) {
if(checkIfChecksumInEndOfFile(filename, lastPartOfFile)){
printf("Already a correct checksum in this file. \n");
}
else if (addChecksumToFile(filename, hash)) {
printf("Checksum was printed to file.\n");
} else {
printf("Something went wrong when printing hash to file.\n");
}
} else if (strcmp(command, "-test") == 0) {
if(checkIfChecksumInEndOfFile(filename, lastPartOfFile)){
printf("Checksum was correct. File has not changed. \n");
}
else{
printf("File has changed or there was never a checksum in file.\n");
}
} else if (strcmp(command, "-strip") == 0) {
if(checkIfChecksumInEndOfFile(filename, lastPartOfFile)){
if(removeChecksumFromFile(filename)){
printf("Checksum was removed from file. \n");
}
else{
printf("Something went wrong when removing checksum.\n");
}
}else{
printf("No checksum in end of file.\nNothing to remove. \n");
}
}
free(hash);
free(filename);
}
free(command);
return 0;
}