CMakeSetupDialog.cpp 43 KB

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