/[pcsx2_0.9.7]/branch/debug/0.X/0.9.X/0.9.7/r3113/plugins/CDVDiso/src/Windows/Win32.cpp
ViewVC logotype

Contents of /branch/debug/0.X/0.9.X/0.9.7/r3113/plugins/CDVDiso/src/Windows/Win32.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 59 - (show annotations) (download)
Tue Sep 7 06:17:51 2010 UTC (10 years, 8 months ago) by william
File size: 7462 byte(s)
create working branch for pcsx2-0.9.7-r3113-debug
1 #include <windows.h>
2 #include <windowsx.h>
3 #include <commctrl.h>
4 #include <stdio.h>
5 #include <stdarg.h>
6 #include <direct.h>
7 #include <sys/stat.h>
8 #include <string.h>
9
10 #include <zlib/zlib.h>
11
12
13 #include "Config.h"
14 #include "../CDVDiso.h"
15 #include "resource.h"
16
17 HINSTANCE hInst;
18 #define MAXFILENAME 256
19
20 u8 Zbuf[2352 * 10 * 2];
21 HWND hDlg;
22 HWND hProgress;
23 HWND hIsoFile;
24 HWND hMethod;
25 HWND hBlockDump;
26 int stop;
27
28 void SysMessage(char *fmt, ...)
29 {
30 va_list list;
31 char tmp[512];
32
33 va_start(list, fmt);
34 vsprintf(tmp, fmt, list);
35 va_end(list);
36 MessageBox(GetActiveWindow(), tmp, "CDVDiso Msg", 0);
37 }
38
39 int _GetFile(char *out)
40 {
41 OPENFILENAME ofn;
42 char szFileName[MAXFILENAME];
43 char szFileTitle[MAXFILENAME];
44
45 memset(&szFileName, 0, sizeof(szFileName));
46 memset(&szFileTitle, 0, sizeof(szFileTitle));
47
48 ofn.lStructSize = sizeof(OPENFILENAME);
49 ofn.hwndOwner = GetActiveWindow();
50 ofn.lpstrFilter =
51 "Supported Formats\0*.bin;*.iso;*.img;*.nrg;*.mdf;*.Z;*.Z2;*.BZ2;*.dump\0"
52 "Cd Iso Format (*.bin;*.iso;*.img;*.nrg;*.mdf)\0"
53 "*.bin;*.iso;*.img;*.nrg;*.mdf\0"
54 "Compressed Z Iso Format (*.Z;*.Z2)\0"
55 "*.Z;*.Z2\0Compressed BZ Iso Format (*.BZ2)\0"
56 "*.BZ2\0Block Dumps (*.dump)\0*.dump\0All Files\0*.*\0";
57
58 ofn.lpstrCustomFilter = NULL;
59 ofn.nMaxCustFilter = 0;
60 ofn.nFilterIndex = 1;
61 ofn.lpstrFile = szFileName;
62 ofn.nMaxFile = MAXFILENAME;
63 ofn.lpstrInitialDir = (IsoCWD[0] == 0) ? NULL : IsoCWD;
64 ofn.lpstrFileTitle = szFileTitle;
65 ofn.nMaxFileTitle = MAXFILENAME;
66 ofn.lpstrTitle = NULL;
67 ofn.lpstrDefExt = NULL;
68 ofn.Flags = OFN_HIDEREADONLY;
69
70 if (GetOpenFileName((LPOPENFILENAME)&ofn))
71 {
72 strcpy(out, szFileName);
73 return 1;
74 }
75
76 return 0;
77 }
78
79 int _OpenFile(int saveConf)
80 {
81
82 int retval = 0;
83
84 // for saving the pcsx2 current working directory;
85 char* cwd_pcsx2 = _getcwd(NULL, MAXFILENAME);
86
87 if (IsoCWD[0] != 0)
88 _chdir(IsoCWD);
89
90 if (_GetFile(IsoFile) == 1)
91 {
92 // Save the user's new cwd:
93 if (_getcwd(IsoCWD, MAXFILENAME) == NULL)
94 IsoCWD[0] = 0;
95
96 if (saveConf)
97 SaveConf();
98
99 retval = 1;
100 }
101
102 // Restore Pcsx2's path.
103 if (cwd_pcsx2 != NULL)
104 {
105 _chdir(cwd_pcsx2);
106 free(cwd_pcsx2);
107 cwd_pcsx2 = NULL;
108 }
109 return retval;
110 }
111
112 void CfgOpenFile()
113 {
114 _OpenFile(TRUE);
115 }
116
117 void UpdZmode()
118 {
119 if (ComboBox_GetCurSel(hMethod) == 0)
120 {
121 Zmode = 1;
122 }
123 else
124 {
125 Zmode = 2;
126 }
127 }
128
129
130 void SysUpdate()
131 {
132 MSG msg;
133
134 while (PeekMessage(&msg, NULL, 0U, 0U, PM_REMOVE))
135 {
136 TranslateMessage(&msg);
137 DispatchMessage(&msg);
138 }
139 }
140
141 void OnCompress()
142 {
143 u32 lsn;
144 u8 cdbuff[10*2352];
145 char Zfile[256];
146 int ret;
147 isoFile *src;
148 isoFile *dst;
149
150 Edit_GetText(hIsoFile, IsoFile, 256);
151 UpdZmode();
152
153 if (Zmode == 1)
154 {
155 sprintf(Zfile, "%s.Z2", IsoFile);
156 }
157 else
158 {
159 sprintf(Zfile, "%s.BZ2", IsoFile);
160 }
161
162 src = isoOpen(IsoFile);
163 if (src == NULL) return;
164 if (Zmode == 1)
165 {
166 dst = isoCreate(Zfile, ISOFLAGS_Z2);
167 }
168 else
169 {
170 dst = isoCreate(Zfile, ISOFLAGS_BZ2);
171 }
172 if (dst == NULL) return;
173
174 isoSetFormat(dst, src->blockofs, src->blocksize, src->blocks);
175 Button_Enable(GetDlgItem(hDlg, IDC_COMPRESSISO), FALSE);
176 Button_Enable(GetDlgItem(hDlg, IDC_DECOMPRESSISO), FALSE);
177 stop = 0;
178
179 for (lsn = 0; lsn < src->blocks; lsn++)
180 {
181 //printf("block %d ", lsn);
182 //putchar(13);
183 //fflush(stdout);
184 ret = isoReadBlock(src, cdbuff, lsn);
185 if (ret == -1) break;
186 ret = isoWriteBlock(dst, cdbuff, lsn);
187 if (ret == -1) break;
188
189 SendMessage(hProgress, PBM_SETPOS, (lsn * 100) / src->blocks, 0);
190 SysUpdate();
191 if (stop) break;
192 }
193 isoClose(src);
194 isoClose(dst);
195
196 if (!stop) Edit_SetText(hIsoFile, Zfile);
197
198 Button_Enable(GetDlgItem(hDlg, IDC_COMPRESSISO), TRUE);
199 Button_Enable(GetDlgItem(hDlg, IDC_DECOMPRESSISO), TRUE);
200
201 if (!stop)
202 {
203 if (ret == -1)
204 {
205 SysMessage("Error compressing iso image");
206 }
207 else
208 {
209 SysMessage("Iso image compressed OK");
210 }
211 }
212 }
213
214 void OnDecompress()
215 {
216 char file[256];
217 u8 cdbuff[10*2352];
218 u32 lsn;
219 isoFile *src;
220 isoFile *dst;
221 int ret;
222
223 Edit_GetText(hIsoFile, IsoFile, 256);
224
225 src = isoOpen(IsoFile);
226 if (src == NULL) return;
227
228 strcpy(file, IsoFile);
229 if (src->flags & ISOFLAGS_Z)
230 {
231 file[strlen(file) - 2] = 0;
232 }
233 else
234 if (src->flags & ISOFLAGS_Z2)
235 {
236 file[strlen(file) - 3] = 0;
237 }
238 else
239 if (src->flags & ISOFLAGS_BZ2)
240 {
241 file[strlen(file) - 3] = 0;
242 }
243 else
244 {
245 SysMessage("%s is not a compressed image", IsoFile);
246 return;
247 }
248
249 dst = isoCreate(file, 0);
250 if (dst == NULL) return;
251
252 isoSetFormat(dst, src->blockofs, src->blocksize, src->blocks);
253 Button_Enable(GetDlgItem(hDlg, IDC_COMPRESSISO), FALSE);
254 Button_Enable(GetDlgItem(hDlg, IDC_DECOMPRESSISO), FALSE);
255 stop = 0;
256
257 for (lsn = 0; lsn < src->blocks; lsn++)
258 {
259 printf("block %d ", lsn);
260 putchar(13);
261 fflush(stdout);
262 ret = isoReadBlock(src, cdbuff, lsn);
263 if (ret == -1) break;
264 ret = isoWriteBlock(dst, cdbuff, lsn);
265 if (ret == -1) break;
266
267 SendMessage(hProgress, PBM_SETPOS, (lsn * 100) / src->blocks, 0);
268 SysUpdate();
269 if (stop) break;
270 }
271 if (!stop) Edit_SetText(hIsoFile, file);
272
273 isoClose(src);
274 isoClose(dst);
275
276 Button_Enable(GetDlgItem(hDlg, IDC_COMPRESSISO), TRUE);
277 Button_Enable(GetDlgItem(hDlg, IDC_DECOMPRESSISO), TRUE);
278
279 if (!stop)
280 {
281 if (ret == -1)
282 {
283 SysMessage("Error decompressing iso image");
284 }
285 else
286 {
287 SysMessage("Iso image decompressed OK");
288 }
289 }
290 }
291
292 BOOL CALLBACK ConfigureDlgProc(HWND hW, UINT uMsg, WPARAM wParam, LPARAM lParam)
293 {
294 int i;
295
296 switch (uMsg)
297 {
298 case WM_INITDIALOG:
299 hDlg = hW;
300 LoadConf();
301
302 hProgress = GetDlgItem(hW, IDC_PROGRESS);
303 hIsoFile = GetDlgItem(hW, IDC_ISOFILE);
304 hMethod = GetDlgItem(hW, IDC_METHOD);
305 hBlockDump = GetDlgItem(hW, IDC_BLOCKDUMP);
306
307 for (i = 0; methods[i] != NULL; i++)
308 {
309 ComboBox_AddString(hMethod, methods[i]);
310 }
311
312 Edit_SetText(hIsoFile, IsoFile);
313 ComboBox_SetCurSel(hMethod, 0);
314 /* if (strstr(IsoFile, ".Z") != NULL)
315 ComboBox_SetCurSel(hMethod, 1);
316 else ComboBox_SetCurSel(hMethod, 0);*/
317 Button_SetCheck(hBlockDump, BlockDump);
318
319 return TRUE;
320
321 case WM_COMMAND:
322 switch (LOWORD(wParam))
323 {
324 case IDC_SELECTISO:
325 if (_OpenFile(FALSE) == 1)
326 Edit_SetText(hIsoFile, IsoFile);
327 return TRUE;
328
329 case IDC_COMPRESSISO:
330 OnCompress();
331 return TRUE;
332
333 case IDC_DECOMPRESSISO:
334 OnDecompress();
335 return TRUE;
336
337 case IDC_STOP:
338 stop = 1;
339 return TRUE;
340
341 case IDCANCEL:
342 EndDialog(hW, TRUE);
343 return TRUE;
344
345 case IDOK:
346 Edit_GetText(hIsoFile, IsoFile, 256);
347 BlockDump = Button_GetCheck(hBlockDump);
348
349 SaveConf();
350 EndDialog(hW, FALSE);
351 return TRUE;
352 }
353 }
354 return FALSE;
355 }
356
357 EXPORT_C_(void) CDVDconfigure()
358 {
359 DialogBox(hInst,
360 MAKEINTRESOURCE(IDD_CONFIG),
361 GetActiveWindow(),
362 (DLGPROC)ConfigureDlgProc);
363 }
364
365 BOOL CALLBACK AboutDlgProc(HWND hW, UINT uMsg, WPARAM wParam, LPARAM lParam)
366 {
367 switch (uMsg)
368 {
369 case WM_INITDIALOG:
370 return TRUE;
371
372 case WM_COMMAND:
373 switch (LOWORD(wParam))
374 {
375 case IDOK:
376 EndDialog(hW, TRUE);
377 return FALSE;
378 }
379 }
380 return FALSE;
381 }
382
383 EXPORT_C_(void) CDVDabout()
384 {
385 DialogBox(hInst,
386 MAKEINTRESOURCE(IDD_ABOUT),
387 GetActiveWindow(),
388 (DLGPROC)AboutDlgProc);
389 }
390
391 BOOL APIENTRY DllMain(HANDLE hModule, // DLL INIT
392 DWORD dwReason,
393 LPVOID lpReserved)
394 {
395 hInst = (HINSTANCE)hModule;
396 return TRUE; // very quick :)
397 }
398

  ViewVC Help
Powered by ViewVC 1.1.22