oops
[Evergreen.git] / Evergreen / staff_client / chrome / content / evergreen / util / file.js
1 sdump('D_TRACE','Loading file.js\n');
2
3 var dirService = Components.classes["@mozilla.org/file/directory_service;1"].
4         getService( Components.interfaces.nsIProperties );
5
6 function create_input_stream(file) {
7         try {
8                 if (typeof(file)=='string') file = get_file( file );
9                 var f = Components.classes["@mozilla.org/network/file-input-stream;1"]
10                         .createInstance(Components.interfaces.nsIFileInputStream);
11                 if (file && file.exists()) {
12                         f.init(file, 0x01, 0, 0);
13                         var s = Components.classes["@mozilla.org/scriptableinputstream;1"]
14                                 .createInstance(Components.interfaces.nsIScriptableInputStream);
15                         if (f) {
16                                 s.init(f);
17                                 return s;
18                         }
19                 }
20         } catch(E) {
21                 sdump('D_ERROR', E);
22         }
23         return null;
24 }
25
26 function create_output_stream(file) {
27         try {
28                 if (typeof(file)=='string') file = get_file( file );
29                 var f = Components.classes["@mozilla.org/network/file-output-stream;1"]
30                         .createInstance(Components.interfaces.nsIFileOutputStream);
31                 if (file) {
32                         if (! file.exists()) file.create( 0, 0640 );
33                         f.init(file, 0x02 | 0x08 | 0x20, 0644, 0);
34                         return f;
35                 }
36         } catch(E) {
37                 sdump('D_ERROR', E);
38         }
39         return null;
40 }
41
42 function get_file( fname ) {
43         try {
44                 file = dirService.get( "AChrom",  Components.interfaces.nsIFile );
45                 file.append(mw.myPackageDir); file.append("content"); file.append("conf"); file.append(fname);
46                 sdump('D_FILE','get_file( ' + fname + ').path = ' + file.path + '\n');
47                 alert('get_file( ' + fname + ').path = ' + file.path + '\n');
48                 return file;
49         } catch(E) {
50                 sdump('D_ERROR', E);
51                 return null;
52         }
53 }