CMakeSetupDialog.cpp 40 KB

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