@@ -28,9 +28,12 @@ This file is part of VCC (Virtual Color Computer).
2828#include " cloud9.h"
2929#include " ..\fileops.h"
3030
31+ #define DEF_HD_SIZE 132480
32+
3133static char VHDfile0[MAX_PATH] { 0 };
3234static char VHDfile1[MAX_PATH] { 0 };
3335static char *VHDfile; // Selected drive file name
36+ static char NewVHDfile[MAX_PATH];
3437static char IniFile[MAX_PATH] { 0 };
3538static char HardDiskPath[MAX_PATH];
3639
@@ -52,7 +55,7 @@ void LoadHardDisk(int drive);
5255void LoadConfig (void );
5356void SaveConfig (void );
5457void BuildDynaMenu (void );
55- BOOL CreateDisk (int );
58+ int CreateDisk (HWND, int );
5659
5760static HINSTANCE g_hinstDLL;
5861
@@ -285,13 +288,16 @@ void LoadHardDisk(int drive)
285288 return ;
286289 }
287290
291+ strncpy (NewVHDfile,VHDfile,MAX_PATH);
292+ HWND hWnd = GetActiveWindow ();
293+
288294 // Prompt user for vhd filename
289295 memset (&ofn,0 ,sizeof (ofn));
290296 ofn.lStructSize = sizeof (OPENFILENAME) ;
291- ofn.hwndOwner = NULL ;
297+ ofn.hwndOwner = hWnd ;
292298 ofn.lpstrFilter = " HardDisk Images\0 *.vhd\0\0 " ; // filter VHD images
293299 ofn.nFilterIndex = 1 ; // current filter index
294- ofn.lpstrFile = VHDfile; // full filename on return
300+ ofn.lpstrFile = NewVHDfile; // full filename on return
295301 ofn.nMaxFile = MAX_PATH; // sizeof lpstrFile
296302 ofn.lpstrFileTitle = NULL ; // filename only
297303 ofn.nMaxFileTitle = MAX_PATH ; // sizeof lpstrFileTitle
@@ -302,22 +308,25 @@ void LoadHardDisk(int drive)
302308 if (GetOpenFileName (&ofn)) {
303309
304310 // Append .vhd file type if type missing
305- if (ofn.nFileExtension ==0 ) strncat (VHDfile ," .vhd" ,MAX_PATH);
311+ if (ofn.nFileExtension ==0 ) strncat (NewVHDfile ," .vhd" ,MAX_PATH);
306312
307313 // Present new disk dialog if file does not exist
308- // Dialog box clears VHD file name if it is not created
309- if (GetFileAttributes (VHDfile) == INVALID_FILE_ATTRIBUTES) {
310- DialogBox ( g_hinstDLL, (LPCTSTR)IDD_NEWDISK,
311- GetActiveWindow (), (DLGPROC) NewDisk);
312- if (*VHDfile == ' \0 ' ) return ;
314+ if (GetFileAttributes (NewVHDfile) == INVALID_FILE_ATTRIBUTES) {
315+ // Dialog box returns zero if file is not created
316+ if (DialogBox (g_hinstDLL,(LPCTSTR)IDD_NEWDISK,hWnd,(DLGPROC)NewDisk)==0 )
317+ return ;
313318 }
314319
315320 // Actual file mount is done in cc3vhd
316- if (MountHD (VHDfile,drive)==0 ) {
317- snprintf (msg,300 ," Can't open %s" ,VHDfile);
318- MessageBox (NULL ,msg," Error" ,0 );
321+ if (MountHD (NewVHDfile,drive)==0 ) {
322+ snprintf (msg,300 ," Can't mount %s" ,NewVHDfile);
323+ MessageBox (hWnd,msg," Error" ,0 );
324+ *VHDfile = ' \0 ' ;
325+ return ;
319326 }
320327
328+ strncpy (VHDfile,NewVHDfile,MAX_PATH);
329+
321330 // Save vhd directory for config file
322331 string tmp = ofn.lpstrFile ;
323332 int idx;
@@ -423,42 +432,38 @@ void BuildDynaMenu(void)
423432// Dialog for creating a new hard disk
424433LRESULT CALLBACK NewDisk (HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
425434{
426- unsigned int hdsize=0 ;
427-
435+ unsigned int hdsize=DEF_HD_SIZE;
428436 switch (message)
429437 {
430438 case WM_INITDIALOG:
431- SetDlgItemInt (hDlg,IDC_HDSIZE,hdsize ,0 );
439+ SetDlgItemInt (hDlg,IDC_HDSIZE,DEF_HD_SIZE ,0 );
432440 return TRUE ;
433- break ;
434441
435442 case WM_COMMAND:
436443 switch (LOWORD (wParam)) {
437444 case IDOK:
438445 hdsize=GetDlgItemInt (hDlg,IDC_HDSIZE,NULL ,0 );
439- EndDialog (hDlg, LOWORD (wParam ));
440- return CreateDisk (hdsize) ;
446+ EndDialog (hDlg,CreateDisk (hDlg,hdsize ));
447+ break ;
441448
442449 case IDCANCEL:
443- // Clear file name so LoadHardDisk knows
444- strcpy (VHDfile," " );
445- EndDialog (hDlg, LOWORD (wParam));
446- return FALSE ;
450+ EndDialog (hDlg,0 );
451+ break ;
447452 }
448- return TRUE ;
449453 break ;
450454 }
451455 return FALSE ;
452456}
453457
454- BOOL CreateDisk (int hdsize)
458+ // Create a new disk file, return 1 on success
459+ int CreateDisk (HWND hDlg, int hdsize)
455460{
456- HANDLE hr=CreateFile ( VHDfile , GENERIC_READ | GENERIC_WRITE,
461+ HANDLE hr=CreateFile ( NewVHDfile , GENERIC_READ | GENERIC_WRITE,
457462 0 ,0 ,CREATE_NEW,FILE_ATTRIBUTE_NORMAL,0 );
458463 if (hr==INVALID_HANDLE_VALUE) {
459- strcpy (VHDfile, " " ) ;
460- MessageBox (0 ," Can't create File" ," Error" ,0 );
461- return ( 0 ) ;
464+ *NewVHDfile= ' \0 ' ;
465+ MessageBox (hDlg ," Can't create File" ," Error" ,0 );
466+ return 0 ;
462467 }
463468
464469 if (hdsize>0 ) {
@@ -467,5 +472,5 @@ BOOL CreateDisk(int hdsize)
467472 }
468473
469474 CloseHandle (hr);
470- return ( 1 ) ;
475+ return 1 ;
471476}
0 commit comments