fixed show mapped drives in windows

This commit is contained in:
Radek Davidek 2026-03-08 15:07:15 +01:00
parent a06d421e84
commit dc6670ab96
2 changed files with 48 additions and 4 deletions

View File

@ -25,11 +25,36 @@ public class DriveSelector extends JDialog {
((JComponent) getContentPane()).setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
// Get list of available drives
File[] roots = File.listRoots();
List<DriveInfo> drives = new ArrayList<>();
java.util.Set<File> driveSet = new java.util.LinkedHashSet<>();
for (File root : roots) {
drives.add(new DriveInfo(root));
File[] roots = File.listRoots();
if (roots != null) {
for (File r : roots) {
driveSet.add(r);
}
}
// On Windows, additionally add mapped network drives if missed by listRoots
if (cz.kamma.kfmanager.MainApp.CURRENT_OS == cz.kamma.kfmanager.MainApp.OS.WINDOWS) {
javax.swing.filechooser.FileSystemView fsv = javax.swing.filechooser.FileSystemView.getFileSystemView();
File[] fsvRoots = fsv.getRoots();
if (fsvRoots != null) {
for (File r : fsvRoots) {
File[] devices = fsv.getFiles(r, false);
if (devices != null) {
for (File d : devices) {
if (fsv.isDrive(d) || fsv.isFileSystemRoot(d)) {
driveSet.add(d);
}
}
}
}
}
}
List<DriveInfo> drives = new ArrayList<>();
for (File drive : driveSet) {
drives.add(new DriveInfo(drive));
}
// List of drives

View File

@ -491,6 +491,25 @@ public class FilePanel extends JPanel {
driveSet.add(r);
}
}
// On Windows, additionally add mapped network drives if missed by listRoots
if (MainApp.CURRENT_OS == MainApp.OS.WINDOWS) {
javax.swing.filechooser.FileSystemView fsv = javax.swing.filechooser.FileSystemView.getFileSystemView();
File[] fsvRoots = fsv.getRoots();
if (fsvRoots != null) {
for (File r : fsvRoots) {
// This usually returns "Desktop". We need to look into it or other FSV methods.
File[] devices = fsv.getFiles(r, false);
if (devices != null) {
for (File d : devices) {
if (fsv.isDrive(d) || fsv.isFileSystemRoot(d)) {
driveSet.add(d);
}
}
}
}
}
}
// Add home directory
driveSet.add(new File(System.getProperty("user.home")));