Mercurial > msvpvf
annotate src/main.c @ 56:0d62f49c1948
Update gui.c
author | Paper <37962225+mrpapersonic@users.noreply.github.com> |
---|---|
date | Mon, 18 Jul 2022 12:03:45 -0400 |
parents | 652343b56a60 |
children | fcd4b9fe957b |
rev | line source |
---|---|
6
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
1 #include <stdio.h> |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
2 #include <stdlib.h> |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
3 #include <string.h> |
13 | 4 #include <unistd.h> |
5 #include <getopt.h> | |
42
d873a04165f9
use basename() on cli version
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
16
diff
changeset
|
6 #include <libgen.h> |
47
7cb4ca7cf257
Use a common.c file to hold concurrent functions
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
7 #include "../include/common.h" |
6
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
8 #ifdef _MSC_VER |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
9 #define strdup(p) _strdup(p) |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
10 #endif |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
11 |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
12 static struct option options_long[] = { |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
13 {"input", required_argument, NULL, 'i'}, |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
14 {"output", required_argument, NULL, 'o'}, |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
15 {"version", required_argument, NULL, 'v'}, |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
16 {"type", required_argument, NULL, 't'}, |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
17 {"help", 0, NULL, 'h'} |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
18 }; |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
19 |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
20 char* strremove(char* str, const char* sub) { |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
21 size_t len = strlen(sub); |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
22 if (len > 0) { |
16
8bcb6a2d3def
CLI version: use switch statement instead of generic if else... may give us performance benefit??
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
13
diff
changeset
|
23 char* p = str; |
6
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
24 while ((p = strstr(p, sub)) != NULL) { |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
25 memmove(p, p + len, strlen(p + len) + 1); |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
26 } |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
27 } |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
28 return str; |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
29 } |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
30 |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
31 int main(int argc, char *argv[]) { |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
32 int c, option_index = 0; |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
33 unsigned char magic[16]; |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
34 FILE* outfile; |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
35 struct arguments { |
9 | 36 char input[256]; |
37 char output[256]; | |
6
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
38 int version; |
47
7cb4ca7cf257
Use a common.c file to hold concurrent functions
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
39 char type[4]; |
6
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
40 } args; |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
41 strcpy(args.input, " "); |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
42 strcpy(args.output, " "); |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
43 args.version = -1; |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
44 strcpy(args.type, " "); |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
45 |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
46 while ((c = getopt_long(argc, argv, "i:o:v:t:h", options_long, &option_index)) != -1) |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
47 switch(c) { |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
48 case 'i': |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
49 strncpy(args.input, optarg, sizeof(args.input)-1); /* subtract 1 to make sure it's "null-safe" */ |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
50 break; |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
51 case 'o': |
47
7cb4ca7cf257
Use a common.c file to hold concurrent functions
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
52 strncpy(args.output, optarg, sizeof(args.output)-1); |
6
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
53 break; |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
54 case 'v': |
8
9d862edfd3cc
fix fgetc() call
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
6
diff
changeset
|
55 args.version = abs(atoi(strdup(optarg))); /* abs() for possible negative inputs */ |
6
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
56 break; |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
57 case 't': |
47
7cb4ca7cf257
Use a common.c file to hold concurrent functions
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
58 strncpy(args.type, optarg, sizeof(args.type)-1); |
6
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
59 break; |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
60 case 'h': |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
61 default: |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
62 printf("msvpvf by Paper\nusage: %s (-i/--input) infile [(-o/--output) outfile] (-v/--version) version (-t/--type) [vf, veg]\n", argv[0]); |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
63 return 0; |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
64 } |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
65 if (argc == 1) { |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
66 printf("msvpvf by Paper\nusage: %s (-i/--input) infile [(-o/--output) outfile] (-v/--version) version (-t/--type) [vf, veg]\n", argv[0]); |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
67 return 0; |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
68 } |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
69 if (strcmp(args.input, " ") == 0) { |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
70 printf("Input file name?\n"); |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
71 fflush(stdout); |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
72 fgets(args.input, sizeof(args.input)-1, stdin); |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
73 args.input[strcspn(args.input, "\r\n")] = 0; |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
74 } |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
75 if (access(args.input, F_OK) != 0) { |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
76 fprintf(stderr, "Input file \"%s\" doesn't exist! Exiting.", args.input); |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
77 return 1; |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
78 } |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
79 FILE* input_file = fopen(args.input, "r"); |
8
9d862edfd3cc
fix fgetc() call
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
6
diff
changeset
|
80 if (fgetc(input_file) == EOF) { |
6
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
81 fprintf(stderr, "Input file \"%s\" is empty.", args.input); |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
82 fclose(input_file); |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
83 return 1; |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
84 } |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
85 fseek(input_file, 0x46, SEEK_SET); |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
86 printf("Input file version: %d\n", fgetc(input_file)); |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
87 fseek(input_file, 0x18, SEEK_SET); |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
88 int file_version = fgetc(input_file); |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
89 printf("Input file type: "); |
16
8bcb6a2d3def
CLI version: use switch statement instead of generic if else... may give us performance benefit??
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
13
diff
changeset
|
90 switch (file_version) { |
8bcb6a2d3def
CLI version: use switch statement instead of generic if else... may give us performance benefit??
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
13
diff
changeset
|
91 case 0xEF: |
8bcb6a2d3def
CLI version: use switch statement instead of generic if else... may give us performance benefit??
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
13
diff
changeset
|
92 printf("VEGAS Pro\n\n"); |
8bcb6a2d3def
CLI version: use switch statement instead of generic if else... may give us performance benefit??
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
13
diff
changeset
|
93 break; |
8bcb6a2d3def
CLI version: use switch statement instead of generic if else... may give us performance benefit??
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
13
diff
changeset
|
94 case 0xF6: |
8bcb6a2d3def
CLI version: use switch statement instead of generic if else... may give us performance benefit??
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
13
diff
changeset
|
95 printf("Movie Studio\n\n"); |
8bcb6a2d3def
CLI version: use switch statement instead of generic if else... may give us performance benefit??
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
13
diff
changeset
|
96 break; |
8bcb6a2d3def
CLI version: use switch statement instead of generic if else... may give us performance benefit??
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
13
diff
changeset
|
97 default: |
8bcb6a2d3def
CLI version: use switch statement instead of generic if else... may give us performance benefit??
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
13
diff
changeset
|
98 printf("Unknown\n\n"); |
8bcb6a2d3def
CLI version: use switch statement instead of generic if else... may give us performance benefit??
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
13
diff
changeset
|
99 break; |
6
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
100 } |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
101 int* ptr = &args.version; |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
102 if (args.version == -1) { |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
103 printf("What version of VEGAS would you like to spoof to?: "); |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
104 fflush(stdout); |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
105 scanf("%d", ptr); |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
106 } |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
107 if (strcmp(args.type, " ") == 0) { |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
108 printf("Would you like it to be VEGAS Pro or Movie Studio? [veg/vf]: "); |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
109 fflush(stdout); |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
110 scanf("%3s", args.type); |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
111 } |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
112 fflush(stdout); |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
113 if (strcmp(args.output, " ") == 0) { /* string manipulation hell */ |
45
d8ac17c6d6f2
I'm an idiot
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
44
diff
changeset
|
114 char* temp = (char*)calloc(256, sizeof(char)); |
43
9b309701420e
welcome to Ctec and will it compile?
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
42
diff
changeset
|
115 temp[0] = '\0'; |
47
7cb4ca7cf257
Use a common.c file to hold concurrent functions
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
116 char str_version[4]; |
42
d873a04165f9
use basename() on cli version
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
16
diff
changeset
|
117 sprintf(str_version, "V%d", args.version); |
47
7cb4ca7cf257
Use a common.c file to hold concurrent functions
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
118 strncat(temp, str_version, 4); |
7cb4ca7cf257
Use a common.c file to hold concurrent functions
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
119 strncat(temp, "_", 2); |
42
d873a04165f9
use basename() on cli version
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
16
diff
changeset
|
120 strncat(temp, basename(args.input), 248); |
d873a04165f9
use basename() on cli version
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
16
diff
changeset
|
121 strcpy(temp, strremove(temp, strrchr(basename(args.input), ('.')))); /* remove file extension */ |
47
7cb4ca7cf257
Use a common.c file to hold concurrent functions
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
122 strncat(temp, ".", 2); |
7cb4ca7cf257
Use a common.c file to hold concurrent functions
Paper <mrpapersonic@gmail.com>
parents:
46
diff
changeset
|
123 strncat(temp, args.type, 4); |
9 | 124 strncpy(args.output, temp, 255); |
44
4f005d28d912
gah,,
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
43
diff
changeset
|
125 free(temp); |
6
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
126 } |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
127 if (strcmp(args.type, "veg") == 0) { |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
128 const unsigned char T[] = {0xEF, 0x29, 0xC4, 0x46, 0x4A, 0x90, 0xD2, 0x11, 0x87, 0x22, 0x00, 0xC0, 0x4F, 0x8E, 0xDB, 0x8A}; |
16
8bcb6a2d3def
CLI version: use switch statement instead of generic if else... may give us performance benefit??
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
13
diff
changeset
|
129 for (option_index = 0; option_index <= 15; option_index++) { /* this line is repeated, but it's probably best to just leave it be. */ |
6
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
130 magic[option_index] = T[option_index]; |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
131 } |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
132 } else if (strcmp(args.type, "vf") == 0) { |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
133 const unsigned char T[] = {0xF6, 0x1B, 0x3C, 0x53, 0x35, 0xD6, 0xF3, 0x43, 0x8A, 0x90, 0x64, 0xB8, 0x87, 0x23, 0x1F, 0x7F}; |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
134 for (option_index = 0; option_index <= 15; option_index++) { |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
135 magic[option_index] = T[option_index]; |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
136 } |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
137 } else { |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
138 fprintf(stderr, "Type %s is invalid!", args.type); |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
139 return 1; |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
140 } |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
141 copy_file(args.input, args.output); |
16
8bcb6a2d3def
CLI version: use switch statement instead of generic if else... may give us performance benefit??
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents:
13
diff
changeset
|
142 #ifdef _WIN32 /* disallowed characters in filenames */ |
6
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
143 if (strcspn(args.input, "<>:\"/\\|?*") == strlen(args.input)+1) { |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
144 #elif defined(__unix__) |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
145 if (strcspn(args.input, "/") == strlen(args.input)+1) { |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
146 #else |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
147 if (NULL) { |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
148 #endif |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
149 fprintf(stderr, "Invalid output filename detected! Exiting..."); |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
150 return 1; |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
151 } |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
152 outfile = fopen(args.output, "r+b"); |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
153 if (outfile == NULL) { |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
154 fprintf(stderr, "Failed to open file %s! Do you have write permissions?", args.output); |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
155 return 1; |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
156 } |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
157 set_data(magic, args.version, outfile); |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
158 fclose(outfile); |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
159 return 0; |
d1e5b8390cd3
Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff
changeset
|
160 } |