[Complex Test Layouts] Change String to use UTF-32 encoding on all platforms.
This commit is contained in:
@ -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;
|
||||
|
||||
Reference in New Issue
Block a user