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
4 : *
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/
9 : *
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
13 : * License.
14 : *
15 : * The Original Code is mozilla.org code.
16 : *
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.
21 : *
22 : * Contributor(s):
23 : * Brian Ryner <bryner@brianryner.com>
24 : *
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.
36 : *
37 : * ***** END LICENSE BLOCK ***** */
38 :
39 : #ifndef _nsXREDirProvider_h__
40 : #define _nsXREDirProvider_h__
41 :
42 : #include "nsIDirectoryService.h"
43 : #include "nsIProfileMigrator.h"
44 : #include "nsILocalFile.h"
45 :
46 : #include "nsCOMPtr.h"
47 : #include "nsCOMArray.h"
48 :
49 : class nsXREDirProvider : public nsIDirectoryServiceProvider2,
50 : public nsIProfileStartup
51 : {
52 : public:
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);
57 :
58 : NS_DECL_NSIDIRECTORYSERVICEPROVIDER
59 : NS_DECL_NSIDIRECTORYSERVICEPROVIDER2
60 : NS_DECL_NSIPROFILESTARTUP
61 :
62 : nsXREDirProvider();
63 :
64 : // if aXULAppDir is null, use gArgv[0]
65 : nsresult Initialize(nsIFile *aXULAppDir,
66 : nsILocalFile *aGREDir,
67 : nsIDirectoryServiceProvider* aAppProvider = nsnull);
68 : ~nsXREDirProvider();
69 :
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);
75 :
76 : void DoShutdown();
77 :
78 : nsresult GetProfileDefaultsDir(nsIFile* *aResult);
79 :
80 22 : static nsresult GetUserAppDataDirectory(nsILocalFile* *aFile) {
81 22 : return GetUserDataDirectory(aFile, false);
82 : }
83 0 : static nsresult GetUserLocalDataDirectory(nsILocalFile* *aFile) {
84 0 : return GetUserDataDirectory(aFile, true);
85 : }
86 :
87 : /* make sure you clone it, if you need to do stuff to it */
88 0 : nsIFile* GetGREDir() { return mGREDir; }
89 22 : nsIFile* GetAppDir() {
90 22 : if (mXULAppDir)
91 22 : return mXULAppDir;
92 0 : return mGREDir;
93 : }
94 :
95 : /**
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.
99 : */
100 : nsresult GetUpdateRootDir(nsIFile* *aResult);
101 :
102 : /**
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.
106 : */
107 : nsresult GetProfileStartupDir(nsIFile* *aResult);
108 :
109 : /**
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.
113 : */
114 : nsresult GetProfileDir(nsIFile* *aResult);
115 :
116 : protected:
117 : nsresult GetFilesInternal(const char* aProperty, nsISimpleEnumerator** aResult);
118 : static nsresult GetUserDataDirectory(nsILocalFile* *aFile, bool aLocal);
119 : static nsresult GetUserDataDirectoryHome(nsILocalFile* *aFile, bool aLocal);
120 : static nsresult GetSysUserExtensionsDirectory(nsILocalFile* *aFile);
121 : #if defined(XP_UNIX) || defined(XP_MACOSX)
122 : static nsresult GetSystemExtensionsDirectory(nsILocalFile** aFile);
123 : #endif
124 : static nsresult EnsureDirectoryExists(nsIFile* aDirectory);
125 : void EnsureProfileFileExists(nsIFile* aFile);
126 :
127 : // Determine the profile path within the UAppData directory. This is different
128 : // on every major platform.
129 : static nsresult AppendProfilePath(nsIFile* aFile);
130 :
131 : static nsresult AppendSysUserExtensionPath(nsIFile* aFile);
132 :
133 : // Internal helper that splits a path into components using the '/' and '\\'
134 : // delimiters.
135 : static inline nsresult AppendProfileString(nsIFile* aFile, const char* aPath);
136 :
137 : // Calculate and register extension and theme bundle directories.
138 : void LoadExtensionBundleDirectories();
139 :
140 : // Calculate and register app-bundled extension directories.
141 : void LoadAppBundleDirs();
142 :
143 : void Append(nsIFile* aDirectory);
144 :
145 : nsCOMPtr<nsIDirectoryServiceProvider> mAppProvider;
146 : nsCOMPtr<nsILocalFile> mGREDir;
147 : nsCOMPtr<nsIFile> mXULAppDir;
148 : nsCOMPtr<nsIFile> mProfileDir;
149 : nsCOMPtr<nsIFile> mProfileLocalDir;
150 : bool mProfileNotified;
151 : nsCOMArray<nsIFile> mAppBundleDirectories;
152 : nsCOMArray<nsIFile> mExtensionDirectories;
153 : nsCOMArray<nsIFile> mThemeDirectories;
154 : };
155 :
156 : #endif
|