From 658114024f6e78b3526dd8bbcddccb42a5863f59 Mon Sep 17 00:00:00 2001 From: Toni Wilen Date: Sat, 30 Jun 2018 13:12:10 +0300 Subject: [PATCH] Copy config to configstore at startup. --- cfgfile.cpp | 57 ++++++++++++++++++++++++++++++++++++++++++----- include/options.h | 2 ++ include/zfile.h | 1 + main.cpp | 1 + zfile.cpp | 9 ++++++++ 5 files changed, 64 insertions(+), 6 deletions(-) diff --git a/cfgfile.cpp b/cfgfile.cpp index be04536d..91d95f12 100644 --- a/cfgfile.cpp +++ b/cfgfile.cpp @@ -592,7 +592,7 @@ static TCHAR *getnextentry (const TCHAR **valuep, const TCHAR separator) static TCHAR *cfgfile_subst_path2 (const TCHAR *path, const TCHAR *subst, const TCHAR *file) { /* @@@ use strcasecmp for some targets. */ - if (_tcslen (path) > 0 && _tcsncmp (file, path, _tcslen (path)) == 0) { + if (path != NULL && subst != NULL && _tcslen (path) > 0 && _tcsncmp (file, path, _tcslen (path)) == 0) { int l; TCHAR *p2, *p = xmalloc (TCHAR, _tcslen (file) + _tcslen (subst) + 2); _tcscpy (p, subst); @@ -675,6 +675,7 @@ static TCHAR *cfgfile_put_multipath (struct multipath *mp, const TCHAR *s) return my_strdup (s); } + static TCHAR *cfgfile_subst_path_load (const TCHAR *path, struct multipath *mp, const TCHAR *file, bool dir) { TCHAR *s = cfgfile_get_multipath2 (mp, path, file, dir); @@ -976,6 +977,39 @@ static void cfgfile_adjust_path(TCHAR *path, int maxsz, struct multipath *mp) xfree(s); } +void cfgfile_resolve_path_out(const TCHAR *path, TCHAR *out, int size, int type) +{ + struct uae_prefs *p = &currprefs; + TCHAR *s = NULL; + switch (type) + { + case PATH_DIR: + 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); + break; + case PATH_FLOPPY: + _tcscpy(out, path); + cfgfile_adjust_path(out, MAX_DPATH, &p->path_floppy); + break; + default: + s = cfgfile_subst_path(NULL, NULL, path); + break; + } + if (s) { + _tcscpy(out, s); + xfree(s); + } + my_resolvesoftlink(out, size); +} + +void cfgfile_resolve_path(TCHAR *path, int size, int type) +{ + cfgfile_resolve_path_out(path, path, size, type); +} + + static void write_filesys_config (struct uae_prefs *p, struct zfile *f) { TCHAR tmp[MAX_DPATH], tmp2[MAX_DPATH], tmp3[MAX_DPATH], hdcs[MAX_DPATH]; @@ -4702,8 +4736,10 @@ 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); @@ -5279,6 +5315,8 @@ static int cfgfile_parse_hardware (struct uae_prefs *p, const TCHAR *option, TCH if (cfgfile_yesno(option, value, _T("fpu_msvc_long_double"), &dummybool)) { if (dummybool) p->fpu_mode = -1; + else if (p->fpu_mode < 0) + p->fpu_mode = 0; return 1; } #endif @@ -5816,7 +5854,6 @@ void cfgfile_compatibility_romtype(struct uae_prefs *p) romtype_restricted(p, restricted_pci); } -static bool createconfigstore (struct uae_prefs*); static int getconfigstoreline (const TCHAR *option, TCHAR *value); static void calcformula (struct uae_prefs *prefs, TCHAR *in) @@ -5830,7 +5867,7 @@ static void calcformula (struct uae_prefs *prefs, TCHAR *in) if (_tcslen (in) < 2 || in[0] != '[' || in[_tcslen (in) - 1] != ']') return; if (!configstore || updatestore) - createconfigstore (prefs); + cfgfile_createconfigstore (prefs); updatestore = false; if (!configstore) return; @@ -6096,6 +6133,14 @@ static void subst (TCHAR *p, TCHAR *f, int n) free (str); } +const TCHAR *cfgfile_getconfigdata(int *len) +{ + *len = -1; + if (!configstore) + return NULL; + return (TCHAR*)zfile_get_data_pointer(configstore, len); +} + static int getconfigstoreline (const TCHAR *option, TCHAR *value) { TCHAR tmp[CONFIG_BLEN * 2], tmp2[CONFIG_BLEN * 2]; @@ -6113,7 +6158,7 @@ static int getconfigstoreline (const TCHAR *option, TCHAR *value) } } -static bool createconfigstore (struct uae_prefs *p) +bool cfgfile_createconfigstore(struct uae_prefs *p) { uae_u8 zeros[4] = { 0 }; zfile_fclose (configstore); @@ -6981,7 +7026,7 @@ int cfgfile_searchconfig(const TCHAR *in, int index, TCHAR *out, int outsize) *out = 0; if (!configstore) - createconfigstore(&currprefs); + cfgfile_createconfigstore(&currprefs); if (!configstore) return 20; @@ -7090,7 +7135,7 @@ uae_u32 cfgfile_modify (uae_u32 index, const TCHAR *parms, uae_u32 size, TCHAR * argv = cmdlineparser (parms, argc, UAELIB_MAX_PARSE); if (argv <= 1 && index == 0xffffffff) { - createconfigstore (&currprefs); + cfgfile_createconfigstore (&currprefs); xfree (configsearch); configsearch = NULL; if (!configstore) { diff --git a/include/options.h b/include/options.h index 99511216..b984f88f 100644 --- a/include/options.h +++ b/include/options.h @@ -938,6 +938,8 @@ extern void fixup_cpu (struct uae_prefs *prefs); extern void cfgfile_compatibility_romtype(struct uae_prefs *p); extern void cfgfile_compatibility_rtg(struct uae_prefs *p); extern bool cfgfile_detect_art(struct uae_prefs *p, TCHAR *path); +extern const TCHAR *cfgfile_getconfigdata(int *len); +extern bool cfgfile_createconfigstore(struct uae_prefs *p); extern void check_prefs_changed_custom (void); extern void check_prefs_changed_cpu (void); diff --git a/include/zfile.h b/include/zfile.h index 878e5b77..0d97583b 100644 --- a/include/zfile.h +++ b/include/zfile.h @@ -50,6 +50,7 @@ extern struct zfile *zfile_fopen_load_zfile (struct zfile *f); extern uae_u8 *zfile_load_data (const TCHAR *name, const uae_u8 *data,int datalen, int *outlen); extern uae_u8 *zfile_load_file(const TCHAR *name, int *outlen); extern struct zfile *zfile_fopen_parent (struct zfile*, const TCHAR*, uae_u64 offset, uae_u64 size); +extern uae_u8 *zfile_get_data_pointer(struct zfile *z, int *len); extern int zfile_exists (const TCHAR *name); extern void zfile_fclose (struct zfile *); diff --git a/main.cpp b/main.cpp index 93a6db37..abc7f51a 100644 --- a/main.cpp +++ b/main.cpp @@ -746,6 +746,7 @@ void fixup_prefs (struct uae_prefs *p, bool userconfig) blkdev_fix_prefs (p); inputdevice_fix_prefs(p, userconfig); target_fixup_options (p); + cfgfile_createconfigstore(p); } int quit_program = 0; diff --git a/zfile.cpp b/zfile.cpp index 5fe73af0..a5636488 100644 --- a/zfile.cpp +++ b/zfile.cpp @@ -2092,6 +2092,15 @@ struct zfile *zfile_fopen_data (const TCHAR *name, uae_u64 size, const uae_u8 *d return l; } +/* dump file use only */ +uae_u8 *zfile_get_data_pointer(struct zfile *z, int *len) +{ + if (!z->data) + return NULL; + *len = z->size; + return z->data; +} + uae_u8 *zfile_load_data (const TCHAR *name, const uae_u8 *data,int datalen, int *outlen) { struct zfile *zf, *f; -- 2.47.3