You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-04 12:00:25 +00:00
[Complex Test Layouts] Change String to use UTF-32 encoding on all platforms.
This commit is contained in:
@@ -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("");
|
||||
|
||||
Reference in New Issue
Block a user