You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-05 12:10:55 +00:00
Add / to the unix shortcut drive list
Also made `get_current_drive()` to pick the longest match on Unix.
(cherry picked from commit 67f04b381b)
This commit is contained in:
committed by
Rémi Verschelde
parent
8e29a37800
commit
e40bb68c05
@@ -81,13 +81,19 @@
|
|||||||
<return type="String" />
|
<return type="String" />
|
||||||
<argument index="0" name="idx" type="int" />
|
<argument index="0" name="idx" type="int" />
|
||||||
<description>
|
<description>
|
||||||
On Windows, returns the name of the drive (partition) passed as an argument (e.g. [code]C:[/code]). On other platforms, or if the requested drive does not exist, the method returns an empty String.
|
On Windows, returns the name of the drive (partition) passed as an argument (e.g. [code]C:[/code]).
|
||||||
|
On macOS, returns the path to the mounted volume passed as an argument.
|
||||||
|
On Linux, returns the path to the mounted volume or GTK 3 bookmark passed as an argument.
|
||||||
|
On other platforms, or if the requested drive does not exist, the method returns an empty String.
|
||||||
</description>
|
</description>
|
||||||
</method>
|
</method>
|
||||||
<method name="get_drive_count">
|
<method name="get_drive_count">
|
||||||
<return type="int" />
|
<return type="int" />
|
||||||
<description>
|
<description>
|
||||||
On Windows, returns the number of drives (partitions) mounted on the current filesystem. On other platforms, the method returns 0.
|
On Windows, returns the number of drives (partitions) mounted on the current filesystem.
|
||||||
|
On macOS, returns the number of mounted volumes.
|
||||||
|
On Linux, returns the number of mounted volumes and GTK 3 bookmarks.
|
||||||
|
On other platforms, the method returns 0.
|
||||||
</description>
|
</description>
|
||||||
</method>
|
</method>
|
||||||
<method name="get_next">
|
<method name="get_next">
|
||||||
|
|||||||
@@ -194,6 +194,8 @@ static bool _filter_drive(struct mntent *mnt) {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
static void _get_drives(List<String> *list) {
|
static void _get_drives(List<String> *list) {
|
||||||
|
list->push_back("/");
|
||||||
|
|
||||||
#if defined(HAVE_MNTENT) && defined(X11_ENABLED)
|
#if defined(HAVE_MNTENT) && defined(X11_ENABLED)
|
||||||
// Check /etc/mtab for the list of mounted partitions
|
// Check /etc/mtab for the list of mounted partitions
|
||||||
FILE *mtab = setmntent("/etc/mtab", "r");
|
FILE *mtab = setmntent("/etc/mtab", "r");
|
||||||
@@ -262,6 +264,20 @@ String DirAccessUnix::get_drive(int p_drive) {
|
|||||||
return list[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() {
|
bool DirAccessUnix::drives_are_shortcuts() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -63,6 +63,7 @@ public:
|
|||||||
|
|
||||||
virtual int get_drive_count();
|
virtual int get_drive_count();
|
||||||
virtual String get_drive(int p_drive);
|
virtual String get_drive(int p_drive);
|
||||||
|
virtual int get_current_drive();
|
||||||
virtual bool drives_are_shortcuts();
|
virtual bool drives_are_shortcuts();
|
||||||
|
|
||||||
virtual Error change_dir(String p_dir); ///< can be relative or absolute, return false on success
|
virtual Error change_dir(String p_dir); ///< can be relative or absolute, return false on success
|
||||||
|
|||||||
Reference in New Issue
Block a user