CMakeSetupDialog.cpp 44 KB

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