comparison dwt/browser/AppFileLocProvider.d @ 344:8198e6052012

more fixups:
author John Reimer <terminal.node@gmail.com>
date Mon, 27 Oct 2008 22:41:01 -0700
parents 3f4a5c7d138f
children 2e591eb01162
comparison
equal deleted inserted replaced
343:96243e3ebcf0 344:8198e6052012
15 import tango.sys.Environment; 15 import tango.sys.Environment;
16 import tango.text.Util; 16 import tango.text.Util;
17 17
18 import dwt.dwthelper.utils; 18 import dwt.dwthelper.utils;
19 import dwt.browser.Mozilla; 19 import dwt.browser.Mozilla;
20 import dwt.browser.SimpleEnumerator;
20 21
21 import dwt.internal.Compatibility; 22 import dwt.internal.Compatibility;
22 23
23 import XPCOM = dwt.internal.mozilla.XPCOM; 24 import XPCOM = dwt.internal.mozilla.XPCOM;
24 25
87 } 88 }
88 89
89 void setProfilePath (String path) { 90 void setProfilePath (String path) {
90 profilePath = path; 91 profilePath = path;
91 if (!Compatibility.fileExists (path, "")) { //$NON-NLS-1$ 92 if (!Compatibility.fileExists (path, "")) { //$NON-NLS-1$
92 nsILocalFile result; 93 nsILocalFile file;
93 scope auto nsEmbedString pathString = new nsEmbedString (toString16(path)); 94 scope auto nsEmbedString pathString = new nsEmbedString (toString16(path));
94 int rc = XPCOM.NS_NewLocalFile (cast(nsAString*)pathString, 1, &result); 95 int rc = XPCOM.NS_NewLocalFile (cast(nsAString*)pathString, 1, &file);
95 if (rc !is XPCOM.NS_OK) Mozilla.error (rc); 96 if (rc !is XPCOM.NS_OK) Mozilla.error (rc);
96 if (result is null) Mozilla.error (XPCOM.NS_ERROR_NULL_POINTER); 97 if (file is null) Mozilla.error (XPCOM.NS_ERROR_NULL_POINTER);
97 98
98 rc = result.Create (nsILocalFile.DIRECTORY_TYPE, 0700); 99 rc = file.Create (nsILocalFile.DIRECTORY_TYPE, 0700);
99 if (rc !is XPCOM.NS_OK) Mozilla.error (rc); 100 if (rc !is XPCOM.NS_OK) Mozilla.error (rc);
100 file.Release (); 101 file.Release ();
101 } 102 }
102 } 103 }
103 104
104 /* nsIDirectoryServiceProvider2 */ 105 /* nsIDirectoryServiceProvider2 */
105 106
106 nsresult GetFiles (char* prop, nsISimpleEnumerator* _retval) { 107 nsresult GetFiles (char* prop, nsISimpleEnumerator* _retval) {
107 String propertyName = prop.fromStringz; 108 String propertyName = fromStringz(prop);
108 String[] propertyValues = null; 109 String[] propertyValues = null;
109 110
110 if (propertyName == XPCOM.NS_APP_PLUGINS_DIR_LIST) { 111 if (propertyName == XPCOM.NS_APP_PLUGINS_DIR_LIST) {
111 if (pluginDirs is null) { 112 if (pluginDirs is null) {
112 int index = 0; 113 int index = 0;
113 /* set the first value(s) to the MOZ_PLUGIN_PATH environment variable value if it's defined */ 114 /* set the first value(s) to the MOZ_PLUGIN_PATH environment variable value if it's defined */
114 String value = Environment.get (XPCOM.MOZILLA_PLUGIN_PATH); 115 String value = Environment.get (XPCOM.MOZILLA_PLUGIN_PATH);
115 if (value !is null) { 116 if (value !is null) {
116 if (value.length > 0) { 117 if (value.length > 0) {
117 String separator = System.getProperty ("path.separator"); // $NON-NLS-1$ 118 String separator = System.getProperty ("file.separator"); // $NON-NLS-1$
118 foreach (segment; delimiter(value, separator)) 119 foreach (segment; delimiters(value, separator))
119 pluginDirs ~= segment; 120 pluginDirs ~= segment;
120 } 121 }
121 } 122 }
122 if (pluginDirs is null) { 123 if (pluginDirs is null) {
123 pluginDirs = new String[2]; 124 pluginDirs = new String[2];
138 nsILocalFile localFile; 139 nsILocalFile localFile;
139 nsIFile file; 140 nsIFile file;
140 nsISupports[] files = new nsISupports [propertyValues.length]; 141 nsISupports[] files = new nsISupports [propertyValues.length];
141 int index = 0; 142 int index = 0;
142 for (int i = 0; i < propertyValues.length; i++) { 143 for (int i = 0; i < propertyValues.length; i++) {
143 scope auto pathString = new nsEmbedString (propertyValues[i]); 144 scope auto pathString = new nsEmbedString (toString16(propertyValues[i]));
144 int rc = XPCOM.NS_NewLocalFile (cast(nsAString*)pathString, 1, &(cast(void*)localFile)); 145 int rc = XPCOM.NS_NewLocalFile (cast(nsAString*)pathString, 1, &localFile);
145 if (rc !is XPCOM.NS_ERROR_FILE_UNRECOGNIZED_PATH) { 146 if (rc !is XPCOM.NS_ERROR_FILE_UNRECOGNIZED_PATH) {
146 /* value appears to be a valid pathname */ 147 /* value appears to be a valid pathname */
147 if (rc !is XPCOM.NS_OK) Mozilla.error (rc); 148 if (rc !is XPCOM.NS_OK) Mozilla.error (rc);
148 if (localFile is null) Mozilla.error (XPCOM.NS_ERROR_NULL_POINTER); 149 if (localFile is null) Mozilla.error (XPCOM.NS_ERROR_NULL_POINTER);
149 150
150 rc = localFile.QueryInterface (nsIFile.NS_IFILE_IID, cast(void**)&file); 151 rc = localFile.QueryInterface (&nsIFile.IID, cast(void**)&file);
151 if (rc !is XPCOM.NS_OK) Mozilla.error (rc); 152 if (rc !is XPCOM.NS_OK) Mozilla.error (rc);
152 if (file is null) Mozilla.error (XPCOM.NS_ERROR_NO_INTERFACE); 153 if (file is null) Mozilla.error (XPCOM.NS_ERROR_NO_INTERFACE);
153 localFile.Release (); 154 localFile.Release ();
154 155
155 files[index++] = cast(nsISupports)file; 156 files[index++] = cast(nsISupports)file;
156 } 157 }
157 } 158 }
158 159
159 if (index < propertyValues.length) { 160 if (index < propertyValues.length) {
160 /* there were some invalid values so remove the trailing empty array slots */ 161 /* there were some invalid values so remove the trailing empty array slots */
161 nsISupports[] temp = new nsISupports [index]; 162 files = files[0..index];
162 System.arraycopy (files, 0, temp, 0, index);
163 files = temp;
164 } 163 }
165 164
166 auto enumerator = new SimpleEnumerator (files); 165 auto enumerator = new SimpleEnumerator (files);
167 enumerator.AddRef (); 166 enumerator.AddRef ();
168 *_retval = cast(nsISimpleEnumerator)enumerator; 167 *_retval = cast(nsISimpleEnumerator)enumerator;
226 225
227 *persistent = true; /* PRBool */ 226 *persistent = true; /* PRBool */
228 *_retval = null; 227 *_retval = null;
229 if (propertyValue !is null && propertyValue.length > 0) { 228 if (propertyValue !is null && propertyValue.length > 0) {
230 nsILocalFile localFile; 229 nsILocalFile localFile;
231 scope auto pathString = new nsEmbedString (propertyValue); 230 scope auto pathString = new nsEmbedString (propertyValue.toString16());
232 int rc = XPCOM.NS_NewLocalFile (cast(nsAString*)pathString, 1, &(cast(void*)localFile)); 231 int rc = XPCOM.NS_NewLocalFile (cast(nsAString*)pathString, 1, &localFile);
233 if (rc !is XPCOM.NS_OK) Mozilla.error (rc); 232 if (rc !is XPCOM.NS_OK) Mozilla.error (rc);
234 if (localFile is null) Mozilla.error (XPCOM.NS_ERROR_NULL_POINTER); 233 if (localFile is null) Mozilla.error (XPCOM.NS_ERROR_NULL_POINTER);
235 234
236 nsIFile file; 235 nsIFile file;
237 rc = localFile.QueryInterface (&nsIFile.IID, cast(void**)&file); 236 rc = localFile.QueryInterface (&nsIFile.IID, cast(void**)&file);