diff options
author | Li Jin <dragon-fly@qq.com> | 2022-11-15 17:23:46 +0800 |
---|---|---|
committer | Li Jin <dragon-fly@qq.com> | 2022-11-15 17:52:09 +0800 |
commit | 94f8330613877b3582d32bd11abd83a97b4399ad (patch) | |
tree | 5359de314be1ebde17f8d1e48632a97d18f9e50f /src/3rdParty/efsw/platform/win | |
parent | 60f8f00a022ac08701792b2897b72d8c99b50f52 (diff) | |
download | yuescript-94f8330613877b3582d32bd11abd83a97b4399ad.tar.gz yuescript-94f8330613877b3582d32bd11abd83a97b4399ad.tar.bz2 yuescript-94f8330613877b3582d32bd11abd83a97b4399ad.zip |
adding -w option to Yuescript tool.
Diffstat (limited to 'src/3rdParty/efsw/platform/win')
-rwxr-xr-x | src/3rdParty/efsw/platform/win/FileSystemImpl.cpp | 111 | ||||
-rwxr-xr-x | src/3rdParty/efsw/platform/win/FileSystemImpl.hpp | 31 | ||||
-rwxr-xr-x | src/3rdParty/efsw/platform/win/MutexImpl.cpp | 25 | ||||
-rwxr-xr-x | src/3rdParty/efsw/platform/win/MutexImpl.hpp | 33 | ||||
-rwxr-xr-x | src/3rdParty/efsw/platform/win/SystemImpl.cpp | 46 | ||||
-rwxr-xr-x | src/3rdParty/efsw/platform/win/SystemImpl.hpp | 25 | ||||
-rwxr-xr-x | src/3rdParty/efsw/platform/win/ThreadImpl.cpp | 56 | ||||
-rwxr-xr-x | src/3rdParty/efsw/platform/win/ThreadImpl.hpp | 42 |
8 files changed, 369 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 | |||
17 | namespace efsw { namespace Platform { | ||
18 | |||
19 | bool 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 | |||
33 | std::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 | |||
50 | FileInfoMap 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 | |||
87 | char FileSystem::getOSSlash() { | ||
88 | return '\\'; | ||
89 | } | ||
90 | |||
91 | bool 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 | |||
96 | bool 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 | ||
diff --git a/src/3rdParty/efsw/platform/win/FileSystemImpl.hpp b/src/3rdParty/efsw/platform/win/FileSystemImpl.hpp new file mode 100755 index 0000000..e952efc --- /dev/null +++ b/src/3rdParty/efsw/platform/win/FileSystemImpl.hpp | |||
@@ -0,0 +1,31 @@ | |||
1 | #ifndef EFSW_FILESYSTEMIMPLWIN_HPP | ||
2 | #define EFSW_FILESYSTEMIMPLWIN_HPP | ||
3 | |||
4 | #include <efsw/FileInfo.hpp> | ||
5 | #include <efsw/String.hpp> | ||
6 | #include <efsw/base.hpp> | ||
7 | |||
8 | #if EFSW_PLATFORM == EFSW_PLATFORM_WIN32 | ||
9 | |||
10 | namespace efsw { namespace Platform { | ||
11 | |||
12 | class FileSystem { | ||
13 | public: | ||
14 | static FileInfoMap filesInfoFromPath( const std::string& path ); | ||
15 | |||
16 | static char getOSSlash(); | ||
17 | |||
18 | static bool isDirectory( const std::string& path ); | ||
19 | |||
20 | static bool isRemoteFS( const std::string& directory ); | ||
21 | |||
22 | static bool changeWorkingDirectory( const std::string& path ); | ||
23 | |||
24 | static std::string getCurrentWorkingDirectory(); | ||
25 | }; | ||
26 | |||
27 | }} // namespace efsw::Platform | ||
28 | |||
29 | #endif | ||
30 | |||
31 | #endif | ||
diff --git a/src/3rdParty/efsw/platform/win/MutexImpl.cpp b/src/3rdParty/efsw/platform/win/MutexImpl.cpp new file mode 100755 index 0000000..62b7f83 --- /dev/null +++ b/src/3rdParty/efsw/platform/win/MutexImpl.cpp | |||
@@ -0,0 +1,25 @@ | |||
1 | #include <efsw/platform/win/MutexImpl.hpp> | ||
2 | |||
3 | #if EFSW_PLATFORM == EFSW_PLATFORM_WIN32 | ||
4 | |||
5 | namespace efsw { namespace Platform { | ||
6 | |||
7 | MutexImpl::MutexImpl() { | ||
8 | InitializeCriticalSection( &mMutex ); | ||
9 | } | ||
10 | |||
11 | MutexImpl::~MutexImpl() { | ||
12 | DeleteCriticalSection( &mMutex ); | ||
13 | } | ||
14 | |||
15 | void MutexImpl::lock() { | ||
16 | EnterCriticalSection( &mMutex ); | ||
17 | } | ||
18 | |||
19 | void MutexImpl::unlock() { | ||
20 | LeaveCriticalSection( &mMutex ); | ||
21 | } | ||
22 | |||
23 | }} // namespace efsw::Platform | ||
24 | |||
25 | #endif | ||
diff --git a/src/3rdParty/efsw/platform/win/MutexImpl.hpp b/src/3rdParty/efsw/platform/win/MutexImpl.hpp new file mode 100755 index 0000000..7b06492 --- /dev/null +++ b/src/3rdParty/efsw/platform/win/MutexImpl.hpp | |||
@@ -0,0 +1,33 @@ | |||
1 | #ifndef EFSW_MUTEXIMPLWIN_HPP | ||
2 | #define EFSW_MUTEXIMPLWIN_HPP | ||
3 | |||
4 | #include <efsw/base.hpp> | ||
5 | |||
6 | #if EFSW_PLATFORM == EFSW_PLATFORM_WIN32 | ||
7 | |||
8 | #ifndef WIN32_LEAN_AND_MEAN | ||
9 | #define WIN32_LEAN_AND_MEAN | ||
10 | #endif | ||
11 | #include <windows.h> | ||
12 | |||
13 | namespace efsw { namespace Platform { | ||
14 | |||
15 | class MutexImpl { | ||
16 | public: | ||
17 | MutexImpl(); | ||
18 | |||
19 | ~MutexImpl(); | ||
20 | |||
21 | void lock(); | ||
22 | |||
23 | void unlock(); | ||
24 | |||
25 | private: | ||
26 | CRITICAL_SECTION mMutex; | ||
27 | }; | ||
28 | |||
29 | }} // namespace efsw::Platform | ||
30 | |||
31 | #endif | ||
32 | |||
33 | #endif | ||
diff --git a/src/3rdParty/efsw/platform/win/SystemImpl.cpp b/src/3rdParty/efsw/platform/win/SystemImpl.cpp new file mode 100755 index 0000000..d1f2b21 --- /dev/null +++ b/src/3rdParty/efsw/platform/win/SystemImpl.cpp | |||
@@ -0,0 +1,46 @@ | |||
1 | #include <efsw/String.hpp> | ||
2 | #include <efsw/platform/win/SystemImpl.hpp> | ||
3 | |||
4 | #if EFSW_PLATFORM == EFSW_PLATFORM_WIN32 | ||
5 | |||
6 | #ifndef WIN32_LEAN_AND_MEAN | ||
7 | #define WIN32_LEAN_AND_MEAN | ||
8 | #endif | ||
9 | #include <cstdlib> | ||
10 | #include <windows.h> | ||
11 | |||
12 | namespace efsw { namespace Platform { | ||
13 | |||
14 | void System::sleep( const unsigned long& ms ) { | ||
15 | ::Sleep( ms ); | ||
16 | } | ||
17 | |||
18 | std::string System::getProcessPath() { | ||
19 | // Get path to executable: | ||
20 | WCHAR szDrive[_MAX_DRIVE]; | ||
21 | WCHAR szDir[_MAX_DIR]; | ||
22 | WCHAR szFilename[_MAX_DIR]; | ||
23 | WCHAR szExt[_MAX_DIR]; | ||
24 | std::wstring dllName( _MAX_DIR, 0 ); | ||
25 | |||
26 | GetModuleFileNameW( 0, &dllName[0], _MAX_PATH ); | ||
27 | |||
28 | #ifdef EFSW_COMPILER_MSVC | ||
29 | _wsplitpath_s( dllName.c_str(), szDrive, _MAX_DRIVE, szDir, _MAX_DIR, szFilename, _MAX_DIR, | ||
30 | szExt, _MAX_DIR ); | ||
31 | #else | ||
32 | _wsplitpath( dllName.c_str(), szDrive, szDir, szFilename, szExt ); | ||
33 | #endif | ||
34 | |||
35 | return String( szDrive ).toUtf8() + String( szDir ).toUtf8(); | ||
36 | } | ||
37 | |||
38 | void System::maxFD() {} | ||
39 | |||
40 | Uint64 System::getMaxFD() { // Number of ReadDirectory per thread | ||
41 | return 60; | ||
42 | } | ||
43 | |||
44 | }} // namespace efsw::Platform | ||
45 | |||
46 | #endif | ||
diff --git a/src/3rdParty/efsw/platform/win/SystemImpl.hpp b/src/3rdParty/efsw/platform/win/SystemImpl.hpp new file mode 100755 index 0000000..99b4867 --- /dev/null +++ b/src/3rdParty/efsw/platform/win/SystemImpl.hpp | |||
@@ -0,0 +1,25 @@ | |||
1 | #ifndef EFSW_SYSTEMIMPLWIN_HPP | ||
2 | #define EFSW_SYSTEMIMPLWIN_HPP | ||
3 | |||
4 | #include <efsw/base.hpp> | ||
5 | |||
6 | #if EFSW_PLATFORM == EFSW_PLATFORM_WIN32 | ||
7 | |||
8 | namespace efsw { namespace Platform { | ||
9 | |||
10 | class System { | ||
11 | public: | ||
12 | static void sleep( const unsigned long& ms ); | ||
13 | |||
14 | static std::string getProcessPath(); | ||
15 | |||
16 | static void maxFD(); | ||
17 | |||
18 | static Uint64 getMaxFD(); | ||
19 | }; | ||
20 | |||
21 | }} // namespace efsw::Platform | ||
22 | |||
23 | #endif | ||
24 | |||
25 | #endif | ||
diff --git a/src/3rdParty/efsw/platform/win/ThreadImpl.cpp b/src/3rdParty/efsw/platform/win/ThreadImpl.cpp new file mode 100755 index 0000000..d0fde8b --- /dev/null +++ b/src/3rdParty/efsw/platform/win/ThreadImpl.cpp | |||
@@ -0,0 +1,56 @@ | |||
1 | #include <assert.h> | ||
2 | #include <efsw/Thread.hpp> | ||
3 | #include <efsw/platform/win/ThreadImpl.hpp> | ||
4 | |||
5 | #if EFSW_PLATFORM == EFSW_PLATFORM_WIN32 | ||
6 | |||
7 | #include <efsw/Debug.hpp> | ||
8 | |||
9 | namespace efsw { namespace Platform { | ||
10 | |||
11 | ThreadImpl::ThreadImpl( Thread* owner ) { | ||
12 | mThread = reinterpret_cast<HANDLE>( | ||
13 | _beginthreadex( NULL, 0, &ThreadImpl::entryPoint, owner, 0, &mThreadId ) ); | ||
14 | |||
15 | if ( !mThread ) { | ||
16 | efDEBUG( "Failed to create thread\n" ); | ||
17 | } | ||
18 | } | ||
19 | |||
20 | ThreadImpl::~ThreadImpl() { | ||
21 | if ( mThread ) { | ||
22 | CloseHandle( mThread ); | ||
23 | } | ||
24 | } | ||
25 | |||
26 | void ThreadImpl::wait() { | ||
27 | // Wait for the thread to finish, no timeout | ||
28 | if ( mThread ) { | ||
29 | assert( mThreadId != GetCurrentThreadId() ); // A thread cannot wait for itself! | ||
30 | |||
31 | WaitForSingleObject( mThread, INFINITE ); | ||
32 | } | ||
33 | } | ||
34 | |||
35 | void ThreadImpl::terminate() { | ||
36 | if ( mThread ) { | ||
37 | TerminateThread( mThread, 0 ); | ||
38 | } | ||
39 | } | ||
40 | |||
41 | unsigned int __stdcall ThreadImpl::entryPoint( void* userData ) { | ||
42 | // The Thread instance is stored in the user data | ||
43 | Thread* owner = static_cast<Thread*>( userData ); | ||
44 | |||
45 | // Forward to the owner | ||
46 | owner->run(); | ||
47 | |||
48 | // Optional, but it is cleaner | ||
49 | _endthreadex( 0 ); | ||
50 | |||
51 | return 0; | ||
52 | } | ||
53 | |||
54 | }} // namespace efsw::Platform | ||
55 | |||
56 | #endif | ||
diff --git a/src/3rdParty/efsw/platform/win/ThreadImpl.hpp b/src/3rdParty/efsw/platform/win/ThreadImpl.hpp new file mode 100755 index 0000000..1afb593 --- /dev/null +++ b/src/3rdParty/efsw/platform/win/ThreadImpl.hpp | |||
@@ -0,0 +1,42 @@ | |||
1 | #ifndef EFSW_THREADIMPLWIN_HPP | ||
2 | #define EFSW_THREADIMPLWIN_HPP | ||
3 | |||
4 | #include <efsw/base.hpp> | ||
5 | |||
6 | #if EFSW_PLATFORM == EFSW_PLATFORM_WIN32 | ||
7 | |||
8 | #ifndef WIN32_LEAN_AND_MEAN | ||
9 | #define WIN32_LEAN_AND_MEAN | ||
10 | #endif | ||
11 | #include <process.h> | ||
12 | #include <windows.h> | ||
13 | |||
14 | namespace efsw { | ||
15 | |||
16 | class Thread; | ||
17 | |||
18 | namespace Platform { | ||
19 | |||
20 | class ThreadImpl { | ||
21 | public: | ||
22 | ThreadImpl( Thread* owner ); | ||
23 | |||
24 | ~ThreadImpl(); | ||
25 | |||
26 | void wait(); | ||
27 | |||
28 | void terminate(); | ||
29 | |||
30 | protected: | ||
31 | static unsigned int __stdcall entryPoint( void* userData ); | ||
32 | |||
33 | HANDLE mThread; | ||
34 | unsigned int mThreadId; | ||
35 | }; | ||
36 | |||
37 | } // namespace Platform | ||
38 | } // namespace efsw | ||
39 | |||
40 | #endif | ||
41 | |||
42 | #endif | ||