Back to index

lightning-sunbird  0.9+nobinonly
nsProfileAccess.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
00002  *
00003  * ***** BEGIN LICENSE BLOCK *****
00004  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00005  *
00006  * The contents of this file are subject to the Mozilla Public License Version
00007  * 1.1 (the "License"); you may not use this file except in compliance with
00008  * the License. You may obtain a copy of the License at
00009  * http://www.mozilla.org/MPL/
00010  *
00011  * Software distributed under the License is distributed on an "AS IS" basis,
00012  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00013  * for the specific language governing rights and limitations under the
00014  * License.
00015  *
00016  * The Original Code is mozilla.org Code.
00017  *
00018  * The Initial Developer of the Original Code is
00019  * Netscape Communications Corporation.
00020  * Portions created by the Initial Developer are Copyright (C) 1998
00021  * the Initial Developer. All Rights Reserved.
00022  *
00023  * Contributor(s):
00024  *
00025  * Alternatively, the contents of this file may be used under the terms of
00026  * either of the GNU General Public License Version 2 or later (the "GPL"),
00027  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00028  * in which case the provisions of the GPL or the LGPL are applicable instead
00029  * of those above. If you wish to allow use of your version of this file only
00030  * under the terms of either the GPL or the LGPL, and not to allow others to
00031  * use your version of this file under the terms of the MPL, indicate your
00032  * decision by deleting the provisions above and replace them with the notice
00033  * and other provisions required by the GPL or the LGPL. If you do not delete
00034  * the provisions above, a recipient may use your version of this file under
00035  * the terms of any one of the MPL, the GPL or the LGPL.
00036  *
00037  * ***** END LICENSE BLOCK ***** */
00038 
00039 #ifndef __nsProfileAccess_h___
00040 #define __nsProfileAccess_h___
00041 
00042 #include "nsCOMPtr.h"
00043 #include "nsISupports.h"
00044 #include "nsString.h"
00045 #include "nsIRegistry.h"
00046 #include "nsXPIDLString.h"
00047 #include "nsVoidArray.h"
00048 #include "nsIFile.h"
00049 #include "nsILocalFile.h"
00050 
00051 #ifdef XP_WIN
00052 #include <windows.h>
00053 #endif
00054 
00055 #ifdef XP_OS2
00056 #define INCL_DOSERRORS
00057 #define INCL_DOSFILEMGR
00058 #include <os2.h>
00059 #endif
00060 
00061 class ProfileStruct
00062 {    
00063 public:
00064      ProfileStruct();
00065      ProfileStruct(const ProfileStruct& src);
00066                 
00067     ~ProfileStruct() { }
00068     
00069      ProfileStruct& operator=(const ProfileStruct& rhs);
00070     
00071     /*
00072      * GetResolvedProfileDir returns the directory specified in the
00073      * registry. It will return NULL if the spec in the registry
00074      * could not be resolved to a path. This directory does not
00075      * nescesarily exist, although it can be created (i.e. the path
00076      * is not on an unmounted drive or something).
00077      */            
00078     nsresult    GetResolvedProfileDir(nsILocalFile **aDirectory);
00079     
00080     /*
00081      * SetResolvedProfileDir will update the directory in the profile
00082      * entry. The next time this entry is externalized, this directory
00083      * will replace the existing entry in the registry.
00084      */
00085     nsresult    SetResolvedProfileDir(nsILocalFile *aDirectory);
00086     
00087     /*
00088      * Copies private members to another ProfileStruct
00089      */
00090     nsresult    CopyProfileLocation(ProfileStruct *destStruct);
00091     
00092     /*
00093      * Methods used by routines which internalize
00094      * and externalize profile info.
00095      */
00096     nsresult    InternalizeLocation(nsIRegistry *aRegistry, nsRegistryKey profKey, PRBool is4x);
00097     nsresult    ExternalizeLocation(nsIRegistry *aRegistry, nsRegistryKey profKey);
00098     nsresult    InternalizeMigratedFromLocation(nsIRegistry *aRegistry, nsRegistryKey profKey);
00099     nsresult    ExternalizeMigratedFromLocation(nsIRegistry *aRegistry, nsRegistryKey profKey);
00100     
00101 public:
00102     nsString    profileName;
00103     PRBool      isMigrated;
00104 
00105     // The directory from which this profile was migrated from (if any)
00106     // Added in mozilla1.0.1 and maintained in the registry
00107     nsCOMPtr<nsILocalFile> migratedFrom;
00108 
00109     nsString    NCProfileName;
00110     nsString    NCDeniedService;
00111     nsString    NCEmailAddress;
00112     nsString    NCHavePregInfo;
00113     PRBool      updateProfileEntry;
00114     // this flag detemines if we added this profile to the list for the import module.
00115     PRBool      isImportType; 
00116     // These fields were added in mozilla1.0.1 and maintained in the registry.
00117     // Values are in milliseconds since midnight Jan 1, 1970 GMT (same as nsIFile)
00118     // Their values will be LL_ZERO if undefined.
00119     PRInt64     creationTime;
00120     PRInt64     lastModTime; 
00121 
00122 private:
00123     nsresult    EnsureDirPathExists(nsILocalFile *aFile, PRBool *wasCreated);
00124     
00125 private:
00126     // These are mutually exclusive - We have one or the other.    
00127     nsString regLocationData;
00128     nsCOMPtr<nsILocalFile> resolvedLocation;
00129 };
00130 
00131 
00132 class nsProfileAccess
00133 {
00134 
00135 private:
00136     nsCOMPtr <nsIFile> mNewRegFile;
00137 
00138     // This is an array that holds all the profile information--migrated/unmigrated
00139     // unmigrated: if the profileinfo is migrated--i.e. -installer option is used
00140     nsVoidArray*  mProfiles;
00141 
00142     nsString      mCurrentProfile;
00143     nsString      mHavePREGInfo;
00144     PRBool        m4xProfilesAdded;
00145     PRBool        mStartWithLastProfile;
00146 public:
00147     PRBool        mProfileDataChanged;
00148     PRBool        mForgetProfileCalled;
00149 
00150 public:
00151 
00152     nsProfileAccess();
00153     virtual ~nsProfileAccess();
00154 
00155     void GetNumProfiles(PRInt32 *numProfiles);
00156     void GetNum4xProfiles(PRInt32 *numProfiles);
00157     void GetFirstProfile(PRUnichar **firstProfile);
00158     nsresult GetProfileList(PRInt32 whichKind, PRUint32 *length, PRUnichar ***result);
00159     nsresult GetOriginalProfileDir(const PRUnichar *profileName, nsILocalFile **orginalDir);
00160     nsresult SetMigratedFromDir(const PRUnichar *profileName, nsILocalFile *orginalDir);
00161     nsresult SetProfileLastModTime(const PRUnichar *profileName, PRInt64 lastModTime);
00162     nsresult GetStartWithLastUsedProfile(PRBool *aStartWithLastUsedProfile);
00163     nsresult SetStartWithLastUsedProfile(PRBool aStartWithLastUsedProfile);
00164     
00165     // if fromImport is true all the 4.x profiles will be added to mProfiles with the isImportType flag set.
00166     // pass fromImport as True only if you are calling from the Import Module.
00167     nsresult Get4xProfileInfo(nsIFile *registryFile, PRBool fromImport);
00168 
00169     void SetCurrentProfile(const PRUnichar *profileName);
00170     void GetCurrentProfile(PRUnichar **profileName);
00171     
00172     nsresult GetValue(const PRUnichar* profileName, ProfileStruct** aProfile);
00173     nsresult SetValue(ProfileStruct* aProfile);
00174     void CheckRegString(const PRUnichar *profileName, char** regString);
00175     void RemoveSubTree(const PRUnichar* profileName);
00176 
00177     PRBool ProfileExists(const PRUnichar *profileName);
00178 
00179     nsresult DetermineForceMigration(PRBool *forceMigration);
00180     nsresult UpdateRegistry(nsIFile* regName);
00181 
00182 private:
00183     nsresult FillProfileInfo(nsIFile* regName);
00184 
00185 
00186 
00187     nsresult HavePregInfo(char **info);
00188 
00189     // if forImport is true searches only the ImportType profiles
00190     // else searches the non-ImportType profiles.
00191     PRInt32    FindProfileIndex(const PRUnichar* profileName, PRBool forImport);
00192 
00193     void SetPREGInfo(const char* pregInfo);
00194     void FreeProfileMembers(nsVoidArray *aProfile);
00195     nsresult ResetProfileMembers();
00196 };
00197 
00198 
00199 #endif // __nsProfileAccess_h___
00200