From 6fde7e8b24bfcc81e9e6c10c978cf3ae67a879b3 Mon Sep 17 00:00:00 2001 From: Toni Wilen Date: Tue, 10 Jul 2018 09:43:10 +0300 Subject: [PATCH] Floppies, tapes, filesystem filesys and geometry, disk swapper: Resolve environmental variables/lnk only when needed, keep original path in config data. (Hardfile path in b1). Fixed bugs in b1 update. --- audio.cpp | 14 +++++-- blkdev.cpp | 4 +- blkdev_cdimage.cpp | 18 ++++---- cfgfile.cpp | 97 +++++++++++++++++-------------------------- disk.cpp | 74 +++++++++++++++++++-------------- filesys.cpp | 19 ++++++--- hardfile.cpp | 4 +- include/disk.h | 2 +- include/options.h | 3 +- od-win32/win32gfx.cpp | 1 - od-win32/win32gui.cpp | 22 ++++++++-- savestate.cpp | 25 +++++++++-- scsitape.cpp | 8 ++-- 13 files changed, 167 insertions(+), 124 deletions(-) diff --git a/audio.cpp b/audio.cpp index a670a60e..e700e602 100644 --- a/audio.cpp +++ b/audio.cpp @@ -228,15 +228,21 @@ void audio_sampleripper (int mode) while (rs) { if (rs->changed) { + int type = -1; rs->changed = 0; fetch_ripperpath (path, sizeof (path) / sizeof (TCHAR)); name[0] = 0; - if (currprefs.floppyslots[0].dfxtype >= 0) - _tcscpy (name, currprefs.floppyslots[0].df); - else if (currprefs.cdslots[0].inuse) - _tcscpy (name, currprefs.cdslots[0].name); + if (currprefs.floppyslots[0].dfxtype >= 0) { + _tcscpy(name, currprefs.floppyslots[0].df); + type = PATH_FLOPPY; + } else if (currprefs.cdslots[0].inuse) { + _tcscpy(name, currprefs.cdslots[0].name); + type = PATH_CD; + } if (!name[0]) underline[0] = 0; + if (type >= 0) + cfgfile_resolve_path(name, sizeof(name) / sizeof(TCHAR), type); namesplit (name); _tcscpy (extension, _T("wav")); _stprintf (filename, _T("%s%s%s%03d.%s"), path, name, underline, cnt, extension); diff --git a/blkdev.cpp b/blkdev.cpp index ae537ae4..6c8d0e79 100644 --- a/blkdev.cpp +++ b/blkdev.cpp @@ -416,8 +416,10 @@ static void cd_statusline_label(int unitnum) { TCHAR *p = currprefs.cdslots[unitnum].name; if (p[0]) { + TCHAR name[MAX_DPATH]; struct device_info di; - const TCHAR *fname = my_getfilepart(p); + cfgfile_resolve_path_out(p, name, sizeof(name) / sizeof(TCHAR), PATH_CD); + const TCHAR *fname = my_getfilepart(name); if (sys_command_info(unitnum, &di, 0) && di.volume_id[0]) statusline_add_message(STATUSTYPE_CD, _T("CD%d: [%s] %s"), unitnum, di.volume_id, fname); else diff --git a/blkdev_cdimage.cpp b/blkdev_cdimage.cpp index 2c71bf80..ae5a62e6 100644 --- a/blkdev_cdimage.cpp +++ b/blkdev_cdimage.cpp @@ -98,7 +98,8 @@ struct cdunit { int cdda_delay, cdda_delay_frames; bool thread_active; - TCHAR imgname[MAX_DPATH]; + TCHAR imgname_in[MAX_DPATH]; + TCHAR imgname_out[MAX_DPATH]; uae_sem_t sub_sem; struct device_info di; #ifdef WITH_CHD @@ -2173,7 +2174,7 @@ static struct device_info *info_device (int unitnum, struct device_info *di, int di->sectorspertrack = (int)(cdu->cdsize / di->bytespersector); if (ismedia (unitnum, 1)) { di->media_inserted = 1; - _tcscpy (di->mediapath, cdu->imgname); + _tcscpy (di->mediapath, cdu->imgname_out); di->audio_playing = cdu->cdda_play > 0; } memset (&di->toc, 0, sizeof (struct cd_toc_head)); @@ -2228,9 +2229,12 @@ static int open_device (int unitnum, const TCHAR *ident, int flags) if (!cdu->open) { uae_sem_init (&cdu->sub_sem, 0, 1); - cdu->imgname[0] = 0; - if (ident) - _tcscpy (cdu->imgname, ident); + cdu->imgname_out[0] = 0; + cdu->imgname_in[0] = 0; + if (ident) { + _tcscpy(cdu->imgname_in, ident); + cfgfile_resolve_path_out(cdu->imgname_in, cdu->imgname_out, MAX_DPATH, PATH_CD); + } parse_image (cdu, ident); cdu->open = true; cdu->enabled = true; @@ -2244,7 +2248,7 @@ static int open_device (int unitnum, const TCHAR *ident, int flags) } ret = 1; } - blkdev_cd_change (unitnum, cdu->imgname); + blkdev_cd_change (unitnum, cdu->imgname_in); return ret; } @@ -2266,7 +2270,7 @@ static void close_device (int unitnum) unload_image (cdu); uae_sem_destroy (&cdu->sub_sem); } - blkdev_cd_change (unitnum, cdu->imgname); + blkdev_cd_change (unitnum, cdu->imgname_in); } static void close_bus (void) diff --git a/cfgfile.cpp b/cfgfile.cpp index 91d95f12..f939ca28 100644 --- a/cfgfile.cpp +++ b/cfgfile.cpp @@ -987,7 +987,10 @@ void cfgfile_resolve_path_out(const TCHAR *path, TCHAR *out, int size, int type) s = cfgfile_subst_path_load(UNEXPANDED, &p->path_hardfile, path, true); break; case PATH_HDF: - s = cfgfile_subst_path_load(UNEXPANDED, &p->path_hardfile, path, true); + s = cfgfile_subst_path_load(UNEXPANDED, &p->path_hardfile, path, false); + break; + case PATH_CD: + s = cfgfile_subst_path_load(UNEXPANDED, &p->path_cd, path, false); break; case PATH_FLOPPY: _tcscpy(out, path); @@ -1084,7 +1087,6 @@ static void write_filesys_config (struct uae_prefs *p, struct zfile *f) } else if (ci->type == UAEDEV_HDF || ci->type == UAEDEV_CD || ci->type == UAEDEV_TAPE) { TCHAR filesyspath[MAX_DPATH]; _tcscpy(filesyspath, ci->filesys); - cfgfile_adjust_path(filesyspath, MAX_DPATH, NULL); TCHAR *sfilesys = cfgfile_escape_min(filesyspath); TCHAR *sgeometry = cfgfile_escape(ci->geometry, NULL, true); _stprintf (tmp, _T("%s,%s:%s,%d,%d,%d,%d,%d,%s,%s"), @@ -1691,7 +1693,7 @@ void cfgfile_save_options (struct zfile *f, struct uae_prefs *p, int type) p->nr_floppies = 4; for (i = 0; i < 4; i++) { _stprintf (tmp, _T("floppy%d"), i); - cfgfile_write_path (f, &p->path_floppy, tmp, p->floppyslots[i].df); + cfgfile_write_str(f, tmp, p->floppyslots[i].df); _stprintf (tmp, _T("floppy%dwp"), i); cfgfile_dwrite_bool (f, tmp, p->floppyslots[i].forcedwriteprotect); _stprintf (tmp, _T("floppy%dtype"), i); @@ -1714,7 +1716,7 @@ void cfgfile_save_options (struct zfile *f, struct uae_prefs *p, int type) for (i = 0; i < MAX_SPARE_DRIVES; i++) { if (p->dfxlist[i][0]) { _stprintf (tmp, _T("diskimage%d"), i); - cfgfile_dwrite_path (f, &p->path_floppy, tmp, p->dfxlist[i]); + cfgfile_dwrite_str(f, tmp, p->dfxlist[i]); } } @@ -1722,9 +1724,7 @@ void cfgfile_save_options (struct zfile *f, struct uae_prefs *p, int type) if (p->cdslots[i].name[0] || p->cdslots[i].inuse) { TCHAR tmp2[MAX_DPATH]; _stprintf (tmp, _T("cdimage%d"), i); - TCHAR *s = cfgfile_put_multipath (&p->path_cd, p->cdslots[i].name); - _tcscpy (tmp2, s); - xfree (s); + _tcscpy (tmp2, p->cdslots[i].name); if (p->cdslots[i].type != SCSI_UNIT_DEFAULT || _tcschr (p->cdslots[i].name, ',') || p->cdslots[i].delayed) { _tcscat (tmp2, _T(",")); if (p->cdslots[i].delayed) { @@ -2716,27 +2716,19 @@ static int cfgfile_path (const TCHAR *option, const TCHAR *value, const TCHAR *n return cfgfile_path (option, value, name, location, maxsz, NULL); } -static int cfgfile_pathext(const TCHAR *option, const TCHAR *value, const TCHAR *name, TCHAR *location, int maxsz) -{ - if (!cfgfile_string(option, value, name, location, maxsz)) - return 0; - if (_tcschr(value, '/') || _tcschr(value, '\\') || _tcschr(value, ':')) - return cfgfile_path(option, value, name, location, maxsz, NULL); - return 1; -} - -static int cfgfile_multipath (const TCHAR *option, const TCHAR *value, const TCHAR *name, struct multipath *mp) +static int cfgfile_multipath (const TCHAR *option, const TCHAR *value, const TCHAR *name, struct multipath *mp, struct uae_prefs *p) { TCHAR tmploc[MAX_DPATH]; - if (!cfgfile_string (option, value, name, tmploc, 256)) + if (!cfgfile_string (option, value, name, tmploc, PATH_MAX)) return 0; for (int i = 0; i < MAX_PATHS; i++) { if (mp->path[i][0] == 0 || (i == 0 && (!_tcscmp (mp->path[i], _T(".\\")) || !_tcscmp (mp->path[i], _T("./"))))) { TCHAR *s = target_expand_environment (tmploc, NULL, 0); - _tcsncpy (mp->path[i], s, 256 - 1); - mp->path[i][256 - 1] = 0; + _tcsncpy (mp->path[i], s, PATH_MAX - 1); + mp->path[i][PATH_MAX - 1] = 0; fixtrailing (mp->path[i]); xfree (s); + target_multipath_modified(p); return 1; } } @@ -2934,10 +2926,10 @@ static int cfgfile_parse_host (struct uae_prefs *p, TCHAR *option, TCHAR *value) *tmpp = '\0'; if (_tcscmp (section, TARGET_NAME) == 0) { /* We special case the various path options here. */ - if (cfgfile_multipath (option, value, _T("rom_path"), &p->path_rom) - || cfgfile_multipath (option, value, _T("floppy_path"), &p->path_floppy) - || cfgfile_multipath (option, value, _T("cd_path"), &p->path_cd) - || cfgfile_multipath (option, value, _T("hardfile_path"), &p->path_hardfile)) + if (cfgfile_multipath (option, value, _T("rom_path"), &p->path_rom, p) + || cfgfile_multipath (option, value, _T("floppy_path"), &p->path_floppy, p) + || cfgfile_multipath (option, value, _T("cd_path"), &p->path_cd, p) + || cfgfile_multipath (option, value, _T("hardfile_path"), &p->path_hardfile, p)) return 1; return target_parse_option (p, option, value); } @@ -2946,11 +2938,7 @@ static int cfgfile_parse_host (struct uae_prefs *p, TCHAR *option, TCHAR *value) for (i = 0; i < MAX_SPARE_DRIVES; i++) { _stprintf (tmpbuf, _T("diskimage%d"), i); - if (cfgfile_path (option, value, tmpbuf, p->dfxlist[i], sizeof p->dfxlist[i] / sizeof (TCHAR), &p->path_floppy)) { -#if 0 - if (i < 4 && !p->df[i][0]) - _tcscpy (p->df[i], p->dfxlist[i]); -#endif + if (cfgfile_string(option, value, tmpbuf, p->dfxlist[i], sizeof p->dfxlist[i] / sizeof(TCHAR))) { return 1; } } @@ -3008,9 +2996,7 @@ static int cfgfile_parse_host (struct uae_prefs *p, TCHAR *option, TCHAR *value) cfgfile_intval (option, next, tmp, &unitnum, 1); } if (_tcslen (value) > 0) { - TCHAR *s = cfgfile_get_multipath (&p->path_cd, NULL, value, false); - _tcsncpy (p->cdslots[i].name, s, sizeof p->cdslots[i].name / sizeof (TCHAR)); - xfree (s); + _tcsncpy (p->cdslots[i].name, value, sizeof p->cdslots[i].name / sizeof (TCHAR)); } p->cdslots[i].name[sizeof p->cdslots[i].name - 1] = 0; p->cdslots[i].inuse = true; @@ -3127,14 +3113,14 @@ static int cfgfile_parse_host (struct uae_prefs *p, TCHAR *option, TCHAR *value) || cfgfile_intval (option, value, _T("floppy_channel_mask"), &p->dfxclickchannelmask, 1)) return 1; - if (cfgfile_pathext (option, value, _T("floppy0soundext"), p->floppyslots[0].dfxclickexternal, sizeof p->floppyslots[0].dfxclickexternal / sizeof (TCHAR)) - || cfgfile_pathext (option, value, _T("floppy1soundext"), p->floppyslots[1].dfxclickexternal, sizeof p->floppyslots[1].dfxclickexternal / sizeof (TCHAR)) - || cfgfile_pathext (option, value, _T("floppy2soundext"), p->floppyslots[2].dfxclickexternal, sizeof p->floppyslots[2].dfxclickexternal / sizeof (TCHAR)) - || cfgfile_pathext (option, value, _T("floppy3soundext"), p->floppyslots[3].dfxclickexternal, sizeof p->floppyslots[3].dfxclickexternal / sizeof (TCHAR)) + if (cfgfile_string(option, value, _T("floppy0soundext"), p->floppyslots[0].dfxclickexternal, sizeof p->floppyslots[0].dfxclickexternal / sizeof (TCHAR)) + || cfgfile_string(option, value, _T("floppy1soundext"), p->floppyslots[1].dfxclickexternal, sizeof p->floppyslots[1].dfxclickexternal / sizeof (TCHAR)) + || cfgfile_string(option, value, _T("floppy2soundext"), p->floppyslots[2].dfxclickexternal, sizeof p->floppyslots[2].dfxclickexternal / sizeof (TCHAR)) + || cfgfile_string(option, value, _T("floppy3soundext"), p->floppyslots[3].dfxclickexternal, sizeof p->floppyslots[3].dfxclickexternal / sizeof (TCHAR)) || cfgfile_string(option, value, _T("debugging_options"), p->debugging_options, sizeof p->debugging_options / sizeof(TCHAR)) - || cfgfile_string (option, value, _T("config_window_title"), p->config_window_title, sizeof p->config_window_title / sizeof (TCHAR)) - || cfgfile_string (option, value, _T("config_info"), p->info, sizeof p->info / sizeof (TCHAR)) - || cfgfile_string (option, value, _T("config_description"), p->description, sizeof p->description / sizeof (TCHAR))) + || cfgfile_string(option, value, _T("config_window_title"), p->config_window_title, sizeof p->config_window_title / sizeof (TCHAR)) + || cfgfile_string(option, value, _T("config_info"), p->info, sizeof p->info / sizeof (TCHAR)) + || cfgfile_string(option, value, _T("config_description"), p->description, sizeof p->description / sizeof (TCHAR))) return 1; if (cfgfile_yesno(option, value, _T("use_debugger"), &p->start_debugger) @@ -4305,8 +4291,10 @@ static bool parse_geo (const TCHAR *tname, struct uaedev_config_info *uci, struc TCHAR tmp[200], section[200]; struct ini_data *ini; bool ret = false; + TCHAR tgname[MAX_DPATH]; - ini = ini_load(tname); + cfgfile_resolve_path_out(tname, tgname, MAX_DPATH, PATH_HDF); + ini = ini_load(tgname); if (!ini) return ret; @@ -4336,7 +4324,7 @@ static bool parse_geo (const TCHAR *tname, struct uaedev_config_info *uci, struc if (found) { ret = true; - write_log(_T("Geometry file '%s' section '%s' found\n"), tname, section); + write_log(_T("Geometry file '%s' section '%s' found\n"), tgname, section); if (addgeom) { _tcscpy(uci->geometry, tname); } @@ -4736,10 +4724,6 @@ empty_fs: memmove (uci.rootdir, uci.rootdir + 2, (_tcslen (uci.rootdir + 2) + 1) * sizeof (TCHAR)); uci.rootdir[0] = ':'; } -#if 0 - str = cfgfile_subst_path_load (UNEXPANDED, &p->path_hardfile, uci.rootdir, false); - _tcscpy (uci.rootdir, str); -#endif } if (uci.geometry[0]) { parse_geo(uci.geometry, &uci, NULL, false, true); @@ -5519,7 +5503,7 @@ static int cfgfile_parse_hardware (struct uae_prefs *p, const TCHAR *option, TCH for (i = 0; i < 4; i++) { _stprintf (tmpbuf, _T("floppy%d"), i); - if (cfgfile_path (option, value, tmpbuf, p->floppyslots[i].df, sizeof p->floppyslots[i].df / sizeof (TCHAR), &p->path_floppy)) + if (cfgfile_string(option, value, tmpbuf, p->floppyslots[i].df, sizeof p->floppyslots[i].df / sizeof(TCHAR))) return 1; } @@ -6272,14 +6256,17 @@ static int cfgfile_load_2 (struct uae_prefs *p, const TCHAR *filename, bool real cfgfile_path (line1b, line2b, _T("config_all_path"), p->config_all_path, sizeof p->config_all_path / sizeof(TCHAR)); cfgfile_string (line1b, line2b, _T("config_window_title"), p->config_window_title, sizeof p->config_window_title / sizeof (TCHAR)); // boxart checks - cfgfile_path(line1b, line2b, _T("floppy0"), p->floppyslots[0].df, sizeof p->floppyslots[0].df / sizeof(TCHAR)); + cfgfile_string(line1b, line2b, _T("floppy0"), p->floppyslots[0].df, sizeof p->floppyslots[0].df / sizeof(TCHAR)); + cfgfile_resolve_path(p->floppyslots[0].df, MAX_DPATH, PATH_FLOPPY); TCHAR tmp[MAX_DPATH]; if (!p->mountitems && (cfgfile_string(line1b, line2b, _T("hardfile2"), tmp, sizeof tmp / sizeof(TCHAR)) || cfgfile_string(line1b, line2b, _T("filesystem2"), tmp, sizeof tmp / sizeof(TCHAR)))) { const TCHAR *s = _tcschr(tmp, ':'); if (s) { + bool isvsys = false; if (!_tcscmp(line1b, _T("filesystem2"))) { s++; s = _tcschr(s, ':'); + isvsys = true; } if (s) { s++; @@ -6292,7 +6279,7 @@ static int cfgfile_load_2 (struct uae_prefs *p, const TCHAR *filename, bool real if (se) { tmp[se - tmp] = 0; _tcscpy(p->mountconfig[0].ci.rootdir, s); - cfgfile_adjust_path(p->mountconfig[0].ci.rootdir, MAX_DPATH, NULL); + cfgfile_resolve_path(p->mountconfig[0].ci.rootdir, MAX_DPATH, isvsys ? PATH_DIR : PATH_HDF); p->mountitems = 1; } } @@ -6310,8 +6297,8 @@ static int cfgfile_load_2 (struct uae_prefs *p, const TCHAR *filename, bool real if (se) tmp[se - tmp] = 0; } - cfgfile_adjust_path(s, MAX_DPATH, NULL); _tcscpy(p->cdslots[0].name, s); + cfgfile_resolve_path(p->cdslots[0].name, MAX_DPATH, PATH_CD); p->cdslots[0].inuse = 1; } } @@ -6330,8 +6317,6 @@ static int cfgfile_load_2 (struct uae_prefs *p, const TCHAR *filename, bool real cfgfile_parse_line (p, line, 0); } - for (i = 0; i < 4; i++) - subst (p->path_floppy.path[0], p->floppyslots[i].df, sizeof p->floppyslots[i].df / sizeof (TCHAR)); subst (p->path_rom.path[0], p->romfile, sizeof p->romfile / sizeof (TCHAR)); subst (p->path_rom.path[0], p->romextfile, sizeof p->romextfile / sizeof (TCHAR)); subst (p->path_rom.path[0], p->romextfile2, sizeof p->romextfile2 / sizeof (TCHAR)); @@ -6496,14 +6481,6 @@ bool cfgfile_detect_art(struct uae_prefs *p, TCHAR *path) return false; } -int cfgfile_configuration_change (int v) -{ - static int mode; - if (v >= 0) - mode = v; - return mode; -} - void cfgfile_show_usage (void) { int i; @@ -7281,7 +7258,7 @@ uae_u8 *restore_configuration (uae_u8 *src) for (int i = 0; i < MAX_SPARE_DRIVES; i++) { _stprintf(tmp, _T("diskimage%d"), i); if (!_tcscmp(option, tmp)) { - cfgfile_path(option, value, tmp, p->dfxlist[i], sizeof p->dfxlist[i] / sizeof(TCHAR), &p->path_floppy); + cfgfile_string(option, value, tmp, p->dfxlist[i], sizeof p->dfxlist[i] / sizeof(TCHAR)); break; } } diff --git a/disk.cpp b/disk.cpp index f4a4c4b3..88ed715f 100644 --- a/disk.cpp +++ b/disk.cpp @@ -759,20 +759,27 @@ static void update_drive_gui (int num, bool force) static void drive_fill_bigbuf (drive * drv,int); -int DISK_validate_filename (struct uae_prefs *p, const TCHAR *fname, int leave_open, bool *wrprot, uae_u32 *crc32, struct zfile **zf) +int DISK_validate_filename (struct uae_prefs *p, const TCHAR *fname_in, TCHAR *outfname, int leave_open, bool *wrprot, uae_u32 *crc32, struct zfile **zf) { + TCHAR outname[MAX_DPATH]; + if (zf) *zf = NULL; if (crc32) *crc32 = 0; if (wrprot) *wrprot = p->floppy_read_only ? 1 : 0; + + cfgfile_resolve_path_out(fname_in, outname, MAX_DPATH, PATH_FLOPPY); + if (outfname) + _tcscpy(outfname, outname); + if (leave_open || !zf) { - struct zfile *f = zfile_fopen (fname, _T("r+b"), ZFD_NORMAL | ZFD_DISKHISTORY); + struct zfile *f = zfile_fopen (outname, _T("r+b"), ZFD_NORMAL | ZFD_DISKHISTORY); if (!f) { if (wrprot) *wrprot = 1; - f = zfile_fopen (fname, _T("rb"), ZFD_NORMAL | ZFD_DISKHISTORY); + f = zfile_fopen (outname, _T("rb"), ZFD_NORMAL | ZFD_DISKHISTORY); } if (f && crc32) *crc32 = zfile_crc32 (f); @@ -782,11 +789,11 @@ int DISK_validate_filename (struct uae_prefs *p, const TCHAR *fname, int leave_o *zf = f; return f ? 1 : 0; } else { - if (zfile_exists (fname)) { + if (zfile_exists (outname)) { if (wrprot && !p->floppy_read_only) *wrprot = 0; if (crc32) { - struct zfile *f = zfile_fopen (fname, _T("rb"), ZFD_NORMAL | ZFD_DISKHISTORY); + struct zfile *f = zfile_fopen (outname, _T("rb"), ZFD_NORMAL | ZFD_DISKHISTORY); if (f) *crc32 = zfile_crc32 (f); zfile_fclose (f); @@ -960,13 +967,15 @@ static struct zfile *getexistingwritefile(struct uae_prefs *p, const TCHAR *name { struct zfile *zf = NULL; TCHAR *path; + TCHAR outname[MAX_DPATH]; + path = DISK_get_saveimagepath(name, saveimageoriginalpath); - DISK_validate_filename (p, path, 1, wrprot, NULL, &zf); + DISK_validate_filename (p, path, outname, 1, wrprot, NULL, &zf); xfree(path); if (zf) return zf; path = DISK_get_saveimagepath(name, !saveimageoriginalpath); - DISK_validate_filename (p, path, 1, wrprot, NULL, &zf); + DISK_validate_filename (p, path, outname, 1, wrprot, NULL, &zf); xfree(path); return zf; } @@ -1015,22 +1024,23 @@ static int openwritefile (struct uae_prefs *p, drive *drv, int create) return drv->writediskfile ? 1 : 0; } -static bool diskfile_iswriteprotect (struct uae_prefs *p, const TCHAR *fname, int *needwritefile, drive_type *drvtype) +static bool diskfile_iswriteprotect (struct uae_prefs *p, const TCHAR *fname_in, int *needwritefile, drive_type *drvtype) { struct zfile *zf1, *zf2; bool wrprot1 = 0, wrprot2 = 1; uae_char buffer[25]; + TCHAR outname[MAX_DPATH]; *needwritefile = 0; *drvtype = DRV_35_DD; - DISK_validate_filename (p, fname, 1, &wrprot1, NULL, &zf1); + DISK_validate_filename (p, fname_in, outname, 1, &wrprot1, NULL, &zf1); if (!zf1) return 1; if (zfile_iscompressed (zf1)) { wrprot1 = 1; *needwritefile = 1; } - zf2 = getexistingwritefile(p, fname, &wrprot2); + zf2 = getexistingwritefile(p, fname_in, &wrprot2); zfile_fclose (zf2); zfile_fread (buffer, sizeof (char), 25, zf1); zfile_fclose (zf1); @@ -1089,17 +1099,18 @@ static void update_disk_statusline(int num) statusline_add_message(STATUSTYPE_FLOPPY, _T("DF%d: %s"), num, my_getfilepart(fname)); } -static int drive_insert (drive * drv, struct uae_prefs *p, int dnum, const TCHAR *fname, bool fake, bool forcedwriteprotect) +static int drive_insert (drive * drv, struct uae_prefs *p, int dnum, const TCHAR *fname_in, bool fake, bool forcedwriteprotect) { uae_u8 buffer[2 + 2 + 4 + 4]; trackid *tid; int num_tracks, size; int canauto; + TCHAR outname[MAX_DPATH]; drive_image_free (drv); if (!fake) DISK_examine_image(p, dnum, &disk_info_data); - DISK_validate_filename (p, fname, 1, &drv->wrprot, &drv->crc32, &drv->diskfile); + DISK_validate_filename (p, fname_in, outname, 1, &drv->wrprot, &drv->crc32, &drv->diskfile); drv->forcedwrprot = forcedwriteprotect; if (drv->forcedwrprot) drv->wrprot = true; @@ -1112,7 +1123,7 @@ static int drive_insert (drive * drv, struct uae_prefs *p, int dnum, const TCHAR drv->indexoffset = 0; if (!fake) { drv->dskeject = false; - gui_disk_image_change (dnum, fname, drv->wrprot); + gui_disk_image_change (dnum, outname, drv->wrprot); } if (!drv->motoroff) { @@ -1126,19 +1137,19 @@ static int drive_insert (drive * drv, struct uae_prefs *p, int dnum, const TCHAR } if (!fake) { - inprec_recorddiskchange (dnum, fname, drv->wrprot); + inprec_recorddiskchange (dnum, fname_in, drv->wrprot); - if (currprefs.floppyslots[dnum].df != fname) { - _tcsncpy (currprefs.floppyslots[dnum].df, fname, 255); + if (currprefs.floppyslots[dnum].df != fname_in) { + _tcsncpy (currprefs.floppyslots[dnum].df, fname_in, 255); currprefs.floppyslots[dnum].df[255] = 0; } currprefs.floppyslots[dnum].forcedwriteprotect = forcedwriteprotect; - _tcsncpy (changed_prefs.floppyslots[dnum].df, fname, 255); + _tcsncpy (changed_prefs.floppyslots[dnum].df, fname_in, 255); changed_prefs.floppyslots[dnum].df[255] = 0; changed_prefs.floppyslots[dnum].forcedwriteprotect = forcedwriteprotect; - _tcscpy (drv->newname, fname); + _tcscpy (drv->newname, fname_in); drv->newnamewriteprotected = forcedwriteprotect; - gui_filename (dnum, fname); + gui_filename (dnum, outname); } memset (buffer, 0, sizeof buffer); @@ -1151,11 +1162,11 @@ static int drive_insert (drive * drv, struct uae_prefs *p, int dnum, const TCHAR } canauto = 0; - if (isrecognizedext (fname)) + if (isrecognizedext (outname)) canauto = 1; if (!canauto && drv->diskfile && isrecognizedext (zfile_getname (drv->diskfile))) canauto = 1; - // if PC-only drive, make sure PC-like floppies are alwayss detected + // if PC-only drive, make sure PC-like floppies are always detected if (!canauto && ispcbridgedrive(dnum)) canauto = 1; @@ -2702,7 +2713,7 @@ void DISK_reinsert (int num) setdskchangetime (&floppy[num], 2 * 50 * 312); } -int disk_setwriteprotect (struct uae_prefs *p, int num, const TCHAR *name, bool writeprotected) +int disk_setwriteprotect (struct uae_prefs *p, int num, const TCHAR *fname_in, bool writeprotected) { int needwritefile, oldprotect; struct zfile *zf1, *zf2; @@ -2710,11 +2721,12 @@ int disk_setwriteprotect (struct uae_prefs *p, int num, const TCHAR *name, bool int i; TCHAR *name2; drive_type drvtype; + TCHAR outfname[MAX_DPATH]; - write_log(_T("disk_setwriteprotect %d '%s' %d\n"), num, name, writeprotected); + write_log(_T("disk_setwriteprotect %d '%s' %d\n"), num, fname_in, writeprotected); - oldprotect = diskfile_iswriteprotect (p, name, &needwritefile, &drvtype); - DISK_validate_filename (p, name, 1, &wrprot1, NULL, &zf1); + oldprotect = diskfile_iswriteprotect (p, fname_in, &needwritefile, &drvtype); + DISK_validate_filename (p, fname_in, outfname, 1, &wrprot1, NULL, &zf1); if (!zf1) return 0; @@ -2725,22 +2737,22 @@ int disk_setwriteprotect (struct uae_prefs *p, int num, const TCHAR *name, bool if (zfile_iscompressed (zf1)) wrprot1 = 1; zfile_fclose (zf1); - zf2 = getexistingwritefile(p, name, &wrprot2); - name2 = DISK_get_saveimagepath(name, -2); + zf2 = getexistingwritefile(p, fname_in, &wrprot2); + name2 = DISK_get_saveimagepath(fname_in, -2); if (needwritefile && zf2 == 0) disk_creatediskfile (p, name2, 1, drvtype, -1, NULL, false, false, NULL); zfile_fclose (zf2); - if (writeprotected && iswritefileempty (p, name)) { + if (writeprotected && iswritefileempty (p, fname_in)) { for (i = 0; i < MAX_FLOPPY_DRIVES; i++) { - if (!_tcscmp (name, floppy[i].newname)) + if (!_tcscmp (fname_in, floppy[i].newname)) drive_eject (&floppy[i]); } _wunlink (name2); } if (!needwritefile) - diskfile_readonly (name, writeprotected); + diskfile_readonly (outfname, writeprotected); diskfile_readonly (name2, writeprotected); return 1; } @@ -4490,7 +4502,7 @@ uae_u8 *restore_disk (int num,uae_u8 *src) write_log (_T("-> '%s'\n"), s); _tcscpy (old, currprefs.floppyslots[num].df); _tcsncpy (changed_prefs.floppyslots[num].df, s, 255); - xfree (s); + xfree(s); int dskready_up_time = restore_u16 (); int dskready_down_time = restore_u16 (); newis = changed_prefs.floppyslots[num].df[0] ? 1 : 0; diff --git a/filesys.cpp b/filesys.cpp index eaafa971..6296ffdd 100644 --- a/filesys.cpp +++ b/filesys.cpp @@ -330,11 +330,12 @@ int get_filesys_unitconfig (struct uae_prefs *p, int index, struct mountedinfo * memset (mi, 0, sizeof (struct mountedinfo)); memset (&uitmp, 0, sizeof uitmp); - cfgfile_resolve_path_out(uci->ci.rootdir, filepath, MAX_DPATH, PATH_DIR); - _tcscpy(mi->rootdir, filepath); + _tcscpy(mi->rootdir, uci->ci.rootdir); if (!ui) { ui = &uitmp; if (uci->ci.type == UAEDEV_DIR) { + cfgfile_resolve_path_out(uci->ci.rootdir, filepath, MAX_DPATH, PATH_DIR); + _tcscpy(mi->rootdir, filepath); mi->ismounted = 1; if (filepath[0] == 0) return FILESYS_VIRTUAL; @@ -347,6 +348,8 @@ int get_filesys_unitconfig (struct uae_prefs *p, int index, struct mountedinfo * mi->ismedia = true; return FILESYS_VIRTUAL; } else if (uci->ci.type == UAEDEV_HDF) { + cfgfile_resolve_path_out(uci->ci.rootdir, filepath, MAX_DPATH, PATH_HDF); + _tcscpy(mi->rootdir, filepath); ui->hf.ci.readonly = true; ui->hf.ci.blocksize = uci->ci.blocksize; int err = hdf_open (&ui->hf, filepath); @@ -366,6 +369,8 @@ int get_filesys_unitconfig (struct uae_prefs *p, int index, struct mountedinfo * mi->ismedia = 0; hdf_close (&ui->hf); } else if (uci->ci.type == UAEDEV_CD) { + cfgfile_resolve_path_out(uci->ci.rootdir, filepath, MAX_DPATH, PATH_CD); + _tcscpy(mi->rootdir, filepath); struct device_info di; ui->hf.ci.readonly = true; ui->hf.ci.blocksize = uci->ci.blocksize; @@ -392,6 +397,8 @@ int get_filesys_unitconfig (struct uae_prefs *p, int index, struct mountedinfo * } } if (uci->ci.type == UAEDEV_TAPE) { + cfgfile_resolve_path_out(uci->ci.rootdir, filepath, MAX_DPATH, PATH_TAPE); + _tcscpy(mi->rootdir, filepath); struct device_info di; int unitnum = getuindex (p, index); mi->size = -1; @@ -691,11 +698,11 @@ static int set_filesys_unit_1 (int nr, struct uaedev_config_info *ci, bool custo return nr; } - if (!custom) - cfgfile_resolve_path(c.rootdir, MAX_DPATH, PATH_DIR); - iscd = nr >= cd_unit_offset && nr < cd_unit_offset + cd_unit_number; + if (!custom) + cfgfile_resolve_path(c.rootdir, MAX_DPATH, iscd ? PATH_CD : (ci->volname[0] ? PATH_DIR : PATH_HDF)); + for (i = 0; i < MAX_FILESYSTEM_UNITS; i++) { if (nr == i || !mountinfo.ui[i].open || mountinfo.ui[i].rootdir == NULL || is_hardfile (i) == FILESYS_CD) continue; @@ -8634,7 +8641,7 @@ static int dofakefilesys (TrapContext *ctx, UnitInfo *uip, uaecptr parmpacket, s tmp[0] = 0; if (uip->filesysdir && _tcslen (uip->filesysdir) > 0) { - _tcscpy (tmp, uip->filesysdir); + cfgfile_resolve_path_out(uip->filesysdir, tmp, MAX_DPATH, PATH_HDF); } else if ((dostype & 0xffffff00) == DISK_TYPE_DOS) { _tcscpy (tmp, currprefs.romfile); int i = _tcslen (tmp); diff --git a/hardfile.cpp b/hardfile.cpp index 5ae93ca2..f6955007 100644 --- a/hardfile.cpp +++ b/hardfile.cpp @@ -385,7 +385,9 @@ static void create_virtual_rdb (struct hardfiledata *hfd) if (hfd->ci.filesys[0]) { struct zfile *f = NULL; - filesys = zfile_load_file(hfd->ci.filesys, &filesyslen); + TCHAR fspath[MAX_DPATH]; + cfgfile_resolve_path_out(hfd->ci.filesys, fspath, MAX_DPATH, PATH_HDF); + filesys = zfile_load_file(fspath, &filesyslen); if (filesys) { fsver = get_filesys_version(filesys, filesyslen); if (fsver == 0xffffffff) diff --git a/include/disk.h b/include/disk.h index 0020333b..4b6ae8d6 100644 --- a/include/disk.h +++ b/include/disk.h @@ -69,7 +69,7 @@ extern void disk_insert (int num, const TCHAR *name); extern void disk_insert (int num, const TCHAR *name, bool forcedwriteprotect); extern void disk_insert_force (int num, const TCHAR *name, bool forcedwriteprotect); extern void DISK_vsync (void); -extern int DISK_validate_filename (struct uae_prefs *p, const TCHAR *fname, int leave_open, bool *wrprot, uae_u32 *crc32, struct zfile **zf); +extern int DISK_validate_filename (struct uae_prefs *p, const TCHAR *fname, TCHAR *outfname, int leave_open, bool *wrprot, uae_u32 *crc32, struct zfile **zf); extern void DISK_handler (uae_u32); extern void DISK_update (int hpos); extern void DISK_update_adkcon (int hpos, uae_u16 v); diff --git a/include/options.h b/include/options.h index 5f37e7a1..ce6fdcad 100644 --- a/include/options.h +++ b/include/options.h @@ -30,6 +30,7 @@ struct multipath { TCHAR path[MAX_PATHS][PATH_MAX]; }; +#define PATH_NONE -1 #define PATH_FLOPPY 0 #define PATH_CD 1 #define PATH_DIR 2 @@ -910,6 +911,7 @@ extern int target_cfgfile_load (struct uae_prefs *, const TCHAR *filename, int t extern void cfgfile_save_options (struct zfile *f, struct uae_prefs *p, int type); extern int target_get_display (const TCHAR*); extern const TCHAR *target_get_display_name (int, bool); +extern void target_multipath_modified(struct uae_prefs *); extern void cfgfile_resolve_path_out(const TCHAR *path, TCHAR *out, int size, int type); extern void cfgfile_resolve_path(TCHAR *path, int size, int type); @@ -931,7 +933,6 @@ extern int built_in_prefs (struct uae_prefs *p, int model, int config, int compa extern int built_in_chipset_prefs (struct uae_prefs *p); extern int built_in_cpuboard_prefs(struct uae_prefs *p); extern int cmdlineparser (const TCHAR *s, TCHAR *outp[], int max); -extern int cfgfile_configuration_change (int); extern void fixup_prefs_dimensions (struct uae_prefs *prefs); extern void fixup_prefs (struct uae_prefs *prefs, bool userconfig); extern void fixup_cpu (struct uae_prefs *prefs); diff --git a/od-win32/win32gfx.cpp b/od-win32/win32gfx.cpp index 97b49af5..dc74ad99 100644 --- a/od-win32/win32gfx.cpp +++ b/od-win32/win32gfx.cpp @@ -2346,7 +2346,6 @@ int check_prefs_changed_gfx (void) int keepfsmode = currprefs.gfx_apmode[0].gfx_fullscreen == changed_prefs.gfx_apmode[0].gfx_fullscreen && currprefs.gfx_apmode[1].gfx_fullscreen == changed_prefs.gfx_apmode[1].gfx_fullscreen; - cfgfile_configuration_change (1); currprefs.gfx_autoresolution = changed_prefs.gfx_autoresolution; currprefs.gfx_autoresolution_vga = changed_prefs.gfx_autoresolution_vga; diff --git a/od-win32/win32gui.cpp b/od-win32/win32gui.cpp index e47eb975..63c54885 100644 --- a/od-win32/win32gui.cpp +++ b/od-win32/win32gui.cpp @@ -2143,6 +2143,15 @@ static struct ConfigStruct *getconfigstorefrompath (TCHAR *path, TCHAR *out, int return 0; } +void target_multipath_modified(struct uae_prefs *p) +{ + if (p != &workprefs) + return; + memcpy(&currprefs.path_hardfile, &p->path_hardfile, sizeof(struct multipath)); + memcpy(&currprefs.path_floppy, &p->path_floppy, sizeof(struct multipath)); + memcpy(&currprefs.path_cd, &p->path_cd, sizeof(struct multipath)); +} + int target_cfgfile_load (struct uae_prefs *p, const TCHAR *filename, int type, int isdefault) { int v, i, type2; @@ -2191,6 +2200,10 @@ int target_cfgfile_load (struct uae_prefs *p, const TCHAR *filename, int type, i ct2 = 0; regqueryint (NULL, _T("ConfigFile_NoAuto"), &ct2); v = cfgfile_load (p, fname, &type2, ct2, isdefault ? 0 : 1); + if (p == &workprefs) { + memcpy(&currprefs.path_hardfile, &p->path_hardfile, sizeof(struct multipath)); + memcpy(&currprefs.path_floppy, &p->path_floppy, sizeof(struct multipath)); + } if (!v) return v; if (type > 0) @@ -2245,7 +2258,7 @@ static void flipgui(int opengui) if (opengui) { DirectDraw_FlipToGDISurface(); } else { - if (uae_quit) + if (quit_program) return; full_redraw_all(); } @@ -2476,14 +2489,15 @@ void gui_infotextbox(HWND hDlg, const TCHAR *text) static void infofloppy (HWND hDlg, int n) { struct diskinfo di; - TCHAR tmp2[MAX_DPATH]; + TCHAR tmp2[MAX_DPATH], tmp1[MAX_DPATH]; TCHAR text[20000]; DISK_examine_image (&workprefs, n, &di); + DISK_validate_filename(&workprefs, workprefs.floppyslots[n].df, tmp1, 0, NULL, NULL, NULL); _stprintf (tmp2, _T("'%s'\r\nDisk readable: %s\r\nCRC32: %08X\r\nBoot block checksum valid: %s\r\nBoot block type: %s\r\n"), - workprefs.floppyslots[n].df, + tmp1, di.unreadable ? _T("No") : _T("Yes"), di.crc32, di.bb_crc_valid ? _T("Yes") : _T("No"), @@ -14742,7 +14756,7 @@ static void addfloppytype (HWND hDlg, int n) CheckDlgButton (hDlg, f_wp, chk); if (f_info >= 0) ew (hDlg, f_info, text[0] != 0); - chk = !showcd && state && DISK_validate_filename (&workprefs, text, 0, NULL, NULL, NULL) ? TRUE : FALSE; + chk = !showcd && state && DISK_validate_filename (&workprefs, text, NULL, 0, NULL, NULL, NULL) ? TRUE : FALSE; if (f_wp >= 0) { ew (hDlg, f_wp, chk && !workprefs.floppy_read_only); if (f_wptext >= 0) diff --git a/savestate.cpp b/savestate.cpp index be34fb56..b43b38cf 100644 --- a/savestate.cpp +++ b/savestate.cpp @@ -66,6 +66,7 @@ #include "threaddep/thread.h" #include "a2091.h" #include "devices.h" +#include "fsdb.h" int savestate_state = 0; static int savestate_first_capture; @@ -253,6 +254,14 @@ TCHAR *restore_string_func (uae_u8 **dstp) xfree (to); return s; } + +static bool state_path_exists(const TCHAR *path, int type) +{ + if (type == SAVESTATE_PATH_VDIR) + return my_existsdir(path); + return my_existsfile(path); +} + TCHAR *restore_path_func (uae_u8 **dstp, int type) { TCHAR *newpath; @@ -266,8 +275,16 @@ TCHAR *restore_path_func (uae_u8 **dstp, int type) return s; if (type == SAVESTATE_PATH_HD) return s; +#if 0 + _tcscpy(tmp, s); + fullpath(tmp, sizeof(tmp) / sizeof(TCHAR)); + if (state_path_exists(tmp, type)) { + xfree(s); + return my_strdup(tmp); + } +#endif getfilepart (tmp, sizeof tmp / sizeof (TCHAR), s); - if (zfile_exists (tmp)) { + if (state_path_exists(tmp, type)) { xfree (s); return my_strdup (tmp); } @@ -285,14 +302,14 @@ TCHAR *restore_path_func (uae_u8 **dstp, int type) fixtrailing (tmp2); _tcscat (tmp2, tmp); fullpath (tmp2, sizeof tmp2 / sizeof (TCHAR)); - if (zfile_exists (tmp2)) { + if (state_path_exists(tmp2, type)) { xfree (s); return my_strdup (tmp2); } } getpathpart (tmp2, sizeof tmp2 / sizeof (TCHAR), savestate_fname); _tcscat (tmp2, tmp); - if (zfile_exists (tmp2)) { + if (state_path_exists(tmp2, type)) { xfree (s); return my_strdup (tmp2); } @@ -1756,7 +1773,7 @@ retry2: input_record++; for (i = 0; i < 4; i++) { bool wp = true; - DISK_validate_filename (&currprefs, currprefs.floppyslots[i].df, false, &wp, NULL, NULL); + DISK_validate_filename (&currprefs, currprefs.floppyslots[i].df, NULL, false, &wp, NULL, NULL); inprec_recorddiskchange (i, currprefs.floppyslots[i].df, wp); } input_record--; diff --git a/scsitape.cpp b/scsitape.cpp index 2848bcdc..21c7b36e 100644 --- a/scsitape.cpp +++ b/scsitape.cpp @@ -61,9 +61,11 @@ void tape_free (struct scsi_data_tape *tape) static void tape_init (int unit, struct scsi_data_tape *tape, const TCHAR *tape_directory, bool readonly) { TCHAR path[MAX_DPATH]; + TCHAR tape_dir_path[MAX_DPATH]; memset (tape, 0, sizeof (struct scsi_data_tape)); - _tcscpy (tape->tape_dir, tape_directory); + cfgfile_resolve_path_out(tape_directory, tape_dir_path, MAX_DPATH, PATH_TAPE); + _tcscpy(tape->tape_dir, tape_dir_path); path[0] = 0; tape->blocksize = 512; @@ -82,7 +84,7 @@ static void tape_init (int unit, struct scsi_data_tape *tape, const TCHAR *tape_ if (my_existsdir(tape->tape_dir)) { tape->realdir = true; } else { - _tcscpy(tape->tape_dir, tape_directory); + _tcscpy(tape->tape_dir, tape_dir_path); zfile_fclose(tape->index); tape->index = NULL; } @@ -95,7 +97,7 @@ static void tape_init (int unit, struct scsi_data_tape *tape, const TCHAR *tape_ } if (!tape->index) { - _tcscpy(path, tape_directory); + _tcscpy(path, tape_dir_path); _tcscat(path, FSDB_DIR_SEPARATOR_S); _tcscat(path, TAPE_INDEX); tape->index = zfile_fopen(path, _T("rb"), ZFD_NORMAL); -- 2.47.3