CMakeSetupDialog.cpp 41 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447
  1. // pcbuilderdialogDlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "shellapi.h"
  5. // a fun undef for DOT NET
  6. #undef DEBUG
  7. #include "CMakeSetup.h"
  8. #include "MakeHelp.h"
  9. #include "PathDialog.h"
  10. #include "CMakeSetupDialog.h"
  11. #include "CMakeCommandLineInfo.h"
  12. #include "../cmListFileCache.h"
  13. #include "../cmCacheManager.h"
  14. #include "../cmake.h"
  15. #include "../cmGlobalGenerator.h"
  16. #include "../cmDynamicLoader.h"
  17. #ifdef _DEBUG
  18. #define new DEBUG_NEW
  19. #undef THIS_FILE
  20. static char THIS_FILE[] = __FILE__;
  21. #endif
  22. // Convert to Win32 path (slashes). But it's not in cmSystemTools, so
  23. // the 2 billions people that are using the CMake API can not mistake
  24. // it with cmMakeMyCoffeeButNoSugarPlease().
  25. std::string ConvertToWindowsPath(const char* path)
  26. {
  27. // Convert to output path.
  28. // Remove the "" around it (if any) since it's an output path for
  29. // the shell. If another shell-oriented feature is not designed
  30. // for a GUI use, then we are in trouble.
  31. std::string s = cmSystemTools::ConvertToOutputPath(path);
  32. std::string::iterator i = s.begin();
  33. if (*i == '\"')
  34. {
  35. s.erase(i, i + 1);
  36. }
  37. i = s.begin() + s.length() - 1;
  38. if (*i == '\"')
  39. {
  40. s.erase(i, i + 1);
  41. }
  42. return s;
  43. }
  44. /////////////////////////////////////////////////////////////////////////////
  45. // CAboutDlg dialog used for App About
  46. class CAboutDlg : public CDialog
  47. {
  48. public:
  49. CAboutDlg();
  50. // Dialog Data
  51. //{{AFX_DATA(CAboutDlg)
  52. enum { IDD = IDD_ABOUTBOX };
  53. //}}AFX_DATA
  54. // ClassWizard generated virtual function overrides
  55. //{{AFX_VIRTUAL(CAboutDlg)
  56. protected:
  57. virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
  58. //}}AFX_VIRTUAL
  59. // Implementation
  60. protected:
  61. //{{AFX_MSG(CAboutDlg)
  62. //}}AFX_MSG
  63. DECLARE_MESSAGE_MAP()
  64. };
  65. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  66. {
  67. //{{AFX_DATA_INIT(CAboutDlg)
  68. //}}AFX_DATA_INIT
  69. }
  70. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  71. {
  72. CDialog::DoDataExchange(pDX);
  73. //{{AFX_DATA_MAP(CAboutDlg)
  74. //}}AFX_DATA_MAP
  75. }
  76. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  77. //{{AFX_MSG_MAP(CAboutDlg)
  78. // No message handlers
  79. //}}AFX_MSG_MAP
  80. END_MESSAGE_MAP();
  81. void MFCMessageCallback(const char* m, const char* title, bool& nomore, void*)
  82. {
  83. std::string message = m;
  84. message += "\n\n(Press Cancel to suppress any further messages.)";
  85. if(::MessageBox(0, message.c_str(), title,
  86. MB_OKCANCEL|MB_TASKMODAL) == IDCANCEL)
  87. {
  88. nomore = true;
  89. }
  90. }
  91. /////////////////////////////////////////////////////////////////////////////
  92. // CMakeSetupDialog dialog
  93. void updateProgress(const char *msg, float prog, void *cd)
  94. {
  95. char tmp[1024];
  96. if (prog >= 0)
  97. {
  98. sprintf(tmp,"%s %i%%",msg,(int)(100*prog));
  99. }
  100. else
  101. {
  102. sprintf(tmp,"%s",msg);
  103. }
  104. CMakeSetupDialog *self = (CMakeSetupDialog *)cd;
  105. self->SetDlgItemText(IDC_PROGRESS, tmp);
  106. CWnd* cancel = self->GetDlgItem(IDCANCEL);
  107. //
  108. // Retrieve and dispatch any waiting messages.
  109. //
  110. MSG wmsg;
  111. while (::PeekMessage (&wmsg, NULL, 0, 0, PM_REMOVE))
  112. {
  113. switch(wmsg.message)
  114. {
  115. case WM_LBUTTONDOWN:
  116. case WM_LBUTTONUP:
  117. case WM_LBUTTONDBLCLK:
  118. {
  119. if(wmsg.hwnd == cancel->m_hWnd)
  120. {
  121. ::DispatchMessage(&wmsg);
  122. }
  123. }
  124. break;
  125. case WM_COMMAND:
  126. case WM_SETCURSOR:
  127. case WM_PAINT:
  128. ::DispatchMessage(&wmsg);
  129. break;
  130. }
  131. }
  132. }
  133. CMakeSetupDialog::CMakeSetupDialog(const CMakeCommandLineInfo& cmdInfo,
  134. CWnd* pParent /*=NULL*/)
  135. : CDialog(CMakeSetupDialog::IDD, pParent)
  136. {
  137. m_Cursor = LoadCursor(NULL, IDC_ARROW);
  138. m_RunningConfigure = false;
  139. cmSystemTools::SetRunCommandHideConsole(true);
  140. cmSystemTools::SetErrorCallback(MFCMessageCallback);
  141. m_RegistryKey = "Software\\Kitware\\CMakeSetup\\Settings\\StartPath";
  142. m_CacheEntriesList.m_CMakeSetupDialog = this;
  143. m_CMakeInstance = new cmake;
  144. m_CMakeInstance->SetProgressCallback(updateProgress, (void *)this);
  145. //{{AFX_DATA_INIT(CMakeSetupDialog)
  146. //}}AFX_DATA_INIT
  147. // Get the parameters from the command line info
  148. // If an unknown parameter is found, try to interpret it too, since it
  149. // is likely to be a file dropped on the shortcut :)
  150. if (cmdInfo.m_LastUnknownParameter.IsEmpty())
  151. {
  152. this->m_WhereSource = cmdInfo.m_WhereSource;
  153. this->m_WhereBuild = cmdInfo.m_WhereBuild;
  154. this->m_GeneratorChoiceString = cmdInfo.m_GeneratorChoiceString;
  155. this->m_AdvancedValues = cmdInfo.m_AdvancedValues;
  156. }
  157. else
  158. {
  159. this->m_WhereSource = _T("");
  160. this->m_WhereBuild = _T("");
  161. this->m_AdvancedValues = FALSE;
  162. this->m_GeneratorChoiceString = _T("");
  163. this->ChangeDirectoriesFromFile((LPCTSTR)cmdInfo.m_LastUnknownParameter);
  164. }
  165. // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
  166. m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  167. m_BuildPathChanged = false;
  168. // Find the path to the cmake.exe executable
  169. char fname[1024];
  170. ::GetModuleFileName(NULL,fname,1023);
  171. // extract just the path part
  172. m_PathToExecutable = cmSystemTools::GetProgramPath(fname).c_str();
  173. // add the cmake.exe to the path
  174. m_PathToExecutable += "/cmake.exe";
  175. m_oldCX = -1;
  176. m_deltaXRemainder = 0;
  177. }
  178. CMakeSetupDialog::~CMakeSetupDialog()
  179. {
  180. delete m_CMakeInstance;
  181. // clean up globals
  182. cmListFileCache::GetInstance()->ClearCache();
  183. cmDynamicLoader::FlushCache();
  184. }
  185. void CMakeSetupDialog::DoDataExchange(CDataExchange* pDX)
  186. {
  187. CDialog::DoDataExchange(pDX);
  188. //{{AFX_DATA_MAP(CMakeSetupDialog)
  189. DDX_Control(pDX, IDC_AdvancedValues, m_AdvancedValuesControl);
  190. DDX_Control(pDX, IDC_BuildForLabel, m_BuildForLabel);
  191. DDX_Control(pDX, IDC_BROWSE_SOURCE, m_BrowseSource);
  192. DDX_Control(pDX, IDC_BROWSE_BUILD, m_BrowseBuild);
  193. DDX_Control(pDX, IDC_HELP_BUTTON, m_HelpButton);
  194. DDX_Control(pDX, IDC_Generator, m_GeneratorChoice);
  195. DDX_Control(pDX, IDC_OK, m_OKButton);
  196. DDX_Control(pDX, IDCANCEL, m_CancelButton);
  197. DDX_CBStringExact(pDX, IDC_WhereSource, m_WhereSource);
  198. DDX_CBStringExact(pDX, IDC_WhereBuild, m_WhereBuild);
  199. DDX_Control(pDX, IDC_FRAME, m_ListFrame);
  200. DDX_Control(pDX, IDC_WhereSource, m_WhereSourceControl);
  201. DDX_Control(pDX, IDC_WhereBuild, m_WhereBuildControl);
  202. DDX_Control(pDX, IDC_LIST2, m_CacheEntriesList);
  203. DDX_Control(pDX, IDC_MouseHelpCaption, m_MouseHelp);
  204. DDX_Control(pDX, IDC_PROGRESS, m_StatusDisplay);
  205. DDX_Control(pDX, IDC_BuildProjects, m_Configure);
  206. DDX_CBStringExact(pDX, IDC_Generator, m_GeneratorChoiceString);
  207. DDX_Check(pDX, IDC_AdvancedValues, m_AdvancedValues);
  208. //}}AFX_DATA_MAP
  209. }
  210. BEGIN_MESSAGE_MAP(CMakeSetupDialog, CDialog)
  211. //{{AFX_MSG_MAP(CMakeSetupDialog)
  212. ON_WM_SYSCOMMAND()
  213. ON_WM_PAINT()
  214. ON_WM_QUERYDRAGICON()
  215. ON_BN_CLICKED(IDC_BUTTON2, OnBrowseWhereSource)
  216. ON_BN_CLICKED(IDC_BuildProjects, OnConfigure)
  217. ON_BN_CLICKED(IDC_BUTTON3, OnBrowseWhereBuild)
  218. ON_CBN_EDITCHANGE(IDC_WhereBuild, OnChangeWhereBuild)
  219. ON_CBN_SELCHANGE(IDC_WhereBuild, OnSelendokWhereBuild)
  220. ON_CBN_EDITCHANGE(IDC_WhereSource, OnChangeWhereSource)
  221. ON_CBN_SELENDOK(IDC_WhereSource, OnSelendokWhereSource)
  222. ON_WM_SIZE()
  223. ON_WM_GETMINMAXINFO()
  224. ON_BN_CLICKED(IDC_OK, OnOk)
  225. ON_CBN_EDITCHANGE(IDC_Generator, OnEditchangeGenerator)
  226. ON_BN_CLICKED(IDC_HELP_BUTTON, OnHelpButton)
  227. ON_BN_CLICKED(IDC_AdvancedValues, OnAdvancedValues)
  228. ON_BN_DOUBLECLICKED(IDC_AdvancedValues, OnDoubleclickedAdvancedValues)
  229. ON_WM_DROPFILES()
  230. ON_BN_CLICKED(IDCANCEL, OnCancel)
  231. ON_WM_SETCURSOR()
  232. //}}AFX_MSG_MAP
  233. END_MESSAGE_MAP()
  234. /////////////////////////////////////////////////////////////////////////////
  235. // CMakeSetupDialog message handlers
  236. BOOL CMakeSetupDialog::OnInitDialog()
  237. {
  238. CDialog::OnInitDialog();
  239. this->DragAcceptFiles(true);
  240. // Add "Create shortcut" menu item to system menu.
  241. // IDM_CREATESHORTCUT must be in the system command range.
  242. ASSERT((IDM_CREATESHORTCUT & 0xFFF0) == IDM_CREATESHORTCUT);
  243. ASSERT(IDM_CREATESHORTCUT < 0xF000);
  244. // Add "About..." menu item to system menu.
  245. // IDM_ABOUTBOX must be in the system command range.
  246. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
  247. ASSERT(IDM_ABOUTBOX < 0xF000);
  248. CMenu* pSysMenu = GetSystemMenu(FALSE);
  249. if (pSysMenu != NULL)
  250. {
  251. CString strCreateShortcutMenu;
  252. strCreateShortcutMenu.LoadString(IDS_CREATESHORTCUT);
  253. if (!strCreateShortcutMenu.IsEmpty())
  254. {
  255. pSysMenu->AppendMenu(MF_SEPARATOR);
  256. pSysMenu->AppendMenu(MF_STRING,
  257. IDM_CREATESHORTCUT,
  258. strCreateShortcutMenu);
  259. }
  260. CString strAboutMenu;
  261. strAboutMenu.LoadString(IDS_ABOUTBOX);
  262. if (!strAboutMenu.IsEmpty())
  263. {
  264. pSysMenu->AppendMenu(MF_SEPARATOR);
  265. pSysMenu->AppendMenu(MF_STRING,
  266. IDM_ABOUTBOX,
  267. strAboutMenu);
  268. }
  269. }
  270. // Set the icon for this dialog. The framework does this automatically
  271. // when the application's main window is not a dialog
  272. SetIcon(m_hIcon, TRUE); // Set big icon
  273. SetIcon(m_hIcon, FALSE); // Set small icon
  274. // Load source and build dirs from registry
  275. this->LoadFromRegistry();
  276. std::vector<std::string> names;
  277. this->m_CMakeInstance->GetRegisteredGenerators(names);
  278. for(std::vector<std::string>::iterator i = names.begin();
  279. i != names.end(); ++i)
  280. {
  281. m_GeneratorChoice.AddString(i->c_str());
  282. }
  283. if (m_GeneratorChoiceString == _T(""))
  284. {
  285. // check for vs7 in registry then decide what default to use
  286. std::string mp;
  287. mp = "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\7.1;InstallDir]";
  288. cmSystemTools::ExpandRegistryValues(mp);
  289. if (mp != "/registry")
  290. {
  291. m_GeneratorChoiceString = "Visual Studio 7 .NET 2003";
  292. }
  293. else
  294. {
  295. mp = "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\7.0;InstallDir]";
  296. cmSystemTools::ExpandRegistryValues(mp);
  297. if (mp != "/registry")
  298. {
  299. m_GeneratorChoiceString = "Visual Studio 7";
  300. }
  301. else
  302. {
  303. m_GeneratorChoiceString = "Visual Studio 6";
  304. }
  305. }
  306. }
  307. // try to load the cmake cache from disk
  308. this->LoadCacheFromDiskToGUI();
  309. m_WhereBuildControl.LimitText(2048);
  310. m_WhereSourceControl.LimitText(2048);
  311. m_GeneratorChoice.LimitText(2048);
  312. // Set the version number
  313. char tmp[1024];
  314. sprintf(tmp,"CMake %d.%d - %s", cmake::GetMajorVersion(),
  315. cmake::GetMinorVersion(), cmake::GetReleaseVersion());
  316. SetDlgItemText(IDC_PROGRESS, "");
  317. this->SetWindowText(tmp);
  318. this->UpdateData(FALSE);
  319. return TRUE; // return TRUE unless you set the focus to a control
  320. }
  321. // About dialog invoke
  322. void CMakeSetupDialog::OnSysCommand(UINT nID, LPARAM lParam)
  323. {
  324. if ((nID & 0xFFF0) == IDM_ABOUTBOX)
  325. {
  326. CAboutDlg dlgAbout;
  327. dlgAbout.DoModal();
  328. }
  329. else if ((nID & 0xFFF0) == IDM_CREATESHORTCUT)
  330. {
  331. CreateShortcut();
  332. }
  333. else
  334. {
  335. CDialog::OnSysCommand(nID, lParam);
  336. }
  337. }
  338. // If you add a minimize button to your dialog, you will need the code below
  339. // to draw the icon. For MFC applications using the document/view model,
  340. // this is automatically done for you by the framework.
  341. void CMakeSetupDialog::OnPaint()
  342. {
  343. if (IsIconic())
  344. {
  345. CPaintDC dc(this); // device context for painting
  346. SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
  347. // Center icon in client rectangle
  348. int cxIcon = GetSystemMetrics(SM_CXICON);
  349. int cyIcon = GetSystemMetrics(SM_CYICON);
  350. CRect rect;
  351. GetClientRect(&rect);
  352. int x = (rect.Width() - cxIcon + 1) / 2;
  353. int y = (rect.Height() - cyIcon + 1) / 2;
  354. // Draw the icon
  355. dc.DrawIcon(x, y, m_hIcon);
  356. }
  357. else
  358. {
  359. CDialog::OnPaint();
  360. }
  361. }
  362. // The system calls this to obtain the cursor to display while the user drags
  363. // the minimized window.
  364. HCURSOR CMakeSetupDialog::OnQueryDragIcon()
  365. {
  366. return (HCURSOR) m_hIcon;
  367. }
  368. // Browse button
  369. bool CMakeSetupDialog::Browse(CString &result, const char *title)
  370. {
  371. CPathDialog dlg("Select Path", title, result);
  372. if(dlg.DoModal()==IDOK)
  373. {
  374. result = dlg.GetPathName();
  375. return true;
  376. }
  377. else
  378. {
  379. return false;
  380. }
  381. }
  382. void CMakeSetupDialog::SaveToRegistry()
  383. {
  384. HKEY hKey;
  385. DWORD dwDummy;
  386. if(RegCreateKeyEx(HKEY_CURRENT_USER,
  387. m_RegistryKey,
  388. 0, "", REG_OPTION_NON_VOLATILE, KEY_READ|KEY_WRITE,
  389. NULL, &hKey, &dwDummy) != ERROR_SUCCESS)
  390. {
  391. return;
  392. }
  393. else
  394. {
  395. // save some values
  396. CString regvalue;
  397. this->ReadRegistryValue(hKey, &(regvalue),"WhereSource1","C:\\");
  398. int shiftEnd = 9;
  399. if(m_WhereSource != regvalue)
  400. {
  401. char keyName[1024];
  402. char keyName2[1024];
  403. int i;
  404. for (i = 2; i < 10; ++i)
  405. {
  406. regvalue = "";
  407. sprintf(keyName,"WhereSource%i",i);
  408. this->ReadRegistryValue(hKey, &(regvalue),keyName,"");
  409. // check for short circuit, if the new value is already in
  410. // the list then we stop
  411. if (m_WhereSource == regvalue)
  412. {
  413. shiftEnd = i - 1;
  414. }
  415. }
  416. for (i = shiftEnd; i; --i)
  417. {
  418. regvalue = "";
  419. sprintf(keyName,"WhereSource%i",i);
  420. sprintf(keyName2,"WhereSource%i",i+1);
  421. this->ReadRegistryValue(hKey, &(regvalue),keyName,"");
  422. if (strlen(regvalue))
  423. {
  424. RegSetValueEx(hKey, _T(keyName2), 0, REG_SZ,
  425. (CONST BYTE *)(const char *)regvalue,
  426. regvalue.GetLength());
  427. }
  428. }
  429. RegSetValueEx(hKey, _T("WhereSource1"), 0, REG_SZ,
  430. (CONST BYTE *)(const char *)m_WhereSource,
  431. m_WhereSource.GetLength());
  432. }
  433. this->ReadRegistryValue(hKey, &(regvalue),"WhereBuild1","C:\\");
  434. if(m_WhereBuild != regvalue)
  435. {
  436. int i;
  437. char keyName[1024];
  438. char keyName2[1024];
  439. for (i = 2; i < 10; ++i)
  440. {
  441. regvalue = "";
  442. sprintf(keyName,"WhereBuild%i",i);
  443. this->ReadRegistryValue(hKey, &(regvalue),keyName,"");
  444. // check for short circuit, if the new value is already in
  445. // the list then we stop
  446. if (m_WhereBuild == regvalue)
  447. {
  448. shiftEnd = i - 1;
  449. }
  450. }
  451. for (i = shiftEnd; i; --i)
  452. {
  453. regvalue = "";
  454. sprintf(keyName,"WhereBuild%i",i);
  455. sprintf(keyName2,"WhereBuild%i",i+1);
  456. this->ReadRegistryValue(hKey, &(regvalue),keyName,"");
  457. if (strlen(regvalue))
  458. {
  459. RegSetValueEx(hKey, _T(keyName2), 0, REG_SZ,
  460. (CONST BYTE *)(const char *)regvalue,
  461. regvalue.GetLength());
  462. }
  463. }
  464. RegSetValueEx(hKey, _T("WhereBuild1"), 0, REG_SZ,
  465. (CONST BYTE *)(const char *)m_WhereBuild,
  466. m_WhereBuild.GetLength());
  467. }
  468. }
  469. RegCloseKey(hKey);
  470. }
  471. void CMakeSetupDialog::ReadRegistryValue(HKEY hKey,
  472. CString *val,
  473. const char *key,
  474. const char *adefault)
  475. {
  476. DWORD dwType, dwSize;
  477. char *pb;
  478. dwType = REG_SZ;
  479. pb = val->GetBuffer(MAX_PATH);
  480. dwSize = MAX_PATH;
  481. if(RegQueryValueEx(hKey,_T(key), NULL, &dwType,
  482. (BYTE *)pb, &dwSize) != ERROR_SUCCESS)
  483. {
  484. val->ReleaseBuffer();
  485. *val = _T(adefault);
  486. }
  487. else
  488. {
  489. val->ReleaseBuffer();
  490. }
  491. }
  492. void CMakeSetupDialog::LoadFromRegistry()
  493. {
  494. HKEY hKey;
  495. if(RegOpenKeyEx(HKEY_CURRENT_USER,
  496. m_RegistryKey,
  497. 0, KEY_READ, &hKey) != ERROR_SUCCESS)
  498. {
  499. return;
  500. }
  501. else
  502. {
  503. // load some values
  504. if (m_WhereSource.IsEmpty())
  505. {
  506. this->ReadRegistryValue(hKey, &(m_WhereSource),"WhereSource1","C:\\");
  507. }
  508. if (m_WhereBuild.IsEmpty())
  509. {
  510. this->ReadRegistryValue(hKey, &(m_WhereBuild),"WhereBuild1","C:\\");
  511. }
  512. m_WhereSourceControl.AddString(m_WhereSource);
  513. m_WhereBuildControl.AddString(m_WhereBuild);
  514. char keyname[1024];
  515. CString regvalue;
  516. int i;
  517. for (i = 2; i <= 10; ++i)
  518. {
  519. sprintf(keyname,"WhereSource%i",i);
  520. regvalue = "";
  521. this->ReadRegistryValue(hKey, &(regvalue),keyname,"C:\\");
  522. if (strcmp("C:\\",regvalue))
  523. {
  524. m_WhereSourceControl.AddString(regvalue);
  525. }
  526. sprintf(keyname,"WhereBuild%i",i);
  527. regvalue = "";
  528. this->ReadRegistryValue(hKey, &(regvalue),keyname,"C:\\");
  529. if (strcmp("C:\\",regvalue))
  530. {
  531. m_WhereBuildControl.AddString(regvalue);
  532. }
  533. }
  534. }
  535. RegCloseKey(hKey);
  536. }
  537. // Callback for browse source button
  538. void CMakeSetupDialog::OnBrowseWhereSource()
  539. {
  540. this->UpdateData();
  541. Browse(m_WhereSource, "Enter Path to Source");
  542. this->UpdateData(false);
  543. this->OnChangeWhereSource();
  544. }
  545. // Callback for browser build button
  546. void CMakeSetupDialog::OnBrowseWhereBuild()
  547. {
  548. this->UpdateData();
  549. Browse(m_WhereBuild, "Enter Path to Build");
  550. this->UpdateData(false);
  551. this->OnChangeWhereBuild();
  552. }
  553. void CMakeSetupDialog::RunCMake(bool generateProjectFiles)
  554. {
  555. if(!cmSystemTools::FileExists(m_WhereBuild))
  556. {
  557. std::string message =
  558. "Build directory does not exist, should I create it?\n\n"
  559. "Directory: ";
  560. message += (const char*)m_WhereBuild;
  561. if(MessageBox(message.c_str(), "Create Directory", MB_OKCANCEL) == IDOK)
  562. {
  563. cmSystemTools::MakeDirectory(m_WhereBuild);
  564. }
  565. else
  566. {
  567. MessageBox("Build Project aborted, nothing done.");
  568. return;
  569. }
  570. }
  571. // set the wait cursor
  572. m_Cursor = LoadCursor(NULL, IDC_WAIT);
  573. ::SetCursor(m_Cursor);
  574. m_RunningConfigure = true;
  575. // get all the info from the dialog
  576. this->UpdateData();
  577. // always save the current gui values to disk
  578. this->SaveCacheFromGUI();
  579. // Make sure we are working from the cache on disk
  580. this->LoadCacheFromDiskToGUI();
  581. m_OKButton.EnableWindow(false);
  582. // setup the cmake instance
  583. if (generateProjectFiles)
  584. {
  585. if(m_CMakeInstance->Generate() != 0)
  586. {
  587. cmSystemTools::Error(
  588. "Error in generation process, project files may be invalid");
  589. }
  590. }
  591. else
  592. {
  593. m_CMakeInstance->SetHomeDirectory(m_WhereSource);
  594. m_CMakeInstance->SetStartDirectory(m_WhereSource);
  595. m_CMakeInstance->SetHomeOutputDirectory(m_WhereBuild);
  596. m_CMakeInstance->SetStartOutputDirectory(m_WhereBuild);
  597. m_CMakeInstance->SetGlobalGenerator(
  598. m_CMakeInstance->CreateGlobalGenerator(m_GeneratorChoiceString));
  599. m_CMakeInstance->SetCMakeCommand(m_PathToExecutable);
  600. m_CMakeInstance->LoadCache();
  601. if(m_CMakeInstance->Configure() != 0)
  602. {
  603. cmSystemTools::Error(
  604. "Error in configuration process, project files may be invalid");
  605. }
  606. // update the GUI with any new values in the caused by the
  607. // generation process
  608. this->LoadCacheFromDiskToGUI();
  609. }
  610. // save source and build paths to registry
  611. this->SaveToRegistry();
  612. // path is up-to-date now
  613. m_BuildPathChanged = false;
  614. // put the cursor back
  615. m_Cursor = LoadCursor(NULL, IDC_ARROW);
  616. ::SetCursor(m_Cursor);
  617. m_RunningConfigure = false;
  618. cmSystemTools::ResetErrorOccuredFlag();
  619. }
  620. // Callback for build projects button
  621. void CMakeSetupDialog::OnConfigure()
  622. {
  623. // enable error messages each time configure is pressed
  624. cmSystemTools::EnableMessages();
  625. this->RunCMake(false);
  626. }
  627. // callback for combo box menu where build selection
  628. void CMakeSetupDialog::OnSelendokWhereBuild()
  629. {
  630. m_WhereBuildControl.GetLBText(m_WhereBuildControl.GetCurSel(),
  631. m_WhereBuild);
  632. m_WhereBuildControl.SetWindowText( m_WhereBuild);
  633. this->UpdateData(FALSE);
  634. this->OnChangeWhereBuild();
  635. }
  636. // callback for combo box menu where source selection
  637. void CMakeSetupDialog::OnSelendokWhereSource()
  638. {
  639. m_WhereSourceControl.GetLBText(m_WhereSourceControl.GetCurSel(),
  640. m_WhereSource);
  641. this->UpdateData(FALSE);
  642. this->OnChangeWhereSource();
  643. }
  644. // callback for chaing source directory
  645. void CMakeSetupDialog::OnChangeWhereSource()
  646. {
  647. }
  648. // callback for changing the build directory
  649. void CMakeSetupDialog::OnChangeWhereBuild()
  650. {
  651. this->UpdateData();
  652. // The build dir has changed, check if there is a cache, and
  653. // grab the source dir from it
  654. std::string path = this->m_WhereBuild;
  655. cmSystemTools::ConvertToUnixSlashes(path);
  656. // adjust the cmake instance
  657. m_CMakeInstance->SetHomeOutputDirectory(m_WhereBuild);
  658. m_CMakeInstance->SetStartOutputDirectory(m_WhereBuild);
  659. std::string cache_file = path;
  660. cache_file += "/CMakeCache.txt";
  661. cmCacheManager *cachem = this->m_CMakeInstance->GetCacheManager();
  662. cmCacheManager::CacheIterator it = cachem->NewIterator();
  663. if (cmSystemTools::FileExists(cache_file.c_str()) &&
  664. cachem->LoadCache(path.c_str()) &&
  665. it.Find("CMAKE_HOME_DIRECTORY"))
  666. {
  667. path = ConvertToWindowsPath(it.GetValue());
  668. this->m_WhereSource = path.c_str();
  669. this->m_WhereSourceControl.SetWindowText(this->m_WhereSource);
  670. this->OnChangeWhereSource();
  671. }
  672. m_CacheEntriesList.RemoveAll();
  673. m_CacheEntriesList.ShowWindow(SW_SHOW);
  674. this->LoadCacheFromDiskToGUI();
  675. m_BuildPathChanged = true;
  676. }
  677. // copy from the cache manager to the cache edit list box
  678. void CMakeSetupDialog::FillCacheGUIFromCacheManager()
  679. {
  680. cmCacheManager *cachem = this->m_CMakeInstance->GetCacheManager();
  681. size_t size = m_CacheEntriesList.GetItems().size();
  682. bool reverseOrder = false;
  683. // if there are already entries in the cache, then
  684. // put the new ones in the top, so they show up first
  685. if(size)
  686. {
  687. reverseOrder = true;
  688. }
  689. // all the current values are not new any more
  690. std::set<CPropertyItem*> items = m_CacheEntriesList.GetItems();
  691. for(std::set<CPropertyItem*>::iterator i = items.begin();
  692. i != items.end(); ++i)
  693. {
  694. CPropertyItem* item = *i;
  695. item->m_NewValue = false;
  696. }
  697. for(cmCacheManager::CacheIterator i = cachem->NewIterator();
  698. !i.IsAtEnd(); i.Next())
  699. {
  700. const char* key = i.GetName();
  701. // if value has trailing space or tab, enclose it in single quotes
  702. // to enforce the fact that it has 'invisible' trailing stuff
  703. std::string value = i.GetValue();
  704. if (value.size() &&
  705. (value[value.size() - 1] == ' ' ||
  706. value[value.size() - 1] == '\t'))
  707. {
  708. value = '\'' + value + '\'';
  709. }
  710. if(!m_AdvancedValues)
  711. {
  712. if(i.GetPropertyAsBool("ADVANCED"))
  713. {
  714. m_CacheEntriesList.RemoveProperty(key);
  715. continue;
  716. }
  717. }
  718. switch(i.GetType() )
  719. {
  720. case cmCacheManager::BOOL:
  721. if(cmSystemTools::IsOn(value.c_str()))
  722. {
  723. m_CacheEntriesList.AddProperty(key,
  724. "ON",
  725. i.GetProperty("HELPSTRING"),
  726. CPropertyList::COMBO,"ON|OFF",
  727. reverseOrder
  728. );
  729. }
  730. else
  731. {
  732. m_CacheEntriesList.AddProperty(key,
  733. "OFF",
  734. i.GetProperty("HELPSTRING"),
  735. CPropertyList::COMBO,"ON|OFF",
  736. reverseOrder
  737. );
  738. }
  739. break;
  740. case cmCacheManager::PATH:
  741. m_CacheEntriesList.AddProperty(key,
  742. value.c_str(),
  743. i.GetProperty("HELPSTRING"),
  744. CPropertyList::PATH,"",
  745. reverseOrder
  746. );
  747. break;
  748. case cmCacheManager::FILEPATH:
  749. m_CacheEntriesList.AddProperty(key,
  750. value.c_str(),
  751. i.GetProperty("HELPSTRING"),
  752. CPropertyList::FILE,"",
  753. reverseOrder
  754. );
  755. break;
  756. case cmCacheManager::STRING:
  757. m_CacheEntriesList.AddProperty(key,
  758. value.c_str(),
  759. i.GetProperty("HELPSTRING"),
  760. CPropertyList::EDIT,"",
  761. reverseOrder
  762. );
  763. break;
  764. case cmCacheManager::INTERNAL:
  765. m_CacheEntriesList.RemoveProperty(key);
  766. break;
  767. }
  768. }
  769. m_OKButton.EnableWindow(false);
  770. if(cachem->GetSize() > 0 && !cmSystemTools::GetErrorOccuredFlag())
  771. {
  772. bool enable = true;
  773. items = m_CacheEntriesList.GetItems();
  774. for(std::set<CPropertyItem*>::iterator i = items.begin();
  775. i != items.end(); ++i)
  776. {
  777. CPropertyItem* item = *i;
  778. if(item->m_NewValue)
  779. {
  780. // if one new value then disable to OK button
  781. enable = false;
  782. break;
  783. }
  784. }
  785. if(enable)
  786. {
  787. m_OKButton.EnableWindow(true);
  788. }
  789. }
  790. // redraw the list
  791. m_CacheEntriesList.SetTopIndex(0);
  792. m_CacheEntriesList.Invalidate();
  793. }
  794. // copy from the list box to the cache manager
  795. void CMakeSetupDialog::FillCacheManagerFromCacheGUI()
  796. {
  797. cmCacheManager *cachem = this->m_CMakeInstance->GetCacheManager();
  798. std::set<CPropertyItem*> items = m_CacheEntriesList.GetItems();
  799. cmCacheManager::CacheIterator it = cachem->NewIterator();
  800. for(std::set<CPropertyItem*>::iterator i = items.begin();
  801. i != items.end(); ++i)
  802. {
  803. CPropertyItem* item = *i;
  804. if ( it.Find((const char*)item->m_propName) )
  805. {
  806. // if value is enclosed in single quotes ('foo') then remove them
  807. // they were used to enforce the fact that it had 'invisible'
  808. // trailing stuff
  809. if (item->m_curValue.GetLength() >= 2 &&
  810. item->m_curValue[0] == '\'' &&
  811. item->m_curValue[item->m_curValue.GetLength() - 1] == '\'')
  812. {
  813. it.SetValue(item->m_curValue.Mid(
  814. 1, item->m_curValue.GetLength() - 2));
  815. }
  816. else
  817. {
  818. it.SetValue(item->m_curValue);
  819. }
  820. }
  821. }
  822. }
  823. //! Load cache file from m_WhereBuild and display in GUI editor
  824. void CMakeSetupDialog::LoadCacheFromDiskToGUI()
  825. {
  826. cmCacheManager *cachem = this->m_CMakeInstance->GetCacheManager();
  827. if(m_WhereBuild != "")
  828. {
  829. cachem->LoadCache(m_WhereBuild);
  830. this->FillCacheGUIFromCacheManager();
  831. cmCacheManager::CacheIterator it =
  832. cachem->GetCacheIterator("CMAKE_GENERATOR");
  833. if(!it.IsAtEnd())
  834. {
  835. std::string curGen = it.GetValue();
  836. if(m_GeneratorChoiceString != curGen.c_str())
  837. {
  838. m_GeneratorChoiceString = curGen.c_str();
  839. this->UpdateData(FALSE);
  840. }
  841. }
  842. }
  843. }
  844. //! Save GUI values to cmCacheManager and then save to disk.
  845. void CMakeSetupDialog::SaveCacheFromGUI()
  846. {
  847. cmCacheManager *cachem = this->m_CMakeInstance->GetCacheManager();
  848. this->FillCacheManagerFromCacheGUI();
  849. if(m_WhereBuild != "")
  850. {
  851. cachem->SaveCache(m_WhereBuild);
  852. }
  853. }
  854. void CMakeSetupDialog::OnSize(UINT nType, int cx, int cy)
  855. {
  856. if (nType == SIZE_MINIMIZED)
  857. {
  858. CDialog::OnSize(nType, cx, cy);
  859. return;
  860. }
  861. if (m_oldCX == -1)
  862. {
  863. m_oldCX = cx;
  864. m_oldCY = cy;
  865. }
  866. int deltax = cx - m_oldCX;
  867. int deltay = cy - m_oldCY;
  868. m_oldCX = cx;
  869. m_oldCY = cy;
  870. CDialog::OnSize(nType, cx, cy);
  871. if (deltax == 0 && deltay == 0)
  872. {
  873. return;
  874. }
  875. if(m_CacheEntriesList.m_hWnd)
  876. {
  877. // get the original sizes/positions
  878. CRect cRect;
  879. m_AdvancedValuesControl.GetWindowRect(&cRect);
  880. this->ScreenToClient(&cRect);
  881. m_AdvancedValuesControl.SetWindowPos(&wndTop, cRect.left + deltax,
  882. cRect.top,
  883. 0, 0,
  884. SWP_NOCOPYBITS |
  885. SWP_NOSIZE | SWP_NOZORDER);
  886. m_BuildForLabel.GetWindowRect(&cRect);
  887. this->ScreenToClient(&cRect);
  888. m_BuildForLabel.SetWindowPos(&wndTop, cRect.left + deltax,
  889. cRect.top,
  890. 0, 0,
  891. SWP_NOCOPYBITS | SWP_NOSIZE | SWP_NOZORDER);
  892. m_GeneratorChoice.GetWindowRect(&cRect);
  893. this->ScreenToClient(&cRect);
  894. m_GeneratorChoice.SetWindowPos(&wndTop, cRect.left + deltax,
  895. cRect.top,
  896. 0, 0,
  897. SWP_NOCOPYBITS | SWP_NOSIZE | SWP_NOZORDER);
  898. m_BrowseSource.GetWindowRect(&cRect);
  899. this->ScreenToClient(&cRect);
  900. m_BrowseSource.SetWindowPos(&wndTop, cRect.left + deltax,
  901. cRect.top,
  902. 0, 0,
  903. SWP_NOCOPYBITS | SWP_NOSIZE | SWP_NOZORDER);
  904. m_BrowseBuild.GetWindowRect(&cRect);
  905. this->ScreenToClient(&cRect);
  906. m_BrowseBuild.SetWindowPos(&wndTop, cRect.left + deltax,
  907. cRect.top,
  908. 0, 0,
  909. SWP_NOCOPYBITS | SWP_NOSIZE | SWP_NOZORDER);
  910. m_WhereSourceControl.GetWindowRect(&cRect);
  911. m_WhereSourceControl.SetWindowPos(&wndTop, cRect.left, cRect.top,
  912. cRect.Width() + deltax,
  913. cRect.Height(),
  914. SWP_NOCOPYBITS |
  915. SWP_NOMOVE | SWP_NOZORDER);
  916. m_WhereBuildControl.GetWindowRect(&cRect);
  917. m_WhereBuildControl.SetWindowPos(&wndTop, cRect.left, cRect.top,
  918. cRect.Width() + deltax,
  919. cRect.Height(),
  920. SWP_NOCOPYBITS |
  921. SWP_NOMOVE | SWP_NOZORDER);
  922. m_ListFrame.GetWindowRect(&cRect);
  923. m_ListFrame.SetWindowPos(&wndTop, cRect.left, cRect.top,
  924. cRect.Width() + deltax,
  925. cRect.Height() + deltay,
  926. SWP_NOCOPYBITS | SWP_NOMOVE | SWP_NOZORDER);
  927. m_CacheEntriesList.GetWindowRect(&cRect);
  928. m_CacheEntriesList.SetWindowPos(&wndTop, cRect.left, cRect.top,
  929. cRect.Width() + deltax,
  930. cRect.Height() + deltay,
  931. SWP_NOCOPYBITS | SWP_NOMOVE | SWP_NOZORDER);
  932. m_StatusDisplay.GetWindowRect(&cRect);
  933. this->ScreenToClient(&cRect);
  934. m_StatusDisplay.SetWindowPos(&wndBottom, cRect.left,
  935. cRect.top + deltay,
  936. cRect.Width() + deltax, cRect.Height(),
  937. SWP_NOCOPYBITS);
  938. m_MouseHelp.GetWindowRect(&cRect);
  939. this->ScreenToClient(&cRect);
  940. m_MouseHelp.SetWindowPos(&wndTop, cRect.left ,
  941. cRect.top + deltay,
  942. cRect.Width() + deltax, cRect.Height(),
  943. SWP_NOCOPYBITS | SWP_NOZORDER);
  944. deltax = int(deltax + m_deltaXRemainder);
  945. m_deltaXRemainder = float(deltax%2);
  946. m_Configure.GetWindowRect(&cRect);
  947. this->ScreenToClient(&cRect);
  948. m_Configure.SetWindowPos(&wndTop, cRect.left + deltax/2,
  949. cRect.top + deltay,
  950. 0, 0,
  951. SWP_NOCOPYBITS | SWP_NOSIZE);
  952. m_CancelButton.GetWindowRect(&cRect);
  953. this->ScreenToClient(&cRect);
  954. m_CancelButton.SetWindowPos(&wndTop, cRect.left + deltax/2,
  955. cRect.top + deltay,
  956. 0, 0,
  957. SWP_NOCOPYBITS | SWP_NOSIZE);
  958. m_OKButton.GetWindowRect(&cRect);
  959. this->ScreenToClient(&cRect);
  960. m_OKButton.SetWindowPos(&wndTop, cRect.left + deltax/2,
  961. cRect.top + deltay,
  962. 0, 0,
  963. SWP_NOCOPYBITS | SWP_NOSIZE);
  964. m_HelpButton.GetWindowRect(&cRect);
  965. this->ScreenToClient(&cRect);
  966. m_HelpButton.SetWindowPos(&wndTop, cRect.left + deltax/2,
  967. cRect.top + deltay,
  968. 0, 0,
  969. SWP_NOCOPYBITS | SWP_NOSIZE);
  970. }
  971. }
  972. void CMakeSetupDialog::OnGetMinMaxInfo( MINMAXINFO FAR* lpMMI )
  973. {
  974. lpMMI->ptMinTrackSize.x = 550;
  975. lpMMI->ptMinTrackSize.y = 272;
  976. }
  977. void CMakeSetupDialog::OnCancel()
  978. {
  979. if(m_RunningConfigure)
  980. {
  981. if(MessageBox("You are in the middle of a Configure.\n"
  982. "If you Cancel now the configure information will be lost.\n"
  983. "Are you sure you want to Cancel?", "Confirm Exit",
  984. MB_YESNO) == IDYES)
  985. {
  986. cmSystemTools::SetFatalErrorOccured();
  987. }
  988. return;
  989. }
  990. if(m_CacheEntriesList.IsDirty())
  991. {
  992. if(MessageBox("You have changed options but not rebuilt, "
  993. "are you sure you want to exit?", "Confirm Exit",
  994. MB_YESNO) == IDYES)
  995. {
  996. CDialog::OnOK();
  997. }
  998. }
  999. else
  1000. {
  1001. CDialog::OnOK();
  1002. }
  1003. }
  1004. void CMakeSetupDialog::OnOk()
  1005. {
  1006. // enable error messages each time configure is pressed
  1007. cmSystemTools::EnableMessages();
  1008. m_CacheEntriesList.ClearDirty();
  1009. this->RunCMake(true);
  1010. if (!(::GetKeyState(VK_SHIFT) & 0x1000))
  1011. {
  1012. CDialog::OnOK();
  1013. }
  1014. }
  1015. void CMakeSetupDialog::OnEditchangeGenerator()
  1016. {
  1017. // TODO: Add your control notification handler code here
  1018. }
  1019. // Create a shortcut on the desktop with the current Source/Build dir.
  1020. int CMakeSetupDialog::CreateShortcut()
  1021. {
  1022. // Find the desktop folder and create the link name
  1023. HKEY hKey;
  1024. if(RegOpenKeyEx(HKEY_CURRENT_USER,
  1025. "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders",
  1026. 0, KEY_READ, &hKey) != ERROR_SUCCESS)
  1027. {
  1028. AfxMessageBox ("Create shortcut: unable to find 'Shell Folders' key in registry!");
  1029. return 1;
  1030. }
  1031. DWORD dwType, dwSize;
  1032. #define MAXPATH 1024
  1033. char link_name[MAXPATH];
  1034. dwSize = MAXPATH;
  1035. if(RegQueryValueEx(hKey,
  1036. (LPCTSTR)"Desktop",
  1037. NULL,
  1038. &dwType,
  1039. (BYTE *)link_name,
  1040. &dwSize) != ERROR_SUCCESS)
  1041. {
  1042. AfxMessageBox ("Create shortcut: unable to find 'Desktop' registry value in 'Shell Folders' key!");
  1043. return 1;
  1044. }
  1045. if(dwType != REG_SZ)
  1046. {
  1047. AfxMessageBox ("Create shortcut: 'Desktop' registry value in 'Shell Folders' key has wrong type!");
  1048. return 1;
  1049. }
  1050. strcat(link_name, "\\CMake - ");
  1051. std::string current_dir = cmSystemTools::GetFilenameName((LPCTSTR)m_WhereSource);
  1052. strcat(link_name, current_dir.c_str());
  1053. strcat(link_name, ".lnk");
  1054. // Find the path to the current executable
  1055. char path_to_current_exe[MAXPATH];
  1056. ::GetModuleFileName(NULL, path_to_current_exe, MAXPATH);
  1057. // Create the shortcut
  1058. HRESULT hres;
  1059. IShellLink *psl;
  1060. // Initialize the COM library
  1061. hres = CoInitialize(NULL);
  1062. if (! SUCCEEDED (hres))
  1063. {
  1064. AfxMessageBox ("Create shortcut: unable to initialize the COM library!");
  1065. return 1;
  1066. }
  1067. // Create an IShellLink object and get a pointer to the IShellLink
  1068. // interface (returned from CoCreateInstance).
  1069. hres = CoCreateInstance(CLSID_ShellLink,
  1070. NULL,
  1071. CLSCTX_INPROC_SERVER,
  1072. IID_IShellLink,
  1073. (void **)&psl);
  1074. if (! SUCCEEDED (hres))
  1075. {
  1076. AfxMessageBox ("Create shortcut: unable to create IShellLink instance!");
  1077. return 1;
  1078. }
  1079. IPersistFile *ppf;
  1080. // Query IShellLink for the IPersistFile interface for
  1081. // saving the shortcut in persistent storage.
  1082. hres = psl->QueryInterface(IID_IPersistFile, (void **)&ppf);
  1083. if (SUCCEEDED (hres))
  1084. {
  1085. // Set the path to the shortcut target.
  1086. hres = psl->SetPath(path_to_current_exe);
  1087. if (! SUCCEEDED (hres))
  1088. {
  1089. AfxMessageBox ("Create shortcut: SetPath failed!");
  1090. }
  1091. // Set the arguments of the shortcut.
  1092. CString args = " /H=\"" + m_WhereSource + "\" /B=\"" + m_WhereBuild + "\" /G=\"" + m_GeneratorChoiceString + "\" /A=\"" + (m_AdvancedValues ? "TRUE" : "FALSE") + "\"";
  1093. hres = psl->SetArguments(args);
  1094. if (! SUCCEEDED (hres))
  1095. {
  1096. AfxMessageBox ("Create shortcut: SetArguments failed!");
  1097. }
  1098. // Set the description of the shortcut.
  1099. hres = psl->SetDescription("Shortcut to CMakeSetup");
  1100. if (! SUCCEEDED (hres))
  1101. {
  1102. AfxMessageBox ("Create shortcut: SetDescription failed!");
  1103. }
  1104. // Ensure that the string consists of ANSI characters.
  1105. WORD wsz[MAX_PATH];
  1106. MultiByteToWideChar(CP_ACP, 0, link_name, -1, wsz, MAX_PATH);
  1107. // Save the shortcut via the IPersistFile::Save member function.
  1108. hres = ppf->Save(wsz, TRUE);
  1109. if (! SUCCEEDED (hres))
  1110. {
  1111. AfxMessageBox ("Create shortcut: Save failed!");
  1112. }
  1113. // Release the pointer to IPersistFile.
  1114. ppf->Release ();
  1115. }
  1116. // Release the pointer to IShellLink.
  1117. psl->Release ();
  1118. return 0;
  1119. }
  1120. void CMakeSetupDialog::OnHelpButton()
  1121. {
  1122. CMakeHelp dialog;
  1123. dialog.DoModal();
  1124. }
  1125. void CMakeSetupDialog::ShowAdvancedValues()
  1126. {
  1127. cmCacheManager *cachem = this->m_CMakeInstance->GetCacheManager();
  1128. for(cmCacheManager::CacheIterator i = cachem->NewIterator();
  1129. !i.IsAtEnd(); i.Next())
  1130. {
  1131. const char* key = i.GetName();
  1132. if(!i.GetPropertyAsBool("ADVANCED"))
  1133. {
  1134. continue;
  1135. }
  1136. switch(i.GetType() )
  1137. {
  1138. case cmCacheManager::BOOL:
  1139. if(cmSystemTools::IsOn(i.GetValue()))
  1140. {
  1141. m_CacheEntriesList.AddProperty(key,
  1142. "ON",
  1143. i.GetProperty("HELPSTRING"),
  1144. CPropertyList::COMBO,"ON|OFF",
  1145. true
  1146. );
  1147. }
  1148. else
  1149. {
  1150. m_CacheEntriesList.AddProperty(key,
  1151. "OFF",
  1152. i.GetProperty("HELPSTRING"),
  1153. CPropertyList::COMBO,"ON|OFF",
  1154. true
  1155. );
  1156. }
  1157. break;
  1158. case cmCacheManager::PATH:
  1159. m_CacheEntriesList.AddProperty(key,
  1160. i.GetValue(),
  1161. i.GetProperty("HELPSTRING"),
  1162. CPropertyList::PATH,"",
  1163. true
  1164. );
  1165. break;
  1166. case cmCacheManager::FILEPATH:
  1167. m_CacheEntriesList.AddProperty(key,
  1168. i.GetValue(),
  1169. i.GetProperty("HELPSTRING"),
  1170. CPropertyList::FILE,"",
  1171. true
  1172. );
  1173. break;
  1174. case cmCacheManager::STRING:
  1175. m_CacheEntriesList.AddProperty(key,
  1176. i.GetValue(),
  1177. i.GetProperty("HELPSTRING"),
  1178. CPropertyList::EDIT,"",
  1179. true
  1180. );
  1181. break;
  1182. case cmCacheManager::INTERNAL:
  1183. m_CacheEntriesList.RemoveProperty(key);
  1184. break;
  1185. }
  1186. }
  1187. }
  1188. void CMakeSetupDialog::RemoveAdvancedValues()
  1189. {
  1190. cmCacheManager *cachem = this->m_CMakeInstance->GetCacheManager();
  1191. for(cmCacheManager::CacheIterator i = cachem->NewIterator();
  1192. !i.IsAtEnd(); i.Next())
  1193. {
  1194. const char* key = i.GetName();
  1195. if(i.GetPropertyAsBool("ADVANCED"))
  1196. {
  1197. m_CacheEntriesList.RemoveProperty(key);
  1198. }
  1199. }
  1200. }
  1201. void CMakeSetupDialog::OnAdvancedValues()
  1202. {
  1203. this->UpdateData();
  1204. if(m_AdvancedValues)
  1205. {
  1206. this->ShowAdvancedValues();
  1207. }
  1208. else
  1209. {
  1210. this->RemoveAdvancedValues();
  1211. }
  1212. }
  1213. void CMakeSetupDialog::OnDoubleclickedAdvancedValues()
  1214. {
  1215. this->OnAdvancedValues();
  1216. }
  1217. // Handle param or single dropped file.
  1218. // If the dropped file is a build directory or any file in a
  1219. // build directory, set the source dir from the cache file,
  1220. // otherwise set the source and build dirs to this file (or dir).
  1221. void CMakeSetupDialog::ChangeDirectoriesFromFile(const char* buffer)
  1222. {
  1223. // Get the path to this file
  1224. std::string path = buffer;
  1225. if (!cmSystemTools::FileIsDirectory(path.c_str()))
  1226. {
  1227. path = cmSystemTools::GetFilenamePath(path);
  1228. }
  1229. else
  1230. {
  1231. cmSystemTools::ConvertToUnixSlashes(path);
  1232. }
  1233. // Check if it's a build dir and grab the cache
  1234. std::string cache_file = path;
  1235. cache_file += "/CMakeCache.txt";
  1236. cmCacheManager *cachem = this->m_CMakeInstance->GetCacheManager();
  1237. cmCacheManager::CacheIterator it =
  1238. cachem->NewIterator();
  1239. if (cmSystemTools::FileExists(cache_file.c_str()) &&
  1240. cachem->LoadCache(path.c_str()) &&
  1241. it.Find("CMAKE_HOME_DIRECTORY"))
  1242. {
  1243. path = ConvertToWindowsPath(path.c_str());
  1244. this->m_WhereBuild = path.c_str();
  1245. path = ConvertToWindowsPath(it.GetValue());
  1246. this->m_WhereSource = path.c_str();
  1247. }
  1248. else
  1249. {
  1250. path = ConvertToWindowsPath(path.c_str());
  1251. this->m_WhereSource = this->m_WhereBuild = path.c_str();
  1252. }
  1253. }
  1254. // The framework calls this member function when the user releases the
  1255. // left mouse button over a window that has registered itself as the
  1256. // recipient of dropped files.
  1257. void CMakeSetupDialog::OnDropFiles(HDROP hDropInfo)
  1258. {
  1259. UINT nb_files = DragQueryFile(hDropInfo, 0xFFFFFFFF, NULL, 0);
  1260. if (nb_files > 0)
  1261. {
  1262. UINT buffer_size = DragQueryFile(hDropInfo, 0, NULL, 0);
  1263. char *buffer = new char [buffer_size + 1];
  1264. DragQueryFile(hDropInfo, 0, buffer, buffer_size + 1);
  1265. this->ChangeDirectoriesFromFile(buffer);
  1266. delete [] buffer;
  1267. this->m_WhereSourceControl.SetWindowText(this->m_WhereSource);
  1268. this->m_WhereBuildControl.SetWindowText(this->m_WhereBuild);
  1269. this->UpdateData(FALSE);
  1270. this->OnChangeWhereSource();
  1271. this->OnChangeWhereBuild();
  1272. }
  1273. DragFinish(hDropInfo);
  1274. }
  1275. BOOL CMakeSetupDialog::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
  1276. {
  1277. ::SetCursor(m_Cursor);
  1278. return true;
  1279. }