static int set_attach_device_readonly(int value, void *param) { unsigned int unit = vice_ptr_to_uint(param); const char *old_filename; char *new_filename; int rc; int val = value ? 1 : 0; /* Do nothing if resource is unchanged. */ if (attach_device_readonly_enabled[unit - 8] == val) { return 0; } old_filename = file_system_get_disk_name(unit); /* If no disk is attached, just changed the resource. */ if (old_filename == NULL) { attach_device_readonly_enabled[unit - 8] = val; return 0; } /* Old filename will go away after the image is detached. */ new_filename = lib_stralloc(old_filename); file_system_detach_disk(unit); attach_device_readonly_enabled[unit - 8] = val; rc = file_system_attach_disk(unit, new_filename); lib_free(new_filename); return rc; }
static TUI_MENU_CALLBACK(attach_disk_callback) { const char *s; if (been_activated) { char *default_item, *directory; char *name, *file; unsigned int file_number = 0; s = file_system_get_disk_name((unsigned int)param); util_fname_split(s, &directory, &default_item); name = tui_file_selector("Attach a disk image", directory, "*.d64;*.d71;*.d81;*.g64;*.g41;*.x64;*.p64;*.d80;*.d82;*.d67;*.d1m;*.d2m;*.d4m;" "*.d6z;*.d7z;*.d8z;*.g6z;*.g4z;*.x6z;*.zip;*.gz;*.lzh", default_item, diskcontents_filesystem_read, &file, &file_number); if (file_number > 0) { if (autostart_disk(name, NULL, file_number, AUTOSTART_MODE_RUN) < 0) { tui_error("Cannot autostart disk image."); } else { *behavior = TUI_MENU_BEH_RESUME; } } else if (name != NULL && (s == NULL || strcasecmp(name, s) != 0) && file_system_attach_disk((int)param, name) < 0) { tui_error("Invalid disk image."); } lib_free(file); ui_update_menus(); lib_free(directory); lib_free(default_item); lib_free(name); } s = file_system_get_disk_name((unsigned int)param); if (s == NULL || *s == '\0') { return "(none)"; } else { return s; } }
static TUI_MENU_CALLBACK(detach_disk_callback) { const char *s; if (been_activated) { file_system_detach_disk((int)param); ui_update_menus(); } s = file_system_get_disk_name((unsigned int)param); if (s == NULL || *s == '\0') { return "(none)"; } else { return s; } }
static BOOL store_dialog_results(HWND hwnd, unsigned int num) { char s[MAX_PATH]; TCHAR st[MAX_PATH]; int devtype = ATTACH_DEVICE_NONE; if (iec_available_busses() & IEC_BUS_IEC) { resources_set_int_sprintf("IECDevice%d", (IsDlgButtonChecked(hwnd, IDC_TOGGLE_USEIECDEVICE) == BST_CHECKED), num); } if (IsDlgButtonChecked(hwnd, IDC_SELECTDISK) == BST_CHECKED || IsDlgButtonChecked(hwnd, IDC_SELECTDIR) == BST_CHECKED) { devtype = ATTACH_DEVICE_FS; } #ifdef HAVE_OPENCBM if (opencbmlib_is_available()) { if (IsDlgButtonChecked(hwnd, IDC_SELECTREAL) == BST_CHECKED) { devtype = ATTACH_DEVICE_REAL; } } #endif resources_set_int_sprintf("FileSystemDevice%d", devtype, num); resources_set_int_sprintf("FSDevice%dConvertP00", (IsDlgButtonChecked(hwnd, IDC_TOGGLE_READP00) == BST_CHECKED), num); resources_set_int_sprintf("FSDevice%dSaveP00", (IsDlgButtonChecked(hwnd, IDC_TOGGLE_WRITEP00) == BST_CHECKED), num); resources_set_int_sprintf("FSDevice%dHideCBMFiles", (IsDlgButtonChecked(hwnd, IDC_TOGGLE_HIDENONP00) == BST_CHECKED), num); resources_set_int_sprintf("AttachDevice%dReadonly", (IsDlgButtonChecked(hwnd, IDC_TOGGLE_ATTACH_READONLY) == BST_CHECKED), num); GetDlgItemText(hwnd, IDC_DIR, st, MAX_PATH); system_wcstombs(s, st, MAX_PATH); resources_set_string_sprintf("FSDevice%dDir", s, num); if (IsDlgButtonChecked(hwnd, IDC_SELECTDISK) == BST_CHECKED) { GetDlgItemText(hwnd, IDC_DISKIMAGE, st, MAX_PATH); system_wcstombs(s, st, MAX_PATH); if (file_system_attach_disk(num, s) < 0 ) { ui_error(translate_text(IDS_CANNOT_ATTACH_FILE)); return 0; } } else { if ((IsDlgButtonChecked(hwnd, IDC_SELECTDIR) == BST_CHECKED) && file_system_get_disk_name(num)) { file_system_detach_disk(num); } } return 1; }
static void init_dialog(HWND hwnd, unsigned int num) { const char *disk_image, *dir; TCHAR *st_disk_image, *st_dir; int devtype, n; int xpos, xpos1, xpos2, xpos3; int distance1, distance2; RECT rect; uilib_localize_dialog_param *diskdevice_dialog = #ifdef HAVE_OPENCBM (opencbmlib_is_available()) ? diskdevice_opencbm_dialog : #endif diskdevice_normal_dialog; if (num >= 8 && num <= 11) { /* translate all dialog items */ uilib_localize_dialog(hwnd, diskdevice_dialog); /* adjust the size of the elements in the diskdevice_left_group */ uilib_adjust_group_width(hwnd, diskdevice_left_group); /* adjust the size of the 'read-only' element */ uilib_adjust_group_width(hwnd, diskdevice_read_only); /* get the min x of the read only element */ uilib_get_element_min_x(hwnd, IDC_TOGGLE_ATTACH_READONLY, &xpos3); /* get the min x of the autostart element */ uilib_get_element_min_x(hwnd, IDC_AUTOSTART, &xpos2); /* get the max x of the first browse element */ uilib_get_element_max_x(hwnd, IDC_BROWSEDISK, &xpos1); /* calculate the distance between the browse button and the autostart button */ distance1 = xpos2 - xpos1; /* get the max x of the autostart element */ uilib_get_element_max_x(hwnd, IDC_AUTOSTART, &xpos2); /* calculate the distance between the browse button and the read only element */ distance2 = xpos3 - xpos2; /* get the max x of the disk_device_left_group items */ uilib_get_group_max_x(hwnd, diskdevice_left_group, &xpos); /* move the filename elements and browse buttons to the right position */ uilib_move_group(hwnd, diskdevice_middle_group, xpos + 10); /* get the max x of the first browse element */ uilib_get_element_max_x(hwnd, IDC_BROWSEDISK, &xpos); /* move the autostart element to the right position */ uilib_move_element(hwnd, IDC_AUTOSTART, xpos + distance1); /* resize the autostart element */ uilib_adjust_element_width(hwnd, IDC_AUTOSTART); /* get the max x of the autostart element */ uilib_get_element_max_x(hwnd, IDC_AUTOSTART, &xpos); /* move the read only element to the right position */ uilib_move_element(hwnd, IDC_TOGGLE_ATTACH_READONLY, xpos + distance2); #ifdef HAVE_OPENCBM if (opencbmlib_is_available()) { /* adjust the size of the real iec element */ uilib_adjust_element_width(hwnd, IDC_SELECTREAL); /* get the max x of the real iec element */ uilib_get_element_max_x(hwnd, IDC_SELECTREAL, &xpos1); } else { xpos1 = 0; } #else xpos1 = 0; #endif /* get the max x of the second browse button */ uilib_get_element_max_x(hwnd, IDC_BROWSEDIR, &xpos2); if (xpos2 > xpos1) { xpos = xpos2 + 20; } else { xpos = xpos1 + 20; } /* move the diskdevice_right_group to the right position */ uilib_move_group(hwnd, diskdevice_right_group, xpos); /* move the p00 group element to the right position */ uilib_move_element(hwnd, IDC_DISKDEVICE_OPTIONS, xpos - 5); /* adjust the diskdevice_right_group elements size */ uilib_adjust_group_width(hwnd, diskdevice_right_group); /* adjust the p00 group element size */ uilib_adjust_element_width(hwnd, IDC_DISKDEVICE_OPTIONS); /* get the width of the disk_device_right_group items */ uilib_get_group_width(hwnd, diskdevice_right_group, &xpos1); /* get the width of the p00 group element */ uilib_get_element_width(hwnd, IDC_DISKDEVICE_OPTIONS, &xpos2); if (xpos2 + 5 > xpos1) { xpos = xpos2 + 15; } else { xpos = xpos1 + 10; } /* set the width of the p00 group element */ uilib_set_element_width(hwnd, IDC_DISKDEVICE_OPTIONS, xpos); /* adjust the none element size */ uilib_adjust_element_width(hwnd, IDC_SELECTNONE); /* adjust the size of the use iec device element */ uilib_adjust_element_width(hwnd, IDC_TOGGLE_USEIECDEVICE); /* get the max x of the window filling elements */ uilib_get_group_max_x(hwnd, diskdevice_filling_group, &xpos); /* set the width of the dialog to 'surround' all the elements */ GetWindowRect(hwnd, &rect); MoveWindow(hwnd, rect.left, rect.top, xpos + 10, rect.bottom - rect.top, TRUE); disk_image = file_system_get_disk_name(num); st_disk_image = system_mbstowcs_alloc(disk_image); SetDlgItemText(hwnd, IDC_DISKIMAGE, st_disk_image != NULL ? st_disk_image : TEXT("")); system_mbstowcs_free(st_disk_image); resources_get_string_sprintf("FSDevice%dDir", &dir, num); st_dir = system_mbstowcs_alloc(dir); SetDlgItemText(hwnd, IDC_DIR, st_dir != NULL ? st_dir : TEXT("")); system_mbstowcs_free(st_dir); resources_get_int_sprintf("FSDevice%dConvertP00", &n, num); CheckDlgButton(hwnd, IDC_TOGGLE_READP00, n ? BST_CHECKED : BST_UNCHECKED); resources_get_int_sprintf("FSDevice%dSaveP00", &n, num); CheckDlgButton(hwnd, IDC_TOGGLE_WRITEP00, n ? BST_CHECKED : BST_UNCHECKED); resources_get_int_sprintf("FSDevice%dHideCBMFiles", &n, num); CheckDlgButton(hwnd, IDC_TOGGLE_HIDENONP00, n ? BST_CHECKED : BST_UNCHECKED); resources_get_int_sprintf("AttachDevice%dReadonly", &n, num); CheckDlgButton(hwnd, IDC_TOGGLE_ATTACH_READONLY, n ? BST_CHECKED : BST_UNCHECKED); resources_get_int_sprintf("FileSystemDevice%d", &devtype, num); switch (devtype) { case ATTACH_DEVICE_FS: if (disk_image != NULL) { n = IDC_SELECTDISK; } else { n = IDC_SELECTDIR; } break; #ifdef HAVE_OPENCBM case ATTACH_DEVICE_REAL: n = IDC_SELECTREAL; break; #endif default: n = IDC_SELECTNONE; } #ifdef HAVE_OPENCBM if (opencbmlib_is_available()) { CheckRadioButton(hwnd, IDC_SELECTDISK, IDC_SELECTREAL, n); } else { CheckRadioButton(hwnd, IDC_SELECTDISK, IDC_SELECTDIR, n); } #else CheckRadioButton(hwnd, IDC_SELECTDISK, IDC_SELECTDIR, n); #endif enable_controls_for_disk_device_type(hwnd, n); if (iec_available_busses() & IEC_BUS_IEC) { resources_get_int_sprintf("IECDevice%d", &n, num); CheckDlgButton(hwnd, IDC_TOGGLE_USEIECDEVICE, n ? BST_CHECKED : BST_UNCHECKED); } else { CheckDlgButton(hwnd, IDC_TOGGLE_USEIECDEVICE, BST_UNCHECKED); ShowWindow(GetDlgItem(hwnd, IDC_TOGGLE_USEIECDEVICE), FALSE); } enable_controls(hwnd); } }
/** * Show and process the floppy disk image dialog. */ void DlgFloppy_Main(void) { int but, i; char *newdisk; char dlgname[MAX_FLOPPYDRIVES][64], dlgdiskdir[64]; SDLGui_CenterDlg(floppydlg); /* Set up dialog to actual values: */ const char *name; floppydlg[FLOPPYDLG_ATTACH2FLIPLIST].state &= ~SG_SELECTED; name = file_system_get_disk_name(8); /* Filename */ if (!name)dlgname[0][0] = '\0'; else File_ShrinkName(dlgname[0], name,floppydlg[FLOPPYDLG_DISKA].w); floppydlg[FLOPPYDLG_DISKA].txt = dlgname[0]; name = file_system_get_disk_name(9); /* Filename */ if (!name)dlgname[1][0] = '\0'; else File_ShrinkName(dlgname[1], name,floppydlg[FLOPPYDLG_DISKB].w); floppydlg[FLOPPYDLG_DISKB].txt = dlgname[1]; name = file_system_get_disk_name(10); /* Filename */ if (!name)dlgname[2][0] = '\0'; else File_ShrinkName(dlgname[2], name,floppydlg[FLOPPYDLG_DISK2].w); floppydlg[FLOPPYDLG_DISK2].txt = dlgname[2]; name = file_system_get_disk_name(11); /* Filename */ if (!name)dlgname[3][0] = '\0'; else File_ShrinkName(dlgname[3], name,floppydlg[FLOPPYDLG_DISK3].w); floppydlg[FLOPPYDLG_DISK3].txt = dlgname[3]; /* Default image directory: */ File_ShrinkName(dlgdiskdir,szDiskImageDirectory, floppydlg[FLOPPYDLG_IMGDIR].w); floppydlg[FLOPPYDLG_IMGDIR].txt = dlgdiskdir; /* Draw and process the dialog */ do { but = SDLGui_DoDialog(floppydlg, NULL); switch (but) { case FLOPPYDLG_EJECTA: /* Eject disk in drive A: */ Floppy_SetDiskFileNameNone(0); dlgname[0][0] = '\0'; file_system_detach_disk(GET_DRIVE(8)); break; case FLOPPYDLG_BROWSEA: /* Choose a new disk A: */ DlgDisk_BrowseDisk(dlgname[0], 0, FLOPPYDLG_DISKA); if (strlen(szDiskFileName[0]) > 0){ int drivetype; printf("load (%s)-",szDiskFileName[0]); resources_get_int_sprintf("Drive%iType", &drivetype, GET_DRIVE(8)); printf("(Drive%iType)\n",drivetype); cartridge_detach_image(-1); tape_image_detach(1); // file_system_detach_disk(GET_DRIVE(8)); if(File_DoesFileExtensionMatch(szDiskFileName[0],"CRT")) cartridge_attach_image(CARTRIDGE_CRT, szDiskFileName[0]); else { //FIXME /* if(File_DoesFileExtensionMatch(szDiskFileName[0],"D81") && drivetype!=1581) resources_set_int_sprintf("Drive%iType", 1581, GET_DRIVE(8)); else if (drivetype!=1542 && !File_DoesFileExtensionMatch(szDiskFileName[0],"D81")) resources_set_int_sprintf("Drive%iType", 1542, GET_DRIVE(8)); */ if (floppydlg[FLOPPYDLG_ATTACH2FLIPLIST].state & SG_SELECTED){ file_system_detach_disk(GET_DRIVE(8)); printf("Attach to flip list\n"); file_system_attach_disk(8, szDiskFileName[0]); fliplist_add_image(8) ; } else { printf("autostart\n"); autostart_autodetect(szDiskFileName[0], NULL, 0, AUTOSTART_MODE_RUN); } } } break; case FLOPPYDLG_EJECTB: /* Eject disk in drive B: */ Floppy_SetDiskFileNameNone(1); dlgname[1][0] = '\0'; file_system_detach_disk(GET_DRIVE(9)); break; case FLOPPYDLG_BROWSEB: /* Choose a new disk B: */ DlgDisk_BrowseDisk(dlgname[1], 1, FLOPPYDLG_DISKB); if (strlen(szDiskFileName[1]) > 0){ file_system_detach_disk(GET_DRIVE(9)); file_system_attach_disk(9, szDiskFileName[1]); } case FLOPPYDLG_EJECT2: /* Eject disk in drive A: */ Floppy_SetDiskFileNameNone(2); dlgname[2][0] = '\0'; file_system_detach_disk(GET_DRIVE(10)); break; case FLOPPYDLG_BROWSE2: /* Choose a new disk A: */ DlgDisk_BrowseDisk(dlgname[2], 0, FLOPPYDLG_DISK2); if (strlen(szDiskFileName[2]) > 0){ //strcpy(prefs->DrivePath[2], szDiskFileName[2]); } break; case FLOPPYDLG_EJECT3: /* Eject disk in drive B: */ Floppy_SetDiskFileNameNone(3); dlgname[3][0] = '\0'; file_system_detach_disk(GET_DRIVE(11)); break; case FLOPPYDLG_BROWSE3: /* Choose a new disk B: */ DlgDisk_BrowseDisk(dlgname[3], 1, FLOPPYDLG_DISKB); if (strlen(szDiskFileName[3]) > 0){ // strcpy(prefs->DrivePath[3], szDiskFileName[3]); } break; case FLOPPYDLG_BROWSEIMG: DlgDisk_BrowseDir(dlgdiskdir,szDiskImageDirectory,floppydlg[FLOPPYDLG_IMGDIR].w); break; /* case FLOPPYDLG_CREATEIMG: newdisk = DlgNewDisk_Main(); if (newdisk) { DlgFloppy_QueryInsert(dlgname[0], FLOPPYDLG_DISKA, dlgname[1], FLOPPYDLG_DISKB, newdisk); free(newdisk); } break; */ } gui_poll_events(); } while (but != FLOPPYDLG_EXIT && but != SDLGUI_QUIT && but != SDLGUI_ERROR && !bQuitProgram); /* if (floppydlg[FLOPPYDLG_AUTOSTART].state & SG_SELECTED){ if(!ThePrefs.Emul1541Proc){ prefs->Emul1541Proc = !prefs->Emul1541Proc; } } else { if(ThePrefs.Emul1541Proc){ prefs->Emul1541Proc = !prefs->Emul1541Proc; } } */ }