1 | package org.greenstone.gatherer.file;
|
---|
2 |
|
---|
3 | import java.io.File;
|
---|
4 | import javax.swing.filechooser.FileSystemView;
|
---|
5 | import org.greenstone.gatherer.Dictionary;
|
---|
6 | import org.greenstone.gatherer.Gatherer;
|
---|
7 | import org.greenstone.gatherer.file.FileNode;
|
---|
8 | import org.greenstone.gatherer.util.ArrayTools;
|
---|
9 |
|
---|
10 |
|
---|
11 | public class FileSystem
|
---|
12 | {
|
---|
13 | static public FileNode getLocalFileSystem(FileSystemModel model)
|
---|
14 | // static public FileNode getLocalFileSystem()
|
---|
15 | {
|
---|
16 | FileNode file_system_root = null;
|
---|
17 |
|
---|
18 | // Get all the available roots mounted on the filesystem
|
---|
19 | File[] roots = File.listRoots();
|
---|
20 | if (roots == null) {
|
---|
21 | return null;
|
---|
22 | }
|
---|
23 |
|
---|
24 | // If there is just one root use it as the tree root (Linux)
|
---|
25 | if (roots.length == 1) {
|
---|
26 | file_system_root = new FileNode(roots[0], Dictionary.get("Tree.Root"));
|
---|
27 | }
|
---|
28 |
|
---|
29 | // Otherwise build a dummy node which has the roots as children
|
---|
30 | else {
|
---|
31 | file_system_root = new FileNode(Dictionary.get("Tree.Root"));
|
---|
32 | file_system_root.setModel(model);
|
---|
33 |
|
---|
34 | // Sort the roots into alphabetical order
|
---|
35 | ArrayTools.sort(roots);
|
---|
36 | for (int i = 0; i < roots.length; i++) {
|
---|
37 | // Only add root if it isn't a floppy drive
|
---|
38 | if (!FileSystemView.getFileSystemView().isFloppyDrive(roots[i])) {
|
---|
39 | file_system_root.insert(new FileNode(roots[i]));
|
---|
40 | }
|
---|
41 | }
|
---|
42 | }
|
---|
43 |
|
---|
44 | return file_system_root;
|
---|
45 | }
|
---|
46 |
|
---|
47 |
|
---|
48 | static public FileNode getUserHomeMapping()
|
---|
49 | {
|
---|
50 | // Get the name of the OS we're running on
|
---|
51 | String os_name = System.getProperty("os.name");
|
---|
52 | if (os_name == null) {
|
---|
53 | return null;
|
---|
54 | }
|
---|
55 |
|
---|
56 | // Make sure we're running on a multiuser OS where the idea of a "user home" is valid
|
---|
57 | Gatherer.println("Property os.name: " + os_name);
|
---|
58 | String os_name_lc = os_name.toLowerCase();
|
---|
59 | if (os_name_lc.equals("windows 95") || os_name_lc.equals("windows 98") || os_name_lc.equals("windows me")) {
|
---|
60 | return null;
|
---|
61 | }
|
---|
62 |
|
---|
63 | // Get the user's home folder
|
---|
64 | String home_folder_str = System.getProperty("user.home");
|
---|
65 | if (home_folder_str == null || home_folder_str.length() == 0) {
|
---|
66 | return null;
|
---|
67 | }
|
---|
68 |
|
---|
69 | // Generate a special mapping to the user home folder
|
---|
70 | File home_folder = new File(home_folder_str);
|
---|
71 | String[] args = new String[1];
|
---|
72 | args[0] = home_folder.getName();
|
---|
73 | return new FileNode(home_folder, Dictionary.get("Tree.Home", args));
|
---|
74 | }
|
---|
75 | }
|
---|