1 | package org.greenstone.gatherer.file;
|
---|
2 |
|
---|
3 | import java.io.File;
|
---|
4 | import org.greenstone.gatherer.DebugStream;
|
---|
5 | import org.greenstone.gatherer.Dictionary;
|
---|
6 | import org.greenstone.gatherer.Gatherer;
|
---|
7 |
|
---|
8 |
|
---|
9 | public class FileSystem
|
---|
10 | {
|
---|
11 | static public WorkspaceTreeNode getLocalFilespaceNode(FileSystemModel model)
|
---|
12 | {
|
---|
13 | // Get all the available roots mounted on the filesystem
|
---|
14 | File[] roots = File.listRoots();
|
---|
15 | if (roots == null) {
|
---|
16 | return null;
|
---|
17 | }
|
---|
18 |
|
---|
19 | // If there is just one root use it as the tree root (Unix)
|
---|
20 | if (roots.length == 1) {
|
---|
21 | return new WorkspaceTreeNode(roots[0], Dictionary.get("Tree.Root"));
|
---|
22 | }
|
---|
23 |
|
---|
24 | // Otherwise build a dummy node which has the roots as children (Windows)
|
---|
25 | else {
|
---|
26 | return new WorkspaceTreeNode(null, Dictionary.get("Tree.Root"));
|
---|
27 | }
|
---|
28 | }
|
---|
29 |
|
---|
30 |
|
---|
31 | static public WorkspaceTreeNode getHomeFolderNode()
|
---|
32 | {
|
---|
33 | // Get the name of the OS we're running on
|
---|
34 | String os_name = System.getProperty("os.name");
|
---|
35 | if (os_name == null) {
|
---|
36 | return null;
|
---|
37 | }
|
---|
38 |
|
---|
39 | // Make sure we're running on a multiuser OS where the idea of a "user home" is valid
|
---|
40 | DebugStream.println("Property os.name: " + os_name);
|
---|
41 | String os_name_lc = os_name.toLowerCase();
|
---|
42 | if (os_name_lc.equals("windows 95") || os_name_lc.equals("windows 98") || os_name_lc.equals("windows me")) {
|
---|
43 | return null;
|
---|
44 | }
|
---|
45 |
|
---|
46 | // Get the user's home folder
|
---|
47 | String home_folder_str = System.getProperty("user.home");
|
---|
48 | if (home_folder_str == null || home_folder_str.length() == 0) {
|
---|
49 | return null;
|
---|
50 | }
|
---|
51 |
|
---|
52 | // Generate a special mapping to the user home folder
|
---|
53 | File home_folder = new File(home_folder_str);
|
---|
54 | return new WorkspaceTreeNode(home_folder, Dictionary.get("Tree.Home", home_folder.getName()));
|
---|
55 | }
|
---|
56 |
|
---|
57 |
|
---|
58 | static public WorkspaceTreeNode getDownloadedFilesNode()
|
---|
59 | {
|
---|
60 | // Return a mapping to the downloaded files folder
|
---|
61 | return new WorkspaceTreeNode(new File(Gatherer.getGLIUserCacheDirectoryPath()), Dictionary.get("Tree.DownloadedFiles"));
|
---|
62 | }
|
---|
63 | }
|
---|