actually this is less invasive, based on code that was already there, and works in all cases, previous attempt failed when writing sfiii3 nvram (nw)

This commit is contained in:
mamehaze 2015-01-09 22:04:59 +00:00
parent 451bd0731c
commit 6e8a78dd0b

View File

@ -22,12 +22,6 @@
#include "winutil.h" #include "winutil.h"
#include "winutf8.h" #include "winutf8.h"
#if defined(SDLMAME_WIN32) || defined(SDLMAME_OS2)
#define INVPATHSEPCH '/'
#else
#define INVPATHSEPCH '\\'
#endif
#include "winfile.h" #include "winfile.h"
//============================================================ //============================================================
@ -96,8 +90,13 @@ file_error osd_open(const char *path, UINT32 openflags, osd_file **file, UINT64
// convert the path into something Windows compatible // convert the path into something Windows compatible
dst = (*file)->filename; dst = (*file)->filename;
#if defined(SDLMAME_WIN32) || defined(SDLMAME_OS2)
for (src = t_path; *src != 0; src++)
*dst++ = (*src == '/') ? '\\' : *src;
#else
for (src = t_path; *src != 0; src++) for (src = t_path; *src != 0; src++)
*dst++ = *src;//(*src == '/') ? '\\' : *src; *dst++ = *src;//(*src == '/') ? '\\' : *src;
#endif
*dst++ = 0; *dst++ = 0;
// select the file open modes // select the file open modes
@ -127,13 +126,13 @@ file_error osd_open(const char *path, UINT32 openflags, osd_file **file, UINT64
// create the path if necessary // create the path if necessary
if (error == ERROR_PATH_NOT_FOUND && (openflags & OPEN_FLAG_CREATE) && (openflags & OPEN_FLAG_CREATE_PATHS)) if (error == ERROR_PATH_NOT_FOUND && (openflags & OPEN_FLAG_CREATE) && (openflags & OPEN_FLAG_CREATE_PATHS))
{ {
TCHAR *pathsep = _tcsrchr((*file)->filename, INVPATHSEPCH); TCHAR *pathsep = _tcsrchr((*file)->filename, '\\');
if (pathsep != NULL) if (pathsep != NULL)
{ {
// create the path up to the file // create the path up to the file
*pathsep = 0; *pathsep = 0;
error = create_path_recursive((*file)->filename); error = create_path_recursive((*file)->filename);
*pathsep = INVPATHSEPCH; *pathsep = '\\';
// attempt to reopen the file // attempt to reopen the file
if (error == NO_ERROR) if (error == NO_ERROR)
@ -406,14 +405,14 @@ int osd_uchar_from_osdchar(UINT32 *uchar, const char *osdchar, size_t count)
DWORD create_path_recursive(const TCHAR *path) DWORD create_path_recursive(const TCHAR *path)
{ {
TCHAR *sep = (TCHAR *)_tcsrchr(path, INVPATHSEPCH); TCHAR *sep = (TCHAR *)_tcsrchr(path, '\\');
// if there's still a separator, and it's not the root, nuke it and recurse // if there's still a separator, and it's not the root, nuke it and recurse
if (sep != NULL && sep > path && sep[0] != ':' && sep[-1] != INVPATHSEPCH) if (sep != NULL && sep > path && sep[0] != ':' && sep[-1] != '\\')
{ {
*sep = 0; *sep = 0;
create_path_recursive(path); create_path_recursive(path);
*sep = INVPATHSEPCH; *sep = '\\';
} }
// if the path already exists, we're done // if the path already exists, we're done