aboutsummaryrefslogtreecommitdiff
path: root/drivers/windows
diff options
context:
space:
mode:
authorRémi Verschelde2017-03-05 16:44:50 +0100
committerRémi Verschelde2017-03-05 16:44:50 +0100
commit5dbf1809c6e3e905b94b8764e99491e608122261 (patch)
tree5e5a5360db15d86d59ec8c6e4f7eb511388c5a9a /drivers/windows
parent45438e9918d421b244bfd7776a30e67dc7f2d3e3 (diff)
downloadgodot-5dbf1809c6e3e905b94b8764e99491e608122261.tar.gz
godot-5dbf1809c6e3e905b94b8764e99491e608122261.tar.zst
godot-5dbf1809c6e3e905b94b8764e99491e608122261.zip
Diffstat (limited to 'drivers/windows')
-rw-r--r--drivers/windows/dir_access_windows.cpp160
-rw-r--r--drivers/windows/dir_access_windows.h9
-rw-r--r--drivers/windows/file_access_windows.cpp132
-rw-r--r--drivers/windows/file_access_windows.h10
-rw-r--r--drivers/windows/mutex_windows.cpp46
-rw-r--r--drivers/windows/mutex_windows.h19
-rw-r--r--drivers/windows/rw_lock_windows.cpp18
-rw-r--r--drivers/windows/rw_lock_windows.h6
-rw-r--r--drivers/windows/semaphore_windows.cpp37
-rw-r--r--drivers/windows/semaphore_windows.h10
-rw-r--r--drivers/windows/shell_windows.cpp9
-rw-r--r--drivers/windows/shell_windows.h4
-rw-r--r--drivers/windows/thread_windows.cpp59
-rw-r--r--drivers/windows/thread_windows.h29
14 files changed, 227 insertions, 321 deletions
diff --git a/drivers/windows/dir_access_windows.cpp b/drivers/windows/dir_access_windows.cpp
index 14742aa42..bb5ab02d8 100644
--- a/drivers/windows/dir_access_windows.cpp
+++ b/drivers/windows/dir_access_windows.cpp
@@ -32,10 +32,10 @@
#include "os/memory.h"
-#include <windows.h>
-#include <wchar.h>
-#include <stdio.h>
#include "print_string.h"
+#include <stdio.h>
+#include <wchar.h>
+#include <windows.h>
/*
@@ -61,36 +61,32 @@ struct DirAccessWindowsPrivate {
Error DirAccessWindows::list_dir_begin() {
- _cisdir=false;
- _cishidden=false;
+ _cisdir = false;
+ _cishidden = false;
list_dir_end();
- p->h = FindFirstFileExW((current_dir+"\\*").c_str(), FindExInfoStandard, &p->fu, FindExSearchNameMatch, NULL, 0);
-
- return (p->h==INVALID_HANDLE_VALUE) ? ERR_CANT_OPEN : OK;
+ p->h = FindFirstFileExW((current_dir + "\\*").c_str(), FindExInfoStandard, &p->fu, FindExSearchNameMatch, NULL, 0);
+ return (p->h == INVALID_HANDLE_VALUE) ? ERR_CANT_OPEN : OK;
}
-
String DirAccessWindows::get_next() {
- if (p->h==INVALID_HANDLE_VALUE)
+ if (p->h == INVALID_HANDLE_VALUE)
return "";
+ _cisdir = (p->fu.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY);
+ _cishidden = (p->fu.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN);
- _cisdir=(p->fu.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY);
- _cishidden=(p->fu.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN);
-
- String name=p->fu.cFileName;
+ String name = p->fu.cFileName;
if (FindNextFileW(p->h, &p->fu) == 0) {
FindClose(p->h);
- p->h=INVALID_HANDLE_VALUE;
+ p->h = INVALID_HANDLE_VALUE;
}
return name;
-
}
bool DirAccessWindows::current_is_dir() const {
@@ -105,65 +101,60 @@ bool DirAccessWindows::current_is_hidden() const {
void DirAccessWindows::list_dir_end() {
- if (p->h!=INVALID_HANDLE_VALUE) {
+ if (p->h != INVALID_HANDLE_VALUE) {
FindClose(p->h);
- p->h=INVALID_HANDLE_VALUE;
+ 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)
+ if (p_drive < 0 || p_drive >= drive_count)
return "";
- return String::chr(drives[p_drive])+":";
+ return String::chr(drives[p_drive]) + ":";
}
Error DirAccessWindows::change_dir(String p_dir) {
GLOBAL_LOCK_FUNCTION
-
- p_dir=fix_path(p_dir);
-
+ p_dir = fix_path(p_dir);
wchar_t real_current_dir_name[2048];
- GetCurrentDirectoryW(2048,real_current_dir_name);
- String prev_dir=real_current_dir_name;
+ 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);
+ bool worked = (SetCurrentDirectoryW(p_dir.c_str()) != 0);
String base = _get_root_path();
- if (base!="") {
+ if (base != "") {
- GetCurrentDirectoryW(2048,real_current_dir_name);
+ GetCurrentDirectoryW(2048, real_current_dir_name);
String new_dir;
- new_dir = String(real_current_dir_name).replace("\\","/");
+ new_dir = String(real_current_dir_name).replace("\\", "/");
if (!new_dir.begins_with(base)) {
- worked=false;
+ worked = false;
}
}
if (worked) {
-
- GetCurrentDirectoryW(2048,real_current_dir_name);
- current_dir=real_current_dir_name; // TODO, utf8 parser
- current_dir=current_dir.replace("\\","/");
+ GetCurrentDirectoryW(2048, real_current_dir_name);
+ current_dir = real_current_dir_name; // TODO, utf8 parser
+ current_dir = current_dir.replace("\\", "/");
} //else {
- SetCurrentDirectoryW(prev_dir.c_str());
+ SetCurrentDirectoryW(prev_dir.c_str());
//}
- return worked?OK:ERR_INVALID_PARAMETER;
+ return worked ? OK : ERR_INVALID_PARAMETER;
}
Error DirAccessWindows::make_dir(String p_dir) {
@@ -171,18 +162,18 @@ Error DirAccessWindows::make_dir(String p_dir) {
GLOBAL_LOCK_FUNCTION
if (p_dir.is_rel_path())
- p_dir=get_current_dir().plus_file(p_dir);
+ p_dir = get_current_dir().plus_file(p_dir);
- p_dir=fix_path(p_dir);
- p_dir = p_dir.replace("/","\\");
+ p_dir = fix_path(p_dir);
+ p_dir = p_dir.replace("/", "\\");
bool success;
int err;
- p_dir="\\\\?\\"+p_dir; //done according to
-// https://msdn.microsoft.com/en-us/library/windows/desktop/aa363855(v=vs.85).aspx
+ p_dir = "\\\\?\\" + p_dir; //done according to
+ // https://msdn.microsoft.com/en-us/library/windows/desktop/aa363855(v=vs.85).aspx
- success=CreateDirectoryW(p_dir.c_str(), NULL);
+ success = CreateDirectoryW(p_dir.c_str(), NULL);
err = GetLastError();
if (success) {
@@ -196,21 +187,18 @@ Error DirAccessWindows::make_dir(String p_dir) {
return ERR_CANT_CREATE;
}
-
String DirAccessWindows::get_current_dir() {
String base = _get_root_path();
- if (base!="") {
-
+ if (base != "") {
- String bd = current_dir.replace("\\","/").replace_first(base,"");
+ String bd = current_dir.replace("\\", "/").replace_first(base, "");
if (bd.begins_with("/"))
- return _get_root_string()+bd.substr(1,bd.length());
+ return _get_root_string() + bd.substr(1, bd.length());
else
- return _get_root_string()+bd;
+ return _get_root_string() + bd;
} else {
-
}
return current_dir;
@@ -221,9 +209,9 @@ bool DirAccessWindows::file_exists(String p_file) {
GLOBAL_LOCK_FUNCTION
if (!p_file.is_abs_path())
- p_file=get_current_dir().plus_file(p_file);
+ p_file = get_current_dir().plus_file(p_file);
- p_file=fix_path(p_file);
+ p_file = fix_path(p_file);
//p_file.replace("/","\\");
@@ -235,7 +223,7 @@ bool DirAccessWindows::file_exists(String p_file) {
if (INVALID_FILE_ATTRIBUTES == fileAttr)
return false;
- return !(fileAttr&FILE_ATTRIBUTE_DIRECTORY);
+ return !(fileAttr & FILE_ATTRIBUTE_DIRECTORY);
}
bool DirAccessWindows::dir_exists(String p_dir) {
@@ -243,34 +231,33 @@ bool DirAccessWindows::dir_exists(String p_dir) {
GLOBAL_LOCK_FUNCTION
if (p_dir.is_rel_path())
- p_dir=get_current_dir().plus_file(p_dir);
+ p_dir = get_current_dir().plus_file(p_dir);
- p_dir=fix_path(p_dir);
+ p_dir = fix_path(p_dir);
//p_dir.replace("/","\\");
//WIN32_FILE_ATTRIBUTE_DATA fileInfo;
-
DWORD fileAttr;
fileAttr = GetFileAttributesW(p_dir.c_str());
if (INVALID_FILE_ATTRIBUTES == fileAttr)
- return false;
- return (fileAttr&FILE_ATTRIBUTE_DIRECTORY);
+ return false;
+ return (fileAttr & FILE_ATTRIBUTE_DIRECTORY);
}
-Error DirAccessWindows::rename(String p_path,String p_new_path) {
+Error DirAccessWindows::rename(String p_path, String p_new_path) {
if (p_path.is_rel_path())
- p_path=get_current_dir().plus_file(p_path);
+ p_path = get_current_dir().plus_file(p_path);
- p_path=fix_path(p_path);
+ p_path = fix_path(p_path);
if (p_new_path.is_rel_path())
- p_new_path=get_current_dir().plus_file(p_new_path);
+ p_new_path = get_current_dir().plus_file(p_new_path);
- p_new_path=fix_path(p_new_path);
+ p_new_path = fix_path(p_new_path);
if (file_exists(p_new_path)) {
if (remove(p_new_path) != OK) {
@@ -278,18 +265,17 @@ Error DirAccessWindows::rename(String p_path,String p_new_path) {
};
};
- return ::_wrename(p_path.c_str(),p_new_path.c_str())==0?OK:FAILED;
+ return ::_wrename(p_path.c_str(), p_new_path.c_str()) == 0 ? OK : FAILED;
}
-Error DirAccessWindows::remove(String p_path) {
+Error DirAccessWindows::remove(String p_path) {
if (p_path.is_rel_path())
- p_path=get_current_dir().plus_file(p_path);
+ p_path = get_current_dir().plus_file(p_path);
- p_path=fix_path(p_path);
+ p_path = fix_path(p_path);
-
- printf("erasing %s\n",p_path.utf8().get_data());
+ printf("erasing %s\n", p_path.utf8().get_data());
//WIN32_FILE_ATTRIBUTE_DATA fileInfo;
//DWORD fileAttr = GetFileAttributesExW(p_path.c_str(), GetFileExInfoStandard, &fileInfo);
@@ -297,11 +283,11 @@ Error DirAccessWindows::remove(String p_path) {
fileAttr = GetFileAttributesW(p_path.c_str());
if (INVALID_FILE_ATTRIBUTES == fileAttr)
- return FAILED;
- if ((fileAttr&FILE_ATTRIBUTE_DIRECTORY))
- return ::_wrmdir(p_path.c_str())==0?OK:FAILED;
+ 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;
+ return ::_wunlink(p_path.c_str()) == 0 ? OK : FAILED;
}
/*
@@ -331,10 +317,10 @@ FileType DirAccessWindows::get_file_type(const String& p_file) const {
return (attr&FILE_ATTRIBUTE_DIRECTORY)?FILE_TYPE_
}
*/
-size_t DirAccessWindows::get_space_left() {
+size_t DirAccessWindows::get_space_left() {
uint64_t bytes = 0;
- if (!GetDiskFreeSpaceEx(NULL,(PULARGE_INTEGER)&bytes,NULL,NULL))
+ if (!GetDiskFreeSpaceEx(NULL, (PULARGE_INTEGER)&bytes, NULL, NULL))
return 0;
//this is either 0 or a value in bytes.
@@ -343,26 +329,25 @@ size_t DirAccessWindows::get_space_left() {
DirAccessWindows::DirAccessWindows() {
- p = memnew( DirAccessWindowsPrivate );
- p->h=INVALID_HANDLE_VALUE;
- current_dir=".";
+ p = memnew(DirAccessWindowsPrivate);
+ p->h = INVALID_HANDLE_VALUE;
+ current_dir = ".";
- drive_count=0;
+ drive_count = 0;
#ifdef UWP_ENABLED
- Windows::Storage::StorageFolder ^install_folder = Windows::ApplicationModel::Package::Current->InstalledLocation;
+ Windows::Storage::StorageFolder ^ install_folder = Windows::ApplicationModel::Package::Current->InstalledLocation;
change_dir(install_folder->Path->Data());
#else
+ DWORD mask = GetLogicalDrives();
- DWORD mask=GetLogicalDrives();
-
- for (int i=0;i<MAX_DRIVES;i++) {
+ for (int i = 0; i < MAX_DRIVES; i++) {
- if (mask&(1<<i)) { //DRIVE EXISTS
+ if (mask & (1 << i)) { //DRIVE EXISTS
- drives[drive_count]='a'+i;
+ drives[drive_count] = 'a' + i;
drive_count++;
}
}
@@ -371,10 +356,9 @@ DirAccessWindows::DirAccessWindows() {
#endif
}
-
DirAccessWindows::~DirAccessWindows() {
- memdelete( p );
+ memdelete(p);
}
#endif //windows DirAccess support
diff --git a/drivers/windows/dir_access_windows.h b/drivers/windows/dir_access_windows.h
index f4105b7bc..e0815f2c0 100644
--- a/drivers/windows/dir_access_windows.h
+++ b/drivers/windows/dir_access_windows.h
@@ -29,7 +29,6 @@
#ifndef DIR_ACCESS_WINDOWS_H
#define DIR_ACCESS_WINDOWS_H
-
#ifdef WINDOWS_ENABLED
#include "os/dir_access.h"
@@ -40,14 +39,12 @@
struct DirAccessWindowsPrivate;
-
class DirAccessWindows : public DirAccess {
enum {
- MAX_DRIVES=26
+ MAX_DRIVES = 26
};
-
DirAccessWindowsPrivate *p;
/* Windows stuff */
@@ -56,12 +53,10 @@ class DirAccessWindows : public DirAccess {
String current_dir;
-
bool _cisdir;
bool _cishidden;
public:
-
virtual Error list_dir_begin(); ///< This starts dir listing
virtual String get_next();
virtual bool current_is_dir() const;
@@ -74,7 +69,6 @@ public:
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 bool dir_exists(String p_dir);
@@ -88,7 +82,6 @@ public:
DirAccessWindows();
~DirAccessWindows();
-
};
#endif //WINDOWS_ENABLED
diff --git a/drivers/windows/file_access_windows.cpp b/drivers/windows/file_access_windows.cpp
index 894b49231..0bb6c1d19 100644
--- a/drivers/windows/file_access_windows.cpp
+++ b/drivers/windows/file_access_windows.cpp
@@ -28,20 +28,18 @@
/*************************************************************************/
#ifdef WINDOWS_ENABLED
-#include <windows.h>
-#include "shlwapi.h"
#include "file_access_windows.h"
+#include "shlwapi.h"
+#include <windows.h>
-
-#include <sys/types.h>
+#include "print_string.h"
#include <sys/stat.h>
-#include <wchar.h>
+#include <sys/types.h>
#include <tchar.h>
-#include "print_string.h"
-
+#include <wchar.h>
#ifdef _MSC_VER
- #define S_ISREG(m) ((m)&_S_IFREG)
+#define S_ISREG(m) ((m)&_S_IFREG)
#endif
void FileAccessWindows::check_errors() const {
@@ -50,28 +48,26 @@ void FileAccessWindows::check_errors() const {
if (feof(f)) {
- last_error=ERR_FILE_EOF;
+ last_error = ERR_FILE_EOF;
}
-
}
-Error FileAccessWindows::_open(const String& p_filename, int p_mode_flags) {
+Error FileAccessWindows::_open(const String &p_filename, int p_mode_flags) {
- String filename=fix_path(p_filename);
+ String filename = fix_path(p_filename);
if (f)
close();
+ const wchar_t *mode_string;
- 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"rb+";
- else if (p_mode_flags==WRITE_READ)
- mode_string=L"wb+";
+ 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"rb+";
+ else if (p_mode_flags == WRITE_READ)
+ mode_string = L"wb+";
else
return ERR_INVALID_PARAMETER;
@@ -83,27 +79,24 @@ Error FileAccessWindows::_open(const String& p_filename, int p_mode_flags) {
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";
+ 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);
+ f = _wfopen(filename.c_str(), mode_string);
-
- if (f==NULL) {
- last_error=ERR_FILE_CANT_OPEN;
+ if (f == NULL) {
+ last_error = ERR_FILE_CANT_OPEN;
return ERR_FILE_CANT_OPEN;
} else {
- last_error=OK;
- flags=p_mode_flags;
+ last_error = OK;
+ flags = p_mode_flags;
return OK;
}
-
}
void FileAccessWindows::close() {
@@ -113,14 +106,13 @@ void FileAccessWindows::close() {
fclose(f);
f = NULL;
- if (save_path!="") {
+ 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());
-
bool rename_error;
#ifdef UWP_ENABLED
@@ -133,53 +125,50 @@ void FileAccessWindows::close() {
if (!PathFileExistsW(save_path.c_str())) {
#endif
//creating new file
- rename_error = _wrename((save_path+".tmp").c_str(),save_path.c_str())!=0;
+ rename_error = _wrename((save_path + ".tmp").c_str(), save_path.c_str()) != 0;
} else {
//atomic replace for existing file
- rename_error = !ReplaceFileW(save_path.c_str(), (save_path+".tmp").c_str(), NULL, 2|4, NULL, NULL);
+ rename_error = !ReplaceFileW(save_path.c_str(), (save_path + ".tmp").c_str(), NULL, 2 | 4, NULL, NULL);
}
if (rename_error && close_fail_notify) {
close_fail_notify(save_path);
}
- save_path="";
- ERR_FAIL_COND( rename_error );
+ save_path = "";
+ ERR_FAIL_COND(rename_error);
}
-
}
bool FileAccessWindows::is_open() const {
- return (f!=NULL);
+ return (f != NULL);
}
void FileAccessWindows::seek(size_t p_position) {
ERR_FAIL_COND(!f);
- last_error=OK;
- if ( fseek(f,p_position,SEEK_SET) )
+ 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) )
+ 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)) ) {
+ 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);
+ ERR_FAIL_COND_V(!f, 0);
size_t pos = get_pos();
- fseek(f,0,SEEK_END);
+ fseek(f, 0, SEEK_END);
int size = get_pos();
fseek(f, pos, SEEK_SET);
@@ -189,14 +178,14 @@ size_t FileAccessWindows::get_len() const {
bool FileAccessWindows::eof_reached() const {
check_errors();
- return last_error==ERR_FILE_EOF;
+ return last_error == ERR_FILE_EOF;
}
uint8_t FileAccessWindows::get_8() const {
- ERR_FAIL_COND_V(!f,0);
+ ERR_FAIL_COND_V(!f, 0);
uint8_t b;
- if (fread(&b,1,1,f) == 0) {
+ if (fread(&b, 1, 1, f) == 0) {
check_errors();
};
@@ -205,13 +194,12 @@ uint8_t FileAccessWindows::get_8() const {
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);
+ 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;
@@ -220,18 +208,16 @@ Error FileAccessWindows::get_error() const {
void FileAccessWindows::store_8(uint8_t p_dest) {
ERR_FAIL_COND(!f);
- fwrite(&p_dest,1,1,f);
-
+ fwrite(&p_dest, 1, 1, f);
}
-
-bool FileAccessWindows::file_exists(const String& p_name) {
+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) {
+ String filename = fix_path(p_name);
+ g = _wfopen(filename.c_str(), L"rb");
+ if (g == NULL) {
return false;
} else {
@@ -241,11 +227,11 @@ bool FileAccessWindows::file_exists(const String& p_name) {
}
}
-uint64_t FileAccessWindows::_get_modified_time(const String& p_file) {
+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);
+ 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);
@@ -254,25 +240,21 @@ uint64_t FileAccessWindows::_get_modified_time(const String& p_file) {
return st.st_mtime;
} else {
- print_line("no access to "+file );
+ print_line("no access to " + file);
}
-
ERR_FAIL_V(0);
};
-
FileAccessWindows::FileAccessWindows() {
- f=NULL;
- flags=0;
- last_error=OK;
-
+ 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
index 9f06918b7..d64a4b98f 100644
--- a/drivers/windows/file_access_windows.h
+++ b/drivers/windows/file_access_windows.h
@@ -47,12 +47,12 @@ class FileAccessWindows : public FileAccess {
String save_path;
public:
- virtual Error _open(const String& p_path, int p_mode_flags); ///< open a file
+ 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 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
@@ -65,15 +65,13 @@ public:
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
+ virtual bool file_exists(const String &p_name); ///< return true if a file exists
- uint64_t _get_modified_time(const String& p_file);
+ 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
index 6ae7e5212..bacf89efb 100644
--- a/drivers/windows/mutex_windows.cpp
+++ b/drivers/windows/mutex_windows.cpp
@@ -31,76 +31,68 @@
#ifdef WINDOWS_ENABLED
-
-
void MutexWindows::lock() {
#ifdef WINDOWS_USE_MUTEX
- WaitForSingleObject(mutex,INFINITE);
+ WaitForSingleObject(mutex, INFINITE);
#else
- EnterCriticalSection( &mutex );
+ EnterCriticalSection(&mutex);
#endif
}
-
void MutexWindows::unlock() {
#ifdef WINDOWS_USE_MUTEX
ReleaseMutex(mutex);
#else
- LeaveCriticalSection( &mutex );
+ LeaveCriticalSection(&mutex);
#endif
}
Error MutexWindows::try_lock() {
#ifdef WINDOWS_USE_MUTEX
- return (WaitForSingleObject(mutex,0)==WAIT_TIMEOUT)?ERR_BUSY:OK;
+ return (WaitForSingleObject(mutex, 0) == WAIT_TIMEOUT) ? ERR_BUSY : OK;
#else
- if (TryEnterCriticalSection( &mutex ))
- return OK;
- else
- return ERR_BUSY;
+ if (TryEnterCriticalSection(&mutex))
+ return OK;
+ else
+ return ERR_BUSY;
#endif
-
}
Mutex *MutexWindows::create_func_windows(bool p_recursive) {
- return memnew( MutexWindows );
+ return memnew(MutexWindows);
}
void MutexWindows::make_default() {
- create_func=create_func_windows;
+ create_func = create_func_windows;
}
MutexWindows::MutexWindows() {
-
+
#ifdef WINDOWS_USE_MUTEX
- mutex = CreateMutex( NULL, FALSE, NULL );
+ mutex = CreateMutex(NULL, FALSE, NULL);
+#else
+#ifdef UWP_ENABLED
+ InitializeCriticalSectionEx(&mutex, 0, 0);
#else
- #ifdef UWP_ENABLED
- InitializeCriticalSectionEx( &mutex, 0, 0 );
- #else
- InitializeCriticalSection( &mutex );
- #endif
+ InitializeCriticalSection(&mutex);
+#endif
#endif
-
}
-
MutexWindows::~MutexWindows() {
#ifdef WINDOWS_USE_MUTEX
- CloseHandle(mutex);
+ CloseHandle(mutex);
#else
- DeleteCriticalSection(&mutex);
+ DeleteCriticalSection(&mutex);
#endif
-
}
-
#endif
diff --git a/drivers/windows/mutex_windows.h b/drivers/windows/mutex_windows.h
index 4202735f2..0c6cbd472 100644
--- a/drivers/windows/mutex_windows.h
+++ b/drivers/windows/mutex_windows.h
@@ -31,33 +31,30 @@
#ifdef WINDOWS_ENABLED
-#include <windows.h>
#include "os/mutex.h"
+#include <windows.h>
/**
@author Juan Linietsky <reduzio@gmail.com>
*/
class MutexWindows : public Mutex {
#ifdef WINDOWS_USE_MUTEX
- HANDLE mutex;
+ HANDLE mutex;
#else
- CRITICAL_SECTION mutex;
+ CRITICAL_SECTION mutex;
#endif
-
+
static Mutex *create_func_windows(bool p_recursive);
-
-public:
- virtual void lock();
+public:
+ virtual void lock();
virtual void unlock();
- virtual Error try_lock();
-
+ virtual Error try_lock();
static void make_default();
- MutexWindows();
+ MutexWindows();
~MutexWindows();
-
};
#endif
diff --git a/drivers/windows/rw_lock_windows.cpp b/drivers/windows/rw_lock_windows.cpp
index edbd7b6a0..615bcd22a 100644
--- a/drivers/windows/rw_lock_windows.cpp
+++ b/drivers/windows/rw_lock_windows.cpp
@@ -30,14 +30,13 @@
#include "rw_lock_windows.h"
-#include "os/memory.h"
#include "error_macros.h"
+#include "os/memory.h"
#include <stdio.h>
void RWLockWindows::read_lock() {
AcquireSRWLockShared(&lock);
-
}
void RWLockWindows::read_unlock() {
@@ -47,18 +46,16 @@ void RWLockWindows::read_unlock() {
Error RWLockWindows::read_try_lock() {
- if (TryAcquireSRWLockShared(&lock)==0) {
+ if (TryAcquireSRWLockShared(&lock) == 0) {
return ERR_BUSY;
} else {
return OK;
}
-
}
void RWLockWindows::write_lock() {
AcquireSRWLockExclusive(&lock);
-
}
void RWLockWindows::write_unlock() {
@@ -67,34 +64,29 @@ void RWLockWindows::write_unlock() {
}
Error RWLockWindows::write_try_lock() {
- if (TryAcquireSRWLockExclusive(&lock)==0) {
+ if (TryAcquireSRWLockExclusive(&lock) == 0) {
return ERR_BUSY;
} else {
return OK;
}
}
-
RWLock *RWLockWindows::create_func_windows() {
- return memnew( RWLockWindows );
+ return memnew(RWLockWindows);
}
void RWLockWindows::make_default() {
- create_func=create_func_windows;
+ create_func = create_func_windows;
}
-
RWLockWindows::RWLockWindows() {
InitializeSRWLock(&lock);
}
-
RWLockWindows::~RWLockWindows() {
-
-
}
#endif
diff --git a/drivers/windows/rw_lock_windows.h b/drivers/windows/rw_lock_windows.h
index 059704e5c..e4b5367c2 100644
--- a/drivers/windows/rw_lock_windows.h
+++ b/drivers/windows/rw_lock_windows.h
@@ -31,18 +31,16 @@
#if defined(WINDOWS_ENABLED)
-#include <windows.h>
#include "os/rw_lock.h"
+#include <windows.h>
class RWLockWindows : public RWLock {
-
SRWLOCK lock;
static RWLock *create_func_windows();
public:
-
virtual void read_lock();
virtual void read_unlock();
virtual Error read_try_lock();
@@ -56,10 +54,8 @@ public:
RWLockWindows();
~RWLockWindows();
-
};
#endif
-
#endif // RWLOCKWINDOWS_H
diff --git a/drivers/windows/semaphore_windows.cpp b/drivers/windows/semaphore_windows.cpp
index cdd1a7b88..b1c9ee018 100644
--- a/drivers/windows/semaphore_windows.cpp
+++ b/drivers/windows/semaphore_windows.cpp
@@ -34,19 +34,19 @@
Error SemaphoreWindows::wait() {
- WaitForSingleObjectEx(semaphore,INFINITE, false);
+ WaitForSingleObjectEx(semaphore, INFINITE, false);
return OK;
}
Error SemaphoreWindows::post() {
- ReleaseSemaphore(semaphore,1,NULL);
+ ReleaseSemaphore(semaphore, 1, NULL);
return OK;
}
int SemaphoreWindows::get() const {
long previous;
switch (WaitForSingleObjectEx(semaphore, 0, false)) {
case WAIT_OBJECT_0: {
- ERR_FAIL_COND_V(!ReleaseSemaphore(semaphore, 1, &previous),-1);
+ ERR_FAIL_COND_V(!ReleaseSemaphore(semaphore, 1, &previous), -1);
return previous + 1;
} break;
case WAIT_TIMEOUT: {
@@ -58,41 +58,38 @@ int SemaphoreWindows::get() const {
ERR_FAIL_V(-1);
}
-
Semaphore *SemaphoreWindows::create_semaphore_windows() {
- return memnew( SemaphoreWindows );
+ return memnew(SemaphoreWindows);
}
void SemaphoreWindows::make_default() {
- create_func=create_semaphore_windows;
+ create_func = create_semaphore_windows;
}
SemaphoreWindows::SemaphoreWindows() {
#ifdef UWP_ENABLED
- semaphore=CreateSemaphoreEx(
- NULL,
- 0,
- 0xFFFFFFF, //wathever
- NULL,
- 0,
- SEMAPHORE_ALL_ACCESS);
+ semaphore = CreateSemaphoreEx(
+ NULL,
+ 0,
+ 0xFFFFFFF, //wathever
+ NULL,
+ 0,
+ SEMAPHORE_ALL_ACCESS);
#else
- semaphore=CreateSemaphore(
- NULL,
- 0,
- 0xFFFFFFF, //wathever
- NULL);
+ semaphore = CreateSemaphore(
+ NULL,
+ 0,
+ 0xFFFFFFF, //wathever
+ NULL);
#endif
}
-
SemaphoreWindows::~SemaphoreWindows() {
CloseHandle(semaphore);
}
-
#endif
diff --git a/drivers/windows/semaphore_windows.h b/drivers/windows/semaphore_windows.h
index 564087a69..5594cb0c5 100644
--- a/drivers/windows/semaphore_windows.h
+++ b/drivers/windows/semaphore_windows.h
@@ -29,8 +29,6 @@
#ifndef SEMAPHORE_WINDOWS_H
#define SEMAPHORE_WINDOWS_H
-
-
#include "os/semaphore.h"
#ifdef WINDOWS_ENABLED
@@ -41,21 +39,19 @@
*/
class SemaphoreWindows : public Semaphore {
- mutable HANDLE semaphore;
+ mutable HANDLE semaphore;
static Semaphore *create_semaphore_windows();
public:
-
virtual Error wait();
- virtual Error post();
+ virtual Error post();
virtual int get() const;
static void make_default();
SemaphoreWindows();
-
- ~SemaphoreWindows();
+ ~SemaphoreWindows();
};
#endif
diff --git a/drivers/windows/shell_windows.cpp b/drivers/windows/shell_windows.cpp
index a96bc6a7d..715d886ed 100644
--- a/drivers/windows/shell_windows.cpp
+++ b/drivers/windows/shell_windows.cpp
@@ -52,17 +52,12 @@
void ShellWindows::execute(String p_path) {
ShellExecuteW(NULL, L"open", p_path.c_str(), NULL, NULL, SW_SHOWNORMAL);
-
}
-
-ShellWindows::ShellWindows()
-{
+ShellWindows::ShellWindows() {
}
-
-ShellWindows::~ShellWindows()
-{
+ShellWindows::~ShellWindows() {
}
#endif
diff --git a/drivers/windows/shell_windows.h b/drivers/windows/shell_windows.h
index 92203df98..e0baf3e76 100644
--- a/drivers/windows/shell_windows.h
+++ b/drivers/windows/shell_windows.h
@@ -37,13 +37,11 @@
*/
class ShellWindows : public Shell {
public:
-
virtual void execute(String p_path);
ShellWindows();
-
- ~ShellWindows();
+ ~ShellWindows();
};
#endif
diff --git a/drivers/windows/thread_windows.cpp b/drivers/windows/thread_windows.cpp
index dbe2f93fd..e6143b4af 100644
--- a/drivers/windows/thread_windows.cpp
+++ b/drivers/windows/thread_windows.cpp
@@ -32,24 +32,23 @@
#include "os/memory.h"
-
Thread::ID ThreadWindows::get_ID() const {
- return id;
+ return id;
}
-Thread* ThreadWindows::create_thread_windows() {
+Thread *ThreadWindows::create_thread_windows() {
- return memnew( ThreadWindows );
+ return memnew(ThreadWindows);
}
-DWORD ThreadWindows::thread_callback( LPVOID userdata ) {
+DWORD ThreadWindows::thread_callback(LPVOID userdata) {
- ThreadWindows *t=reinterpret_cast<ThreadWindows*>(userdata);
+ ThreadWindows *t = reinterpret_cast<ThreadWindows *>(userdata);
ScriptServer::thread_enter(); //scripts may need to attach a stack
- t->id=(ID)GetCurrentThreadId(); // must implement
+ t->id = (ID)GetCurrentThreadId(); // must implement
t->callback(t->user);
ScriptServer::thread_exit();
@@ -57,53 +56,47 @@ DWORD ThreadWindows::thread_callback( LPVOID userdata ) {
return 0;
}
-Thread* ThreadWindows::create_func_windows(ThreadCreateCallback p_callback,void *p_user,const Settings&) {
+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
- 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)GetCurrentThreadId(); //must implement
}
-void ThreadWindows::wait_to_finish_func_windows(Thread* p_thread) {
+void ThreadWindows::wait_to_finish_func_windows(Thread *p_thread) {
-
- ThreadWindows *tp=static_cast<ThreadWindows*>(p_thread);
+ ThreadWindows *tp = static_cast<ThreadWindows *>(p_thread);
ERR_FAIL_COND(!tp);
- WaitForSingleObject( tp->handle, INFINITE );
+ WaitForSingleObject(tp->handle, INFINITE);
CloseHandle(tp->handle);
- //`memdelete(tp);
+ //`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;
-
+ 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;
+ handle = NULL;
}
-
ThreadWindows::~ThreadWindows() {
-
}
-
#endif
diff --git a/drivers/windows/thread_windows.h b/drivers/windows/thread_windows.h
index c8f395e06..5b2c076c7 100644
--- a/drivers/windows/thread_windows.h
+++ b/drivers/windows/thread_windows.h
@@ -41,36 +41,29 @@
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 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();
+ static void wait_to_finish_func_windows(Thread *p_thread);
+
+ ThreadWindows();
+
public:
-
-
virtual ID get_ID() const;
-
+
static void make_default();
-
-
- ~ThreadWindows();
+ ~ThreadWindows();
};
-
#endif
#endif