CMakeSetupDialog.cpp 41 KB

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