aboutsummaryrefslogtreecommitdiff
path: root/src/3rdParty/efsw/platform/win/FileSystemImpl.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/3rdParty/efsw/platform/win/FileSystemImpl.cpp')
-rwxr-xr-xsrc/3rdParty/efsw/platform/win/FileSystemImpl.cpp111
1 files changed, 111 insertions, 0 deletions
diff --git a/src/3rdParty/efsw/platform/win/FileSystemImpl.cpp b/src/3rdParty/efsw/platform/win/FileSystemImpl.cpp
new file mode 100755
index 0000000..2b87513
--- /dev/null
+++ b/src/3rdParty/efsw/platform/win/FileSystemImpl.cpp
@@ -0,0 +1,111 @@
1#include <efsw/platform/win/FileSystemImpl.hpp>
2
3#if EFSW_PLATFORM == EFSW_PLATFORM_WIN32
4
5#include <climits>
6#ifndef WIN32_LEAN_AND_MEAN
7#define WIN32_LEAN_AND_MEAN
8#endif
9#include <windows.h>
10
11#ifndef EFSW_COMPILER_MSVC
12#include <dirent.h>
13#else
14#include <direct.h>
15#endif
16
17namespace efsw { namespace Platform {
18
19bool FileSystem::changeWorkingDirectory( const std::string& path ) {
20 int res;
21#ifdef EFSW_COMPILER_MSVC
22#ifdef UNICODE
23 res = _wchdir( String::fromUtf8( path.c_str() ).toWideString().c_str() );
24#else
25 res = _chdir( String::fromUtf8( path.c_str() ).toAnsiString().c_str() );
26#endif
27#else
28 res = chdir( path.c_str() );
29#endif
30 return -1 != res;
31}
32
33std::string FileSystem::getCurrentWorkingDirectory() {
34#ifdef EFSW_COMPILER_MSVC
35#if defined( UNICODE ) && !defined( EFSW_NO_WIDECHAR )
36 wchar_t dir[_MAX_PATH];
37 return ( 0 != GetCurrentDirectoryW( _MAX_PATH, dir ) ) ? String( dir ).toUtf8() : std::string();
38#else
39 char dir[_MAX_PATH];
40 return ( 0 != GetCurrentDirectory( _MAX_PATH, dir ) ) ? String( dir, std::locale() ).toUtf8()
41 : std::string();
42#endif
43#else
44 char dir[PATH_MAX + 1];
45 getcwd( dir, PATH_MAX + 1 );
46 return std::string( dir );
47#endif
48}
49
50FileInfoMap FileSystem::filesInfoFromPath( const std::string& path ) {
51 FileInfoMap files;
52
53 String tpath( path );
54
55 if ( tpath[tpath.size() - 1] == '/' || tpath[tpath.size() - 1] == '\\' ) {
56 tpath += "*";
57 } else {
58 tpath += "\\*";
59 }
60
61 WIN32_FIND_DATAW findFileData;
62 HANDLE hFind = FindFirstFileW( (LPCWSTR)tpath.toWideString().c_str(), &findFileData );
63
64 if ( hFind != INVALID_HANDLE_VALUE ) {
65 std::string name( String( findFileData.cFileName ).toUtf8() );
66 std::string fpath( path + name );
67
68 if ( name != "." && name != ".." ) {
69 files[name] = FileInfo( fpath );
70 }
71
72 while ( FindNextFileW( hFind, &findFileData ) ) {
73 name = String( findFileData.cFileName ).toUtf8();
74 fpath = path + name;
75
76 if ( name != "." && name != ".." ) {
77 files[name] = FileInfo( fpath );
78 }
79 }
80
81 FindClose( hFind );
82 }
83
84 return files;
85}
86
87char FileSystem::getOSSlash() {
88 return '\\';
89}
90
91bool FileSystem::isDirectory( const std::string& path ) {
92 DWORD attrs = GetFileAttributesW( String( path ).toWideString().c_str() );
93 return attrs != INVALID_FILE_ATTRIBUTES && ( attrs & FILE_ATTRIBUTE_DIRECTORY ) != 0;
94}
95
96bool FileSystem::isRemoteFS( const std::string& directory ) {
97 if ( ( directory[0] == '\\' || directory[0] == '/' ) &&
98 ( directory[1] == '\\' || directory[1] == '/' ) ) {
99 return true;
100 }
101
102 if ( directory.size() >= 3 ) {
103 return 4 == GetDriveTypeA( directory.substr( 0, 3 ).c_str() );
104 }
105
106 return false;
107}
108
109}} // namespace efsw::Platform
110
111#endif