diff options
Diffstat (limited to 'src/3rdParty/efsw/FileSystem.cpp')
-rw-r--r--[-rwxr-xr-x] | src/3rdParty/efsw/FileSystem.cpp | 59 |
1 files changed, 51 insertions, 8 deletions
diff --git a/src/3rdParty/efsw/FileSystem.cpp b/src/3rdParty/efsw/FileSystem.cpp index 867f120..1ed346c 100755..100644 --- a/src/3rdParty/efsw/FileSystem.cpp +++ b/src/3rdParty/efsw/FileSystem.cpp | |||
@@ -1,10 +1,19 @@ | |||
1 | #include <cstring> | ||
1 | #include <efsw/FileSystem.hpp> | 2 | #include <efsw/FileSystem.hpp> |
2 | #include <efsw/platform/platformimpl.hpp> | 3 | #include <efsw/platform/platformimpl.hpp> |
4 | #include <climits> | ||
3 | 5 | ||
4 | #if EFSW_OS == EFSW_OS_MACOSX | 6 | #if EFSW_OS == EFSW_OS_MACOSX |
5 | #include <CoreFoundation/CoreFoundation.h> | 7 | #include <CoreFoundation/CoreFoundation.h> |
6 | #endif | 8 | #endif |
7 | 9 | ||
10 | #if EFSW_OS == EFSW_OS_WIN | ||
11 | #ifndef WIN32_LEAN_AND_MEAN | ||
12 | #define WIN32_LEAN_AND_MEAN | ||
13 | #endif | ||
14 | #include <windows.h> | ||
15 | #endif | ||
16 | |||
8 | namespace efsw { | 17 | namespace efsw { |
9 | 18 | ||
10 | bool FileSystem::isDirectory( const std::string& path ) { | 19 | bool FileSystem::isDirectory( const std::string& path ) { |
@@ -26,13 +35,13 @@ bool FileSystem::slashAtEnd( std::string& dir ) { | |||
26 | } | 35 | } |
27 | 36 | ||
28 | void FileSystem::dirAddSlashAtEnd( std::string& dir ) { | 37 | void FileSystem::dirAddSlashAtEnd( std::string& dir ) { |
29 | if ( dir.size() > 1 && dir[dir.size() - 1] != getOSSlash() ) { | 38 | if ( dir.size() >= 1 && dir[dir.size() - 1] != getOSSlash() ) { |
30 | dir.push_back( getOSSlash() ); | 39 | dir.push_back( getOSSlash() ); |
31 | } | 40 | } |
32 | } | 41 | } |
33 | 42 | ||
34 | void FileSystem::dirRemoveSlashAtEnd( std::string& dir ) { | 43 | void FileSystem::dirRemoveSlashAtEnd( std::string& dir ) { |
35 | if ( dir.size() > 1 && dir[dir.size() - 1] == getOSSlash() ) { | 44 | if ( dir.size() >= 1 && dir[dir.size() - 1] == getOSSlash() ) { |
36 | dir.erase( dir.size() - 1 ); | 45 | dir.erase( dir.size() - 1 ); |
37 | } | 46 | } |
38 | } | 47 | } |
@@ -91,13 +100,30 @@ std::string FileSystem::precomposeFileName( const std::string& name ) { | |||
91 | 100 | ||
92 | CFStringNormalize( cfMutable, kCFStringNormalizationFormC ); | 101 | CFStringNormalize( cfMutable, kCFStringNormalizationFormC ); |
93 | 102 | ||
94 | char c_str[255 + 1]; | 103 | const char* c_str = CFStringGetCStringPtr( cfMutable, kCFStringEncodingUTF8 ); |
95 | CFStringGetCString( cfMutable, c_str, sizeof( c_str ) - 1, kCFStringEncodingUTF8 ); | 104 | if ( c_str != NULL ) { |
96 | 105 | std::string result( c_str ); | |
97 | CFRelease( cfStringRef ); | 106 | CFRelease( cfStringRef ); |
98 | CFRelease( cfMutable ); | 107 | CFRelease( cfMutable ); |
108 | return result; | ||
109 | } | ||
110 | CFIndex length = CFStringGetLength( cfMutable ); | ||
111 | CFIndex maxSize = CFStringGetMaximumSizeForEncoding( length, kCFStringEncodingUTF8 ); | ||
112 | if ( maxSize == kCFNotFound ) { | ||
113 | CFRelease( cfStringRef ); | ||
114 | CFRelease( cfMutable ); | ||
115 | return std::string(); | ||
116 | } | ||
99 | 117 | ||
100 | return std::string( c_str ); | 118 | std::string result( maxSize + 1, '\0' ); |
119 | if ( CFStringGetCString( cfMutable, &result[0], result.size(), kCFStringEncodingUTF8 ) ) { | ||
120 | result.resize( std::strlen( result.c_str() ) ); | ||
121 | CFRelease( cfStringRef ); | ||
122 | CFRelease( cfMutable ); | ||
123 | } else { | ||
124 | result.clear(); | ||
125 | } | ||
126 | return result; | ||
101 | #else | 127 | #else |
102 | return name; | 128 | return name; |
103 | #endif | 129 | #endif |
@@ -115,4 +141,21 @@ std::string FileSystem::getCurrentWorkingDirectory() { | |||
115 | return Platform::FileSystem::getCurrentWorkingDirectory(); | 141 | return Platform::FileSystem::getCurrentWorkingDirectory(); |
116 | } | 142 | } |
117 | 143 | ||
144 | std::string FileSystem::getRealPath( const std::string& path ) { | ||
145 | std::string realPath; | ||
146 | #if defined( EFSW_PLATFORM_POSIX ) | ||
147 | char dir[PATH_MAX]; | ||
148 | realpath( path.c_str(), &dir[0] ); | ||
149 | realPath = std::string( dir ); | ||
150 | #elif EFSW_OS == EFSW_OS_WIN | ||
151 | wchar_t dir[_MAX_PATH + 1]; | ||
152 | GetFullPathNameW( String::fromUtf8( path ).toWideString().c_str(), _MAX_PATH, &dir[0], | ||
153 | nullptr ); | ||
154 | realPath = String( dir ).toUtf8(); | ||
155 | #else | ||
156 | #warning FileSystem::getRealPath() not implemented on this platform. | ||
157 | #endif | ||
158 | return realPath; | ||
159 | } | ||
160 | |||
118 | } // namespace efsw | 161 | } // namespace efsw |