root / src / pithos / content / localfile.js @ 29:ec9750e9cceb
History | View | Annotate | Download (2.4 kB)
1 |
|
---|---|
2 |
function load_local_directory(path) { |
3 |
var dir_obj = new Object(); |
4 |
|
5 |
dir_obj.files = new Array();
|
6 |
dir_obj.folders = new Array();
|
7 |
dir_obj.permissions = new Array();
|
8 |
|
9 |
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
|
10 |
var file = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile); |
11 |
try {
|
12 |
file.initWithPath(path); |
13 |
} catch(error) {
|
14 |
alert('Could load path - ' + path);
|
15 |
|
16 |
return dir_obj;
|
17 |
} |
18 |
|
19 |
//
|
20 |
var r_username = connection_obj.user_homepage().username;
|
21 |
|
22 |
// set standard attributes
|
23 |
dir_obj.name = file.leafName; |
24 |
dir_obj.owner = r_username; |
25 |
dir_obj.deleted = false;
|
26 |
dir_obj.createdBy = r_username; |
27 |
dir_obj.creationDate = file.lastModifiedTime; |
28 |
dir_obj.modifiedBy = r_username; |
29 |
dir_obj.modificationDate = file.lastModifierTime; |
30 |
//
|
31 |
var dentries = file.directoryEntries;
|
32 |
|
33 |
while(dentries.hasMoreElements()) {
|
34 |
var entry = dentries.getNext();
|
35 |
entry.QueryInterface(Components.interfaces.nsIFile); |
36 |
if (entry.isHidden()) { continue; } |
37 |
|
38 |
if (entry.isDirectory()) {
|
39 |
var local_folder = new Object(); |
40 |
local_folder.name = entry.leafName; |
41 |
local_folder.uri = entry.path; |
42 |
|
43 |
dir_obj.folders.push(local_folder); |
44 |
} |
45 |
|
46 |
if (entry.isFile()) {
|
47 |
var local_file = new Object(); |
48 |
|
49 |
local_file.name = entry.leafName; |
50 |
local_file.owner = r_username; |
51 |
local_file.creationDate = entry.lastModifiedTime; |
52 |
local_file.modificationDate = entry.lastModifiedTime; |
53 |
local_file.size = entry.fileSize; |
54 |
local_file.content = mimes.getByExtension(local_file.name); |
55 |
local_file.version = 0;
|
56 |
local_file.uri = entry.path; |
57 |
local_file.path = entry.path; |
58 |
|
59 |
dir_obj.files.push(local_file); |
60 |
} |
61 |
} |
62 |
|
63 |
return dir_obj;
|
64 |
} |
65 |
|
66 |
function loadLocalFile(path) { |
67 |
var file_obj = new Object(); |
68 |
|
69 |
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
|
70 |
var file = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile); |
71 |
try {
|
72 |
file_obj.initWithPath(path); |
73 |
file_obj.name = file.leafName; |
74 |
file_obj.owner = connection_obj.username; |
75 |
file_obj.creationDate = file.lastModifiedTime; |
76 |
file_obj.modificationDate = file.lastModifiedTime; |
77 |
file_obj.size = file.fileSize; |
78 |
file_obj.content = mimes.getByExtension(file_obj.name); |
79 |
file_obj.version = 0;
|
80 |
file_obj.uri = file.path; |
81 |
file_obj.path = file.path; |
82 |
} catch(error) {
|
83 |
alert('Could load path - ' + path);
|
84 |
} |
85 |
|
86 |
|
87 |
return file_obj;
|
88 |
} |