From 90e901f4a3106517d857ba5ff90afca593511f99 Mon Sep 17 00:00:00 2001 From: Stefanos Kornilios Mitsis Poiitidis Date: Wed, 18 Apr 2018 22:28:05 +0200 Subject: [PATCH] gdi: Normalize paths, add test gdi files --- core/imgread/gdi.cpp | 28 +++++++++++++++++++++++-- tests/files/test_gdis/a/cs.gdi | 4 ++++ tests/files/test_gdis/a/tracks/cs01.bin | 0 tests/files/test_gdis/a/tracks/cs02.raw | 0 tests/files/test_gdis/a/tracks/cs03.bin | 0 tests/files/test_gdis/b/cs.gdi | 4 ++++ tests/files/test_gdis/b/cs01.bin | 0 tests/files/test_gdis/b/cs02.raw | 0 tests/files/test_gdis/b/cs03.bin | 0 tests/files/test_gdis/c/cs.gdi | 4 ++++ tests/files/test_gdis/c/tracks/cs01.bin | 0 tests/files/test_gdis/c/tracks/cs02.raw | 0 tests/files/test_gdis/c/tracks/cs03.bin | 0 13 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 tests/files/test_gdis/a/cs.gdi create mode 100644 tests/files/test_gdis/a/tracks/cs01.bin create mode 100644 tests/files/test_gdis/a/tracks/cs02.raw create mode 100644 tests/files/test_gdis/a/tracks/cs03.bin create mode 100644 tests/files/test_gdis/b/cs.gdi create mode 100644 tests/files/test_gdis/b/cs01.bin create mode 100644 tests/files/test_gdis/b/cs02.raw create mode 100644 tests/files/test_gdis/b/cs03.bin create mode 100644 tests/files/test_gdis/c/cs.gdi create mode 100644 tests/files/test_gdis/c/tracks/cs01.bin create mode 100644 tests/files/test_gdis/c/tracks/cs02.raw create mode 100644 tests/files/test_gdis/c/tracks/cs03.bin diff --git a/core/imgread/gdi.cpp b/core/imgread/gdi.cpp index 3ab1d6ad5..4c19a1310 100644 --- a/core/imgread/gdi.cpp +++ b/core/imgread/gdi.cpp @@ -1,6 +1,7 @@ #include "common.h" #include #include +#include // given file/name.ext or file\name.ext returns file/ or file\, depending on the platform // given name.ext returns ./ or .\, depending on the platform @@ -24,6 +25,19 @@ string OS_dirname(string file) return file.substr(0, last_slash + 1); } +// On windows, transform / to \\ +// On linux, transform \\ to / +string normalize_path_separator(string path) +{ + #if HOST_OS == OS_WINDOWS + std::replace( path.begin(), path.end(), '/', '\\'); + #else + std::replace( path.begin(), path.end(), '\\', '/'); + #endif + + return path; +} + #if 0 // TODO: Move this to some tests, make it platform agnostic namespace { struct OS_dirname_Test { @@ -33,7 +47,17 @@ namespace { verify(OS_dirname("local/path/three\\a.exe") == "local/path/"); verify(OS_dirname("local.ext") == "./"); } - } test; + } test1; + + struct normalize_path_separator_Test { + normalize_path_separator_Test() { + verify(normalize_path_separator("local/path") == "local/path"); + verify(normalize_path_separator("local\\path") == "local/path"); + verify(normalize_path_separator("local\\path\\") == "local/path/"); + verify(normalize_path_separator("\\local\\path\\") == "/local/path/"); + verify(normalize_path_separator("loc\\al\\pa\\th") == "loc/al/pa/th"); + } + } test2; } #endif @@ -114,7 +138,7 @@ Disc* load_gdi(const char* file) if (SSIZE!=0) { - string path = basepath + track_filename; + string path = basepath + normalize_path_separator(track_filename); t.file = new RawTrackFile(core_fopen(path.c_str()),OFFSET,t.StartFAD,SSIZE); } disc->tracks.push_back(t); diff --git a/tests/files/test_gdis/a/cs.gdi b/tests/files/test_gdis/a/cs.gdi new file mode 100644 index 000000000..faca45760 --- /dev/null +++ b/tests/files/test_gdis/a/cs.gdi @@ -0,0 +1,4 @@ +3 +1 0 4 2352 tracks\cs01.bin 0 +2 450 0 2352 tracks\cs02.raw 0 +3 45000 4 2352 tracks\cs03.bin 0 diff --git a/tests/files/test_gdis/a/tracks/cs01.bin b/tests/files/test_gdis/a/tracks/cs01.bin new file mode 100644 index 000000000..e69de29bb diff --git a/tests/files/test_gdis/a/tracks/cs02.raw b/tests/files/test_gdis/a/tracks/cs02.raw new file mode 100644 index 000000000..e69de29bb diff --git a/tests/files/test_gdis/a/tracks/cs03.bin b/tests/files/test_gdis/a/tracks/cs03.bin new file mode 100644 index 000000000..e69de29bb diff --git a/tests/files/test_gdis/b/cs.gdi b/tests/files/test_gdis/b/cs.gdi new file mode 100644 index 000000000..5562ee8c8 --- /dev/null +++ b/tests/files/test_gdis/b/cs.gdi @@ -0,0 +1,4 @@ +3 +1 0 4 2352 cs01.bin 0 +2 450 0 2352 cs02.raw 0 +3 45000 4 2352 cs03.bin 0 diff --git a/tests/files/test_gdis/b/cs01.bin b/tests/files/test_gdis/b/cs01.bin new file mode 100644 index 000000000..e69de29bb diff --git a/tests/files/test_gdis/b/cs02.raw b/tests/files/test_gdis/b/cs02.raw new file mode 100644 index 000000000..e69de29bb diff --git a/tests/files/test_gdis/b/cs03.bin b/tests/files/test_gdis/b/cs03.bin new file mode 100644 index 000000000..e69de29bb diff --git a/tests/files/test_gdis/c/cs.gdi b/tests/files/test_gdis/c/cs.gdi new file mode 100644 index 000000000..73563f35e --- /dev/null +++ b/tests/files/test_gdis/c/cs.gdi @@ -0,0 +1,4 @@ +3 +1 0 4 2352 tracks/cs01.bin 0 +2 450 0 2352 tracks/cs02.raw 0 +3 45000 4 2352 tracks/cs03.bin 0 diff --git a/tests/files/test_gdis/c/tracks/cs01.bin b/tests/files/test_gdis/c/tracks/cs01.bin new file mode 100644 index 000000000..e69de29bb diff --git a/tests/files/test_gdis/c/tracks/cs02.raw b/tests/files/test_gdis/c/tracks/cs02.raw new file mode 100644 index 000000000..e69de29bb diff --git a/tests/files/test_gdis/c/tracks/cs03.bin b/tests/files/test_gdis/c/tracks/cs03.bin new file mode 100644 index 000000000..e69de29bb