changeset 58:fcd4b9fe957b

[gui.c]: show version and type in a box
author Paper <37962225+mrpapersonic@users.noreply.github.com>
date Thu, 21 Jul 2022 00:46:18 -0400
parents 01c605e78f48
children 8feb66207b99
files include/common.h src/common.c src/gui.c src/main.c
diffstat 4 files changed, 38 insertions(+), 33 deletions(-) [+]
line wrap: on
line diff
--- a/include/common.h	Wed Jul 20 21:31:26 2022 -0400
+++ b/include/common.h	Thu Jul 21 00:46:18 2022 -0400
@@ -1,2 +1,2 @@
-void set_data(unsigned char magic[], int version, FILE* target);
+void set_data(unsigned char* magic, int version, FILE* target);
 int copy_file(char* source_file, char* target_file);
--- a/src/common.c	Wed Jul 20 21:31:26 2022 -0400
+++ b/src/common.c	Thu Jul 21 00:46:18 2022 -0400
@@ -1,7 +1,7 @@
 #include <stdio.h>
 #include <stdint.h>
 
-void set_data(unsigned char magic[], uint16_t version, FILE* target) {
+void set_data(unsigned char* magic, uint16_t version, FILE* target) {
 	int i;
 	fseek(target, 0x46, SEEK_SET);
 	fputc(version, target);
--- a/src/gui.c	Wed Jul 20 21:31:26 2022 -0400
+++ b/src/gui.c	Thu Jul 21 00:46:18 2022 -0400
@@ -31,15 +31,16 @@
 #define _WIN32_WINNT 0x0400
 #define ARRAYSIZE(a) \
 	sizeof(a)/sizeof(a[0])
-#define OPEN_FILE_BUTTON 0
-#define COMBOBOX         1
-#define LISTBOX          2
-#define SAVE_FILE_BUTTON 3
+#define OPEN_FILE_BUTTON	0
+#define COMBOBOX		1
+#define LISTBOX			2
+#define SAVE_FILE_BUTTON	3
+#define VERSION			4
 #ifdef _MSC_VER
 #define strdup(p) _strdup(p)
 #endif
 
-HWND hWndListBox, hWndComboBox;
+HWND hWndListBox, hWndComboBox, hWndVersion;
 int16_t version = 13;
 enum types {
 	vf,
@@ -49,17 +50,25 @@
 
 void display_file(char* path) {
 	/* Read the file to memory */
-        /* eventually this will contain code to show the version and type */
 	FILE* file;
 	file = fopen(path, "rb");
-	fseek(file, 0, SEEK_END);
-	int _size = ftell(file);
-	rewind(file);
-	char* data = calloc(_size+1, sizeof(char*));
-	fread(data, _size, 1, file);
-	data[_size] = '\0';
-
-	free(data);
+	fseek(file, 0x46, SEEK_SET);
+	int f_version = fgetc(file);
+	fseek(file, 0x18, SEEK_SET);
+	TCHAR p[32];
+	switch (fgetc(file)) {
+		case 0xEF:
+			snprintf(p, 32, "File version: %s %d", "VEGAS Pro", f_version);
+			break;
+		case 0xF6:
+			snprintf(p, 32, "File version: %s %d", "Movie Studio", f_version);
+			break;
+		default:
+			snprintf(p, 32, "File version: %s %d", "Unknown", f_version);
+			break;
+	}
+	printf("%s", p);
+	SendMessage(hWndVersion, WM_SETTEXT, (WPARAM)0, (LPARAM)p);
 	fclose(file);
 }
 
@@ -118,21 +127,15 @@
 		MessageBox(hWnd, TEXT("Failed to save project file!"), TEXT("Saving project failed!"), MB_ICONEXCLAMATION); 
 		return;
 	}
+	unsigned char* magic;
+	static const unsigned char magic_veg[] = {0xEF, 0x29, 0xC4, 0x46, 0x4A, 0x90, 0xD2, 0x11, 0x87, 0x22, 0x00, 0xC0, 0x4F, 0x8E, 0xDB, 0x8A};
+	static const unsigned char magic_vf[] = {0xF6, 0x1B, 0x3C, 0x53, 0x35, 0xD6, 0xF3, 0x43, 0x8A, 0x90, 0x64, 0xB8, 0x87, 0x23, 0x1F, 0x7F};
+	if (type == veg)
+		memcpy(magic, magic_veg, sizeof(magic_veg));
+	else
+		memcpy(magic, magic_vf,  sizeof(magic_vf) );
 
-	switch ((int)type) {
-		case vf: {
-			unsigned char magic[] = {0xEF, 0x29, 0xC4, 0x46, 0x4A, 0x90, 0xD2, 0x11, 
-									 0x87, 0x22, 0x00, 0xC0, 0x4F, 0x8E, 0xDB, 0x8A};
-			set_data(magic, version, output);
-			break;
-		}
-		default: {
-			unsigned char magic[] = {0xF6, 0x1B, 0x3C, 0x53, 0x35, 0xD6, 0xF3, 0x43, 
-									 0x8A, 0x90, 0x64, 0xB8, 0x87, 0x23, 0x1F, 0x7F};
-			set_data(magic, version, output);
-			break;
-		}
-	}
+	set_data(magic, version, output);
 
 	fclose(output);
 }
@@ -168,7 +171,9 @@
 	}
 	SendMessage(hWndListBox, LB_SETCURSEL, (WPARAM)0, (LPARAM)0);
 	/* Save File */
-	HWND save_button = CreateWindowA("Button", "Save", WS_VISIBLE | WS_CHILD, (int)((225 - 50)/2), 90, 50, 20, hWnd, (HMENU)SAVE_FILE_BUTTON, NULL, NULL);
+	HWND save_button = CreateWindow("Button", "Save", WS_VISIBLE | WS_CHILD, (int)((225 - 50)/2), 90, 50, 20, hWnd, (HMENU)SAVE_FILE_BUTTON, NULL, NULL);
+	/* Version and Type display */
+	hWndVersion = CreateWindow("Edit", "", WS_VISIBLE | WS_CHILD | WS_BORDER | ES_READONLY | ES_CENTER | ES_MULTILINE | SS_CENTER, (int)((225 - 150)/2), 120, 150, 40, hWnd, (HMENU)VERSION, NULL, NULL);
 	if (open_button == NULL || save_button == NULL || hWndListBox == NULL || hWndComboBox == NULL)
 		MessageBox(hWnd, TEXT("how did you even trigger this"), TEXT("GUI could not be initialized!"), MB_ICONEXCLAMATION); 
 }
@@ -192,10 +197,10 @@
 					file_name = open_file(hWnd);
 				case COMBOBOX:
 				case LISTBOX:
+				case VERSION:
 					break;
 				case SAVE_FILE_BUTTON:
 					save_file(hWnd, file_name);
-					break;
 			}
 			break;
 		case WM_CREATE: {
--- a/src/main.c	Wed Jul 20 21:31:26 2022 -0400
+++ b/src/main.c	Thu Jul 21 00:46:18 2022 -0400
@@ -154,7 +154,7 @@
 		fprintf(stderr, "Failed to open file %s! Do you have write permissions?", args.output);
 		return 1;
 	}
-	set_data(magic, args.version, outfile);
+	set_data(&magic, args.version, outfile);
 	fclose(outfile);
 	return 0;
 }