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