Mercurial > projects > dwt-mac
comparison dwt/browser/AppFileLocProvider.d @ 125:5583f8eeee6c
Synced mozilla with dwt-linux
author | Jacob Carlborg <doob@me.com> |
---|---|
date | Fri, 16 Jan 2009 12:49:08 +0100 |
parents | d8635bb48c7c |
children | 535243e6d16a |
comparison
equal
deleted
inserted
replaced
124:540fa4e9974a | 125:5583f8eeee6c |
---|---|
1 /******************************************************************************* | 1 /******************************************************************************* |
2 * Copyright (c) 2003, 2008 IBM Corporation and others. | 2 * Copyright (c) 2003, 2007 IBM Corporation and others. |
3 * All rights reserved. This program and the accompanying materials | 3 * All rights reserved. This program and the accompanying materials |
4 * are made available under the terms of the Eclipse Public License v1.0 | 4 * are made available under the terms of the Eclipse Public License v1.0 |
5 * which accompanies this distribution, and is available at | 5 * which accompanies this distribution, and is available at |
6 * http://www.eclipse.org/legal/epl-v10.html | 6 * http://www.eclipse.org/legal/epl-v10.html |
7 * | 7 * |
8 * Contributors: | 8 * Contributors: |
9 * IBM Corporation - initial API and implementation | 9 * IBM Corporation - initial API and implementation |
10 * Port to the D programming language: | |
11 * John Reimer <terminal.node@gmail.com> | |
10 *******************************************************************************/ | 12 *******************************************************************************/ |
11 module dwt.browser.AppFileLocProvider; | 13 module dwt.browser.AppFileLocProvider; |
12 | 14 |
15 import tango.sys.Environment; | |
16 import tango.text.Util; | |
17 | |
13 import dwt.dwthelper.utils; | 18 import dwt.dwthelper.utils; |
14 | 19 import dwt.browser.Mozilla; |
15 import java.util.Vector; | 20 import dwt.browser.SimpleEnumerator; |
16 | 21 |
17 import dwt.internal.C; | |
18 import dwt.internal.Compatibility; | 22 import dwt.internal.Compatibility; |
19 import dwt.internal.mozilla.XPCOM; | 23 |
20 import dwt.internal.mozilla.XPCOMObject; | 24 import XPCOM = dwt.internal.mozilla.XPCOM; |
25 | |
26 import dwt.internal.mozilla.Common; | |
27 import dwt.internal.mozilla.nsISimpleEnumerator; | |
21 import dwt.internal.mozilla.nsEmbedString; | 28 import dwt.internal.mozilla.nsEmbedString; |
22 import dwt.internal.mozilla.nsID; | 29 import dwt.internal.mozilla.nsID; |
23 import dwt.internal.mozilla.nsIDirectoryServiceProvider; | 30 import dwt.internal.mozilla.nsIDirectoryService; |
24 import dwt.internal.mozilla.nsIDirectoryServiceProvider2; | |
25 import dwt.internal.mozilla.nsIFile; | 31 import dwt.internal.mozilla.nsIFile; |
26 import dwt.internal.mozilla.nsILocalFile; | 32 import dwt.internal.mozilla.nsILocalFile; |
27 import dwt.internal.mozilla.nsISupports; | 33 import dwt.internal.mozilla.nsISupports; |
28 | 34 import dwt.internal.mozilla.nsStringAPI; |
29 class AppFileLocProvider { | 35 |
30 XPCOMObject supports; | 36 class AppFileLocProvider : nsIDirectoryServiceProvider2 { |
31 XPCOMObject directoryServiceProvider; | |
32 XPCOMObject directoryServiceProvider2; | |
33 int refCount = 0; | 37 int refCount = 0; |
34 String mozillaPath, profilePath; | 38 String mozillaPath, profilePath; |
35 String[] pluginDirs; | 39 String[] pluginDirs; |
36 bool isXULRunner; | 40 bool isXULRunner; |
37 | 41 |
38 static final String SEPARATOR_OS = System.getProperty ("file.separator"); //$NON-NLS-1$ | 42 static String SEPARATOR_OS; |
39 static final String CHROME_DIR = "chrome"; //$NON-NLS-1$ | 43 static final String CHROME_DIR = "chrome"; //$NON-NLS-1$ |
40 static final String COMPONENTS_DIR = "components"; //$NON-NLS-1$ | 44 static final String COMPONENTS_DIR = "components"; //$NON-NLS-1$ |
41 static final String HISTORY_FILE = "history.dat"; //$NON-NLS-1$ | 45 static final String HISTORY_FILE = "history.dat"; //$NON-NLS-1$ |
42 static final String LOCALSTORE_FILE = "localstore.rdf"; //$NON-NLS-1$ | 46 static final String LOCALSTORE_FILE = "localstore.rdf"; //$NON-NLS-1$ |
43 static final String MIMETYPES_FILE = "mimeTypes.rdf"; //$NON-NLS-1$ | 47 static final String MIMETYPES_FILE = "mimeTypes.rdf"; //$NON-NLS-1$ |
44 static final String PLUGINS_DIR = "plugins"; //$NON-NLS-1$ | 48 static final String PLUGINS_DIR = "plugins"; //$NON-NLS-1$ |
45 static final String USER_PLUGINS_DIR = ".mozilla" + SEPARATOR_OS + "plugins"; //$NON-NLS-1$ //$NON-NLS-2$ | 49 static String USER_PLUGINS_DIR; |
46 static final String PREFERENCES_FILE = "prefs.js"; //$NON-NLS-1$ | 50 static final String PREFERENCES_FILE = "prefs.js"; //$NON-NLS-1$ |
47 | 51 |
52 static this () { | |
53 SEPARATOR_OS = System.getProperty ("file.separator"); | |
54 USER_PLUGINS_DIR = ".mozilla" ~ SEPARATOR_OS ~ "plugins"; | |
55 } | |
56 | |
48 this (String path) { | 57 this (String path) { |
49 mozillaPath = path + SEPARATOR_OS; | 58 mozillaPath = path ~ SEPARATOR_OS; |
50 createCOMInterfaces (); | 59 } |
51 } | 60 |
52 | 61 extern(System) |
53 int AddRef () { | 62 nsrefcnt AddRef () { |
54 refCount++; | 63 refCount++; |
55 return refCount; | 64 return refCount; |
56 } | 65 } |
57 | 66 |
58 void createCOMInterfaces () { | 67 extern(System) |
59 /* Create each of the interfaces that this object implements */ | 68 nsresult QueryInterface (nsID* riid, void** ppvObject) { |
60 supports = new XPCOMObject (new int[] {2, 0, 0}) { | 69 if (riid is null || ppvObject is null) return XPCOM.NS_ERROR_NO_INTERFACE; |
61 public int /*long*/ method0 (int /*long*/[] args) {return QueryInterface (args[0], args[1]);} | 70 |
62 public int /*long*/ method1 (int /*long*/[] args) {return AddRef ();} | 71 if (*riid == nsISupports.IID) { |
63 public int /*long*/ method2 (int /*long*/[] args) {return Release ();} | 72 *ppvObject = cast(void*)cast(nsISupports)this; |
64 }; | 73 AddRef (); |
74 return XPCOM.NS_OK; | |
75 } | |
76 if (*riid == nsIDirectoryServiceProvider.IID) { | |
77 *ppvObject = cast(void*)cast(nsIDirectoryServiceProvider)this; | |
78 AddRef (); | |
79 return XPCOM.NS_OK; | |
80 } | |
81 if (*riid == nsIDirectoryServiceProvider2.IID) { | |
82 *ppvObject = cast(void*)cast(nsIDirectoryServiceProvider2)this; | |
83 AddRef (); | |
84 return XPCOM.NS_OK; | |
85 } | |
65 | 86 |
66 directoryServiceProvider = new XPCOMObject (new int[] {2, 0, 0, 3}) { | 87 *ppvObject = null; |
67 public int /*long*/ method0 (int /*long*/[] args) {return QueryInterface (args[0], args[1]);} | |
68 public int /*long*/ method1 (int /*long*/[] args) {return AddRef ();} | |
69 public int /*long*/ method2 (int /*long*/[] args) {return Release ();} | |
70 public int /*long*/ method3 (int /*long*/[] args) {return getFile (args[0], args[1], args[2]);} | |
71 }; | |
72 | |
73 directoryServiceProvider2 = new XPCOMObject (new int[] {2, 0, 0, 3, 2}) { | |
74 public int /*long*/ method0 (int /*long*/[] args) {return QueryInterface (args[0], args[1]);} | |
75 public int /*long*/ method1 (int /*long*/[] args) {return AddRef ();} | |
76 public int /*long*/ method2 (int /*long*/[] args) {return Release ();} | |
77 public int /*long*/ method3 (int /*long*/[] args) {return getFile (args[0], args[1], args[2]);} | |
78 public int /*long*/ method4 (int /*long*/[] args) {return getFiles (args[0], args[1]);} | |
79 }; | |
80 } | |
81 | |
82 void disposeCOMInterfaces () { | |
83 if (supports !is null) { | |
84 supports.dispose (); | |
85 supports = null; | |
86 } | |
87 if (directoryServiceProvider !is null) { | |
88 directoryServiceProvider.dispose (); | |
89 directoryServiceProvider = null; | |
90 } | |
91 if (directoryServiceProvider2 !is null) { | |
92 directoryServiceProvider2.dispose (); | |
93 directoryServiceProvider2 = null; | |
94 } | |
95 } | |
96 | |
97 int /*long*/ getAddress () { | |
98 return directoryServiceProvider.getAddress (); | |
99 } | |
100 | |
101 int QueryInterface (int /*long*/ riid, int /*long*/ ppvObject) { | |
102 if (riid is 0 || ppvObject is 0) return XPCOM.NS_ERROR_NO_INTERFACE; | |
103 nsID guid = new nsID (); | |
104 XPCOM.memmove (guid, riid, nsID.sizeof); | |
105 | |
106 if (guid.Equals (nsISupports.NS_ISUPPORTS_IID)) { | |
107 XPCOM.memmove (ppvObject, new int /*long*/[] {supports.getAddress ()}, C.PTR_SIZEOF); | |
108 AddRef (); | |
109 return XPCOM.NS_OK; | |
110 } | |
111 if (guid.Equals (nsIDirectoryServiceProvider.NS_IDIRECTORYSERVICEPROVIDER_IID)) { | |
112 XPCOM.memmove (ppvObject, new int /*long*/[] {directoryServiceProvider.getAddress ()}, C.PTR_SIZEOF); | |
113 AddRef (); | |
114 return XPCOM.NS_OK; | |
115 } | |
116 if (guid.Equals (nsIDirectoryServiceProvider2.NS_IDIRECTORYSERVICEPROVIDER2_IID)) { | |
117 XPCOM.memmove (ppvObject, new int /*long*/[] {directoryServiceProvider2.getAddress ()}, C.PTR_SIZEOF); | |
118 AddRef (); | |
119 return XPCOM.NS_OK; | |
120 } | |
121 | |
122 XPCOM.memmove (ppvObject, new int /*long*/[] {0}, C.PTR_SIZEOF); | |
123 return XPCOM.NS_ERROR_NO_INTERFACE; | 88 return XPCOM.NS_ERROR_NO_INTERFACE; |
124 } | 89 } |
125 | 90 |
126 int Release () { | 91 extern(System) |
92 nsrefcnt Release () { | |
127 refCount--; | 93 refCount--; |
128 if (refCount is 0) disposeCOMInterfaces (); | 94 if (refCount is 0) return 0; |
129 return refCount; | 95 return refCount; |
130 } | 96 } |
131 | 97 |
132 void setProfilePath (String path) { | 98 void setProfilePath (String path) { |
133 profilePath = path; | 99 profilePath = path; |
134 if (!Compatibility.fileExists (path, "")) { //$NON-NLS-1$ | 100 if (!Compatibility.fileExists (path, "")) { //$NON-NLS-1$ |
135 int /*long*/[] result = new int /*long*/[1]; | 101 nsILocalFile file; |
136 nsEmbedString pathString = new nsEmbedString (path); | 102 scope auto nsEmbedString pathString = new nsEmbedString (toString16(path)); |
137 int rc = XPCOM.NS_NewLocalFile (pathString.getAddress (), 1, result); | 103 int rc = XPCOM.NS_NewLocalFile (cast(nsAString*)pathString, 1, &file); |
138 if (rc !is XPCOM.NS_OK) Mozilla.error (rc); | 104 if (rc !is XPCOM.NS_OK) Mozilla.error (rc); |
139 if (result[0] is 0) Mozilla.error (XPCOM.NS_ERROR_NULL_POINTER); | 105 if (file is null) Mozilla.error (XPCOM.NS_ERROR_NULL_POINTER); |
140 pathString.dispose (); | 106 |
141 | |
142 nsILocalFile file = new nsILocalFile (result [0]); | |
143 rc = file.Create (nsILocalFile.DIRECTORY_TYPE, 0700); | 107 rc = file.Create (nsILocalFile.DIRECTORY_TYPE, 0700); |
144 if (rc !is XPCOM.NS_OK) Mozilla.error (rc); | 108 if (rc !is XPCOM.NS_OK) Mozilla.error (rc); |
145 file.Release (); | 109 file.Release (); |
146 } | 110 } |
147 } | 111 } |
148 | 112 |
149 /* nsIDirectoryServiceProvider2 */ | 113 /* nsIDirectoryServiceProvider2 */ |
150 | 114 extern(System) |
151 int getFiles (int /*long*/ prop, int /*long*/ _retval) { | 115 nsresult GetFiles (char* prop, nsISimpleEnumerator* _retval) { |
152 int size = XPCOM.strlen (prop); | 116 String propertyName = fromStringz(prop); |
153 byte[] bytes = new byte[size]; | |
154 XPCOM.memmove (bytes, prop, size); | |
155 String propertyName = new String (MozillaDelegate.mbcsToWcs (null, bytes)); | |
156 String[] propertyValues = null; | 117 String[] propertyValues = null; |
157 | 118 |
158 if (propertyName.equals (XPCOM.NS_APP_PLUGINS_DIR_LIST)) { | 119 if (propertyName == XPCOM.NS_APP_PLUGINS_DIR_LIST) { |
159 if (pluginDirs is null) { | 120 if (pluginDirs is null) { |
160 int index = 0; | 121 int index = 0; |
161 /* set the first value(s) to the MOZ_PLUGIN_PATH environment variable value if it's defined */ | 122 /* set the first value(s) to the MOZ_PLUGIN_PATH environment variable value if it's defined */ |
162 int /*long*/ ptr = C.getenv (MozillaDelegate.wcsToMbcs (null, XPCOM.MOZILLA_PLUGIN_PATH, true)); | 123 String value = Environment.get (XPCOM.MOZILLA_PLUGIN_PATH); |
163 if (ptr !is 0) { | 124 if (value !is null) { |
164 int length = C.strlen (ptr); | 125 if (value.length > 0) { |
165 byte[] buffer = new byte[length]; | 126 String separator = System.getProperty ("file.separator"); // $NON-NLS-1$ |
166 C.memmove (buffer, ptr, length); | 127 foreach (segment; delimiters(value, separator)) |
167 String value = new String (MozillaDelegate.mbcsToWcs (null, buffer)); | 128 pluginDirs ~= segment; |
168 if (value.length () > 0) { | |
169 String separator = System.getProperty ("path.separator"); // $NON-NLS-1$ | |
170 Vector segments = new Vector (); | |
171 int start, end = -1; | |
172 do { | |
173 start = end + 1; | |
174 end = value.indexOf (separator, start); | |
175 String segment; | |
176 if (end is -1) { | |
177 segment = value.substring (start); | |
178 } else { | |
179 segment = value.substring (start, end); | |
180 } | |
181 if (segment.length () > 0) segments.addElement (segment); | |
182 } while (end !is -1); | |
183 int segmentsSize = segments.size (); | |
184 pluginDirs = new String [segmentsSize + 2]; | |
185 for (index = 0; index < segmentsSize; index++) { | |
186 pluginDirs[index] = cast(String)segments.elementAt (index); | |
187 } | |
188 } | 129 } |
189 } | 130 } |
190 if (pluginDirs is null) { | 131 if (pluginDirs is null) { |
191 pluginDirs = new String[2]; | 132 pluginDirs = new String[2]; |
192 } | 133 } |
193 | 134 |
194 /* set the next value to the GRE path + "plugins" */ | 135 /* set the next value to the GRE path + "plugins" */ |
195 pluginDirs[index++] = mozillaPath + PLUGINS_DIR; | 136 pluginDirs ~= mozillaPath ~ PLUGINS_DIR; |
196 | 137 |
197 /* set the next value to the home directory + "/.mozilla/plugins" */ | 138 /* set the next value to the home directory + "/.mozilla/plugins" */ |
198 pluginDirs[index++] = System.getProperty("user.home") + SEPARATOR_OS + USER_PLUGINS_DIR; | 139 pluginDirs ~= System.getProperty("user.home") ~ SEPARATOR_OS ~ USER_PLUGINS_DIR; |
199 } | 140 } |
200 propertyValues = pluginDirs; | 141 propertyValues = pluginDirs; |
201 } | 142 } |
202 | 143 |
203 XPCOM.memmove(_retval, new int /*long*/[] {0}, C.PTR_SIZEOF); | 144 *_retval = null; |
145 //XPCOM.memmove(_retval, new int /*long*/[] {0}, C.PTR_SIZEOF); | |
204 if (propertyValues !is null) { | 146 if (propertyValues !is null) { |
205 int /*long*/[] result = new int /*long*/[1]; | 147 nsILocalFile localFile; |
148 nsIFile file; | |
206 nsISupports[] files = new nsISupports [propertyValues.length]; | 149 nsISupports[] files = new nsISupports [propertyValues.length]; |
207 int index = 0; | 150 int index = 0; |
208 for (int i = 0; i < propertyValues.length; i++) { | 151 for (int i = 0; i < propertyValues.length; i++) { |
209 nsEmbedString pathString = new nsEmbedString (propertyValues[i]); | 152 scope auto pathString = new nsEmbedString (toString16(propertyValues[i])); |
210 int rc = XPCOM.NS_NewLocalFile (pathString.getAddress (), 1, result); | 153 int rc = XPCOM.NS_NewLocalFile (cast(nsAString*)pathString, 1, &localFile); |
211 if (rc !is XPCOM.NS_ERROR_FILE_UNRECOGNIZED_PATH) { | 154 if (rc !is XPCOM.NS_ERROR_FILE_UNRECOGNIZED_PATH) { |
212 /* value appears to be a valid pathname */ | 155 /* value appears to be a valid pathname */ |
213 if (rc !is XPCOM.NS_OK) Mozilla.error (rc); | 156 if (rc !is XPCOM.NS_OK) Mozilla.error (rc); |
214 if (result[0] is 0) Mozilla.error (XPCOM.NS_ERROR_NULL_POINTER); | 157 if (localFile is null) Mozilla.error (XPCOM.NS_ERROR_NULL_POINTER); |
215 | 158 |
216 nsILocalFile localFile = new nsILocalFile (result[0]); | 159 rc = localFile.QueryInterface (&nsIFile.IID, cast(void**)&file); |
217 result[0] = 0; | |
218 rc = localFile.QueryInterface (nsIFile.NS_IFILE_IID, result); | |
219 if (rc !is XPCOM.NS_OK) Mozilla.error (rc); | 160 if (rc !is XPCOM.NS_OK) Mozilla.error (rc); |
220 if (result[0] is 0) Mozilla.error (XPCOM.NS_ERROR_NO_INTERFACE); | 161 if (file is null) Mozilla.error (XPCOM.NS_ERROR_NO_INTERFACE); |
221 localFile.Release (); | 162 localFile.Release (); |
222 | 163 |
223 nsIFile file = new nsIFile (result[0]); | 164 files[index++] = cast(nsISupports)file; |
224 files[index++] = file; | |
225 } | 165 } |
226 pathString.dispose (); | |
227 result[0] = 0; | |
228 } | 166 } |
229 | 167 |
230 if (index < propertyValues.length) { | 168 if (index < propertyValues.length) { |
231 /* there were some invalid values so remove the trailing empty array slots */ | 169 /* there were some invalid values so remove the trailing empty array slots */ |
232 nsISupports[] temp = new nsISupports [index]; | 170 files = files[0..index]; |
233 System.arraycopy (files, 0, temp, 0, index); | |
234 files = temp; | |
235 } | 171 } |
236 | 172 |
237 SimpleEnumerator enumerator = new SimpleEnumerator (files); | 173 auto enumerator = new SimpleEnumerator (files); |
238 enumerator.AddRef (); | 174 enumerator.AddRef (); |
239 XPCOM.memmove (_retval, new int /*long*/[] {enumerator.getAddress ()}, C.PTR_SIZEOF); | 175 *_retval = cast(nsISimpleEnumerator)enumerator; |
240 return XPCOM.NS_OK; | 176 return XPCOM.NS_OK; |
241 } | 177 } |
242 | 178 |
243 return XPCOM.NS_ERROR_FAILURE; | 179 return XPCOM.NS_ERROR_FAILURE; |
244 } | 180 } |
245 | 181 |
246 /* nsIDirectoryServiceProvider implementation */ | 182 /* nsIDirectoryServiceProvider implementation */ |
247 | 183 extern(System) |
248 int getFile(int /*long*/ prop, int /*long*/ persistent, int /*long*/ _retval) { | 184 nsresult GetFile(char* prop, PRBool* persistent, nsIFile* _retval) { |
249 int size = XPCOM.strlen (prop); | 185 String propertyName = tango.stdc.stringz.fromStringz( prop ); |
250 byte[] bytes = new byte[size]; | |
251 XPCOM.memmove (bytes, prop, size); | |
252 String propertyName = new String (MozillaDelegate.mbcsToWcs (null, bytes)); | |
253 String propertyValue = null; | 186 String propertyValue = null; |
254 | 187 |
255 if (propertyName.equals (XPCOM.NS_APP_HISTORY_50_FILE)) { | 188 if (propertyName == (XPCOM.NS_APP_HISTORY_50_FILE)) { |
256 propertyValue = profilePath + HISTORY_FILE; | 189 propertyValue = profilePath ~ HISTORY_FILE; |
257 } else if (propertyName.equals (XPCOM.NS_APP_USER_MIMETYPES_50_FILE)) { | 190 } else if (propertyName == (XPCOM.NS_APP_USER_MIMETYPES_50_FILE)) { |
258 propertyValue = profilePath + MIMETYPES_FILE; | 191 propertyValue = profilePath ~ MIMETYPES_FILE; |
259 } else if (propertyName.equals (XPCOM.NS_APP_PREFS_50_FILE)) { | 192 } else if (propertyName == (XPCOM.NS_APP_PREFS_50_FILE)) { |
260 propertyValue = profilePath + PREFERENCES_FILE; | 193 propertyValue = profilePath ~ PREFERENCES_FILE; |
261 } else if (propertyName.equals (XPCOM.NS_APP_PREFS_50_DIR)) { | 194 } else if (propertyName == (XPCOM.NS_APP_PREFS_50_DIR)) { |
262 propertyValue = profilePath; | 195 propertyValue = profilePath; |
263 } else if (propertyName.equals (XPCOM.NS_APP_USER_CHROME_DIR)) { | 196 } else if (propertyName == (XPCOM.NS_APP_USER_CHROME_DIR)) { |
264 propertyValue = profilePath + CHROME_DIR; | 197 propertyValue = profilePath ~ CHROME_DIR; |
265 } else if (propertyName.equals (XPCOM.NS_APP_USER_PROFILE_50_DIR)) { | 198 } else if (propertyName == (XPCOM.NS_APP_USER_PROFILE_50_DIR)) { |
266 propertyValue = profilePath; | 199 propertyValue = profilePath; |
267 } else if (propertyName.equals (XPCOM.NS_APP_LOCALSTORE_50_FILE)) { | 200 } else if (propertyName == (XPCOM.NS_APP_LOCALSTORE_50_FILE)) { |
268 propertyValue = profilePath + LOCALSTORE_FILE; | 201 propertyValue = profilePath ~ LOCALSTORE_FILE; |
269 } else if (propertyName.equals (XPCOM.NS_APP_CACHE_PARENT_DIR)) { | 202 } else if (propertyName == (XPCOM.NS_APP_CACHE_PARENT_DIR)) { |
270 propertyValue = profilePath; | 203 propertyValue = profilePath; |
271 } else if (propertyName.equals (XPCOM.NS_OS_HOME_DIR)) { | 204 } else if (propertyName == (XPCOM.NS_OS_HOME_DIR)) { |
272 propertyValue = System.getProperty("user.home"); //$NON-NLS-1$ | 205 propertyValue = System.getProperty("user.home"); //$NON-NLS-1$ |
273 } else if (propertyName.equals (XPCOM.NS_OS_TEMP_DIR)) { | 206 } else if (propertyName == (XPCOM.NS_OS_TEMP_DIR)) { |
274 propertyValue = System.getProperty("java.io.tmpdir"); //$NON-NLS-1$ | 207 propertyValue = System.getProperty("java.io.tmpdir"); //$NON-NLS-1$ |
275 } else if (propertyName.equals (XPCOM.NS_GRE_DIR)) { | 208 } else if (propertyName == (XPCOM.NS_GRE_DIR)) { |
276 propertyValue = mozillaPath; | 209 propertyValue = mozillaPath; |
277 } else if (propertyName.equals (XPCOM.NS_GRE_COMPONENT_DIR)) { | 210 } else if (propertyName == (XPCOM.NS_GRE_COMPONENT_DIR)) { |
278 propertyValue = mozillaPath + COMPONENTS_DIR; | 211 propertyValue = mozillaPath ~ COMPONENTS_DIR; |
279 } else if (propertyName.equals (XPCOM.NS_XPCOM_INIT_CURRENT_PROCESS_DIR)) { | 212 } else if (propertyName == (XPCOM.NS_XPCOM_INIT_CURRENT_PROCESS_DIR)) { |
280 propertyValue = mozillaPath; | 213 propertyValue = mozillaPath; |
281 } else if (propertyName.equals (XPCOM.NS_OS_CURRENT_PROCESS_DIR)) { | 214 } else if (propertyName == (XPCOM.NS_OS_CURRENT_PROCESS_DIR)) { |
282 propertyValue = mozillaPath; | 215 propertyValue = mozillaPath; |
283 } else if (propertyName.equals (XPCOM.NS_XPCOM_COMPONENT_DIR)) { | 216 } else if (propertyName == (XPCOM.NS_XPCOM_COMPONENT_DIR)) { |
284 propertyValue = mozillaPath + COMPONENTS_DIR; | 217 propertyValue = mozillaPath ~ COMPONENTS_DIR; |
285 } else if (propertyName.equals (XPCOM.NS_XPCOM_CURRENT_PROCESS_DIR)) { | 218 } else if (propertyName == (XPCOM.NS_XPCOM_CURRENT_PROCESS_DIR)) { |
286 propertyValue = mozillaPath; | 219 propertyValue = mozillaPath; |
287 } else if (propertyName.equals (XPCOM.NS_APP_PREF_DEFAULTS_50_DIR)) { | 220 } else if (propertyName == (XPCOM.NS_APP_PREF_DEFAULTS_50_DIR)) { |
288 /* | 221 /* |
289 * Answering a value for this property causes problems in Mozilla versions | 222 * Answering a value for this property causes problems in Mozilla versions |
290 * < 1.7. Unfortunately this property is queried early enough in the | 223 * < 1.7. Unfortunately this property is queried early enough in the |
291 * Browser creation process that the Mozilla version being used is not | 224 * Browser creation process that the Mozilla version being used is not |
292 * yet determined. However it is known if XULRunner is being used or not. | 225 * yet determined. However it is known if XULRunner is being used or not. |
296 * in the future to be >= 1.7 then this value can always be answered. | 229 * in the future to be >= 1.7 then this value can always be answered. |
297 */ | 230 */ |
298 if (isXULRunner) propertyValue = profilePath; | 231 if (isXULRunner) propertyValue = profilePath; |
299 } | 232 } |
300 | 233 |
301 XPCOM.memmove (persistent, new int[] {1}, 4); /* PRBool */ | 234 *persistent = true; /* PRBool */ |
302 XPCOM.memmove (_retval, new int /*long*/[] {0}, C.PTR_SIZEOF); | 235 *_retval = null; |
303 if (propertyValue !is null && propertyValue.length () > 0) { | 236 if (propertyValue !is null && propertyValue.length > 0) { |
304 int /*long*/[] result = new int /*long*/[1]; | 237 nsILocalFile localFile; |
305 nsEmbedString pathString = new nsEmbedString (propertyValue); | 238 scope auto pathString = new nsEmbedString (propertyValue.toString16()); |
306 int rc = XPCOM.NS_NewLocalFile (pathString.getAddress (), 1, result); | 239 int rc = XPCOM.NS_NewLocalFile (cast(nsAString*)pathString, 1, &localFile); |
307 if (rc !is XPCOM.NS_OK) Mozilla.error (rc); | 240 if (rc !is XPCOM.NS_OK) Mozilla.error (rc); |
308 if (result[0] is 0) Mozilla.error (XPCOM.NS_ERROR_NULL_POINTER); | 241 if (localFile is null) Mozilla.error (XPCOM.NS_ERROR_NULL_POINTER); |
309 pathString.dispose (); | |
310 | 242 |
311 nsILocalFile localFile = new nsILocalFile (result [0]); | 243 nsIFile file; |
312 result[0] = 0; | 244 rc = localFile.QueryInterface (&nsIFile.IID, cast(void**)&file); |
313 rc = localFile.QueryInterface (nsIFile.NS_IFILE_IID, result); | 245 if (rc !is XPCOM.NS_OK) Mozilla.error (rc); |
314 if (rc !is XPCOM.NS_OK) Mozilla.error (rc); | 246 if (file is null) Mozilla.error (XPCOM.NS_ERROR_NO_INTERFACE); |
315 if (result[0] is 0) Mozilla.error (XPCOM.NS_ERROR_NO_INTERFACE); | 247 |
316 | 248 *_retval = file; |
317 XPCOM.memmove (_retval, new int /*long*/[] {result[0]}, C.PTR_SIZEOF); | |
318 localFile.Release (); | 249 localFile.Release (); |
319 return XPCOM.NS_OK; | 250 return XPCOM.NS_OK; |
320 } | 251 } |
321 | 252 |
322 return XPCOM.NS_ERROR_FAILURE; | 253 return XPCOM.NS_ERROR_FAILURE; |