CMakeSetupDialog.cpp 44 KB

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