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