gdi: Cleanup path code, use C++ strings
This commit is contained in:
parent
052c5c1cb3
commit
4300951b51
|
@ -1,9 +1,40 @@
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#ifdef WIN32
|
|
||||||
#include <BaseTsd.h>
|
// given file/name.ext or file\name.ext returns file/ or file\, depending on the platform
|
||||||
typedef SSIZE_T ssize_t;
|
// given name.ext returns ./ or .\, depending on the platform
|
||||||
|
string OS_dirname(string file)
|
||||||
|
{
|
||||||
|
#if HOST_OS == OS_WINDOWS
|
||||||
|
const char sep = '\\';
|
||||||
|
#else
|
||||||
|
const char sep = '/';
|
||||||
|
#endif
|
||||||
|
|
||||||
|
size_t last_slash = file.find_last_of(sep);
|
||||||
|
|
||||||
|
if (last_slash == string::npos)
|
||||||
|
{
|
||||||
|
string local_dir = ".";
|
||||||
|
local_dir += sep;
|
||||||
|
return local_dir;
|
||||||
|
}
|
||||||
|
|
||||||
|
return file.substr(0, last_slash + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
#if 0 // TODO: Move this to some tests, make it platform agnostic
|
||||||
|
namespace {
|
||||||
|
struct OS_dirname_Test {
|
||||||
|
OS_dirname_Test() {
|
||||||
|
verify(OS_dirname("local/path") == "local/");
|
||||||
|
verify(OS_dirname("local/path/two") == "local/path/");
|
||||||
|
verify(OS_dirname("local/path/three\\a.exe") == "local/path/");
|
||||||
|
verify(OS_dirname("local.ext") == "./");
|
||||||
|
}
|
||||||
|
} test;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
Disc* load_gdi(const char* file)
|
Disc* load_gdi(const char* file)
|
||||||
|
@ -35,21 +66,9 @@ Disc* load_gdi(const char* file)
|
||||||
gdi >> iso_tc;
|
gdi >> iso_tc;
|
||||||
printf("\nGDI : %d tracks\n",iso_tc);
|
printf("\nGDI : %d tracks\n",iso_tc);
|
||||||
|
|
||||||
// FIXME: Data loss if buffer is too small
|
|
||||||
char path[512];
|
|
||||||
strncpy(path, file, sizeof(path));
|
|
||||||
path[sizeof(path) - 1] = '\0';
|
|
||||||
|
|
||||||
ssize_t len = strlen(path);
|
string basepath = OS_dirname(file);
|
||||||
|
|
||||||
while (len>=0)
|
|
||||||
{
|
|
||||||
if (path[len]=='\\' || path[len]=='/')
|
|
||||||
break;
|
|
||||||
len--;
|
|
||||||
}
|
|
||||||
len++;
|
|
||||||
char* pathptr=&path[len];
|
|
||||||
u32 TRACK=0,FADS=0,CTRL=0,SSIZE=0;
|
u32 TRACK=0,FADS=0,CTRL=0,SSIZE=0;
|
||||||
s32 OFFSET=0;
|
s32 OFFSET=0;
|
||||||
for (u32 i=0;i<iso_tc;i++)
|
for (u32 i=0;i<iso_tc;i++)
|
||||||
|
@ -95,8 +114,8 @@ Disc* load_gdi(const char* file)
|
||||||
|
|
||||||
if (SSIZE!=0)
|
if (SSIZE!=0)
|
||||||
{
|
{
|
||||||
strcpy(pathptr, track_filename.c_str());
|
string path = basepath + track_filename;
|
||||||
t.file = new RawTrackFile(core_fopen(path),OFFSET,t.StartFAD,SSIZE);
|
t.file = new RawTrackFile(core_fopen(path.c_str()),OFFSET,t.StartFAD,SSIZE);
|
||||||
}
|
}
|
||||||
disc->tracks.push_back(t);
|
disc->tracks.push_back(t);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue