CMakeSetupDialog.cpp 42 KB

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