diff options
Diffstat (limited to 'drivers/windows/dir_access_windows.cpp')
-rw-r--r-- | drivers/windows/dir_access_windows.cpp | 43 |
1 files changed, 9 insertions, 34 deletions
diff --git a/drivers/windows/dir_access_windows.cpp b/drivers/windows/dir_access_windows.cpp index 3df7eafe13..2653ac1cdb 100644 --- a/drivers/windows/dir_access_windows.cpp +++ b/drivers/windows/dir_access_windows.cpp @@ -53,7 +53,6 @@ */ struct DirAccessWindowsPrivate { - HANDLE h; //handle for findfirstfile WIN32_FIND_DATA f; WIN32_FIND_DATAW fu; //unicode version @@ -62,18 +61,16 @@ 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, NULL, 0); + p->h = FindFirstFileExW((current_dir + "\\*").c_str(), FindExInfoStandard, &p->fu, FindExSearchNameMatch, nullptr, 0); return (p->h == INVALID_HANDLE_VALUE) ? ERR_CANT_OPEN : OK; } String DirAccessWindows::get_next() { - if (p->h == INVALID_HANDLE_VALUE) return ""; @@ -83,7 +80,6 @@ String DirAccessWindows::get_next() { String name = p->fu.cFileName; if (FindNextFileW(p->h, &p->fu) == 0) { - FindClose(p->h); p->h = INVALID_HANDLE_VALUE; } @@ -92,29 +88,25 @@ 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) { +String DirAccessWindows::get_drive(int p_drive) { if (p_drive < 0 || p_drive >= drive_count) return ""; @@ -122,7 +114,6 @@ String DirAccessWindows::get_drive(int p_drive) { } Error DirAccessWindows::change_dir(String p_dir) { - GLOBAL_LOCK_FUNCTION p_dir = fix_path(p_dir); @@ -136,7 +127,6 @@ Error DirAccessWindows::change_dir(String p_dir) { String base = _get_root_path(); if (base != "") { - GetCurrentDirectoryW(2048, real_current_dir_name); String new_dir; new_dir = String(real_current_dir_name).replace("\\", "/"); @@ -146,7 +136,6 @@ 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 = current_dir.replace("\\", "/"); @@ -160,7 +149,6 @@ Error DirAccessWindows::change_dir(String p_dir) { } Error DirAccessWindows::make_dir(String p_dir) { - GLOBAL_LOCK_FUNCTION p_dir = fix_path(p_dir); @@ -175,7 +163,7 @@ 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(), NULL); + success = CreateDirectoryW(p_dir.c_str(), nullptr); err = GetLastError(); if (success) { @@ -190,10 +178,8 @@ Error DirAccessWindows::make_dir(String p_dir) { } 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("/")) return _get_root_string() + bd.substr(1, bd.length()); @@ -217,7 +203,6 @@ 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()) @@ -239,7 +224,6 @@ bool DirAccessWindows::file_exists(String p_file) { } bool DirAccessWindows::dir_exists(String p_dir) { - GLOBAL_LOCK_FUNCTION if (p_dir.is_rel_path()) @@ -260,7 +244,6 @@ bool DirAccessWindows::dir_exists(String p_dir) { } 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); @@ -275,11 +258,11 @@ 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(), NULL, 0, tmpfile)) { + if (!GetTempFileNameW(fix_path(get_current_dir()).c_str(), nullptr, 0, tmpfile)) { return FAILED; } - if (!::ReplaceFileW(tmpfile, p_path.c_str(), NULL, 0, NULL, NULL)) { + if (!::ReplaceFileW(tmpfile, p_path.c_str(), nullptr, 0, nullptr, nullptr)) { DeleteFileW(tmpfile); return FAILED; } @@ -298,16 +281,11 @@ Error DirAccessWindows::rename(String p_path, String p_new_path) { } Error DirAccessWindows::remove(String p_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()); @@ -318,6 +296,7 @@ Error DirAccessWindows::remove(String p_path) { else return ::_wunlink(p_path.c_str()) == 0 ? OK : FAILED; } + /* FileType DirAccessWindows::get_file_type(const String& p_file) const { @@ -345,11 +324,11 @@ FileType DirAccessWindows::get_file_type(const String& p_file) const { return (attr&FILE_ATTRIBUTE_DIRECTORY)?FILE_TYPE_ } + */ size_t DirAccessWindows::get_space_left() { - uint64_t bytes = 0; - if (!GetDiskFreeSpaceEx(NULL, (PULARGE_INTEGER)&bytes, NULL, NULL)) + if (!GetDiskFreeSpaceEx(nullptr, (PULARGE_INTEGER)&bytes, nullptr, nullptr)) return 0; //this is either 0 or a value in bytes. @@ -377,7 +356,6 @@ String DirAccessWindows::get_filesystem_type() const { &dwFileSystemFlags, szFileSystemName, sizeof(szFileSystemName)) == TRUE) { - return String(szFileSystemName); } @@ -385,7 +363,6 @@ String DirAccessWindows::get_filesystem_type() const { } DirAccessWindows::DirAccessWindows() { - p = memnew(DirAccessWindowsPrivate); p->h = INVALID_HANDLE_VALUE; current_dir = "."; @@ -401,7 +378,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 +390,6 @@ DirAccessWindows::DirAccessWindows() { } DirAccessWindows::~DirAccessWindows() { - memdelete(p); } |