Mercurial > msvpvf
comparison src/iup.c @ 88:af4ed765c1ac
*: add IUP GUI
a lot simpler than win32, but I assume there's more going on in
the background that I don't know about :)
author | Paper <paper@tflc.us> |
---|---|
date | Mon, 14 Jul 2025 02:39:24 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
87:2e819b84d7c0 | 88:af4ed765c1ac |
---|---|
1 #include "common.h" | |
2 | |
3 #include <iup.h> | |
4 #include <stddef.h> | |
5 #include <stdio.h> | |
6 #include <stdlib.h> | |
7 | |
8 struct msvpvf { | |
9 struct { | |
10 Ihandle *main; /* main window */ | |
11 Ihandle *program; /* listbox, which program (Vegas Pro/Movie Studio) */ | |
12 Ihandle *ver; /* which version */ | |
13 Ihandle *vbox; /* main window vbox */ | |
14 Ihandle *ofilebtn; /* open file button */ | |
15 Ihandle *sfilebtn; /* save file button */ | |
16 Ihandle *info; /* opened file info */ | |
17 Ihandle *about_button; /* about button */ | |
18 Ihandle *about; /* about dialog */ | |
19 Ihandle *about_text; /* about text */ | |
20 } dlg; | |
21 | |
22 /* XXX this should be FILE *, so we can't randomly lose the file */ | |
23 char *open_file; | |
24 | |
25 uint8_t version; | |
26 enum types type; | |
27 }; | |
28 | |
29 static int msvpvf_info_update(struct msvpvf *m) | |
30 { | |
31 uint8_t ver; | |
32 enum types type; | |
33 char *a; | |
34 | |
35 if (!m) return -1; | |
36 | |
37 { | |
38 FILE *i; | |
39 | |
40 i = fopen(m->open_file, "rb"); | |
41 if (!i) return 0; | |
42 | |
43 get_file_information(i, &ver, &type); | |
44 fclose(i); | |
45 } | |
46 | |
47 a = msvpvf_asprintf("File version: %s %d", type_names[type], (int)ver); | |
48 if (!a) return 0; | |
49 IupSetStrAttribute(m->dlg.info, "VALUE", a); | |
50 free(a); | |
51 | |
52 return 1; | |
53 } | |
54 | |
55 static int open_file(Ihandle *ih) | |
56 { | |
57 /* why is IupGetAttribute not void * */ | |
58 struct msvpvf *m = (struct msvpvf *)IupGetAttribute(ih, "msvpvf"); | |
59 const char *ofile; | |
60 Ihandle *dlg = IupFileDlg(); | |
61 | |
62 IupSetAttribute(dlg, "DIALOGTYPE", "OPEN"); | |
63 IupSetAttribute(dlg, "TITLE", "Vegas Pro / Movie Studio version spoofer"); | |
64 IupSetAttributes(dlg, "FILTER = \"*.veg;*.vf\", FILTERINFO = \"Project files\""); | |
65 | |
66 IupPopup(dlg, IUP_CURRENT, IUP_CURRENT); | |
67 | |
68 if (IupGetInt(dlg, "STATUS") != -1) { | |
69 m->open_file = str_dup(IupGetAttribute(dlg, "VALUE")); | |
70 if (!msvpvf_info_update(m)) | |
71 free(m->open_file); | |
72 } | |
73 | |
74 IupDestroy(dlg); | |
75 return 0; | |
76 } | |
77 | |
78 static int save_file(Ihandle *ih) | |
79 { | |
80 struct msvpvf *m = (struct msvpvf *)IupGetAttribute(ih, "msvpvf"); | |
81 Ihandle *dlg; | |
82 | |
83 if (!m->open_file) | |
84 return 0; | |
85 | |
86 dlg = IupFileDlg(); | |
87 | |
88 IupSetAttribute(dlg, "DIALOGTYPE", "SAVE"); | |
89 IupSetAttribute(dlg, "TITLE", "Vegas Pro / Movie Studio version spoofer"); | |
90 /* FIXME add *.vf here */ | |
91 IupSetAttributes(dlg, "FILTER = \"*.veg;*.vf\", FILTERINFO = \"Project files\""); | |
92 IupSetAttribute(dlg, "EXTDEFAULT", (m->type == TYPES_VF ? "vf" : "veg")); | |
93 | |
94 IupPopup(dlg, IUP_CURRENT, IUP_CURRENT); | |
95 | |
96 if (IupGetInt(dlg, "STATUS") != -1) { | |
97 FILE *i, *o; | |
98 const char *sname; | |
99 | |
100 sname = IupGetAttribute(dlg, "VALUE"); | |
101 | |
102 i = fopen(m->open_file, "rb"); | |
103 o = fopen(sname, "wb"); | |
104 | |
105 if (i && o && (copy_file(i, o) >= 0)) | |
106 set_file_information(o, m->version, m->type); | |
107 | |
108 if (i) fclose(i); | |
109 if (o) fclose(o); | |
110 } | |
111 | |
112 IupDestroy(dlg); | |
113 return 0; | |
114 } | |
115 | |
116 static int type_cb(Ihandle *ih, char *text, int item, int state) | |
117 { | |
118 struct msvpvf *m = (struct msvpvf *)IupGetAttribute(ih, "msvpvf"); | |
119 | |
120 switch (item) { | |
121 case 1: m->type = TYPES_VEG; break; | |
122 case 2: m->type = TYPES_VF; break; | |
123 default: abort(); | |
124 } | |
125 | |
126 return 0; | |
127 } | |
128 | |
129 static int ver_cb(Ihandle *ih) | |
130 { | |
131 struct msvpvf *m = (struct msvpvf *)IupGetAttribute(ih, "msvpvf"); | |
132 | |
133 /* epic */ | |
134 m->version = IupGetIntId(ih, "SPINVALUE", 11); | |
135 | |
136 return 0; | |
137 } | |
138 | |
139 static int about_cb(Ihandle *ih) | |
140 { | |
141 struct msvpvf *m = (struct msvpvf *)IupGetAttribute(ih, "msvpvf"); | |
142 | |
143 IupPopup(m->dlg.about, IUP_CURRENT, IUP_CURRENT); | |
144 | |
145 return 0; | |
146 } | |
147 | |
148 int main(int argc, char *argv[]) | |
149 { | |
150 struct msvpvf msvpvf; | |
151 static const char about_text[] = { | |
152 #embed "../LICENSE" | |
153 , 0 /* nul terminate */ | |
154 }; | |
155 | |
156 IupOpen(&argc, &argv); | |
157 IupSetLanguage("ENGLISH"); | |
158 | |
159 // FIXME: use UTF-8 filenames on Windows | |
160 | |
161 msvpvf.dlg.ofilebtn = IupButton("Open File", NULL); | |
162 IupSetAttribute(msvpvf.dlg.ofilebtn, "msvpvf", (char *)&msvpvf); | |
163 IupSetCallback(msvpvf.dlg.ofilebtn, "ACTION", open_file); | |
164 | |
165 msvpvf.dlg.info = IupText(NULL); | |
166 IupSetAttribute(msvpvf.dlg.info, "READONLY", "YES"); | |
167 IupSetAttribute(msvpvf.dlg.info, "VISIBLECOLUMNS", "15"); | |
168 IupSetAttribute(msvpvf.dlg.info, "VALUE", "No file opened!"); | |
169 IupSetAttribute(msvpvf.dlg.info, "ALIGNMENT", "ACENTER"); | |
170 IupSetAttribute(msvpvf.dlg.info, "CANFOCUS", "NO"); | |
171 IupSetAttribute(msvpvf.dlg.info, "BORDER", "NO"); | |
172 | |
173 msvpvf.dlg.program = IupList(NULL); | |
174 IupSetAttribute(msvpvf.dlg.program, "msvpvf", (char *)&msvpvf); | |
175 IupSetAttribute(msvpvf.dlg.program, "ALIGNMENT", "ACENTER"); | |
176 IupSetAttribute(msvpvf.dlg.program, "1", "Vegas Pro"); | |
177 IupSetAttribute(msvpvf.dlg.program, "2", "Movie Studio"); | |
178 IupSetAttribute(msvpvf.dlg.program, "3", NULL); | |
179 IupSetAttribute(msvpvf.dlg.program, "VALUE", "1"); | |
180 IupSetAttribute(msvpvf.dlg.program, "EXPAND", "YES"); | |
181 IupSetCallback(msvpvf.dlg.program, "ACTION", (Icallback)type_cb); | |
182 msvpvf.type = TYPES_VEG; | |
183 | |
184 msvpvf.dlg.ver = IupText(NULL); | |
185 IupSetAttribute(msvpvf.dlg.ver, "msvpvf", (char *)&msvpvf); | |
186 IupSetAttribute(msvpvf.dlg.ver, "SPIN", "YES"); | |
187 IupSetAttribute(msvpvf.dlg.ver, "SPINMAX", "21"); | |
188 IupSetAttribute(msvpvf.dlg.ver, "SPINMIN", "8"); | |
189 IupSetAttribute(msvpvf.dlg.ver, "SPINVALUE", "11"); /* default */ | |
190 IupSetCallback(msvpvf.dlg.ver, "ACTION", ver_cb); | |
191 msvpvf.version = 11; | |
192 | |
193 msvpvf.dlg.sfilebtn = IupButton("Save File", NULL); | |
194 IupSetAttribute(msvpvf.dlg.sfilebtn, "msvpvf", (char *)&msvpvf); | |
195 IupSetCallback(msvpvf.dlg.sfilebtn, "ACTION", save_file); | |
196 | |
197 msvpvf.dlg.about_button = IupButton("About msvpvf", NULL); | |
198 IupSetAttribute(msvpvf.dlg.about_button, "msvpvf", (char *)&msvpvf); | |
199 IupSetCallback(msvpvf.dlg.about_button, "ACTION", about_cb); | |
200 | |
201 msvpvf.dlg.vbox = IupVbox(msvpvf.dlg.ofilebtn, msvpvf.dlg.info, msvpvf.dlg.program, msvpvf.dlg.ver, msvpvf.dlg.sfilebtn, msvpvf.dlg.about_button, NULL); | |
202 IupSetAttribute(msvpvf.dlg.vbox, "ALIGNMENT", "ACENTER"); | |
203 IupSetAttribute(msvpvf.dlg.vbox, "GAP", "10"); | |
204 IupSetAttribute(msvpvf.dlg.vbox, "MARGIN", "10x10"); | |
205 IupSetAttribute(msvpvf.dlg.vbox, "EXPAND", "YES"); | |
206 | |
207 msvpvf.dlg.main = IupDialog(msvpvf.dlg.vbox); | |
208 IupSetAttribute(msvpvf.dlg.main, "TITLE", "Vegas Pro / Movie Studio version spoofer"); | |
209 //IupSetAttribute(msvpvf.dlg.main, "MINSIZE", "225x200"); | |
210 | |
211 msvpvf.dlg.about_text = IupText(NULL); | |
212 IupSetAttribute(msvpvf.dlg.about_text, "READONLY", "YES"); | |
213 IupSetAttribute(msvpvf.dlg.about_text, "VALUE", about_text); | |
214 IupSetAttribute(msvpvf.dlg.about_text, "CANFOCUS", "NO"); | |
215 IupSetAttribute(msvpvf.dlg.about_text, "BORDER", "NO"); | |
216 IupSetAttribute(msvpvf.dlg.about_text, "MULTILINE", "YES"); | |
217 IupSetAttribute(msvpvf.dlg.about_text, "EXPAND", "YES"); | |
218 IupSetAttribute(msvpvf.dlg.about_text, "PADDING", "10x10"); | |
219 | |
220 msvpvf.dlg.about = IupDialog(msvpvf.dlg.about_text); | |
221 IupSetAttribute(msvpvf.dlg.about, "TITLE", "About Vegas Pro / Movie Studio version spoofer"); | |
222 IupSetAttribute(msvpvf.dlg.about, "MINSIZE", "500x300"); | |
223 | |
224 IupShowXY(msvpvf.dlg.main, IUP_CENTER, IUP_CENTER); | |
225 | |
226 IupMainLoop(); | |
227 | |
228 IupClose(); | |
229 | |
230 return 0; | |
231 } |