diff options
Diffstat (limited to 'drivers/windows')
-rw-r--r-- | drivers/windows/SCsub | 7 | ||||
-rw-r--r-- | drivers/windows/dir_access_windows.cpp | 399 | ||||
-rw-r--r-- | drivers/windows/dir_access_windows.h | 93 | ||||
-rw-r--r-- | drivers/windows/file_access_windows.cpp | 251 | ||||
-rw-r--r-- | drivers/windows/file_access_windows.h | 79 | ||||
-rw-r--r-- | drivers/windows/mutex_windows.cpp | 102 | ||||
-rw-r--r-- | drivers/windows/mutex_windows.h | 65 | ||||
-rw-r--r-- | drivers/windows/semaphore_windows.cpp | 89 | ||||
-rw-r--r-- | drivers/windows/semaphore_windows.h | 62 | ||||
-rw-r--r-- | drivers/windows/shell_windows.cpp | 61 | ||||
-rw-r--r-- | drivers/windows/shell_windows.h | 50 | ||||
-rw-r--r-- | drivers/windows/thread_windows.cpp | 102 | ||||
-rw-r--r-- | drivers/windows/thread_windows.h | 75 |
13 files changed, 1435 insertions, 0 deletions
diff --git a/drivers/windows/SCsub b/drivers/windows/SCsub new file mode 100644 index 0000000000..bcd231579c --- /dev/null +++ b/drivers/windows/SCsub @@ -0,0 +1,7 @@ +Import('env') + +env.add_source_files(env.drivers_sources,"*.cpp") + +Export('env') + + diff --git a/drivers/windows/dir_access_windows.cpp b/drivers/windows/dir_access_windows.cpp new file mode 100644 index 0000000000..30f6ff6d8c --- /dev/null +++ b/drivers/windows/dir_access_windows.cpp @@ -0,0 +1,399 @@ +/*************************************************************************/ +/* dir_access_windows.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ +#ifdef WINDOWS_ENABLED + +#include "dir_access_windows.h" + +#include "os/memory.h" + +#include <windows.h> +#include <wchar.h> +#include <stdio.h> +#include "print_string.h" +/* + +[03:57] <reduz> yessopie, so i dont havemak to rely on unicows +[03:58] <yessopie> reduz- yeah, all of the functions fail, and then you can call GetLastError () which will return 120 +[03:58] <drumstick> CategoryApl, hehe, what? :) +[03:59] <CategoryApl> didn't Verona lead to some trouble +[03:59] <yessopie> 120 = ERROR_CALL_NOT_IMPLEMENTED +[03:59] <yessopie> (you can use that constant if you include winerr.h) +[03:59] <CategoryApl> well answer with winning a compo + +[04:02] <yessopie> if ( SetCurrentDirectoryW ( L"." ) == FALSE && GetLastError () == ERROR_CALL_NOT_IMPLEMENTED ) { use ANSI } +*/ + +struct DirAccessWindowsPrivate { + + HANDLE h; //handle for findfirstfile + WIN32_FIND_DATA f; + WIN32_FIND_DATAW fu; //unicode version +}; + + +bool DirAccessWindows::list_dir_begin() { + + _cisdir=false; + + if (unicode) { + list_dir_end(); + p->h = FindFirstFileW((current_dir+"\\*").c_str(), &p->fu); + + return (p->h==INVALID_HANDLE_VALUE); + } else { + + list_dir_end(); + p->h = FindFirstFileA((current_dir+"\\*").ascii().get_data(), &p->f); + + return (p->h==INVALID_HANDLE_VALUE); + + } + + return false; +} + + +String DirAccessWindows::get_next() { + + if (p->h==INVALID_HANDLE_VALUE) + return ""; + + if (unicode) { + + _cisdir=(p->fu.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY); + String name=p->fu.cFileName; + + if (FindNextFileW(p->h, &p->fu) == 0) { + + FindClose(p->h); + p->h=INVALID_HANDLE_VALUE; + } + + return name; + } else { + + _cisdir=(p->fu.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY); + + String name=p->f.cFileName; + + if (FindNextFileA(p->h, &p->f) == 0) { + + FindClose(p->h); + p->h=INVALID_HANDLE_VALUE; + } + + return name; + + } +} + +bool DirAccessWindows::current_is_dir() const { + + return _cisdir; +} + +void DirAccessWindows::list_dir_end() { + + if (p->h!=INVALID_HANDLE_VALUE) { + + FindClose(p->h); + p->h=INVALID_HANDLE_VALUE; + } + +} +int DirAccessWindows::get_drive_count() { + + return drive_count; + +} +String DirAccessWindows::get_drive(int p_drive) { + + if (p_drive<0 || p_drive>=drive_count) + return ""; + + return String::chr(drives[p_drive])+":"; +} + +Error DirAccessWindows::change_dir(String p_dir) { + + GLOBAL_LOCK_FUNCTION + + p_dir=fix_path(p_dir); + + if (unicode) { + + wchar_t real_current_dir_name[2048]; + GetCurrentDirectoryW(2048,real_current_dir_name); + String prev_dir=real_current_dir_name; + + SetCurrentDirectoryW(current_dir.c_str()); + bool worked=(SetCurrentDirectoryW(p_dir.c_str())!=0); + + String base = _get_root_path(); + if (base!="") { + + GetCurrentDirectoryW(2048,real_current_dir_name); + String new_dir; + new_dir = String(real_current_dir_name).replace("\\","/"); + if (!new_dir.begins_with(base)) { + worked=false; + } + } + + if (worked) { + + GetCurrentDirectoryW(2048,real_current_dir_name); + current_dir=real_current_dir_name; // TODO, utf8 parser + current_dir=current_dir.replace("\\","/"); + + } + + SetCurrentDirectoryW(prev_dir.c_str()); + + return worked?OK:ERR_INVALID_PARAMETER; + } else { + + char real_current_dir_name[2048]; + GetCurrentDirectoryA(2048,real_current_dir_name); + String prev_dir=real_current_dir_name; + + SetCurrentDirectoryA(current_dir.ascii().get_data()); + bool worked=(SetCurrentDirectory(p_dir.ascii().get_data())!=0); + + if (worked) { + + GetCurrentDirectoryA(2048,real_current_dir_name); + current_dir=real_current_dir_name; // TODO, utf8 parser + current_dir=current_dir.replace("\\","/"); + + } + + SetCurrentDirectoryA(prev_dir.ascii().get_data()); + + return worked?OK:ERR_INVALID_PARAMETER; + + } + + return OK; + +} + +Error DirAccessWindows::make_dir(String p_dir) { + + GLOBAL_LOCK_FUNCTION + + p_dir=fix_path(p_dir); + + p_dir.replace("/","\\"); + + bool success; + int err; + + if (unicode) { + wchar_t real_current_dir_name[2048]; + GetCurrentDirectoryW(2048,real_current_dir_name); + + SetCurrentDirectoryW(current_dir.c_str()); + + success=CreateDirectoryW(p_dir.c_str(), NULL); + err = GetLastError(); + + SetCurrentDirectoryW(real_current_dir_name); + + } else { + + char real_current_dir_name[2048]; + GetCurrentDirectoryA(2048,real_current_dir_name); + + SetCurrentDirectoryA(current_dir.ascii().get_data()); + + success=CreateDirectoryA(p_dir.ascii().get_data(), NULL); + err = GetLastError(); + + SetCurrentDirectoryA(real_current_dir_name); + } + + if (success) { + return OK; + }; + + if (err == ERROR_ALREADY_EXISTS) { + return ERR_ALREADY_EXISTS; + }; + + return ERR_CANT_CREATE; +} + + +String DirAccessWindows::get_current_dir() { + + String base = _get_root_path(); + if (base!="") { + + + String bd = current_dir.replace("\\","/").replace_first(base,""); + if (bd.begins_with("/")) + return _get_root_string()+bd.substr(1,bd.length()); + else + return _get_root_string()+bd; + + } else { + + } + + return current_dir; +} + +bool DirAccessWindows::file_exists(String p_file) { + + GLOBAL_LOCK_FUNCTION + + if (!p_file.is_abs_path()) + p_file=get_current_dir()+"/"+p_file; + p_file=fix_path(p_file); + + p_file.replace("/","\\"); + + if (unicode) { + + DWORD fileAttr; + + fileAttr = GetFileAttributesW(p_file.c_str()); + if (0xFFFFFFFF == fileAttr) + return false; + + return !(fileAttr&FILE_ATTRIBUTE_DIRECTORY); + + } else { + DWORD fileAttr; + + fileAttr = GetFileAttributesA(p_file.ascii().get_data()); + if (0xFFFFFFFF == fileAttr) + return false; + return !(fileAttr&FILE_ATTRIBUTE_DIRECTORY); + + } + + return false; +} + +Error DirAccessWindows::rename(String p_path,String p_new_path) { + + p_path=fix_path(p_path); + p_new_path=fix_path(p_new_path); + + if (file_exists(p_new_path)) { + if (remove(p_new_path) != OK) { + return FAILED; + }; + }; + + return ::_wrename(p_path.c_str(),p_new_path.c_str())==0?OK:FAILED; +} + +Error DirAccessWindows::remove(String p_path) { + + p_path=fix_path(p_path); + + printf("erasing %s\n",p_path.utf8().get_data()); + DWORD fileAttr = GetFileAttributesW(p_path.c_str()); + if (fileAttr == INVALID_FILE_ATTRIBUTES) + return FAILED; + + if (fileAttr & FILE_ATTRIBUTE_DIRECTORY) + return ::_wrmdir(p_path.c_str())==0?OK:FAILED; + else + return ::_wunlink(p_path.c_str())==0?OK:FAILED; +} +/* + +FileType DirAccessWindows::get_file_type(const String& p_file) const { + + + wchar_t real_current_dir_name[2048]; + GetCurrentDirectoryW(2048,real_current_dir_name); + String prev_dir=real_current_dir_name; + + bool worked SetCurrentDirectoryW(current_dir.c_str()); + + DWORD attr; + if (worked) { + + attr = GetFileAttributesW(p_file.c_str()); + + } + + SetCurrentDirectoryW(prev_dir.c_str()); + + if (!worked) + return FILE_TYPE_NONE; + + + return (attr&FILE_ATTRIBUTE_DIRECTORY)?FILE_TYPE_ +} +*/ +size_t DirAccessWindows::get_space_left() { + + return -1; +}; + +DirAccessWindows::DirAccessWindows() { + + p = memnew( DirAccessWindowsPrivate ); + current_dir="."; + + drive_count=0; + DWORD mask=GetLogicalDrives(); + + for (int i=0;i<MAX_DRIVES;i++) { + + if (mask&(1<<i)) { //DRIVE EXISTS + + drives[drive_count]='a'+i; + drive_count++; + } + } + + unicode=true; + + /* We are running Windows 95/98/ME, so no unicode allowed */ + if ( SetCurrentDirectoryW ( L"." ) == FALSE && GetLastError () == ERROR_CALL_NOT_IMPLEMENTED ) + unicode=false; + + p->h=INVALID_HANDLE_VALUE; + change_dir("."); +} + + +DirAccessWindows::~DirAccessWindows() { + + memdelete( p ); +} + +#endif //windows DirAccess support diff --git a/drivers/windows/dir_access_windows.h b/drivers/windows/dir_access_windows.h new file mode 100644 index 0000000000..926497c583 --- /dev/null +++ b/drivers/windows/dir_access_windows.h @@ -0,0 +1,93 @@ +/*************************************************************************/ +/* dir_access_windows.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ +#ifndef DIR_ACCESS_WINDOWS_H +#define DIR_ACCESS_WINDOWS_H + + +#ifdef WINDOWS_ENABLED + +#include "os/dir_access.h" + +/** + @author Juan Linietsky <reduz@gmail.com> +*/ + +struct DirAccessWindowsPrivate; + + +class DirAccessWindows : public DirAccess { + + enum { + MAX_DRIVES=25 + }; + + + DirAccessWindowsPrivate *p; + /* Windows stuff */ + + char drives[MAX_DRIVES]; // a-z: + int drive_count; + + String current_dir; + + bool unicode; + bool _cisdir; + +public: + + virtual bool list_dir_begin(); ///< This starts dir listing + virtual String get_next(); + virtual bool current_is_dir() const; + virtual void list_dir_end(); ///< + + virtual int get_drive_count(); + virtual String get_drive(int p_drive); + + virtual Error change_dir(String p_dir); ///< can be relative or absolute, return false on success + virtual String get_current_dir(); ///< return current dir location + + + virtual bool file_exists(String p_file); + + virtual Error make_dir(String p_dir); + + virtual Error rename(String p_from, String p_to); + virtual Error remove(String p_name); + + //virtual FileType get_file_type() const; + size_t get_space_left(); + + DirAccessWindows(); + ~DirAccessWindows(); + +}; + +#endif //WINDOWS_ENABLED + +#endif diff --git a/drivers/windows/file_access_windows.cpp b/drivers/windows/file_access_windows.cpp new file mode 100644 index 0000000000..3cd065841f --- /dev/null +++ b/drivers/windows/file_access_windows.cpp @@ -0,0 +1,251 @@ +/*************************************************************************/ +/* file_access_windows.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ +#ifdef WINDOWS_ENABLED + +#include "file_access_windows.h" + +#include <sys/types.h> +#include <sys/stat.h> +#include <wchar.h> +#include <tchar.h> +#include "print_string.h" + +#ifdef _MSC_VER + #define S_ISREG(m) ((m)&_S_IFREG) +#endif + +void FileAccessWindows::check_errors() const { + + ERR_FAIL_COND(!f); + + if (feof(f)) { + + last_error=ERR_FILE_EOF;; + } + +} + +Error FileAccessWindows::_open(const String& p_filename, int p_mode_flags) { + + String filename=fix_path(p_filename); + + if (f) + close(); + + + const wchar_t* mode_string; + + if (p_mode_flags==READ) + mode_string=L"rb"; + else if (p_mode_flags==WRITE) + mode_string=L"wb"; + else if (p_mode_flags==READ_WRITE) + mode_string=L"wb+"; + else + return ERR_INVALID_PARAMETER; + + /* pretty much every implementation that uses fopen as primary + backend supports utf8 encoding */ + + struct _stat st; + if (_wstat(filename.c_str(), &st) == 0) { + + if (!S_ISREG(st.st_mode)) + return ERR_FILE_CANT_OPEN; + + }; + + if (is_backup_save_enabled() && p_mode_flags&WRITE && !(p_mode_flags&READ)) { + save_path=filename; + filename=filename+".tmp"; + //print_line("saving instead to "+path); + } + + f=_wfopen(filename.c_str(), mode_string); + + + if (f==NULL) { + last_error=ERR_FILE_CANT_OPEN; + return ERR_FILE_CANT_OPEN; + } else { + last_error=OK; + flags=p_mode_flags; + return OK; + } + +} +void FileAccessWindows::close() { + + if (!f) + return; + + fclose(f); + f = NULL; + + if (save_path!="") { + + //unlink(save_path.utf8().get_data()); + //print_line("renaming.."); + _wunlink(save_path.c_str()); //unlink if exists + int rename_error = _wrename((save_path+".tmp").c_str(),save_path.c_str()); + save_path=""; + ERR_FAIL_COND( rename_error != 0); + } + + +} +bool FileAccessWindows::is_open() const { + + return (f!=NULL); +} +void FileAccessWindows::seek(size_t p_position) { + + ERR_FAIL_COND(!f); + last_error=OK; + if ( fseek(f,p_position,SEEK_SET) ) + check_errors(); +} +void FileAccessWindows::seek_end(int64_t p_position) { + + ERR_FAIL_COND(!f); + if ( fseek(f,p_position,SEEK_END) ) + check_errors(); +} +size_t FileAccessWindows::get_pos() const { + + + size_t aux_position=0; + if ( !(aux_position = ftell(f)) ) { + check_errors(); + }; + return aux_position; +} +size_t FileAccessWindows::get_len() const { + + + ERR_FAIL_COND_V(!f,0); + + size_t pos = get_pos(); + fseek(f,0,SEEK_END); + int size = get_pos(); + fseek(f, pos, SEEK_SET); + + return size; +} + +bool FileAccessWindows::eof_reached() const { + + check_errors(); + return last_error==ERR_FILE_EOF; +} + +uint8_t FileAccessWindows::get_8() const { + + ERR_FAIL_COND_V(!f,0); + uint8_t b; + if (fread(&b,1,1,f) == 0) { + check_errors(); + }; + + return b; +} + +int FileAccessWindows::get_buffer(uint8_t *p_dst, int p_length) const { + + ERR_FAIL_COND_V(!f,-1); + int read = fread(p_dst, 1,p_length, f); + check_errors(); + return read; +}; + + +Error FileAccessWindows::get_error() const { + + return last_error; +} + +void FileAccessWindows::store_8(uint8_t p_dest) { + + ERR_FAIL_COND(!f); + fwrite(&p_dest,1,1,f); + +} + + +bool FileAccessWindows::file_exists(const String& p_name) { + + FILE *g; + //printf("opening file %s\n", p_fname.c_str()); + String filename=fix_path(p_name); + g=_wfopen(filename.c_str(),L"rb"); + if (g==NULL) { + + return false; + } else { + + fclose(g); + return true; + } +} + +uint64_t FileAccessWindows::_get_modified_time(const String& p_file) { + + String file=fix_path(p_file); + if (file.ends_with("/") && file!="/") + file=file.substr(0,file.length()-1); + + struct _stat st; + int rv = _wstat(file.c_str(), &st); + + if (rv == 0) { + + return st.st_mtime; + } else { + print_line("no access to "+file ); + } + + + ERR_FAIL_V(0); +}; + + +FileAccessWindows::FileAccessWindows() { + + f=NULL; + flags=0; + last_error=OK; + +} +FileAccessWindows::~FileAccessWindows() { + + close(); + +} + +#endif diff --git a/drivers/windows/file_access_windows.h b/drivers/windows/file_access_windows.h new file mode 100644 index 0000000000..8f16d66fe1 --- /dev/null +++ b/drivers/windows/file_access_windows.h @@ -0,0 +1,79 @@ +/*************************************************************************/ +/* file_access_windows.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ +#ifndef FILE_ACCESS_WINDOWS_H +#define FILE_ACCESS_WINDOWS_H + +#ifdef WINDOWS_ENABLED + +#include "os/file_access.h" +#include "os/memory.h" +#include <stdio.h> + +/** + @author Juan Linietsky <reduzio@gmail.com> +*/ +class FileAccessWindows : public FileAccess { + + FILE *f; + int flags; + void check_errors() const; + mutable Error last_error; + String save_path; + +public: + virtual Error _open(const String& p_path, int p_mode_flags); ///< open a file + virtual void close(); ///< close a file + virtual bool is_open() const; ///< true when file is open + + virtual void seek(size_t p_position); ///< seek to a given position + virtual void seek_end(int64_t p_position=0); ///< seek from the end of file + virtual size_t get_pos() const; ///< get position in the file + virtual size_t get_len() const; ///< get size of the file + + virtual bool eof_reached() const; ///< reading passed EOF + + virtual uint8_t get_8() const; ///< get a byte + virtual int get_buffer(uint8_t *p_dst, int p_length) const; + + virtual Error get_error() const; ///< get last error + + virtual void store_8(uint8_t p_dest); ///< store a byte + + virtual bool file_exists(const String& p_name); ///< return true if a file exists + + uint64_t _get_modified_time(const String& p_file); + + FileAccessWindows(); + virtual ~FileAccessWindows(); + +}; + + +#endif +#endif diff --git a/drivers/windows/mutex_windows.cpp b/drivers/windows/mutex_windows.cpp new file mode 100644 index 0000000000..d42c45fd13 --- /dev/null +++ b/drivers/windows/mutex_windows.cpp @@ -0,0 +1,102 @@ +/*************************************************************************/ +/* mutex_windows.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ +#include "mutex_windows.h" +#include "os/memory.h" + +#ifdef WINDOWS_ENABLED + + + +void MutexWindows::lock() { + +#ifdef WINDOWS_USE_MUTEX + WaitForSingleObject(mutex,INFINITE); +#else + EnterCriticalSection( &mutex ); +#endif +} + + +void MutexWindows::unlock() { + +#ifdef WINDOWS_USE_MUTEX + ReleaseMutex(mutex); +#else + LeaveCriticalSection( &mutex ); +#endif +} + +Error MutexWindows::try_lock() { + +#ifdef WINDOWS_USE_MUTEX + return (WaitForSingleObject(mutex,0)==WAIT_TIMEOUT)?ERR_BUSY:OK; +#else + + if (TryEnterCriticalSection( &mutex )) + return OK; + else + return ERR_BUSY; +#endif + +} + +Mutex *MutexWindows::create_func_windows(bool p_recursive) { + + return memnew( MutexWindows ); +} + +void MutexWindows::make_default() { + + create_func=create_func_windows; +} + +MutexWindows::MutexWindows() { + +#ifdef WINDOWS_USE_MUTEX + mutex = CreateMutex( NULL, FALSE, NULL ); +#else + InitializeCriticalSection( &mutex ); +#endif + +} + + +MutexWindows::~MutexWindows() { + +#ifdef WINDOWS_USE_MUTEX + CloseHandle(mutex); +#else + + DeleteCriticalSection(&mutex); +#endif + +} + + +#endif diff --git a/drivers/windows/mutex_windows.h b/drivers/windows/mutex_windows.h new file mode 100644 index 0000000000..9a3875f053 --- /dev/null +++ b/drivers/windows/mutex_windows.h @@ -0,0 +1,65 @@ +/*************************************************************************/ +/* mutex_windows.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ +#ifndef MUTEX_WINDOWS_H +#define MUTEX_WINDOWS_H + +#ifdef WINDOWS_ENABLED + +#include <windows.h> +#include "os/mutex.h" +/** + @author Juan Linietsky <reduzio@gmail.com> +*/ +class MutexWindows : public Mutex { + +#ifdef WINDOWS_USE_MUTEX + HANDLE mutex; +#else + CRITICAL_SECTION mutex; +#endif + + static Mutex *create_func_windows(bool p_recursive); + +public: + + virtual void lock(); + virtual void unlock(); + virtual Error try_lock(); + + + static void make_default(); + + MutexWindows(); + ~MutexWindows(); + +}; + +#endif + +#endif diff --git a/drivers/windows/semaphore_windows.cpp b/drivers/windows/semaphore_windows.cpp new file mode 100644 index 0000000000..28a04f4acf --- /dev/null +++ b/drivers/windows/semaphore_windows.cpp @@ -0,0 +1,89 @@ +/*************************************************************************/ +/* semaphore_windows.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ +#include "semaphore_windows.h" + +#ifdef WINDOWS_ENABLED + +#include "os/memory.h" + +Error SemaphoreWindows::wait() { + + WaitForSingleObject(semaphore,INFINITE); + return OK; +} +Error SemaphoreWindows::post() { + + ReleaseSemaphore(semaphore,1,NULL); + return OK; +} +int SemaphoreWindows::get() const { + long previous; + switch (WaitForSingleObject(semaphore, 0)) { + case WAIT_OBJECT_0: { + ERR_FAIL_COND_V(!ReleaseSemaphore(semaphore, 1, &previous),-1); + return previous + 1; + } break; + case WAIT_TIMEOUT: { + return 0; + } break; + default: {} + } + + ERR_FAIL_V(-1); +} + + +Semaphore *SemaphoreWindows::create_semaphore_windows() { + + return memnew( SemaphoreWindows ); +} + +void SemaphoreWindows::make_default() { + + create_func=create_semaphore_windows; +} + +SemaphoreWindows::SemaphoreWindows() { + + semaphore=CreateSemaphore( + NULL, + 0, + 0xFFFFFFF, //wathever + NULL); + +} + + +SemaphoreWindows::~SemaphoreWindows() { + + CloseHandle(semaphore); +} + + +#endif diff --git a/drivers/windows/semaphore_windows.h b/drivers/windows/semaphore_windows.h new file mode 100644 index 0000000000..f87b868a68 --- /dev/null +++ b/drivers/windows/semaphore_windows.h @@ -0,0 +1,62 @@ +/*************************************************************************/ +/* semaphore_windows.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ +#ifndef SEMAPHORE_WINDOWS_H +#define SEMAPHORE_WINDOWS_H + + + +#include "os/semaphore.h" + +#ifdef WINDOWS_ENABLED + +#include <windows.h> +/** + @author Juan Linietsky <reduzio@gmail.com> +*/ +class SemaphoreWindows : public Semaphore { + + mutable HANDLE semaphore; + + static Semaphore *create_semaphore_windows(); + +public: + + virtual Error wait(); + virtual Error post(); + virtual int get() const; + + static void make_default(); + SemaphoreWindows(); + + ~SemaphoreWindows(); + +}; + +#endif +#endif diff --git a/drivers/windows/shell_windows.cpp b/drivers/windows/shell_windows.cpp new file mode 100644 index 0000000000..2e5f663b96 --- /dev/null +++ b/drivers/windows/shell_windows.cpp @@ -0,0 +1,61 @@ +/*************************************************************************/ +/* shell_windows.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ +#ifdef WINDOWS_ENABLED +// +// C++ Implementation: shell_windows +// +// Description: +// +// +// Author: Juan Linietsky <reduzio@gmail.com>, (C) 2008 +// +// Copyright: See COPYING file that comes with this distribution +// +// +#include "shell_windows.h" + +#include <windows.h> + +void ShellWindows::execute(String p_path) { + + ShellExecuteW(NULL, L"open", p_path.c_str(), NULL, NULL, SW_SHOWNORMAL); + +} + + +ShellWindows::ShellWindows() +{ +} + + +ShellWindows::~ShellWindows() +{ +} + +#endif diff --git a/drivers/windows/shell_windows.h b/drivers/windows/shell_windows.h new file mode 100644 index 0000000000..8bbf51514c --- /dev/null +++ b/drivers/windows/shell_windows.h @@ -0,0 +1,50 @@ +/*************************************************************************/ +/* shell_windows.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ +#ifndef SHELL_WINDOWS_H +#define SHELL_WINDOWS_H + +#include "os/shell.h" + +#ifdef WINDOWS_ENABLED +/** + @author Juan Linietsky <reduzio@gmail.com> +*/ +class ShellWindows : public Shell { +public: + + virtual void execute(String p_path); + + ShellWindows(); + + ~ShellWindows(); + +}; + +#endif +#endif diff --git a/drivers/windows/thread_windows.cpp b/drivers/windows/thread_windows.cpp new file mode 100644 index 0000000000..a48ec74d09 --- /dev/null +++ b/drivers/windows/thread_windows.cpp @@ -0,0 +1,102 @@ +/*************************************************************************/ +/* thread_windows.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ +#include "thread_windows.h" + +#ifdef WINDOWS_ENABLED + +#include "os/memory.h" + +Thread::ID ThreadWindows::get_ID() const { + + return id; +} + +Thread* ThreadWindows::create_thread_windows() { + + return memnew( ThreadWindows ); +} + +DWORD ThreadWindows::thread_callback( LPVOID userdata ) { + + ThreadWindows *t=reinterpret_cast<ThreadWindows*>(userdata); + t->callback(t->user); + t->id=(ID)0; // must implement + return 0; +} + +Thread* ThreadWindows::create_func_windows(ThreadCreateCallback p_callback,void *p_user,const Settings&) { + + ThreadWindows *tr= memnew(ThreadWindows); + tr->callback=p_callback; + tr->user=p_user; + tr->handle=CreateThread( + NULL, // default security attributes + 0, // use default stack size + thread_callback, // thread function name + tr, // argument to thread function + 0, // use default creation flags + NULL); // returns the thread identifier + + return tr; +} +Thread::ID ThreadWindows::get_thread_ID_func_windows() { + + return (ID)0; //must implement +} +void ThreadWindows::wait_to_finish_func_windows(Thread* p_thread) { + + + ThreadWindows *tp=static_cast<ThreadWindows*>(p_thread); + ERR_FAIL_COND(!tp); + WaitForSingleObject( tp->handle, INFINITE ); + CloseHandle(tp->handle); + //`memdelete(tp); +} + + +void ThreadWindows::make_default() { + + create_func=create_func_windows; + get_thread_ID_func=get_thread_ID_func_windows; + wait_to_finish_func=wait_to_finish_func_windows; + +} + +ThreadWindows::ThreadWindows() { + + handle=NULL; +} + + +ThreadWindows::~ThreadWindows() { + +} + + +#endif diff --git a/drivers/windows/thread_windows.h b/drivers/windows/thread_windows.h new file mode 100644 index 0000000000..d15e77d065 --- /dev/null +++ b/drivers/windows/thread_windows.h @@ -0,0 +1,75 @@ +/*************************************************************************/ +/* thread_windows.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ +#ifndef THREAD_WINDOWS_H +#define THREAD_WINDOWS_H + +/** + @author Juan Linietsky <reduzio@gmail.com> +*/ + +#ifdef WINDOWS_ENABLED + +#include "os/thread.h" +#include <windows.h> + +class ThreadWindows : public Thread { + + + ThreadCreateCallback callback; + void *user; + ID id; + HANDLE handle; + + static Thread* create_thread_windows(); + + + + static DWORD WINAPI thread_callback( LPVOID userdata ); + + static Thread* create_func_windows(ThreadCreateCallback p_callback,void *,const Settings&); + static ID get_thread_ID_func_windows(); + static void wait_to_finish_func_windows(Thread* p_thread); + + ThreadWindows(); +public: + + + virtual ID get_ID() const; + + static void make_default(); + + + ~ThreadWindows(); + +}; + + +#endif + +#endif |