CMakeSetupDialog.cpp 41 KB

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