mirror of https://github.com/bochs-emu/Bochs
- add "Create Image" button to floppy dialog, and make it actually work
This commit is contained in:
parent
7ab99b2ac9
commit
ef4b975884
|
@ -1,5 +1,5 @@
|
|||
/////////////////////////////////////////////////////////////////////////
|
||||
// $Id: siminterface.cc,v 1.47 2002-08-29 14:59:37 bdenney Exp $
|
||||
// $Id: siminterface.cc,v 1.48 2002-08-29 20:13:03 bdenney Exp $
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// See siminterface.h for description of the siminterface concept.
|
||||
|
@ -74,6 +74,7 @@ public:
|
|||
virtual int ask_filename (char *filename, int maxlen, char *prompt, char *the_default, int flags);
|
||||
// called at a regular interval, currently by the keyboard handler.
|
||||
virtual void periodic ();
|
||||
virtual int create_disk_image (const char *filename, int sectors, Boolean overwrite);
|
||||
};
|
||||
|
||||
bx_param_c *
|
||||
|
@ -303,6 +304,7 @@ bx_real_sim_c::get_cdrom_options (int drive, bx_cdrom_options *out)
|
|||
}
|
||||
|
||||
char *floppy_type_names[] = { "none", "1.2M", "1.44M", "2.88M", "720K", "360K", NULL };
|
||||
int floppy_type_n_sectors[] = { -1, 80*2*15, 80*2*18, 80*2*36, 80*2*9, 40*2*9 };
|
||||
int n_floppy_type_names = 6;
|
||||
char *floppy_status_names[] = { "ejected", "inserted", NULL };
|
||||
int n_floppy_status_names = 2;
|
||||
|
@ -412,6 +414,65 @@ bx_real_sim_c::periodic ()
|
|||
#endif
|
||||
}
|
||||
|
||||
// create a disk image file called filename, size=512 bytes * sectors.
|
||||
// If overwrite is true and the file exists, returns -1 without changing it.
|
||||
// Otherwise, opens up the image and starts writing. Returns -2 if
|
||||
// the image could not be opened, or -3 if there are failures during
|
||||
// write, e.g. disk full.
|
||||
//
|
||||
// wxWindows: This may be called from the gui thread.
|
||||
int
|
||||
bx_real_sim_c::create_disk_image (
|
||||
const char *filename,
|
||||
int sectors,
|
||||
Boolean overwrite)
|
||||
{
|
||||
FILE *fp;
|
||||
if (!overwrite) {
|
||||
// check for existence first
|
||||
fp = fopen (filename, "r");
|
||||
if (fp) {
|
||||
// yes it exists
|
||||
fclose (fp);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
fp = fopen (filename, "w");
|
||||
if (fp == NULL) {
|
||||
#ifdef HAVE_PERROR
|
||||
char buffer[1024];
|
||||
sprintf (buffer, "while opening '%s' for writing", filename);
|
||||
perror (buffer);
|
||||
// not sure how to get this back into the CI
|
||||
#endif
|
||||
return -2;
|
||||
}
|
||||
int sec = sectors;
|
||||
/*
|
||||
* seek to sec*512-1 and write a single character.
|
||||
* can't just do: fseek(fp, 512*sec-1, SEEK_SET)
|
||||
* because 512*sec may be too large for signed int.
|
||||
*/
|
||||
while (sec > 0)
|
||||
{
|
||||
/* temp <-- min(sec, 4194303)
|
||||
* 4194303 is (int)(0x7FFFFFFF/512)
|
||||
*/
|
||||
int temp = ((sec < 4194303) ? sec : 4194303);
|
||||
fseek(fp, 512*temp, SEEK_CUR);
|
||||
sec -= temp;
|
||||
}
|
||||
|
||||
fseek(fp, -1, SEEK_CUR);
|
||||
if (fputc('\0', fp) == EOF)
|
||||
{
|
||||
fclose (fp);
|
||||
return -3;
|
||||
}
|
||||
fclose (fp);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
// define methods of bx_param_* and family
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/////////////////////////////////////////////////////////////////////////
|
||||
// $Id: siminterface.h,v 1.50 2002-08-29 14:59:37 bdenney Exp $
|
||||
// $Id: siminterface.h,v 1.51 2002-08-29 20:13:05 bdenney Exp $
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Before I can describe what this file is for, I have to make the
|
||||
|
@ -700,6 +700,7 @@ public:
|
|||
#define BX_FLOPPY_GUESS 20 // decide based on image size
|
||||
|
||||
extern char *floppy_type_names[];
|
||||
extern int floppy_type_n_sectors[];
|
||||
extern int n_floppy_type_names;
|
||||
extern char *floppy_status_names[];
|
||||
extern int n_floppy_status_names;
|
||||
|
@ -810,6 +811,7 @@ public:
|
|||
virtual int ask_filename (char *filename, int maxlen, char *prompt, char *the_default, int flags) {return -1;}
|
||||
// called at a regular interval, currently by the keyboard handler.
|
||||
virtual void periodic () {}
|
||||
virtual int create_disk_image (const char *filename, int sectors, Boolean overwrite) {return -3;}
|
||||
};
|
||||
|
||||
extern bx_simulator_interface_c *SIM;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/////////////////////////////////////////////////////////////////
|
||||
// $Id: wxdialog.cc,v 1.5 2002-08-29 20:09:54 bdenney Exp $
|
||||
// $Id: wxdialog.cc,v 1.6 2002-08-29 20:13:05 bdenney Exp $
|
||||
/////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// misc/wxdialog.cc
|
||||
|
@ -162,6 +162,7 @@ void LogMsgAskDialog::ShowHelp ()
|
|||
// disk image file
|
||||
// filename
|
||||
// browse button
|
||||
// create button
|
||||
// capacitySizer (horizontal):
|
||||
// capacity text
|
||||
// capacity choice box
|
||||
|
@ -211,6 +212,8 @@ FloppyConfigDialog::FloppyConfigDialog(
|
|||
buttonSizer->Add (btn, 0, wxALL, 5);
|
||||
btn = new wxButton (this, wxCANCEL, "Cancel");
|
||||
buttonSizer->Add (btn, 0, wxALL, 5);
|
||||
btn = new wxButton (this, ID_Create, "Create Image");
|
||||
buttonSizer->Add (btn, 0, wxALL, 5);
|
||||
btn = new wxButton (this, wxOK, "Ok");
|
||||
buttonSizer->Add (btn, 0, wxALL, 5);
|
||||
// create filename and diskImageRadioBtn so that we can tweak them before
|
||||
|
@ -339,6 +342,16 @@ void FloppyConfigDialog::OnEvent(wxCommandEvent& event)
|
|||
SetFilename (fdialog->GetPath().c_str ());
|
||||
}
|
||||
break;
|
||||
case ID_Create:
|
||||
// create disk image with name and capacity determined by the filename
|
||||
// and capacity fields of this dialog. Call
|
||||
// SIM->create_image (filename, sectors, overwrite=0) first which
|
||||
// will create the file if it doesn't already exist. If it exists,
|
||||
// it will return a code that says so, and we can ask the user
|
||||
// "are you sure you want to overwrite?". If so call again with
|
||||
// overwrite=1.
|
||||
CreateImage ();
|
||||
break;
|
||||
case wxCANCEL:
|
||||
EndModal (-1);
|
||||
break;
|
||||
|
@ -348,6 +361,48 @@ void FloppyConfigDialog::OnEvent(wxCommandEvent& event)
|
|||
}
|
||||
}
|
||||
|
||||
void FloppyConfigDialog::CreateImage ()
|
||||
{
|
||||
int cap = capacity->GetSelection ();
|
||||
wxLogDebug ("capacity=%d\n", cap);
|
||||
wxLogDebug ("capacity string=%s\n", capacity->GetString (cap).c_str());
|
||||
if (capacity->GetString (cap).Cmp ("none") == 0
|
||||
|| !(cap>=0 && cap<n_floppy_type_names)) {
|
||||
wxMessageBox("You must choose a valid capacity for the new disk image", "Bad Capacity", wxOK | wxICON_ERROR );
|
||||
return;
|
||||
}
|
||||
|
||||
char name[1024];
|
||||
strncpy (name,
|
||||
filename->GetValue ().c_str (),
|
||||
filename->GetValue ().Length ());
|
||||
wxLogDebug ("filename = '%s'\n", name);
|
||||
if (strlen (name) < 1) {
|
||||
wxMessageBox("You must type a file name for the new disk image.", "Bad Filename", wxOK | wxICON_ERROR );
|
||||
return;
|
||||
}
|
||||
// try first with overwrite flag = 0
|
||||
int ret = SIM->create_disk_image (name, floppy_type_n_sectors[cap], 0);
|
||||
if (ret == -1) { // already exists
|
||||
int answer = wxMessageBox ("File exists. Do you want to overwrite it?",
|
||||
"File exists", wxYES_NO | wxCENTER);
|
||||
if (answer == wxYES)
|
||||
ret = SIM->create_disk_image (name, floppy_type_n_sectors[cap], 1);
|
||||
else
|
||||
return; // wxNO
|
||||
}
|
||||
if (ret == -2) {
|
||||
wxMessageBox("I could not create the disk image. Check for permission problems or available disk space.", "Failed", wxOK | wxICON_ERROR );
|
||||
return;
|
||||
}
|
||||
wxASSERT (ret==0);
|
||||
wxString s;
|
||||
s.Printf ("Created a %s disk image called '%s'.",
|
||||
capacity->GetString (cap).c_str (),
|
||||
filename->GetValue ().c_str ());
|
||||
wxMessageBox(s, "Image Created", wxOK | wxICON_INFORMATION);
|
||||
}
|
||||
|
||||
void FloppyConfigDialog::ShowHelp ()
|
||||
{
|
||||
wxMessageBox("No help is available yet.", "No Help", wxOK | wxICON_ERROR );
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
////////////////////////////////////////////////////////////////////
|
||||
// $Id: wxdialog.h,v 1.5 2002-08-29 20:09:54 bdenney Exp $
|
||||
// $Id: wxdialog.h,v 1.6 2002-08-29 20:13:05 bdenney Exp $
|
||||
////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// wxWindows dialogs for Bochs
|
||||
|
@ -77,7 +77,7 @@ DECLARE_EVENT_TABLE()
|
|||
// | Hint: To create a disk image, choose the name and capacity |
|
||||
// | above, then click Ok. |
|
||||
// | |
|
||||
// | [ Help ] [ Cancel ] [ Ok ] |
|
||||
// | [ Help ] [ Cancel ] [ Create Image ] [ Ok ] |
|
||||
// +---------------------------------------------------------------+
|
||||
// To use this dialog:
|
||||
// After constructor, use AddRadio () to add radio buttons, SetFilename()
|
||||
|
@ -97,7 +97,7 @@ public:
|
|||
#define FLOPPY_CONFIG_TITLE "Configure %s"
|
||||
#define FLOPPY_CONFIG_INSTRS "Select the device or image to use when simulating %s."
|
||||
#define FLOPPY_CONFIG_CAP "What is the capacity of this disk?"
|
||||
#define FLOPPY_CONFIG_HINT "Hint: To create a disk image, choose the name and capacity above, then click Ok."
|
||||
#define FLOPPY_CONFIG_HINT "To create a disk image, choose the file name and capacity, then click on \"Create Image\"."
|
||||
#define FLOPPY_CONFIG_DISKIMG "Disk image file: "
|
||||
private:
|
||||
void Init (); // called automatically by ShowModal()
|
||||
|
@ -128,6 +128,7 @@ public:
|
|||
void SetDriveName (const char *name);
|
||||
void SetValidateFunc (validateFunc_t v) { validate = v; }
|
||||
void AddRadio (char *description, char *filename);
|
||||
void CreateImage ();
|
||||
DECLARE_EVENT_TABLE()
|
||||
};
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/////////////////////////////////////////////////////////////////
|
||||
// $Id: wxmain.h,v 1.8 2002-08-29 14:59:37 bdenney Exp $
|
||||
// $Id: wxmain.h,v 1.9 2002-08-29 20:13:05 bdenney Exp $
|
||||
/////////////////////////////////////////////////////////////////
|
||||
// This file defines variables and classes that the wxWindows .cc files
|
||||
// share. It should be included only by wx.cc and wxmain.cc.
|
||||
|
@ -72,6 +72,7 @@ enum
|
|||
ID_Filename,
|
||||
ID_FilenameText,
|
||||
ID_Browse,
|
||||
ID_Create,
|
||||
// dialog box: HDConfigDialog
|
||||
ID_Enable,
|
||||
ID_Cylinders,
|
||||
|
|
Loading…
Reference in New Issue