annotate src/main.c @ 47:7cb4ca7cf257

Use a common.c file to hold concurrent functions Also I fixed that 1.4 KB bug I think
author Paper <mrpapersonic@gmail.com>
date Sat, 21 May 2022 18:41:54 -0400
parents 7cb9fad3f5ee
children 652343b56a60
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
1 #include <inttypes.h>
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
2 #include <stdbool.h>
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
3 #include <stdio.h>
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
4 #include <stdlib.h>
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
5 #include <string.h>
13
a4e604789e2e Multiple changes
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
6 #include <unistd.h>
a4e604789e2e Multiple changes
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
7 #include <getopt.h>
42
d873a04165f9 use basename() on cli version
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents: 16
diff changeset
8 #include <libgen.h>
47
7cb4ca7cf257 Use a common.c file to hold concurrent functions
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
9 #include "../include/common.h"
6
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
10 #ifdef _MSC_VER
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
11 #define strdup(p) _strdup(p)
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
12 #endif
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
13
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
14 static struct option options_long[] = {
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
15 {"input", required_argument, NULL, 'i'},
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
16 {"output", required_argument, NULL, 'o'},
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
17 {"version", required_argument, NULL, 'v'},
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
18 {"type", required_argument, NULL, 't'},
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
19 {"help", 0, NULL, 'h'}
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
20 };
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
21
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
22 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
23 size_t len = strlen(sub);
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
24 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
25 char* p = str;
6
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
26 while ((p = strstr(p, sub)) != NULL) {
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
27 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
28 }
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 return str;
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
31 }
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
32
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
33 int main(int argc, char *argv[]) {
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
34 int c, option_index = 0;
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
35 unsigned char magic[16];
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
36 FILE* outfile;
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
37 struct arguments {
9
d2cd8c5672fa Increase filename limit
Paper <mrpapersonic@gmail.com>
parents: 8
diff changeset
38 char input[256];
d2cd8c5672fa Increase filename limit
Paper <mrpapersonic@gmail.com>
parents: 8
diff changeset
39 char output[256];
6
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
40 int version;
47
7cb4ca7cf257 Use a common.c file to hold concurrent functions
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
41 char type[4];
6
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
42 } args;
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
43 strcpy(args.input, " ");
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
44 strcpy(args.output, " ");
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
45 args.version = -1;
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
46 strcpy(args.type, " ");
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
47
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
48 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
49 switch(c) {
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
50 case 'i':
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
51 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
52 break;
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
53 case 'o':
47
7cb4ca7cf257 Use a common.c file to hold concurrent functions
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
54 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
55 break;
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
56 case 'v':
8
9d862edfd3cc fix fgetc() call
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents: 6
diff changeset
57 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
58 break;
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
59 case 't':
47
7cb4ca7cf257 Use a common.c file to hold concurrent functions
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
60 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
61 break;
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
62 case 'h':
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
63 default:
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
64 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
65 return 0;
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
66 }
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
67 if (argc == 1) {
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
68 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
69 return 0;
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
70 }
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
71 if (strcmp(args.input, " ") == 0) {
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
72 printf("Input file name?\n");
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
73 fflush(stdout);
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
74 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
75 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
76 }
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
77 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
78 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
79 return 1;
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
80 }
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
81 FILE* input_file = fopen(args.input, "r");
8
9d862edfd3cc fix fgetc() call
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents: 6
diff changeset
82 if (fgetc(input_file) == EOF) {
6
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
83 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
84 fclose(input_file);
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
85 return 1;
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
86 }
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
87 fseek(input_file, 0x46, SEEK_SET);
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
88 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
89 fseek(input_file, 0x18, SEEK_SET);
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
90 int file_version = fgetc(input_file);
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
91 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
92 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
93 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
94 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
95 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
96 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
97 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
98 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
99 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
100 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
101 break;
6
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
102 }
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
103 int* ptr = &args.version;
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
104 if (args.version == -1) {
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
105 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
106 fflush(stdout);
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
107 scanf("%d", ptr);
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
108 }
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
109 if (strcmp(args.type, " ") == 0) {
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
110 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
111 fflush(stdout);
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
112 scanf("%3s", args.type);
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
113 }
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
114 fflush(stdout);
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
115 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
116 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
117 temp[0] = '\0';
47
7cb4ca7cf257 Use a common.c file to hold concurrent functions
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
118 char str_version[4];
42
d873a04165f9 use basename() on cli version
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents: 16
diff changeset
119 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
120 strncat(temp, str_version, 4);
7cb4ca7cf257 Use a common.c file to hold concurrent functions
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
121 strncat(temp, "_", 2);
42
d873a04165f9 use basename() on cli version
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents: 16
diff changeset
122 strncat(temp, basename(args.input), 248);
d873a04165f9 use basename() on cli version
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents: 16
diff changeset
123 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
124 strncat(temp, ".", 2);
7cb4ca7cf257 Use a common.c file to hold concurrent functions
Paper <mrpapersonic@gmail.com>
parents: 46
diff changeset
125 strncat(temp, args.type, 4);
9
d2cd8c5672fa Increase filename limit
Paper <mrpapersonic@gmail.com>
parents: 8
diff changeset
126 strncpy(args.output, temp, 255);
44
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents: 43
diff changeset
127 free(temp);
6
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
128 }
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
129 if (strcmp(args.type, "veg") == 0) {
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
130 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
131 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
132 magic[option_index] = T[option_index];
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
133 }
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
134 } 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
135 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
136 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
137 magic[option_index] = T[option_index];
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
138 }
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
139 } else {
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
140 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
141 return 1;
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
142 }
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
143 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
144 #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
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 #elif defined(__unix__)
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
147 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
148 #else
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
149 if (NULL) {
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
150 #endif
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
151 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
152 return 1;
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
153 }
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
154 outfile = fopen(args.output, "r+b");
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
155 if (outfile == NULL) {
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
156 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
157 return 1;
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
158 }
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
159 set_data(magic, args.version, outfile);
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
160 fclose(outfile);
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
161 return 0;
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
162 }