[Windows] Add support for handling network share paths.
This commit is contained in:
parent
6a3ff8fa1f
commit
cba8280515
8 changed files with 69 additions and 16 deletions
|
@ -145,14 +145,18 @@ Error DirAccess::make_dir_recursive(String p_dir) {
|
|||
|
||||
full_dir = full_dir.replace("\\", "/");
|
||||
|
||||
//int slices = full_dir.get_slice_count("/");
|
||||
|
||||
String base;
|
||||
|
||||
if (full_dir.begins_with("res://")) {
|
||||
base = "res://";
|
||||
} else if (full_dir.begins_with("user://")) {
|
||||
base = "user://";
|
||||
} else if (full_dir.is_network_share_path()) {
|
||||
int pos = full_dir.find("/", 2);
|
||||
ERR_FAIL_COND_V(pos < 0, ERR_INVALID_PARAMETER);
|
||||
pos = full_dir.find("/", pos + 1);
|
||||
ERR_FAIL_COND_V(pos < 0, ERR_INVALID_PARAMETER);
|
||||
base = full_dir.substr(0, pos + 1);
|
||||
} else if (full_dir.begins_with("/")) {
|
||||
base = "/";
|
||||
} else if (full_dir.find(":/") != -1) {
|
||||
|
|
|
@ -3558,6 +3558,10 @@ String String::rstrip(const String &p_chars) const {
|
|||
return substr(0, end + 1);
|
||||
}
|
||||
|
||||
bool String::is_network_share_path() const {
|
||||
return begins_with("//") || begins_with("\\\\");
|
||||
}
|
||||
|
||||
String String::simplify_path() const {
|
||||
String s = *this;
|
||||
String drive;
|
||||
|
@ -3570,6 +3574,9 @@ String String::simplify_path() const {
|
|||
} else if (s.begins_with("user://")) {
|
||||
drive = "user://";
|
||||
s = s.substr(7, s.length());
|
||||
} else if (is_network_share_path()) {
|
||||
drive = s.substr(0, 2);
|
||||
s = s.substr(2, s.length() - 2);
|
||||
} else if (s.begins_with("/") || s.begins_with("\\")) {
|
||||
drive = s.substr(0, 1);
|
||||
s = s.substr(1, s.length() - 1);
|
||||
|
@ -4271,13 +4278,13 @@ bool String::is_relative_path() const {
|
|||
String String::get_base_dir() const {
|
||||
int end = 0;
|
||||
|
||||
// url scheme style base
|
||||
// URL scheme style base.
|
||||
int basepos = find("://");
|
||||
if (basepos != -1) {
|
||||
end = basepos + 3;
|
||||
}
|
||||
|
||||
// windows top level directory base
|
||||
// Windows top level directory base.
|
||||
if (end == 0) {
|
||||
basepos = find(":/");
|
||||
if (basepos == -1) {
|
||||
|
@ -4288,7 +4295,24 @@ String String::get_base_dir() const {
|
|||
}
|
||||
}
|
||||
|
||||
// unix root directory base
|
||||
// Windows UNC network share path.
|
||||
if (end == 0) {
|
||||
if (is_network_share_path()) {
|
||||
basepos = find("/", 2);
|
||||
if (basepos == -1) {
|
||||
basepos = find("\\", 2);
|
||||
}
|
||||
int servpos = find("/", basepos + 1);
|
||||
if (servpos == -1) {
|
||||
servpos = find("\\", basepos + 1);
|
||||
}
|
||||
if (servpos != -1) {
|
||||
end = servpos + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Unix root directory base.
|
||||
if (end == 0) {
|
||||
if (begins_with("/")) {
|
||||
end = 1;
|
||||
|
|
|
@ -405,6 +405,7 @@ public:
|
|||
String get_file() const;
|
||||
static String humanize_size(uint64_t p_size);
|
||||
String simplify_path() const;
|
||||
bool is_network_share_path() const;
|
||||
|
||||
String xml_escape(bool p_escape_quotes = false) const;
|
||||
String xml_unescape() const;
|
||||
|
|
|
@ -165,8 +165,11 @@ Error DirAccessWindows::make_dir(String p_dir) {
|
|||
bool success;
|
||||
int err;
|
||||
|
||||
p_dir = "\\\\?\\" + p_dir; //done according to
|
||||
// https://msdn.microsoft.com/en-us/library/windows/desktop/aa363855(v=vs.85).aspx
|
||||
if (!p_dir.is_network_share_path()) {
|
||||
p_dir = "\\\\?\\" + p_dir;
|
||||
// Add "\\?\" to the path to extend max. path length past 248, if it's not a network share UNC path.
|
||||
// See https://msdn.microsoft.com/en-us/library/windows/desktop/aa363855(v=vs.85).aspx
|
||||
}
|
||||
|
||||
success = CreateDirectoryW((LPCWSTR)(p_dir.utf16().get_data()), nullptr);
|
||||
err = GetLastError();
|
||||
|
@ -349,6 +352,10 @@ String DirAccessWindows::get_filesystem_type() const {
|
|||
ERR_FAIL_COND_V(unit_end == -1, String());
|
||||
String unit = path.substr(0, unit_end + 1) + "\\";
|
||||
|
||||
if (path.is_network_share_path()) {
|
||||
return "Network Share";
|
||||
}
|
||||
|
||||
WCHAR szVolumeName[100];
|
||||
WCHAR szFileSystemName[10];
|
||||
DWORD dwSerialNumber = 0;
|
||||
|
|
|
@ -230,7 +230,14 @@ Vector<String> EditorFileDialog::get_selected_files() const {
|
|||
|
||||
void EditorFileDialog::update_dir() {
|
||||
if (drives->is_visible()) {
|
||||
drives->select(dir_access->get_current_drive());
|
||||
if (dir_access->get_current_dir().is_network_share_path()) {
|
||||
_update_drives(false);
|
||||
drives->add_item(RTR("Network"));
|
||||
drives->set_item_disabled(drives->get_item_count() - 1, true);
|
||||
drives->select(drives->get_item_count() - 1);
|
||||
} else {
|
||||
drives->select(dir_access->get_current_drive());
|
||||
}
|
||||
}
|
||||
dir->set_text(dir_access->get_current_dir(false));
|
||||
|
||||
|
@ -1152,7 +1159,7 @@ void EditorFileDialog::_select_drive(int p_idx) {
|
|||
_push_history();
|
||||
}
|
||||
|
||||
void EditorFileDialog::_update_drives() {
|
||||
void EditorFileDialog::_update_drives(bool p_select) {
|
||||
int dc = dir_access->get_drive_count();
|
||||
if (dc == 0 || access != ACCESS_FILESYSTEM) {
|
||||
drives->hide();
|
||||
|
@ -1170,8 +1177,9 @@ void EditorFileDialog::_update_drives() {
|
|||
String d = dir_access->get_drive(i);
|
||||
drives->add_item(dir_access->get_drive(i));
|
||||
}
|
||||
|
||||
drives->select(dir_access->get_current_drive());
|
||||
if (p_select) {
|
||||
drives->select(dir_access->get_current_drive());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -180,7 +180,7 @@ private:
|
|||
|
||||
void _delete_items();
|
||||
|
||||
void _update_drives();
|
||||
void _update_drives(bool p_select = true);
|
||||
|
||||
void _go_up();
|
||||
void _go_back();
|
||||
|
|
|
@ -169,7 +169,14 @@ void FileDialog::update_dir() {
|
|||
dir->set_text(dir_access->get_current_dir(false));
|
||||
|
||||
if (drives->is_visible()) {
|
||||
drives->select(dir_access->get_current_drive());
|
||||
if (dir_access->get_current_dir().is_network_share_path()) {
|
||||
_update_drives(false);
|
||||
drives->add_item(RTR("Network"));
|
||||
drives->set_item_disabled(drives->get_item_count() - 1, true);
|
||||
drives->select(drives->get_item_count() - 1);
|
||||
} else {
|
||||
drives->select(dir_access->get_current_drive());
|
||||
}
|
||||
}
|
||||
|
||||
// Deselect any item, to make "Select Current Folder" button text by default.
|
||||
|
@ -846,7 +853,7 @@ void FileDialog::_select_drive(int p_idx) {
|
|||
_push_history();
|
||||
}
|
||||
|
||||
void FileDialog::_update_drives() {
|
||||
void FileDialog::_update_drives(bool p_select) {
|
||||
int dc = dir_access->get_drive_count();
|
||||
if (dc == 0 || access != ACCESS_FILESYSTEM) {
|
||||
drives->hide();
|
||||
|
@ -864,7 +871,9 @@ void FileDialog::_update_drives() {
|
|||
drives->add_item(dir_access->get_drive(i));
|
||||
}
|
||||
|
||||
drives->select(dir_access->get_current_drive());
|
||||
if (p_select) {
|
||||
drives->select(dir_access->get_current_drive());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -132,7 +132,7 @@ private:
|
|||
void _go_back();
|
||||
void _go_forward();
|
||||
|
||||
void _update_drives();
|
||||
void _update_drives(bool p_select = true);
|
||||
|
||||
virtual void unhandled_input(const Ref<InputEvent> &p_event) override;
|
||||
|
||||
|
|
Loading…
Reference in a new issue