55#include " physfs.h"
66#include " filesystem.h"
77#include " physfsrwops.h"
8- #include " filesystem/path.h"
98#include " ../ChaiLove.h"
109#include " Types/FileSystem/FileInfo.h"
1110
@@ -32,17 +31,15 @@ bool filesystem::init(const std::string& file, const void* data) {
3231 }
3332
3433 // Find the parent and extension of the given file.
35- ::filesystem::path p (file.c_str ());
36- std::string extension (p.extension ());
34+ std::string extension (getFileExtension (file));
3735
3836 // Allow loading from an Archive.
3937 if (extension == " chaigame" || extension == " chailove" || extension == " zip" ) {
4038 return mount (file.c_str (), " /" , false );
4139 }
4240
4341 // If we are just running the core, load the base path.
44- ::filesystem::path parent (p.parent_path ());
45- std::string parentPath (parent.str ());
42+ std::string parentPath (getParentDirectory (file));
4643 if (parentPath.empty ()) {
4744 return mount (" ." , " /" , false );
4845 }
@@ -51,6 +48,36 @@ bool filesystem::init(const std::string& file, const void* data) {
5148 return mount (parentPath.c_str (), " /" , false );
5249}
5350
51+ std::string filesystem::getParentDirectory (const std::string& filepath) {
52+ size_t last = filepath.find_last_of (" /\\ " );
53+ if (last != std::string::npos) {
54+ return filepath.substr (0 , last);
55+ }
56+ return " " ;
57+ }
58+
59+ std::string filesystem::getFileExtension (const std::string& filepath) {
60+ size_t i = filepath.rfind (' .' , filepath.length ());
61+ if (i != std::string::npos) {
62+ return filepath.substr (i + 1 , filepath.length () - i);
63+ }
64+ return " " ;
65+ }
66+
67+ std::string filesystem::getBasename (const std::string& filepath) {
68+ char sep = ' /' ;
69+ if (filepath.find (' \\ ' ) != std::string::npos) {
70+ sep = ' \\ ' ;
71+ }
72+
73+ size_t i = filepath.rfind (sep, filepath.length ());
74+ if (i != std::string::npos) {
75+ return filepath.substr (i + 1 , filepath.length () - i);
76+ }
77+
78+ return filepath;
79+ }
80+
5481void filesystem::mountlibretro () {
5582 // Mount some of the libretro directories.
5683 const char *system_dir = NULL ;
@@ -60,8 +87,8 @@ void filesystem::mountlibretro() {
6087
6188 if (ChaiLove::environ_cb (RETRO_ENVIRONMENT_GET_LIBRETRO_PATH, &core_dir) && core_dir) {
6289 // Make sure to get the directory of the core.
63- ::filesystem::path p ( core_dir);
64- mount (p. parent_path (). str () , " /libretro/core" , false );
90+ std::string parentPath ( getParentDirectory ( core_dir) );
91+ mount (parentPath , " /libretro/core" , false );
6592 }
6693 if (ChaiLove::environ_cb (RETRO_ENVIRONMENT_GET_SYSTEM_DIRECTORY, &system_dir) && system_dir) {
6794 mount (system_dir, " /libretro/system" , false );
0 commit comments