00001
00002
00003
00004
00005
00006 #include <windows.h>
00007 #include "vmsFirefoxExtensionInstaller.h"
00008 #include "vmsFirefoxUtil.h"
00009 #include "vmsFile.h"
00010
00011 vmsFirefoxExtensionInstaller::vmsFirefoxExtensionInstaller()
00012 {
00013
00014 }
00015
00016 vmsFirefoxExtensionInstaller::~vmsFirefoxExtensionInstaller()
00017 {
00018
00019 }
00020
00021 bool vmsFirefoxExtensionInstaller::IsInstalled(LPCSTR pszCID, bool bInDefaultProfileOnly)
00022 {
00023 FEI_STRINGLIST v;
00024 int nDefaultProfile;
00025 get_ProfilesPathes (v, nDefaultProfile);
00026
00027 if (v.size () == 0)
00028 return false;
00029
00030 for (int i = 0; i < v.size (); i++)
00031 {
00032 if (bInDefaultProfileOnly && i != nDefaultProfile)
00033 continue;
00034
00035 char sz [MAX_PATH];
00036 lstrcpy (sz, v [i]);
00037 lstrcat (sz, "\\extensions\\");
00038 lstrcat (sz, pszCID);
00039 if (GetFileAttributes (sz) != DWORD (-1))
00040 return true;
00041 }
00042
00043 return false;
00044 }
00045
00046 bool vmsFirefoxExtensionInstaller::get_ProfilesPathes(FEI_STRINGLIST &v, int& nDefaultProfile)
00047 {
00048 try {
00049 char szPath [MAX_PATH];
00050 vmsFirefoxUtil::GetDataPath (szPath);
00051
00052 char szProfilesIni [MAX_PATH];
00053 lstrcpy (szProfilesIni, szPath);
00054 lstrcat (szProfilesIni, "profiles.ini");
00055
00056 if (GetFileAttributes (szProfilesIni) != DWORD (-1))
00057 {
00058 nDefaultProfile = -1;
00059
00060 for (int i = 0;; i++)
00061 {
00062 char sz [100], szPP [MAX_PATH] = "";
00063 sprintf (sz, "Profile%d", i);
00064 GetPrivateProfileString (sz, "Path", "", szPP, sizeof (szPP), szProfilesIni);
00065 if (*szPP == 0)
00066 break;
00067 LPSTR psz = szPP;
00068 while (*psz) {
00069 if (*psz == '/')
00070 *psz = '\\';
00071 psz++;
00072 }
00073 if (szPP [1] == ':')
00074 {
00075 v.add (szPP);
00076 }
00077 else
00078 {
00079
00080 char sz [MAX_PATH];
00081 lstrcpy (sz, szPath);
00082 lstrcat (sz, szPP);
00083 v.add (sz);
00084 }
00085
00086 if (nDefaultProfile == -1 &&
00087 GetPrivateProfileInt (sz, "Default", 0, szProfilesIni))
00088 nDefaultProfile = i;
00089 }
00090 }
00091
00092 if (v.size () == 0)
00093 {
00094 char szProfiles [MAX_PATH];
00095 vmsFirefoxUtil::GetProfilesPath (szProfiles);
00096 lstrcat (szProfiles, "*");
00097
00098 WIN32_FIND_DATA wfd;
00099 HANDLE hFind = FindFirstFile (szProfiles, &wfd);
00100 if (hFind == INVALID_HANDLE_VALUE)
00101 return false;
00102
00103 do
00104 {
00105 if (0 == lstrcmp (wfd.cFileName, ".") || 0 == lstrcmp (wfd.cFileName, ".."))
00106 continue;
00107
00108 char sz [MAX_PATH];
00109 lstrcpy (sz, szPath);
00110 lstrcat (sz, wfd.cFileName);
00111
00112 DWORD dw = GetFileAttributes (sz);
00113 if (dw != DWORD (-1) && (dw & FILE_ATTRIBUTE_DIRECTORY))
00114 {
00115 char sz2 [MAX_PATH];
00116 lstrcpy (sz2, sz);
00117 lstrcat (sz2, "\\extensions\\");
00118 DWORD dw = GetFileAttributes (sz2);
00119 if (dw != DWORD (-1) && (dw & FILE_ATTRIBUTE_DIRECTORY))
00120 v.add (sz);
00121 }
00122 }
00123 while (FindNextFile (hFind, &wfd));
00124
00125 FindClose (hFind);
00126 }
00127
00128 return true;
00129
00130 }catch (...) {return false;}
00131 }