summaryrefslogtreecommitdiff
path: root/drivers/unix
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <remi@verschelde.fr>2021-12-15 15:21:39 +0100
committerGitHub <noreply@github.com>2021-12-15 15:21:39 +0100
commite55ecd117fc6afadd8d424b8e2686292f0205918 (patch)
tree65b250b5f99fcacf97ac33f4ad8e0aba81366598 /drivers/unix
parentde8348a9b31845dec3e585f5f0e5fc639138df09 (diff)
parent67f04b381bea03857c21d6bda3eb56cfb6c60fd5 (diff)
Merge pull request #55948 from timothyqiu/shortcut-drives
Diffstat (limited to 'drivers/unix')
-rw-r--r--drivers/unix/dir_access_unix.cpp16
-rw-r--r--drivers/unix/dir_access_unix.h1
2 files changed, 17 insertions, 0 deletions
diff --git a/drivers/unix/dir_access_unix.cpp b/drivers/unix/dir_access_unix.cpp
index be993b88e5..f263a8b62b 100644
--- a/drivers/unix/dir_access_unix.cpp
+++ b/drivers/unix/dir_access_unix.cpp
@@ -216,6 +216,8 @@ static bool _filter_drive(struct mntent *mnt) {
#endif
static void _get_drives(List<String> *list) {
+ list->push_back("/");
+
#if defined(HAVE_MNTENT) && defined(X11_ENABLED)
// Check /etc/mtab for the list of mounted partitions
FILE *mtab = setmntent("/etc/mtab", "r");
@@ -286,6 +288,20 @@ String DirAccessUnix::get_drive(int p_drive) {
return list[p_drive];
}
+int DirAccessUnix::get_current_drive() {
+ int drive = 0;
+ int max_length = -1;
+ const String path = get_current_dir().to_lower();
+ for (int i = 0; i < get_drive_count(); i++) {
+ const String d = get_drive(i).to_lower();
+ if (max_length < d.length() && path.begins_with(d)) {
+ max_length = d.length();
+ drive = i;
+ }
+ }
+ return drive;
+}
+
bool DirAccessUnix::drives_are_shortcuts() {
return true;
}
diff --git a/drivers/unix/dir_access_unix.h b/drivers/unix/dir_access_unix.h
index 8b19308967..327707de00 100644
--- a/drivers/unix/dir_access_unix.h
+++ b/drivers/unix/dir_access_unix.h
@@ -63,6 +63,7 @@ public:
virtual int get_drive_count();
virtual String get_drive(int p_drive);
+ virtual int get_current_drive();
virtual bool drives_are_shortcuts();
virtual Error change_dir(String p_dir); ///< can be relative or absolute, return false on success