1
0

CMakeSetupDialog.cpp 43 KB

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