comparison src/gui.c @ 18:b5df3f47a30e

Use enums for `type`
author Paper <37962225+mrpapersonic@users.noreply.github.com>
date Thu, 07 Apr 2022 02:36:03 -0400
parents 812089083c89
children 6d14538a109e
comparison
equal deleted inserted replaced
17:812089083c89 18:b5df3f47a30e
1 /**
2 * msvpvf GUI for Windows
3 * Copyright (c) Paper 2022
4 *
5 * View this file with 4-tab spacing; if you don't it will be a formatting nightmare.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to deal
9 * in the Software without restriction, including without limitation the rights
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 * copies of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included in all
15 * copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 * SOFTWARE.
24 **/
1 #include <stdio.h> 25 #include <stdio.h>
2 #include <windows.h> 26 #include <windows.h>
3 #include <stdint.h> 27 #include <stdint.h>
4 #include <stdbool.h> 28 #include <stdbool.h>
5 #include <commdlg.h> 29 #include <commdlg.h>
7 #define COMBOBOX 1 31 #define COMBOBOX 1
8 #define LISTBOX 2 32 #define LISTBOX 2
9 #define SAVE_FILE_BUTTON 3 33 #define SAVE_FILE_BUTTON 3
10 34
11 HWND hWndListBox, hWndComboBox; 35 HWND hWndListBox, hWndComboBox;
12 int16_t version = 11, type = 1; /* type: 0 is vf, 1 is veg */ 36 int16_t version = 11;
13 char* file_name = " "; /* initialize as a space, a (windows) filename can't just be a space */ 37 enum type {
38 vf,
39 veg
40 }
41 char* file_name = " ";
14 42
15 void set_data(unsigned char magic[], uint16_t version, FILE* target) { 43 void set_data(unsigned char magic[], uint16_t version, FILE* target) {
16 int i; 44 int i;
17 fseek(target, 0x46, SEEK_SET); 45 fseek(target, 0x46, SEEK_SET);
18 fputc(version, target); 46 fputc(version, target);
21 fputc(magic[i], target); 49 fputc(magic[i], target);
22 } 50 }
23 } 51 }
24 52
25 int copy_file(char* source_file, char* target_file) { 53 int copy_file(char* source_file, char* target_file) {
54 /* Copy a file */
26 FILE *source, *target; 55 FILE *source, *target;
27 56
28 source = fopen(source_file, "rb"); 57 source = fopen(source_file, "rb");
29 if (source == NULL) return 1; 58 if (source == NULL) return 1;
30 target = fopen(target_file, "wb"); 59 target = fopen(target_file, "wb");
81 return _strdup(filename); 110 return _strdup(filename);
82 } 111 }
83 112
84 void save_file(HWND hWnd, char* input_file) { 113 void save_file(HWND hWnd, char* input_file) {
85 if (strcmp(input_file, " ") == 0) { 114 if (strcmp(input_file, " ") == 0) {
86 MessageBoxW(hWnd, L"Please open a file first!", L"Invalid input file!", MB_ICONEXCLAMATION); 115 MessageBoxW(hWnd,
116 L"Please open a file first!",
117 L"Invalid input file!",
118 MB_ICONEXCLAMATION);
87 return; 119 return;
88 } 120 }
89 OPENFILENAME ofn; 121 OPENFILENAME ofn;
90 char output_file[256]; 122 char output_file[256];
91 123
105 if (output == NULL) { 137 if (output == NULL) {
106 MessageBoxW(hWnd, L"Failed to save project file!", L"Saving project failed!", MB_ICONEXCLAMATION); 138 MessageBoxW(hWnd, L"Failed to save project file!", L"Saving project failed!", MB_ICONEXCLAMATION);
107 return; 139 return;
108 } 140 }
109 141
110 if (type == 1) { 142 switch (type) {
111 unsigned char magic[] = {0xEF, 0x29, 0xC4, 0x46, 0x4A, 0x90, 0xD2, 0x11, 0x87, 0x22, 0x00, 0xC0, 0x4F, 0x8E, 0xDB, 0x8A}; 143 case vf:
112 set_data(magic, version, output); 144 unsigned char magic[] = {0xEF, 0x29, 0xC4, 0x46, 0x4A, 0x90, 0xD2, 0x11,
113 } else { 145 0x87, 0x22, 0x00, 0xC0, 0x4F, 0x8E, 0xDB, 0x8A};
114 unsigned char magic[] = {0xF6, 0x1B, 0x3C, 0x53, 0x35, 0xD6, 0xF3, 0x43, 0x8A, 0x90, 0x64, 0xB8, 0x87, 0x23, 0x1F, 0x7F}; 146 set_data(magic, version, output);
115 set_data(magic, version, output); 147 break;
148 case veg:
149 unsigned char magic[] = {0xF6, 0x1B, 0x3C, 0x53, 0x35, 0xD6, 0xF3, 0x43,
150 0x8A, 0x90, 0x64, 0xB8, 0x87, 0x23, 0x1F, 0x7F};
151 set_data(magic, version, output);
152 break;
116 } 153 }
117 154
118 fclose(output); 155 fclose(output);
119 } 156 }
120 157
121 void AddControls(HWND hWnd) { 158 void AddControls(HWND hWnd) {
122 /* versions */ 159 /* Versions */
123 hWndComboBox = CreateWindowW(L"ComboBox", NULL, CBS_DROPDOWNLIST | CBS_HASSTRINGS | WS_CHILD | WS_VISIBLE | WS_OVERLAPPED | WS_VSCROLL, (int)((225 - 50)/2), 30, 50, 200, hWnd, (HMENU)COMBOBOX, NULL, NULL); 160 hWndComboBox = CreateWindowW(L"ComboBox", NULL,
124 TCHAR versions[][10] = {TEXT("8"), TEXT("9"), TEXT("10"), TEXT("11"), TEXT("12"), TEXT("13"), TEXT("14"), TEXT("15"), TEXT("16"), TEXT("17"), TEXT("18"), TEXT("19")}; 161 CBS_DROPDOWNLIST | CBS_HASSTRINGS | WS_CHILD | WS_VISIBLE | WS_OVERLAPPED | WS_VSCROLL,
162 (int)((225 - 50)/2), 30, 50, 200,
163 hWnd, (HMENU)COMBOBOX, NULL, NULL); /**
164 * I don't understand what half of
165 * these arguments are for, so chances
166 * are that you don't either.
167 **/
168 TCHAR versions[][10] = {TEXT("8"), TEXT("9"), TEXT("10"),
169 TEXT("11"), TEXT("12"), TEXT("13"),
170 TEXT("14"), TEXT("15"), TEXT("16"),
171 TEXT("17"), TEXT("18"), TEXT("19")};
125 172
126 TCHAR A[16]; 173 TCHAR A[16];
127 174
175 /**
176 * Here we can't just use a for loop
177 * and cast all of those to `TEXT()`.
178 * Why? I don't know. My brain is too
179 * small to figure it out.
180 **/
128 memset(&A,0,sizeof(A)); 181 memset(&A,0,sizeof(A));
129 int i = 0; 182 int i = 0;
130 for (i = 0; i <= 11; i++) { 183 for (i = 0; i <= 11; i++) {
131 wcscpy_s((WCHAR*)A, sizeof(A)/sizeof(TCHAR), (WCHAR*)versions[i]); 184 wcscpy_s((WCHAR*)A, sizeof(A)/sizeof(TCHAR), (WCHAR*)versions[i]);
132 SendMessage(hWndComboBox, (UINT)CB_ADDSTRING, (WPARAM)0, (LPARAM)A); 185 SendMessage(hWndComboBox, (UINT)CB_ADDSTRING, (WPARAM)0, (LPARAM)A);
133 } 186 }
134 SendMessage(hWndComboBox, CB_SETCURSEL, (WPARAM)3, (LPARAM)0); 187 SendMessage(hWndComboBox, CB_SETCURSEL, (WPARAM)3, (LPARAM)0);
135 /* open file */ 188 /* Open File */
136 HWND open_button = CreateWindowW(L"Button", L"Open", WS_VISIBLE | WS_CHILD, (int)((225 - 50)/2), 5, 50, 20, hWnd, (HMENU)OPEN_FILE_BUTTON, NULL, NULL); 189 HWND open_button = CreateWindowW(L"Button", L"Open", WS_VISIBLE | WS_CHILD, (int)((225 - 50)/2), 5, 50, 20, hWnd, (HMENU)OPEN_FILE_BUTTON, NULL, NULL);
137 /* type */ 190 /* Type */
138 TCHAR listbox_items[][13] = {TEXT("VEGAS Pro"), TEXT("Movie Studio")}; 191 TCHAR listbox_items[][13] = {TEXT("VEGAS Pro"), TEXT("Movie Studio")};
139 hWndListBox = CreateWindowW(L"Listbox", NULL, WS_VISIBLE | WS_CHILD | LBS_STANDARD | LBS_NOTIFY, (int)((225 - 100)/2), 55, 100, 40, hWnd, (HMENU)LISTBOX, NULL, NULL); 192 hWndListBox = CreateWindowW(L"Listbox", NULL, WS_VISIBLE | WS_CHILD | LBS_STANDARD | LBS_NOTIFY, (int)((225 - 100)/2), 55, 100, 40, hWnd, (HMENU)LISTBOX, NULL, NULL);
140 for (i = 0; i < ARRAYSIZE(listbox_items); i++) { 193 for (i = 0; i < ARRAYSIZE(listbox_items); i++) {
141 int pos = (int)SendMessage(hWndListBox, LB_ADDSTRING, i, (LPARAM) listbox_items[i]); 194 int pos = (int)SendMessage(hWndListBox, LB_ADDSTRING, i, (LPARAM) listbox_items[i]);
142 SendMessage(hWndListBox, LB_SETITEMDATA, pos, (LPARAM) i); 195 SendMessage(hWndListBox, LB_SETITEMDATA, pos, (LPARAM) i);
143 } 196 }
144 SendMessage(hWndListBox, LB_SETCURSEL, (WPARAM)0, (LPARAM)0); 197 SendMessage(hWndListBox, LB_SETCURSEL, (WPARAM)0, (LPARAM)0);
145 /* save file */ 198 /* Save File */
146 HWND save_button = CreateWindowW(L"Button", L"Save", WS_VISIBLE | WS_CHILD, (int)((225 - 50)/2), 90, 50, 20, hWnd, (HMENU)SAVE_FILE_BUTTON, NULL, NULL); 199 HWND save_button = CreateWindowW(L"Button", L"Save", WS_VISIBLE | WS_CHILD, (int)((225 - 50)/2), 90, 50, 20, hWnd, (HMENU)SAVE_FILE_BUTTON, NULL, NULL);
147 if (open_button == NULL || save_button == NULL || hWndListBox == NULL || hWndComboBox == NULL) 200 if (open_button == NULL || save_button == NULL || hWndListBox == NULL || hWndComboBox == NULL)
148 MessageBoxW(hWnd, L"how did you even trigger this", L"GUI could not be initialized!", MB_ICONEXCLAMATION); 201 MessageBoxW(hWnd, L"how did you even trigger this", L"GUI could not be initialized!", MB_ICONEXCLAMATION);
149 } 202 }
150 203