summaryrefslogtreecommitdiff
path: root/drivers
diff options
context:
space:
mode:
Diffstat (limited to 'drivers')
-rw-r--r--drivers/alsa/audio_driver_alsa.h8
-rw-r--r--drivers/alsamidi/midi_driver_alsamidi.h7
-rw-r--r--drivers/pulseaudio/audio_driver_pulseaudio.h8
-rw-r--r--drivers/unix/file_access_unix.cpp2
-rw-r--r--drivers/unix/os_unix.cpp35
-rw-r--r--drivers/vulkan/rendering_device_vulkan.cpp20
-rw-r--r--drivers/windows/dir_access_windows.cpp132
-rw-r--r--drivers/windows/file_access_windows.cpp57
8 files changed, 137 insertions, 132 deletions
diff --git a/drivers/alsa/audio_driver_alsa.h b/drivers/alsa/audio_driver_alsa.h
index 7aec0c4071..d1220d126e 100644
--- a/drivers/alsa/audio_driver_alsa.h
+++ b/drivers/alsa/audio_driver_alsa.h
@@ -28,11 +28,11 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
-#ifdef ALSA_ENABLED
-
#ifndef AUDIO_DRIVER_ALSA_H
#define AUDIO_DRIVER_ALSA_H
+#ifdef ALSA_ENABLED
+
#include "core/os/mutex.h"
#include "core/os/thread.h"
#include "servers/audio_server.h"
@@ -88,6 +88,6 @@ public:
~AudioDriverALSA() {}
};
-#endif // AUDIO_DRIVER_ALSA_H
-
#endif // ALSA_ENABLED
+
+#endif // AUDIO_DRIVER_ALSA_H
diff --git a/drivers/alsamidi/midi_driver_alsamidi.h b/drivers/alsamidi/midi_driver_alsamidi.h
index e8ed6df5b0..6aabe8e3fd 100644
--- a/drivers/alsamidi/midi_driver_alsamidi.h
+++ b/drivers/alsamidi/midi_driver_alsamidi.h
@@ -28,11 +28,11 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
-#ifdef ALSAMIDI_ENABLED
-
#ifndef MIDI_DRIVER_ALSAMIDI_H
#define MIDI_DRIVER_ALSAMIDI_H
+#ifdef ALSAMIDI_ENABLED
+
#include "core/os/midi_driver.h"
#include "core/os/mutex.h"
#include "core/os/thread.h"
@@ -64,5 +64,6 @@ public:
virtual ~MIDIDriverALSAMidi();
};
-#endif // MIDI_DRIVER_ALSAMIDI_H
#endif // ALSAMIDI_ENABLED
+
+#endif // MIDI_DRIVER_ALSAMIDI_H
diff --git a/drivers/pulseaudio/audio_driver_pulseaudio.h b/drivers/pulseaudio/audio_driver_pulseaudio.h
index 2f2ad0fc38..35ccae94b8 100644
--- a/drivers/pulseaudio/audio_driver_pulseaudio.h
+++ b/drivers/pulseaudio/audio_driver_pulseaudio.h
@@ -28,11 +28,11 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
-#ifdef PULSEAUDIO_ENABLED
-
#ifndef AUDIO_DRIVER_PULSEAUDIO_H
#define AUDIO_DRIVER_PULSEAUDIO_H
+#ifdef PULSEAUDIO_ENABLED
+
#include "core/os/mutex.h"
#include "core/os/thread.h"
#include "servers/audio_server.h"
@@ -124,6 +124,6 @@ public:
~AudioDriverPulseAudio() {}
};
-#endif // AUDIO_DRIVER_PULSEAUDIO_H
-
#endif // PULSEAUDIO_ENABLED
+
+#endif // AUDIO_DRIVER_PULSEAUDIO_H
diff --git a/drivers/unix/file_access_unix.cpp b/drivers/unix/file_access_unix.cpp
index 06bad9f385..51c657007c 100644
--- a/drivers/unix/file_access_unix.cpp
+++ b/drivers/unix/file_access_unix.cpp
@@ -78,7 +78,7 @@ Error FileAccessUnix::_open(const String &p_path, int p_mode_flags) {
path_src = p_path;
path = fix_path(p_path);
- //printf("opening %ls, %i\n", path.c_str(), Memory::get_static_mem_usage());
+ //printf("opening %s, %i\n", path.utf8().get_data(), Memory::get_static_mem_usage());
ERR_FAIL_COND_V_MSG(f, ERR_ALREADY_IN_USE, "File is already in use.");
const char *mode_string;
diff --git a/drivers/unix/os_unix.cpp b/drivers/unix/os_unix.cpp
index 3c212cadb8..6b98a344dc 100644
--- a/drivers/unix/os_unix.cpp
+++ b/drivers/unix/os_unix.cpp
@@ -171,52 +171,53 @@ double OS_Unix::get_unix_time() const {
OS::Date OS_Unix::get_date(bool utc) const {
time_t t = time(nullptr);
- struct tm *lt;
+ struct tm lt;
if (utc) {
- lt = gmtime(&t);
+ gmtime_r(&t, &lt);
} else {
- lt = localtime(&t);
+ localtime_r(&t, &lt);
}
Date ret;
- ret.year = 1900 + lt->tm_year;
+ ret.year = 1900 + lt.tm_year;
// Index starting at 1 to match OS_Unix::get_date
// and Windows SYSTEMTIME and tm_mon follows the typical structure
// of 0-11, noted here: http://www.cplusplus.com/reference/ctime/tm/
- ret.month = (Month)(lt->tm_mon + 1);
- ret.day = lt->tm_mday;
- ret.weekday = (Weekday)lt->tm_wday;
- ret.dst = lt->tm_isdst;
+ ret.month = (Month)(lt.tm_mon + 1);
+ ret.day = lt.tm_mday;
+ ret.weekday = (Weekday)lt.tm_wday;
+ ret.dst = lt.tm_isdst;
return ret;
}
OS::Time OS_Unix::get_time(bool utc) const {
time_t t = time(nullptr);
- struct tm *lt;
+ struct tm lt;
if (utc) {
- lt = gmtime(&t);
+ gmtime_r(&t, &lt);
} else {
- lt = localtime(&t);
+ localtime_r(&t, &lt);
}
Time ret;
- ret.hour = lt->tm_hour;
- ret.min = lt->tm_min;
- ret.sec = lt->tm_sec;
+ ret.hour = lt.tm_hour;
+ ret.min = lt.tm_min;
+ ret.sec = lt.tm_sec;
get_time_zone_info();
return ret;
}
OS::TimeZoneInfo OS_Unix::get_time_zone_info() const {
time_t t = time(nullptr);
- struct tm *lt = localtime(&t);
+ struct tm lt;
+ localtime_r(&t, &lt);
char name[16];
- strftime(name, 16, "%Z", lt);
+ strftime(name, 16, "%Z", &lt);
name[15] = 0;
TimeZoneInfo ret;
ret.name = name;
char bias_buf[16];
- strftime(bias_buf, 16, "%z", lt);
+ strftime(bias_buf, 16, "%z", &lt);
int bias;
bias_buf[15] = 0;
sscanf(bias_buf, "%d", &bias);
diff --git a/drivers/vulkan/rendering_device_vulkan.cpp b/drivers/vulkan/rendering_device_vulkan.cpp
index fb890491a4..9fe3f7e6c0 100644
--- a/drivers/vulkan/rendering_device_vulkan.cpp
+++ b/drivers/vulkan/rendering_device_vulkan.cpp
@@ -3650,7 +3650,7 @@ bool RenderingDeviceVulkan::_uniform_add_binding(Vector<Vector<VkDescriptorSetLa
//print_line("DEBUG: SAMPLER: texel buffer");
} else {
if (r_error) {
- *r_error = "On shader stage '" + String(shader_stage_names[p_stage]) + "', uniform '" + reflection.name.c_str() + "' is of unsupported buffer type.";
+ *r_error = "On shader stage '" + String(shader_stage_names[p_stage]) + "', uniform '" + reflection.name + "' is of unsupported buffer type.";
}
return false;
}
@@ -3673,7 +3673,7 @@ bool RenderingDeviceVulkan::_uniform_add_binding(Vector<Vector<VkDescriptorSetLa
} else {
//print_line("DEBUG: sampler unknown");
if (r_error) {
- *r_error = "On shader stage '" + String(shader_stage_names[p_stage]) + "', uniform '" + reflection.name.c_str() + "' is of unsupported sampler type.";
+ *r_error = "On shader stage '" + String(shader_stage_names[p_stage]) + "', uniform '" + reflection.name + "' is of unsupported sampler type.";
}
return false;
}
@@ -3698,7 +3698,7 @@ bool RenderingDeviceVulkan::_uniform_add_binding(Vector<Vector<VkDescriptorSetLa
if (reflection.getType()->getQualifier().layoutPushConstant) {
uint32_t len = reflection.size;
if (push_constant.push_constant_size != 0 && push_constant.push_constant_size != len) {
- *r_error = "On shader stage '" + String(shader_stage_names[p_stage]) + "', uniform '" + reflection.name.c_str() + "' push constants for different stages should all be the same size.";
+ *r_error = "On shader stage '" + String(shader_stage_names[p_stage]) + "', uniform '" + reflection.name + "' push constants for different stages should all be the same size.";
return false;
}
push_constant.push_constant_size = len;
@@ -3714,7 +3714,7 @@ bool RenderingDeviceVulkan::_uniform_add_binding(Vector<Vector<VkDescriptorSetLa
//print_line("DEBUG: Storage buffer");
} else {
if (r_error) {
- *r_error = "On shader stage '" + String(shader_stage_names[p_stage]) + "', uniform '" + reflection.name.c_str() + "' is of unsupported block type: (" + itos(reflection.getType()->getQualifier().storage) + ").";
+ *r_error = "On shader stage '" + String(shader_stage_names[p_stage]) + "', uniform '" + reflection.name + "' is of unsupported block type: (" + itos(reflection.getType()->getQualifier().storage) + ").";
}
return false;
}
@@ -3743,7 +3743,7 @@ bool RenderingDeviceVulkan::_uniform_add_binding(Vector<Vector<VkDescriptorSetLa
}
if (r_error) {
- *r_error = "On shader stage '" + String(shader_stage_names[p_stage]) + "', uniform '" + reflection.name.c_str() + "' unsupported uniform type.";
+ *r_error = "On shader stage '" + String(shader_stage_names[p_stage]) + "', uniform '" + reflection.name + "' unsupported uniform type.";
}
return false;
}
@@ -3751,7 +3751,7 @@ bool RenderingDeviceVulkan::_uniform_add_binding(Vector<Vector<VkDescriptorSetLa
if (!reflection.getType()->getQualifier().hasBinding()) {
if (r_error) {
- *r_error = "On shader stage '" + String(shader_stage_names[p_stage]) + "', uniform '" + reflection.name.c_str() + "' lacks a binding number.";
+ *r_error = "On shader stage '" + String(shader_stage_names[p_stage]) + "', uniform '" + reflection.name + "' lacks a binding number.";
}
return false;
}
@@ -3760,14 +3760,14 @@ bool RenderingDeviceVulkan::_uniform_add_binding(Vector<Vector<VkDescriptorSetLa
if (set >= MAX_UNIFORM_SETS) {
if (r_error) {
- *r_error = "On shader stage '" + String(shader_stage_names[p_stage]) + "', uniform '" + reflection.name.c_str() + "' uses a set (" + itos(set) + ") index larger than what is supported (" + itos(MAX_UNIFORM_SETS) + ").";
+ *r_error = "On shader stage '" + String(shader_stage_names[p_stage]) + "', uniform '" + reflection.name + "' uses a set (" + itos(set) + ") index larger than what is supported (" + itos(MAX_UNIFORM_SETS) + ").";
}
return false;
}
if (set >= limits.maxBoundDescriptorSets) {
if (r_error) {
- *r_error = "On shader stage '" + String(shader_stage_names[p_stage]) + "', uniform '" + reflection.name.c_str() + "' uses a set (" + itos(set) + ") index larger than what is supported by the hardware (" + itos(limits.maxBoundDescriptorSets) + ").";
+ *r_error = "On shader stage '" + String(shader_stage_names[p_stage]) + "', uniform '" + reflection.name + "' uses a set (" + itos(set) + ") index larger than what is supported by the hardware (" + itos(limits.maxBoundDescriptorSets) + ").";
}
return false;
}
@@ -3781,7 +3781,7 @@ bool RenderingDeviceVulkan::_uniform_add_binding(Vector<Vector<VkDescriptorSetLa
//already exists, verify that it's the same type
if (bindings[set][i].descriptorType != layout_binding.descriptorType) {
if (r_error) {
- *r_error = "On shader stage '" + String(shader_stage_names[p_stage]) + "', uniform '" + reflection.name.c_str() + "' trying to re-use location for set=" + itos(set) + ", binding=" + itos(binding) + " with different uniform type.";
+ *r_error = "On shader stage '" + String(shader_stage_names[p_stage]) + "', uniform '" + reflection.name + "' trying to re-use location for set=" + itos(set) + ", binding=" + itos(binding) + " with different uniform type.";
}
return false;
}
@@ -3789,7 +3789,7 @@ bool RenderingDeviceVulkan::_uniform_add_binding(Vector<Vector<VkDescriptorSetLa
//also, verify that it's the same size
if (bindings[set][i].descriptorCount != layout_binding.descriptorCount || uniform_infos[set][i].length != info.length) {
if (r_error) {
- *r_error = "On shader stage '" + String(shader_stage_names[p_stage]) + "', uniform '" + reflection.name.c_str() + "' trying to re-use location for set=" + itos(set) + ", binding=" + itos(binding) + " with different uniform size.";
+ *r_error = "On shader stage '" + String(shader_stage_names[p_stage]) + "', uniform '" + reflection.name + "' trying to re-use location for set=" + itos(set) + ", binding=" + itos(binding) + " with different uniform size.";
}
return false;
}
diff --git a/drivers/windows/dir_access_windows.cpp b/drivers/windows/dir_access_windows.cpp
index b8153907a9..03e4e30797 100644
--- a/drivers/windows/dir_access_windows.cpp
+++ b/drivers/windows/dir_access_windows.cpp
@@ -65,7 +65,7 @@ Error DirAccessWindows::list_dir_begin() {
_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);
if (p->h == INVALID_HANDLE_VALUE) {
return ERR_CANT_OPEN;
@@ -75,13 +75,14 @@ Error DirAccessWindows::list_dir_begin() {
}
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);
@@ -111,8 +112,9 @@ int DirAccessWindows::get_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]) + ":";
}
@@ -122,18 +124,17 @@ Error DirAccessWindows::change_dir(String p_dir) {
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;
}
@@ -141,13 +142,11 @@ Error DirAccessWindows::change_dir(String p_dir) {
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;
}
@@ -156,8 +155,9 @@ 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("/", "\\");
@@ -167,16 +167,16 @@ 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;
}
@@ -185,12 +185,11 @@ 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) {
@@ -209,20 +208,18 @@ 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);
}
@@ -230,31 +227,30 @@ bool DirAccessWindows::file_exists(String p_file) {
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);
@@ -262,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)) {
@@ -280,60 +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);
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;
@@ -352,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,
@@ -360,7 +356,7 @@ String DirAccessWindows::get_filesystem_type() const {
&dwFileSystemFlags,
szFileSystemName,
sizeof(szFileSystemName)) == TRUE) {
- return String(szFileSystemName);
+ return String::utf16((const char16_t *)szFileSystemName);
}
ERR_FAIL_V("");
diff --git a/drivers/windows/file_access_windows.cpp b/drivers/windows/file_access_windows.cpp
index 50366d0b2d..dd86061ea7 100644
--- a/drivers/windows/file_access_windows.cpp
+++ b/drivers/windows/file_access_windows.cpp
@@ -59,29 +59,32 @@ void FileAccessWindows::check_errors() const {
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
@@ -91,9 +94,9 @@ 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) {
@@ -110,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) {
@@ -130,8 +133,9 @@ Error FileAccessWindows::_open(const String &p_path, int p_mode_flags) {
}
void FileAccessWindows::close() {
- if (!f)
+ if (!f) {
return;
+ }
fclose(f);
f = nullptr;
@@ -148,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--;
@@ -192,15 +196,17 @@ bool FileAccessWindows::is_open() const {
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) {
ERR_FAIL_COND(!f);
- if (fseek(f, p_position, SEEK_END))
+ if (fseek(f, p_position, SEEK_END)) {
check_errors();
+ }
prev_op = 0;
}
@@ -209,7 +215,7 @@ size_t FileAccessWindows::get_position() const {
aux_position = ftell(f);
if (!aux_position) {
check_errors();
- };
+ }
return aux_position;
}
@@ -241,7 +247,7 @@ uint8_t FileAccessWindows::get_8() const {
if (fread(&b, 1, 1, f) == 0) {
check_errors();
b = '\0';
- };
+ }
return b;
}
@@ -266,8 +272,9 @@ Error FileAccessWindows::get_error() const {
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) {
@@ -298,9 +305,9 @@ 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 {
@@ -315,7 +322,7 @@ uint64_t FileAccessWindows::_get_modified_time(const String &p_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;