summaryrefslogtreecommitdiff
path: root/drivers/windows
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/windows')
-rw-r--r--drivers/windows/dir_access_windows.cpp179
-rw-r--r--drivers/windows/dir_access_windows.h15
-rw-r--r--drivers/windows/file_access_windows.cpp101
-rw-r--r--drivers/windows/file_access_windows.h20
-rw-r--r--drivers/windows/rw_lock_windows.cpp95
-rw-r--r--drivers/windows/rw_lock_windows.h64
-rw-r--r--drivers/windows/thread_windows.cpp100
-rw-r--r--drivers/windows/thread_windows.h68
8 files changed, 133 insertions, 509 deletions
diff --git a/drivers/windows/dir_access_windows.cpp b/drivers/windows/dir_access_windows.cpp
index a8618b05d7..2c9f28717d 100644
--- a/drivers/windows/dir_access_windows.cpp
+++ b/drivers/windows/dir_access_windows.cpp
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
+/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -33,7 +33,7 @@
#include "dir_access_windows.h"
#include "core/os/memory.h"
-#include "core/print_string.h"
+#include "core/string/print_string.h"
#include <stdio.h>
#include <wchar.h>
@@ -53,7 +53,6 @@
*/
struct DirAccessWindowsPrivate {
-
HANDLE h; //handle for findfirstfile
WIN32_FIND_DATA f;
WIN32_FIND_DATAW fu; //unicode version
@@ -62,28 +61,30 @@ struct DirAccessWindowsPrivate {
// CreateFolderAsync
Error DirAccessWindows::list_dir_begin() {
-
_cisdir = false;
_cishidden = false;
list_dir_end();
- p->h = FindFirstFileExW((current_dir + "\\*").c_str(), FindExInfoStandard, &p->fu, FindExSearchNameMatch, nullptr, 0);
+ p->h = FindFirstFileExW((LPCWSTR)(String(current_dir + "\\*").utf16().get_data()), FindExInfoStandard, &p->fu, FindExSearchNameMatch, nullptr, 0);
- return (p->h == INVALID_HANDLE_VALUE) ? ERR_CANT_OPEN : OK;
+ if (p->h == INVALID_HANDLE_VALUE) {
+ return ERR_CANT_OPEN;
+ }
+
+ return 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);
- String name = p->fu.cFileName;
+ String name = String::utf16((const char16_t *)(p->fu.cFileName));
if (FindNextFileW(p->h, &p->fu) == 0) {
-
FindClose(p->h);
p->h = INVALID_HANDLE_VALUE;
}
@@ -92,80 +93,71 @@ String DirAccessWindows::get_next() {
}
bool DirAccessWindows::current_is_dir() const {
-
return _cisdir;
}
bool DirAccessWindows::current_is_hidden() const {
-
return _cishidden;
}
void DirAccessWindows::list_dir_end() {
-
if (p->h != INVALID_HANDLE_VALUE) {
-
FindClose(p->h);
p->h = INVALID_HANDLE_VALUE;
}
}
-int DirAccessWindows::get_drive_count() {
+int DirAccessWindows::get_drive_count() {
return drive_count;
}
-String DirAccessWindows::get_drive(int p_drive) {
- if (p_drive < 0 || p_drive >= 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);
- wchar_t real_current_dir_name[2048];
+ WCHAR real_current_dir_name[2048];
GetCurrentDirectoryW(2048, real_current_dir_name);
- String prev_dir = real_current_dir_name;
+ String prev_dir = String::utf16((const char16_t *)real_current_dir_name);
- SetCurrentDirectoryW(current_dir.c_str());
- bool worked = (SetCurrentDirectoryW(p_dir.c_str()) != 0);
+ SetCurrentDirectoryW((LPCWSTR)(current_dir.utf16().get_data()));
+ bool worked = (SetCurrentDirectoryW((LPCWSTR)(p_dir.utf16().get_data())) != 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("\\", "/");
+ String new_dir = String::utf16((const char16_t *)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 = String::utf16((const char16_t *)real_current_dir_name);
current_dir = current_dir.replace("\\", "/");
+ }
- } //else {
-
- SetCurrentDirectoryW(prev_dir.c_str());
- //}
+ SetCurrentDirectoryW((LPCWSTR)(prev_dir.utf16().get_data()));
return worked ? OK : ERR_INVALID_PARAMETER;
}
Error DirAccessWindows::make_dir(String p_dir) {
-
GLOBAL_LOCK_FUNCTION
p_dir = fix_path(p_dir);
- if (p_dir.is_rel_path())
+ if (p_dir.is_rel_path()) {
p_dir = current_dir.plus_file(p_dir);
+ }
p_dir = p_dir.replace("/", "\\");
@@ -175,32 +167,29 @@ Error DirAccessWindows::make_dir(String p_dir) {
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(), nullptr);
+ success = CreateDirectoryW((LPCWSTR)(p_dir.utf16().get_data()), nullptr);
err = GetLastError();
if (success) {
return OK;
- };
+ }
if (err == ERROR_ALREADY_EXISTS || err == ERROR_ACCESS_DENIED) {
return ERR_ALREADY_EXISTS;
- };
+ }
return ERR_CANT_CREATE;
}
String DirAccessWindows::get_current_dir(bool p_include_drive) {
-
String base = _get_root_path();
if (base != "") {
-
String bd = current_dir.replace("\\", "/").replace_first(base, "");
- if (bd.begins_with("/"))
+ if (bd.begins_with("/")) {
return _get_root_string() + bd.substr(1, bd.length());
- else
+ } else {
return _get_root_string() + bd;
-
- } else {
+ }
}
if (p_include_drive) {
@@ -217,57 +206,51 @@ String DirAccessWindows::get_current_dir(bool p_include_drive) {
}
bool DirAccessWindows::file_exists(String p_file) {
-
GLOBAL_LOCK_FUNCTION
- if (!p_file.is_abs_path())
+ if (!p_file.is_abs_path()) {
p_file = get_current_dir().plus_file(p_file);
+ }
p_file = fix_path(p_file);
- //p_file.replace("/","\\");
-
- //WIN32_FILE_ATTRIBUTE_DATA fileInfo;
-
DWORD fileAttr;
- fileAttr = GetFileAttributesW(p_file.c_str());
- if (INVALID_FILE_ATTRIBUTES == fileAttr)
+ fileAttr = GetFileAttributesW((LPCWSTR)(p_file.utf16().get_data()));
+ if (INVALID_FILE_ATTRIBUTES == fileAttr) {
return false;
+ }
return !(fileAttr & FILE_ATTRIBUTE_DIRECTORY);
}
bool DirAccessWindows::dir_exists(String p_dir) {
-
GLOBAL_LOCK_FUNCTION
- if (p_dir.is_rel_path())
+ if (p_dir.is_rel_path()) {
p_dir = get_current_dir().plus_file(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)
+ fileAttr = GetFileAttributesW((LPCWSTR)(p_dir.utf16().get_data()));
+ if (INVALID_FILE_ATTRIBUTES == fileAttr) {
return false;
+ }
return (fileAttr & FILE_ATTRIBUTE_DIRECTORY);
}
Error DirAccessWindows::rename(String p_path, String p_new_path) {
-
- if (p_path.is_rel_path())
+ if (p_path.is_rel_path()) {
p_path = get_current_dir().plus_file(p_path);
+ }
p_path = fix_path(p_path);
- if (p_new_path.is_rel_path())
+ if (p_new_path.is_rel_path()) {
p_new_path = get_current_dir().plus_file(p_new_path);
+ }
p_new_path = fix_path(p_new_path);
@@ -275,16 +258,16 @@ Error DirAccessWindows::rename(String p_path, String p_new_path) {
if (p_path.to_lower() == p_new_path.to_lower()) {
WCHAR tmpfile[MAX_PATH];
- if (!GetTempFileNameW(fix_path(get_current_dir()).c_str(), nullptr, 0, tmpfile)) {
+ if (!GetTempFileNameW((LPCWSTR)(fix_path(get_current_dir()).utf16().get_data()), nullptr, 0, tmpfile)) {
return FAILED;
}
- if (!::ReplaceFileW(tmpfile, p_path.c_str(), nullptr, 0, nullptr, nullptr)) {
+ if (!::ReplaceFileW(tmpfile, (LPCWSTR)(p_path.utf16().get_data()), nullptr, 0, nullptr, nullptr)) {
DeleteFileW(tmpfile);
return FAILED;
}
- return ::_wrename(tmpfile, p_new_path.c_str()) == 0 ? OK : FAILED;
+ return ::_wrename(tmpfile, (LPCWSTR)(p_new_path.utf16().get_data())) == 0 ? OK : FAILED;
} else {
if (file_exists(p_new_path)) {
@@ -293,64 +276,60 @@ 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((LPCWSTR)(p_path.utf16().get_data()), (LPCWSTR)(p_new_path.utf16().get_data())) == 0 ? OK : FAILED;
}
}
Error DirAccessWindows::remove(String p_path) {
-
- if (p_path.is_rel_path())
+ if (p_path.is_rel_path()) {
p_path = get_current_dir().plus_file(p_path);
+ }
p_path = fix_path(p_path);
- printf("erasing %s\n", p_path.utf8().get_data());
- //WIN32_FILE_ATTRIBUTE_DATA fileInfo;
- //DWORD fileAttr = GetFileAttributesExW(p_path.c_str(), GetFileExInfoStandard, &fileInfo);
-
DWORD fileAttr;
- fileAttr = GetFileAttributesW(p_path.c_str());
- if (INVALID_FILE_ATTRIBUTES == fileAttr)
+ fileAttr = GetFileAttributesW((LPCWSTR)(p_path.utf16().get_data()));
+ if (INVALID_FILE_ATTRIBUTES == fileAttr) {
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;
+ }
+ if ((fileAttr & FILE_ATTRIBUTE_DIRECTORY)) {
+ return ::_wrmdir((LPCWSTR)(p_path.utf16().get_data())) == 0 ? OK : FAILED;
+ } else {
+ return ::_wunlink((LPCWSTR)(p_path.utf16().get_data())) == 0 ? OK : FAILED;
+ }
}
+
/*
FileType DirAccessWindows::get_file_type(const String& p_file) const {
+ WCHAR real_current_dir_name[2048];
+ GetCurrentDirectoryW(2048, real_current_dir_name);
+ String prev_dir = Strong::utf16((const char16_t *)real_current_dir_name);
-
- 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());
+ bool worked = SetCurrentDirectoryW((LPCWSTR)(current_dir.utf16().get_data()));
DWORD attr;
if (worked) {
-
- WIN32_FILE_ATTRIBUTE_DATA fileInfo;
- attr = GetFileAttributesExW(p_file.c_str(), GetFileExInfoStandard, &fileInfo);
-
+ WIN32_FILE_ATTRIBUTE_DATA fileInfo;
+ attr = GetFileAttributesExW((LPCWSTR)(p_file.utf16().get_data()), GetFileExInfoStandard, &fileInfo);
}
- SetCurrentDirectoryW(prev_dir.c_str());
+ SetCurrentDirectoryW((LPCWSTR)(prev_dir.utf16().get_data()));
- if (!worked)
+ if (!worked) {
return FILE_TYPE_NONE;
+ }
-
- return (attr&FILE_ATTRIBUTE_DIRECTORY)?FILE_TYPE_
+ return (attr & FILE_ATTRIBUTE_DIRECTORY) ? FILE_TYPE_
}
+
*/
size_t DirAccessWindows::get_space_left() {
-
uint64_t bytes = 0;
- if (!GetDiskFreeSpaceEx(nullptr, (PULARGE_INTEGER)&bytes, nullptr, nullptr))
+ if (!GetDiskFreeSpaceEx(nullptr, (PULARGE_INTEGER)&bytes, nullptr, nullptr)) {
return 0;
+ }
//this is either 0 or a value in bytes.
return (size_t)bytes;
@@ -369,7 +348,7 @@ String DirAccessWindows::get_filesystem_type() const {
DWORD dwMaxFileNameLength = 0;
DWORD dwFileSystemFlags = 0;
- if (::GetVolumeInformationW(unit.c_str(),
+ if (::GetVolumeInformationW((LPCWSTR)(unit.utf16().get_data()),
szVolumeName,
sizeof(szVolumeName),
&dwSerialNumber,
@@ -377,21 +356,17 @@ String DirAccessWindows::get_filesystem_type() const {
&dwFileSystemFlags,
szFileSystemName,
sizeof(szFileSystemName)) == TRUE) {
-
- return String(szFileSystemName);
+ return String::utf16((const char16_t *)szFileSystemName);
}
ERR_FAIL_V("");
}
DirAccessWindows::DirAccessWindows() {
-
p = memnew(DirAccessWindowsPrivate);
p->h = INVALID_HANDLE_VALUE;
current_dir = ".";
- drive_count = 0;
-
#ifdef UWP_ENABLED
Windows::Storage::StorageFolder ^ install_folder = Windows::ApplicationModel::Package::Current->InstalledLocation;
change_dir(install_folder->Path->Data());
@@ -401,7 +376,6 @@ DirAccessWindows::DirAccessWindows() {
DWORD mask = GetLogicalDrives();
for (int i = 0; i < MAX_DRIVES; i++) {
-
if (mask & (1 << i)) { //DRIVE EXISTS
drives[drive_count] = 'A' + i;
@@ -414,7 +388,6 @@ DirAccessWindows::DirAccessWindows() {
}
DirAccessWindows::~DirAccessWindows() {
-
memdelete(p);
}
diff --git a/drivers/windows/dir_access_windows.h b/drivers/windows/dir_access_windows.h
index f59e4d7030..7f10023470 100644
--- a/drivers/windows/dir_access_windows.h
+++ b/drivers/windows/dir_access_windows.h
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
+/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -42,21 +42,20 @@
struct DirAccessWindowsPrivate;
class DirAccessWindows : public DirAccess {
-
enum {
MAX_DRIVES = 26
};
- DirAccessWindowsPrivate *p;
+ DirAccessWindowsPrivate *p = nullptr;
/* Windows stuff */
- char drives[MAX_DRIVES]; // a-z:
- int drive_count;
+ char drives[MAX_DRIVES] = { 0 }; // a-z:
+ int drive_count = 0;
String current_dir;
- bool _cisdir;
- bool _cishidden;
+ bool _cisdir = false;
+ bool _cishidden = false;
public:
virtual Error list_dir_begin(); ///< This starts dir listing
diff --git a/drivers/windows/file_access_windows.cpp b/drivers/windows/file_access_windows.cpp
index 69078b3326..35f61c0623 100644
--- a/drivers/windows/file_access_windows.cpp
+++ b/drivers/windows/file_access_windows.cpp
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
+/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -33,7 +33,7 @@
#include "file_access_windows.h"
#include "core/os/os.h"
-#include "core/print_string.h"
+#include "core/string/print_string.h"
#include <shlwapi.h>
#include <windows.h>
@@ -49,43 +49,42 @@
#endif
void FileAccessWindows::check_errors() const {
-
ERR_FAIL_COND(!f);
if (feof(f)) {
-
last_error = ERR_FILE_EOF;
}
}
Error FileAccessWindows::_open(const String &p_path, int p_mode_flags) {
-
path_src = p_path;
path = fix_path(p_path);
- if (f)
+ if (f) {
close();
+ }
- const wchar_t *mode_string;
+ const WCHAR *mode_string;
- if (p_mode_flags == READ)
+ if (p_mode_flags == READ) {
mode_string = L"rb";
- else if (p_mode_flags == WRITE)
+ } else if (p_mode_flags == WRITE) {
mode_string = L"wb";
- else if (p_mode_flags == READ_WRITE)
+ } else if (p_mode_flags == READ_WRITE) {
mode_string = L"rb+";
- else if (p_mode_flags == WRITE_READ)
+ } else if (p_mode_flags == WRITE_READ) {
mode_string = L"wb+";
- else
+ } else {
return ERR_INVALID_PARAMETER;
+ }
/* pretty much every implementation that uses fopen as primary
backend supports utf8 encoding */
struct _stat st;
- if (_wstat(path.c_str(), &st) == 0) {
-
- if (!S_ISREG(st.st_mode))
+ if (_wstat((LPCWSTR)(path.utf16().get_data()), &st) == 0) {
+ if (!S_ISREG(st.st_mode)) {
return ERR_FILE_CANT_OPEN;
+ }
};
#ifdef TOOLS_ENABLED
@@ -95,11 +94,10 @@ Error FileAccessWindows::_open(const String &p_path, int p_mode_flags) {
// platforms).
if (p_mode_flags == READ) {
WIN32_FIND_DATAW d;
- HANDLE f = FindFirstFileW(path.c_str(), &d);
+ HANDLE f = FindFirstFileW((LPCWSTR)(path.utf16().get_data()), &d);
if (f != INVALID_HANDLE_VALUE) {
- String fname = d.cFileName;
+ String fname = String::utf16((const char16_t *)(d.cFileName));
if (fname != String()) {
-
String base_file = path.get_file();
if (base_file != fname && base_file.findn(fname) == 0) {
WARN_PRINT("Case mismatch opening requested file '" + base_file + "', stored as '" + fname + "' in the filesystem. This file will not open when exported to other case-sensitive platforms.");
@@ -115,7 +113,7 @@ Error FileAccessWindows::_open(const String &p_path, int p_mode_flags) {
path = path + ".tmp";
}
- errno_t errcode = _wfopen_s(&f, path.c_str(), mode_string);
+ errno_t errcode = _wfopen_s(&f, (LPCWSTR)(path.utf16().get_data()), mode_string);
if (f == nullptr) {
switch (errcode) {
@@ -135,15 +133,14 @@ Error FileAccessWindows::_open(const String &p_path, int p_mode_flags) {
}
void FileAccessWindows::close() {
-
- if (!f)
+ if (!f) {
return;
+ }
fclose(f);
f = nullptr;
if (save_path != "") {
-
bool rename_error = true;
int attempts = 4;
while (rename_error && attempts) {
@@ -155,16 +152,16 @@ void FileAccessWindows::close() {
// UWP has no PathFileExists, so we check attributes instead
DWORD fileAttr;
- fileAttr = GetFileAttributesW(save_path.c_str());
+ fileAttr = GetFileAttributesW((LPCWSTR)(save_path.utf16().get_data()));
if (INVALID_FILE_ATTRIBUTES == fileAttr) {
#else
- if (!PathFileExistsW(save_path.c_str())) {
+ if (!PathFileExistsW((LPCWSTR)(save_path.utf16().get_data()))) {
#endif
//creating new file
- rename_error = _wrename((save_path + ".tmp").c_str(), save_path.c_str()) != 0;
+ rename_error = _wrename((LPCWSTR)((save_path + ".tmp").utf16().get_data()), (LPCWSTR)(save_path.utf16().get_data())) != 0;
} else {
//atomic replace for existing file
- rename_error = !ReplaceFileW(save_path.c_str(), (save_path + ".tmp").c_str(), nullptr, 2 | 4, nullptr, nullptr);
+ rename_error = !ReplaceFileW((LPCWSTR)(save_path.utf16().get_data()), (LPCWSTR)((save_path + ".tmp").utf16().get_data()), nullptr, 2 | 4, nullptr, nullptr);
}
if (rename_error) {
attempts--;
@@ -185,45 +182,44 @@ void FileAccessWindows::close() {
}
String FileAccessWindows::get_path() const {
-
return path_src;
}
String FileAccessWindows::get_path_absolute() const {
-
return path;
}
bool FileAccessWindows::is_open() const {
-
return (f != nullptr);
}
-void FileAccessWindows::seek(size_t p_position) {
+void FileAccessWindows::seek(size_t p_position) {
ERR_FAIL_COND(!f);
last_error = OK;
- if (fseek(f, p_position, SEEK_SET))
+ if (fseek(f, p_position, SEEK_SET)) {
check_errors();
+ }
prev_op = 0;
}
-void FileAccessWindows::seek_end(int64_t p_position) {
+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();
+ }
prev_op = 0;
}
-size_t FileAccessWindows::get_position() const {
+size_t FileAccessWindows::get_position() const {
size_t aux_position = 0;
aux_position = ftell(f);
if (!aux_position) {
check_errors();
- };
+ }
return aux_position;
}
-size_t FileAccessWindows::get_len() const {
+size_t FileAccessWindows::get_len() const {
ERR_FAIL_COND_V(!f, 0);
size_t pos = get_position();
@@ -235,13 +231,11 @@ size_t FileAccessWindows::get_len() const {
}
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);
if (flags == READ_WRITE || flags == WRITE_READ) {
if (prev_op == WRITE) {
@@ -253,13 +247,12 @@ uint8_t FileAccessWindows::get_8() const {
if (fread(&b, 1, 1, f) == 0) {
check_errors();
b = '\0';
- };
+ }
return b;
}
int FileAccessWindows::get_buffer(uint8_t *p_dst, int p_length) const {
-
ERR_FAIL_COND_V(!f, -1);
if (flags == READ_WRITE || flags == WRITE_READ) {
if (prev_op == WRITE) {
@@ -273,20 +266,18 @@ int FileAccessWindows::get_buffer(uint8_t *p_dst, int p_length) const {
};
Error FileAccessWindows::get_error() const {
-
return last_error;
}
void FileAccessWindows::flush() {
-
ERR_FAIL_COND(!f);
fflush(f);
- if (prev_op == WRITE)
+ if (prev_op == WRITE) {
prev_op = 0;
+ }
}
void FileAccessWindows::store_8(uint8_t p_dest) {
-
ERR_FAIL_COND(!f);
if (flags == READ_WRITE || flags == WRITE_READ) {
if (prev_op == READ) {
@@ -313,32 +304,27 @@ void FileAccessWindows::store_buffer(const uint8_t *p_src, int p_length) {
}
bool FileAccessWindows::file_exists(const String &p_name) {
-
FILE *g;
- //printf("opening file %s\n", p_fname.c_str());
+ //printf("opening file %s\n", p_fname.utf8().get_data());
String filename = fix_path(p_name);
- _wfopen_s(&g, filename.c_str(), L"rb");
+ _wfopen_s(&g, (LPCWSTR)(filename.utf16().get_data()), L"rb");
if (g == nullptr) {
-
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);
+ int rv = _wstat((LPCWSTR)(file.utf16().get_data()), &st);
if (rv == 0) {
-
return st.st_mtime;
} else {
ERR_FAIL_V_MSG(0, "Failed to get modified time for: " + file + ".");
@@ -353,15 +339,8 @@ Error FileAccessWindows::_set_unix_permissions(const String &p_file, uint32_t p_
return ERR_UNAVAILABLE;
}
-FileAccessWindows::FileAccessWindows() :
- f(nullptr),
- flags(0),
- prev_op(0),
- last_error(OK) {
-}
FileAccessWindows::~FileAccessWindows() {
-
close();
}
-#endif
+#endif // WINDOWS_ENABLED
diff --git a/drivers/windows/file_access_windows.h b/drivers/windows/file_access_windows.h
index 28d4375878..507e0b2c20 100644
--- a/drivers/windows/file_access_windows.h
+++ b/drivers/windows/file_access_windows.h
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
+/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -39,12 +39,11 @@
#include <stdio.h>
class FileAccessWindows : public FileAccess {
-
- FILE *f;
- int flags;
+ FILE *f = nullptr;
+ int flags = 0;
void check_errors() const;
- mutable int prev_op;
- mutable Error last_error;
+ mutable int prev_op = 0;
+ mutable Error last_error = OK;
String path;
String path_src;
String save_path;
@@ -79,9 +78,10 @@ public:
virtual uint32_t _get_unix_permissions(const String &p_file);
virtual Error _set_unix_permissions(const String &p_file, uint32_t p_permissions);
- FileAccessWindows();
+ FileAccessWindows() {}
virtual ~FileAccessWindows();
};
-#endif
-#endif
+#endif // WINDOWS_ENABLED
+
+#endif // FILE_ACCESS_WINDOWS_H
diff --git a/drivers/windows/rw_lock_windows.cpp b/drivers/windows/rw_lock_windows.cpp
deleted file mode 100644
index 438f4bf10d..0000000000
--- a/drivers/windows/rw_lock_windows.cpp
+++ /dev/null
@@ -1,95 +0,0 @@
-/*************************************************************************/
-/* rw_lock_windows.cpp */
-/*************************************************************************/
-/* This file is part of: */
-/* GODOT ENGINE */
-/* https://godotengine.org */
-/*************************************************************************/
-/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
-/* */
-/* 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. */
-/*************************************************************************/
-
-#if defined(WINDOWS_ENABLED)
-
-#include "rw_lock_windows.h"
-
-#include "core/error_macros.h"
-#include "core/os/memory.h"
-
-#include <stdio.h>
-
-void RWLockWindows::read_lock() {
-
- AcquireSRWLockShared(&lock);
-}
-
-void RWLockWindows::read_unlock() {
-
- ReleaseSRWLockShared(&lock);
-}
-
-Error RWLockWindows::read_try_lock() {
-
- if (TryAcquireSRWLockShared(&lock) == 0) {
- return ERR_BUSY;
- } else {
- return OK;
- }
-}
-
-void RWLockWindows::write_lock() {
-
- AcquireSRWLockExclusive(&lock);
-}
-
-void RWLockWindows::write_unlock() {
-
- ReleaseSRWLockExclusive(&lock);
-}
-
-Error RWLockWindows::write_try_lock() {
- if (TryAcquireSRWLockExclusive(&lock) == 0) {
- return ERR_BUSY;
- } else {
- return OK;
- }
-}
-
-RWLock *RWLockWindows::create_func_windows() {
-
- return memnew(RWLockWindows);
-}
-
-void RWLockWindows::make_default() {
-
- 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
deleted file mode 100644
index 3705c1eb38..0000000000
--- a/drivers/windows/rw_lock_windows.h
+++ /dev/null
@@ -1,64 +0,0 @@
-/*************************************************************************/
-/* rw_lock_windows.h */
-/*************************************************************************/
-/* This file is part of: */
-/* GODOT ENGINE */
-/* https://godotengine.org */
-/*************************************************************************/
-/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
-/* */
-/* 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 RWLOCKWINDOWS_H
-#define RWLOCKWINDOWS_H
-
-#if defined(WINDOWS_ENABLED)
-
-#include "core/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();
-
- virtual void write_lock();
- virtual void write_unlock();
- virtual Error write_try_lock();
-
- static void make_default();
-
- RWLockWindows();
-
- ~RWLockWindows();
-};
-
-#endif
-
-#endif // RWLOCKWINDOWS_H
diff --git a/drivers/windows/thread_windows.cpp b/drivers/windows/thread_windows.cpp
deleted file mode 100644
index aea2db2603..0000000000
--- a/drivers/windows/thread_windows.cpp
+++ /dev/null
@@ -1,100 +0,0 @@
-/*************************************************************************/
-/* thread_windows.cpp */
-/*************************************************************************/
-/* This file is part of: */
-/* GODOT ENGINE */
-/* https://godotengine.org */
-/*************************************************************************/
-/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
-/* */
-/* 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"
-
-#if defined(WINDOWS_ENABLED) && !defined(UWP_ENABLED)
-
-#include "core/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);
-
- ScriptServer::thread_enter(); //scripts may need to attach a stack
-
- t->id = (ID)GetCurrentThreadId(); // must implement
- t->callback(t->user);
- SetEvent(t->handle);
-
- ScriptServer::thread_exit();
-
- 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 = CreateEvent(nullptr, TRUE, FALSE, nullptr);
-
- QueueUserWorkItem(thread_callback, tr, WT_EXECUTELONGFUNCTION);
-
- 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) {
-
- 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(nullptr) {
-}
-
-ThreadWindows::~ThreadWindows() {
-}
-
-#endif
diff --git a/drivers/windows/thread_windows.h b/drivers/windows/thread_windows.h
deleted file mode 100644
index 669956cd32..0000000000
--- a/drivers/windows/thread_windows.h
+++ /dev/null
@@ -1,68 +0,0 @@
-/*************************************************************************/
-/* thread_windows.h */
-/*************************************************************************/
-/* This file is part of: */
-/* GODOT ENGINE */
-/* https://godotengine.org */
-/*************************************************************************/
-/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
-/* */
-/* 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
-
-#ifdef WINDOWS_ENABLED
-
-#include "core/os/thread.h"
-#include "core/script_language.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