home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2002 March / PCWMAR02.iso / software / turbocad / v8trial / TurboCADv8ProfessionalNoReg.exe / Data.Cab / F44425_RegenWizardAw.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2001-07-16  |  7.0 KB  |  282 lines

  1. // RegenWizardaw.cpp : implementation file
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "RegenWizard.h"
  6. #include "RegenWizardaw.h"
  7.  
  8.  
  9. #ifdef _PSEUDO_DEBUG
  10. #undef THIS_FILE
  11. static char THIS_FILE[] = __FILE__;
  12. #endif
  13.  
  14. CRegenWizardAppWiz::CRegenWizardAppWiz() :
  15.     CCustomAppWiz(),
  16.     m_strRegistryKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\"),
  17.     m_clsFirstStep(this),
  18.     m_clsSecondStep(this),
  19.     m_clsRegenProps(this),
  20.     m_clsEvents(this),
  21.     m_clsFilterInfo(this),
  22.     m_clsToolBasicInfo(this)
  23. {
  24. }
  25.  
  26. bool CRegenWizardAppWiz::Try(CString strCADName)
  27. {
  28.     unsigned char    *str = new unsigned char[255];
  29.     unsigned long    ulTmp, 
  30.                     ulLength = 255;
  31.     HKEY            hKey = 0;
  32.     CString            strPath;
  33.  
  34.     RegOpenKeyEx(HKEY_LOCAL_MACHINE, m_strRegistryKey + strCADName, 0, KEY_EXECUTE, &hKey);
  35.     if (!hKey) return false;
  36.     
  37.     RegQueryValueEx(hKey, "Path", NULL, &ulTmp, str, &ulLength);
  38.  
  39.     strPath    = str;
  40.     strPath = strPath.Left(strPath.GetLength() - 8);
  41.  
  42.     m_strTCW            = strPath + (CString)"Program\\";
  43.     m_strSDKInclude        = strPath + (CString)"SDK\\Include\\";
  44.     m_strDestination    = strPath + (CString)"Program\\Regens";
  45.  
  46.     m_clsSecondStep.m_strDestination    = m_strDestination;
  47.     m_clsSecondStep.m_strSDKInclude        = m_strSDKInclude;
  48.     
  49.     delete[] str;
  50.     return true;
  51. }
  52.  
  53. void CRegenWizardAppWiz::CreatePathVariables()
  54. {
  55.     if (Try("Tcw70.Exe")) return;
  56.     if (Try("Tcw80.Exe")) return;
  57.     if (Try("Tcw90.Exe")) return;
  58. }
  59.  
  60.  
  61. void CRegenWizardAppWiz::FillDictionary()
  62. {
  63.     CString    cstrStdAfxUUID        = GenGUID();
  64.     cstrStdAfxUUID.Replace("-","_");
  65.  
  66.     m_Dictionary[_T("Project_TypeLibrary_GUID")]    = GenGUID();
  67.     m_Dictionary[_T("Regen_COClass_GUID")]            = GenGUID();
  68.     m_Dictionary[_T("Regen_Interface_GUID")]        = GenGUID();
  69.  
  70.     m_Dictionary[_T("STD_AFX_GUID")]                = cstrStdAfxUUID;
  71.  
  72.     m_Dictionary[_T("SDKIncludeDirectory")]            = m_strSDKInclude;
  73.  
  74.     m_Dictionary[_T("CREATEEVENTSMASK.CPP")]        = _T("CREATEEVENTSMASK.CPP");
  75.  
  76.     m_Dictionary[_T("ALLEVENTS.IDL")]    = _T("EVENTS.IDL");
  77.     m_Dictionary[_T("ALLEVENTS.CPP")]    = _T("EVENTS.CPP");
  78.     m_Dictionary[_T("ALLEVENTS.H")]        = _T("EVENTS.H");
  79.  
  80.     m_Dictionary[_T("REGEN.IDL")]    = _T("REGEN.IDL");
  81.     m_Dictionary[_T("REGEN.CPP")]    = _T("REGEN.CPP");
  82.     m_Dictionary[_T("REGEN.H")]        = _T("REGEN.H");
  83.  
  84.     m_Dictionary[_T("TOOL.IDL")]    = _T("TOOL.IDL");
  85.     m_Dictionary[_T("TOOL.CPP")]    = _T("TOOL.CPP");
  86.     m_Dictionary[_T("TOOL.H")]        = _T("TOOL.H");
  87.  
  88.     m_Dictionary[_T("FILTER.IDL")]    = _T("FILTER.IDL");
  89.     m_Dictionary[_T("FILTER.CPP")]    = _T("FILTER.CPP");
  90.     m_Dictionary[_T("FILTER.H")]    = _T("FILTER.H");
  91.  
  92.     m_Dictionary[_T("TIE.IDL")]        = _T("TIE.IDL");
  93.     m_Dictionary[_T("TIE.CPP")]        = _T("TIE.CPP");
  94.     m_Dictionary[_T("TIE.H")]        = _T("TIE.H");
  95. }
  96.  
  97. // This is called immediately after the custom AppWizard is loaded.  Initialize
  98. //  the state of the custom AppWizard here.
  99. void CRegenWizardAppWiz::InitCustomAppWiz()
  100. {
  101.     // There are no steps in this custom AppWizard.
  102.     SetNumberOfSteps(4);
  103.  
  104.     // Add build step to .hpj if there is one
  105.     m_Dictionary[_T("HELP")] = _T("1");
  106.  
  107.     // Inform AppWizard that we're making a DLL.
  108.     m_Dictionary[_T("PROJTYPE_DLL")] = _T("1");
  109.  
  110.     m_iDlgNumber = 0;
  111.     
  112.     CreatePathVariables();
  113.     FillDictionary();
  114. }
  115.  
  116. // This is called just before the custom AppWizard is unloaded.
  117. void CRegenWizardAppWiz::ExitCustomAppWiz()
  118. {
  119.     // TODO: Add code here to deallocate resources used by the custom AppWizard
  120. }
  121.  
  122. CAppWizStepDlg* CRegenWizardAppWiz::RetDialog()
  123. {
  124.     switch (m_iDlgNumber)
  125.     {
  126.     case 1: return &m_clsFirstStep;
  127.     case 2: 
  128.         {
  129.             m_clsSecondStep.m_strDestination = m_strDestination;
  130.             return &m_clsSecondStep;
  131.         };
  132.     case 3:    return &m_clsEvents;
  133.     case 4:
  134.         {
  135.             if (m_Dictionary [_T("RegenCreating")]    == _T("Yes")) 
  136.                 return &m_clsRegenProps;
  137.             if (m_Dictionary [_T("ToolCreating")]    == _T("Yes"))
  138.                 return &m_clsToolBasicInfo;
  139.             if (m_Dictionary [_T("FilterCreating")]    == _T("Yes"))
  140.                 return &m_clsFilterInfo;
  141.             if (m_Dictionary [_T("TieCreating")]    == _T("Yes"))
  142.                 return NULL;
  143.         };
  144.     default: return NULL;
  145.     };
  146. }
  147.  
  148.  
  149. CAppWizStepDlg* CRegenWizardAppWiz::Back(CAppWizStepDlg* pDlg)
  150. {
  151.     m_iDlgNumber--;
  152.  
  153.     return    RetDialog();
  154. }
  155.  
  156. CAppWizStepDlg* CRegenWizardAppWiz::Next(CAppWizStepDlg* pDlg)
  157. {
  158.     m_iDlgNumber++;
  159.  
  160.     return RetDialog();
  161. }
  162.  
  163. BSTR MakeBSTR(CString str)
  164. {
  165.     return str.AllocSysString();
  166. }
  167.  
  168. BSTR MakeBSTR(const char* str)
  169. {
  170.     CString    cstr = str;
  171.     return    MakeBSTR(cstr);
  172. }
  173.  
  174. void CRegenWizardAppWiz::ChangeToolSettings(IConfiguration *pConfig, const char* strToolName, const char* strSetting, bool boolAdd)
  175. {
  176.     BSTR    bstrName    = MakeBSTR (strToolName);
  177.     BSTR    bstrSetting    = MakeBSTR (strSetting);    
  178.  
  179.     if (boolAdd) 
  180.         pConfig->AddToolSettings(bstrName, bstrSetting, varMissed);
  181.     else
  182.         pConfig->RemoveToolSettings(bstrName, bstrSetting, varMissed);
  183.  
  184.     ::SysFreeString (bstrName);
  185.     ::SysFreeString (bstrSetting);
  186. }
  187.  
  188.  
  189. void CRegenWizardAppWiz::ProcessConfig(IConfiguration *pConfig)
  190. {
  191.     ChangeToolSettings(pConfig, "midl.exe", "/mktyplib203", false);
  192.     ChangeToolSettings(pConfig, "midl.exe",    (CString)"/I\"" + m_strSDKInclude + "\"", true);
  193.  
  194.     ChangeToolSettings(pConfig, "cl.exe",    (CString)"/I\"" + m_strSDKInclude + "\"", true);
  195.  
  196.     ChangeToolSettings(pConfig, "link.exe",    (CString)"/out:\"" + m_strDestination+
  197.                                             (CString)"/"  + m_strRoot+(CString)".dll\"", true);
  198.     ChangeToolSettings(pConfig, "rc.exe",    (CString)"/i\"" + m_strSDKInclude + "\"", true);
  199. }
  200.  
  201. void CRegenWizardAppWiz::SomethingWasByDefault()
  202. {
  203.     m_Dictionary.Lookup(_T("root"), m_strRoot);
  204.  
  205.     // Set value of $$Doc$$, $$DOC$$
  206.     CString strDoc = m_strRoot.Left(6);
  207.     m_Dictionary[_T("Doc")] = strDoc;
  208.     strDoc.MakeUpper();
  209.     m_Dictionary[_T("DOC")] = strDoc;
  210.  
  211.     // Set value of $$MAC_TYPE$$
  212.     CString strTmp = m_strRoot.Left(4);
  213.     int nLen = strTmp.GetLength();
  214.     if (strTmp.GetLength() < 4)
  215.     {
  216.         CString strPad(_T(' '), 4 - nLen);
  217.         strTmp += strPad;
  218.     }
  219.     strTmp.MakeUpper();
  220.     m_Dictionary[_T("MAC_TYPE")] = strTmp;
  221. }
  222.  
  223. CString    CRegenWizardAppWiz::GenGUID()
  224. {
  225.     UUID            uuid;
  226.     unsigned char    *strUUID = NULL;
  227.     CString            strResult;
  228.  
  229.     UuidCreate(&uuid);
  230.     UuidToString(&uuid, &strUUID);
  231.  
  232.     strResult    = strUUID;
  233.     strResult.MakeUpper();
  234.  
  235.     RpcStringFree(&strUUID);
  236.  
  237.     return strResult;
  238. }
  239.  
  240. void CRegenWizardAppWiz::CustomizeProject(IBuildProject* pProject)
  241. {
  242.     SomethingWasByDefault();
  243.  
  244.     HRESULT            hRes        = S_OK;
  245.     IConfigurations    *pConfigs    = NULL;
  246.     IConfiguration    *pConfig    = NULL;
  247.     IEnumVARIANT    *pEachEnum    = NULL;
  248.     VARIANT            varPointer;
  249.     
  250.     varPointer.vt = VT_EMPTY;
  251.     try
  252.     {
  253.         hRes = pProject->get_Configurations(&pConfigs);
  254.         CHECK_HRESULT(hRes);
  255.  
  256.         hRes = pConfigs->get__NewEnum((IUnknown**)&pEachEnum);
  257.         CHECK_HRESULT(hRes);
  258.  
  259.         while (pEachEnum->Next(1, &varPointer, NULL) == S_OK)
  260.         {
  261.             pConfig = (IConfiguration*)varPointer.pdispVal;
  262.  
  263.             ProcessConfig(pConfig);    
  264.  
  265.             RELEASE(pConfig);
  266.         };
  267.     }
  268.     catch (...)
  269.     {
  270.         TRACE("CRegenWizardAppWiz::CustomizeProject");
  271.     };
  272.  
  273.     RELEASE(pConfigs);
  274. }
  275.  
  276.  
  277. // Here we define one instance of the CRegenWizardAppWiz class.  You can access
  278. //  m_Dictionary and any other public members of this class through the
  279. //  global RegenWizardaw.
  280. CRegenWizardAppWiz RegenWizardaw;
  281.  
  282.