comparison msvpvf.c @ 4:78a0ecd756da

Add automated output filename creation
author Paper <mrpapersonic@gmail.com>
date Fri, 21 Jan 2022 01:40:57 -0500
parents 87c7d43b03ff
children 92ec47e63923
comparison
equal deleted inserted replaced
3:87c7d43b03ff 4:78a0ecd756da
103 case 'h': 103 case 'h':
104 default: 104 default:
105 printf("msvpvf by Paper\nusage: %s (-i/--input) infile [(-o/--output) outfile] (-v/--version) version (-t/--type) [vf, veg]", argv[0]); 105 printf("msvpvf by Paper\nusage: %s (-i/--input) infile [(-o/--output) outfile] (-v/--version) version (-t/--type) [vf, veg]", argv[0]);
106 return 0; 106 return 0;
107 } 107 }
108 int* ptr = &args.version; 108 if (strcmp(args.input, " ") == 0) {
109 if (argc <= 5) { 109 printf("Input file name?\n");
110 if (strcmp(args.input, " ") == 0) { 110 fflush(stdout);
111 printf("Input file name?\n"); 111 fgets(args.input, sizeof(args.input)-1, stdin);
112 fflush(stdout); 112 args.input[strcspn(args.input, "\r\n")] = 0;
113 fgets(args.input, sizeof(args.input)-1, stdin);
114 args.input[strcspn(args.input, "\r\n")] = 0;
115 }
116 if (strcmp(args.output, " ") == 0) {
117 char* temp;
118 temp = strncat(strncat("PRO_V", (char*)(intptr_t)args.version, 7), args.input, 127);
119 char* file_extension = strrchr(args.input, ('.')); /* this won't work if your path is /path.to/file but why would you do that in the first place */
120 strncpy(args.output, strncat(strncat(strremove(temp, file_extension), ".", 127), args.type, 127), 127);
121 }
122 if (args.version == -1) {
123 printf("What version would you like to convert to?\n");
124 fflush(stdout);
125 scanf("%d", ptr);
126 }
127 if (strcmp(args.type, " ") == 0) {
128 printf("Which type of project file would you like to use?[veg/vf]:\n");
129 fflush(stdout);
130 fgets(args.type, sizeof(args.input)-1, stdin);
131 args.type[strcspn(args.type, "\r\n")] = 0;
132 }
133 if (argc == 1) {
134 printf("msvpvf by Paper\nusage: %s -i infile [-o outfile] -v version -t [vf, veg]", argv[0]);
135 return 0;
136 }
137 } 113 }
138 if (access(args.input, F_OK) != 0) { /* input file doesn't exist */ 114 if (access(args.input, F_OK) != 0) {
139 fprintf(stderr, "Input file %s doesn't exist! Exiting.", args.input); 115 fprintf(stderr, "Input file \"%s\" doesn't exist! Exiting.", args.input);
140 return 1; 116 return 1;
141 } 117 }
142 if (fgetc(fopen(args.input, "r")) == EOF) { /* input file is empty */ 118 if (fgetc(fopen(args.input, "r")) == EOF) {
143 fprintf(stderr, "Input file %s is empty.", args.input); 119 fprintf(stderr, "Input file \"%s\" is empty.", args.input);
144 return 1; 120 return 1;
121 }
122 FILE* input_file = fopen(args.input, "r");
123 fseek(input_file, 0x46, SEEK_SET);
124 printf("Input file version: %d\n", fgetc(input_file));
125 fseek(input_file, 0x18, SEEK_SET);
126 int file_version = fgetc(input_file);
127 printf("Input file type: ");
128 if (file_version == 0xEF) {
129 printf("VEGAS Pro\n\n");
130 } else if (file_version == 0xF6) {
131 printf("Movie Studio\n\n");
132 } else {
133 printf("Unknown\n\n");
134 }
135 int* ptr = &args.version;
136 if (args.version == -1) {
137 printf("What version of VEGAS would you like to spoof to?: ");
138 fflush(stdout);
139 scanf("%d", ptr);
140 }
141 if (strcmp(args.type, " ") == 0) {
142 printf("Would you like it to be VEGAS Pro or Movie Studio? [veg/vf]: ");
143 fflush(stdout);
144 scanf("%3s", args.type);
145 }
146 fflush(stdout);
147 if (strcmp(args.output, " ") == 0) { /* string manipulation hell */
148 char temp[128] = {'V'};
149 char str_version[16] = {};
150 sprintf(str_version, "%d", args.version);
151 strncat(temp, str_version, 2);
152 strncat(temp, "_", 1);
153 strncat(temp, args.input, 120);
154 strcpy(temp, strremove(temp, strrchr(args.input, ('.')))); /* remove file extension */
155 strncat(temp, ".", 1);
156 strncat(temp, args.type, 3);
157 strncpy(args.output, temp, 127);
145 } 158 }
146 if (strcmp(args.type, "veg") == 0) { 159 if (strcmp(args.type, "veg") == 0) {
147 unsigned char T[] = {0xEF, 0x29, 0xC4, 0x46, 0x4A, 0x90, 0xD2, 0x11, 0x87, 0x22, 0x00, 0xC0, 0x4F, 0x8E, 0xDB, 0x8A}; 160 unsigned char T[] = {0xEF, 0x29, 0xC4, 0x46, 0x4A, 0x90, 0xD2, 0x11, 0x87, 0x22, 0x00, 0xC0, 0x4F, 0x8E, 0xDB, 0x8A};
148 for (option_index = 0; option_index <= 15; option_index++) { 161 for (option_index = 0; option_index <= 15; option_index++) {
149 magic[option_index] = T[option_index]; 162 magic[option_index] = T[option_index];
156 } else { 169 } else {
157 fprintf(stderr, "Type %s is invalid!", args.type); 170 fprintf(stderr, "Type %s is invalid!", args.type);
158 return 1; 171 return 1;
159 } 172 }
160 copy_file(args.input, args.output); 173 copy_file(args.input, args.output);
174 #ifdef _WIN32
175 if (strcspn(args.input, "<>:\"/\\|?*") == strlen(args.input)+1) {
176 #elif defined(__unix__)
177 if (strcspn(args.input, "/") == strlen(args.input)+1) {
178 #else
179 if (NULL) {
180 #endif
181 fprintf(stderr, "Invalid output filename detected! Exiting...")
182 return 1;
183 }
161 outfile = fopen(args.output, "r+b"); 184 outfile = fopen(args.output, "r+b");
185 if (outfile == NULL) {
186 fprintf(stderr, "Failed to open file %s! Is the filename invalid?", args.output);
187 return 1;
188 }
162 set_data(magic, args.version, outfile); 189 set_data(magic, args.version, outfile);
163 fclose(outfile); 190 fclose(outfile);
164 return 0; 191 return 0;
165 } 192 }