1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
15 * The Original Code is mozilla.org code.
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 2002
20 * the Initial Developer. All Rights Reserved.
23 * Brian Ryner <bryner@brianryner.com>
25 * Alternatively, the contents of this file may be used under the terms of
26 * either the GNU General Public License Version 2 or later (the "GPL"), or
27 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the MPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the MPL, the GPL or the LGPL.
37 * ***** END LICENSE BLOCK ***** */
39 #ifndef _nsXREDirProvider_h__
40 #define _nsXREDirProvider_h__
42 #include "nsIDirectoryService.h"
43 #include "nsIProfileMigrator.h"
44 #include "nsILocalFile.h"
47 #include "nsCOMArray.h"
49 class nsXREDirProvider
: public nsIDirectoryServiceProvider2
,
50 public nsIProfileStartup
53 // we use a custom isupports implementation (no refcount)
54 NS_IMETHOD
QueryInterface(REFNSIID aIID
, void** aInstancePtr
);
55 NS_IMETHOD_(nsrefcnt
) AddRef(void);
56 NS_IMETHOD_(nsrefcnt
) Release(void);
58 NS_DECL_NSIDIRECTORYSERVICEPROVIDER
59 NS_DECL_NSIDIRECTORYSERVICEPROVIDER2
60 NS_DECL_NSIPROFILESTARTUP
64 // if aXULAppDir is null, use gArgv[0]
65 nsresult
Initialize(nsIFile
*aXULAppDir
,
66 nsILocalFile
*aGREDir
,
67 nsIDirectoryServiceProvider
* aAppProvider
= nsnull
);
70 // We only set the profile dir, we don't ensure that it exists;
71 // that is the responsibility of the toolkit profile service.
72 // We also don't fire profile-changed notifications... that is
73 // the responsibility of the apprunner.
74 nsresult
SetProfile(nsIFile
* aProfileDir
, nsIFile
* aProfileLocalDir
);
78 nsresult
GetProfileDefaultsDir(nsIFile
* *aResult
);
80 static nsresult
GetUserAppDataDirectory(nsILocalFile
* *aFile
) {
81 return GetUserDataDirectory(aFile
, PR_FALSE
);
83 static nsresult
GetUserLocalDataDirectory(nsILocalFile
* *aFile
) {
84 return GetUserDataDirectory(aFile
, PR_TRUE
);
87 /* make sure you clone it, if you need to do stuff to it */
88 nsIFile
* GetGREDir() { return mGREDir
; }
89 nsIFile
* GetAppDir() {
96 * Get the directory under which update directory is created.
97 * This method may be called before XPCOM is started. aResult
98 * is a clone, it may be modified.
100 nsresult
GetUpdateRootDir(nsIFile
* *aResult
);
103 * Get the profile startup directory as determined by this class or by
104 * mAppProvider. This method may be called before XPCOM is started. aResult
105 * is a clone, it may be modified.
107 nsresult
GetProfileStartupDir(nsIFile
* *aResult
);
110 * Get the profile directory as determined by this class or by an
111 * embedder-provided XPCOM directory provider. Only call this method
112 * when XPCOM is initialized! aResult is a clone, it may be modified.
114 nsresult
GetProfileDir(nsIFile
* *aResult
);
117 nsresult
GetFilesInternal(const char* aProperty
, nsISimpleEnumerator
** aResult
);
118 static nsresult
GetUserDataDirectory(nsILocalFile
* *aFile
, PRBool aLocal
);
119 static nsresult
GetUserDataDirectoryHome(nsILocalFile
* *aFile
, PRBool aLocal
);
120 static nsresult
GetSysUserExtensionsDirectory(nsILocalFile
* *aFile
);
121 #if defined(XP_UNIX) || defined(XP_MACOSX)
122 static nsresult
GetSystemExtensionsDirectory(nsILocalFile
** aFile
);
124 static nsresult
EnsureDirectoryExists(nsIFile
* aDirectory
);
125 void EnsureProfileFileExists(nsIFile
* aFile
);
127 // Determine the profile path within the UAppData directory. This is different
128 // on every major platform.
129 static nsresult
AppendProfilePath(nsIFile
* aFile
);
131 static nsresult
AppendSysUserExtensionPath(nsIFile
* aFile
);
133 // Internal helper that splits a path into components using the '/' and '\\'
135 static inline nsresult
AppendProfileString(nsIFile
* aFile
, const char* aPath
);
137 // Calculate all bundle directories, including distribution bundles,
138 // extensions, and themes
139 void LoadBundleDirectories();
140 void LoadAppBundleDirs();
142 void Append(nsIFile
* aDirectory
);
144 nsCOMPtr
<nsIDirectoryServiceProvider
> mAppProvider
;
145 nsCOMPtr
<nsILocalFile
> mGREDir
;
146 nsCOMPtr
<nsIFile
> mXULAppDir
;
147 nsCOMPtr
<nsIFile
> mProfileDir
;
148 nsCOMPtr
<nsIFile
> mProfileLocalDir
;
149 PRPackedBool mProfileNotified
;
150 PRPackedBool mExtensionsLoaded
;
151 nsCOMArray
<nsIFile
> mAppBundleDirectories
;
152 nsCOMArray
<nsIFile
> mExtensionDirectories
;
153 nsCOMArray
<nsIFile
> mThemeDirectories
;