Back to index

lightning-sunbird  0.9+nobinonly
RegTask.cpp
Go to the documentation of this file.
00001 // RegTask.cpp: implementation of the CRegTask class.
00002 //
00004 
00005 #include "stdafx.h"
00006 #include "regmozctl.h"
00007 #include "RegTask.h"
00008 #include "RegTaskManager.h"
00009 
00010 #ifdef _DEBUG
00011 #undef THIS_FILE
00012 static char THIS_FILE[]=__FILE__;
00013 #define new DEBUG_NEW
00014 #endif
00015 
00017 // Construction/Destruction
00019 
00020 CRegTask::CRegTask()
00021 {
00022 
00023 }
00024 
00025 CRegTask::CRegTask(CRegTaskManager *pMgr)
00026 {
00027     m_pTaskMgr = pMgr;
00028 }
00029 
00030 CRegTask::~CRegTask()
00031 {
00032 
00033 }
00034 
00036 
00037 class CRegTaskRegistry : public CRegTask
00038 {
00039 public:
00040     CRegTaskRegistry(CRegTaskManager *pMgr) : CRegTask(pMgr)
00041     {
00042         m_szDesc = _T("Set BinDirectoryPath registry entry");
00043     }
00044     HRESULT DoTask();
00045 };
00046 
00047 
00048 HRESULT CRegTaskRegistry::DoTask()
00049 {
00050     CString szBinDirPath;
00051     m_pTaskMgr->GetValue(c_szValueBinDirPath, szBinDirPath);
00052     // Create registry key
00053     CRegKey cKey;
00054        cKey.Create(HKEY_LOCAL_MACHINE, MOZ_CONTROL_REG_KEY);
00055        cKey.SetValue(szBinDirPath, MOZ_CONTROL_REG_VALUE_BIN_DIR_PATH);
00056        cKey.Close();
00057     return S_OK;
00058 }
00059 
00061 
00062 class CRegTaskRegSvr : public CRegTask
00063 {
00064 public:
00065     CRegTaskRegSvr(CRegTaskManager *pMgr) : CRegTask(pMgr)
00066     {
00067         m_szDesc = _T("Register Mozilla Control");
00068     }
00069     HRESULT DoTask();
00070 };
00071 
00072 
00073 HRESULT CRegTaskRegSvr::DoTask()
00074 {
00075     BOOL bRegister = TRUE;
00076     CString szBinDirPath;
00077     m_pTaskMgr->GetValue(c_szValueBinDirPath, szBinDirPath);
00078        SetCurrentDirectory(szBinDirPath);
00079 
00080        // Now register the mozilla control
00081        CString szMozCtl = szBinDirPath + CString(_T("\\mozctl.dll"));
00082        HINSTANCE hMod = LoadLibrary(szMozCtl);
00083        if (hMod == NULL)
00084        {
00085               AfxMessageBox(_T("Can't find mozctl.dll in current directory"));
00086         return E_FAIL;
00087        }
00088 
00089     HRESULT hr = E_FAIL;
00090        FARPROC pfn = GetProcAddress(hMod, bRegister ? _T("DllRegisterServer") : _T("DllUnregisterServer"));
00091        if (pfn)
00092        {
00093               hr = pfn();
00094        }
00095        FreeLibrary(hMod);
00096     return hr;
00097 }
00098 
00100 
00101 class CRegTaskPATH : public CRegTask
00102 {
00103 public:
00104     CRegTaskPATH(CRegTaskManager *pMgr) : CRegTask(pMgr)
00105     {
00106         m_szDesc = _T("Set PATH environment variable");
00107     }
00108     HRESULT DoTask();
00109 };
00110 
00111 
00112 HRESULT CRegTaskPATH::DoTask()
00113 {
00114     CString szBinDirPath;
00115     m_pTaskMgr->GetValue(c_szValueBinDirPath, szBinDirPath);
00116 
00117     OSVERSIONINFO osvi;
00118     osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO)
00119     GetVersionEx(&osvi);
00120 
00121     if (osvi.dwPlatformId == VER_PLATFORM_WIN32_NT)
00122     {
00123     }
00124     else if (osvi.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS)
00125     {
00126         FILE *f = fopen("c:\\autoexec.bat", "rw");
00127         if (f == NULL)
00128         {
00129             return NULL;
00130         }
00131 
00132         // TODO read autoexec.bat if necessary and add Mozilla bin path to it
00133 
00134         // READ whole thing into memory
00135         // grep for magic control tags
00136         // if there then replace section
00137         // else append new section
00138 
00139         fclose(f);
00140     }
00141 
00142     return S_OK;
00143 }
00144 
00146 
00147 HRESULT CRegTask::PopulateTasks(CRegTaskManager &cMgr)
00148 {
00149     cMgr.AddTask(new CRegTaskRegistry(&cMgr));
00150     cMgr.AddTask(new CRegTaskPATH(&cMgr));
00151     cMgr.AddTask(new CRegTaskRegSvr(&cMgr));
00152     return S_OK;
00153 }
00154