CMakeSetupDialog.cpp 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488
  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. bool reverseOrder = false;
  686. // if there are already entries in the cache, then
  687. // put the new ones in the top, so they show up first
  688. if(size)
  689. {
  690. reverseOrder = true;
  691. }
  692. // all the current values are not new any more
  693. std::set<CPropertyItem*> items = m_CacheEntriesList.GetItems();
  694. for(std::set<CPropertyItem*>::iterator i = items.begin();
  695. i != items.end(); ++i)
  696. {
  697. CPropertyItem* item = *i;
  698. item->m_NewValue = false;
  699. }
  700. for(cmCacheManager::CacheIterator i = cachem->NewIterator();
  701. !i.IsAtEnd(); i.Next())
  702. {
  703. const char* key = i.GetName();
  704. // if value has trailing space or tab, enclose it in single quotes
  705. // to enforce the fact that it has 'invisible' trailing stuff
  706. std::string value = i.GetValue();
  707. if (value.size() &&
  708. (value[value.size() - 1] == ' ' ||
  709. value[value.size() - 1] == '\t'))
  710. {
  711. value = '\'' + value + '\'';
  712. }
  713. if(!m_AdvancedValues)
  714. {
  715. if(i.GetPropertyAsBool("ADVANCED"))
  716. {
  717. m_CacheEntriesList.RemoveProperty(key);
  718. continue;
  719. }
  720. }
  721. switch(i.GetType() )
  722. {
  723. case cmCacheManager::BOOL:
  724. if(cmSystemTools::IsOn(value.c_str()))
  725. {
  726. m_CacheEntriesList.AddProperty(key,
  727. "ON",
  728. i.GetProperty("HELPSTRING"),
  729. CPropertyList::COMBO,"ON|OFF",
  730. reverseOrder
  731. );
  732. }
  733. else
  734. {
  735. m_CacheEntriesList.AddProperty(key,
  736. "OFF",
  737. i.GetProperty("HELPSTRING"),
  738. CPropertyList::COMBO,"ON|OFF",
  739. reverseOrder
  740. );
  741. }
  742. break;
  743. case cmCacheManager::PATH:
  744. m_CacheEntriesList.AddProperty(key,
  745. value.c_str(),
  746. i.GetProperty("HELPSTRING"),
  747. CPropertyList::PATH,"",
  748. reverseOrder
  749. );
  750. break;
  751. case cmCacheManager::FILEPATH:
  752. m_CacheEntriesList.AddProperty(key,
  753. value.c_str(),
  754. i.GetProperty("HELPSTRING"),
  755. CPropertyList::FILE,"",
  756. reverseOrder
  757. );
  758. break;
  759. case cmCacheManager::STRING:
  760. m_CacheEntriesList.AddProperty(key,
  761. value.c_str(),
  762. i.GetProperty("HELPSTRING"),
  763. CPropertyList::EDIT,"",
  764. reverseOrder
  765. );
  766. break;
  767. case cmCacheManager::INTERNAL:
  768. m_CacheEntriesList.RemoveProperty(key);
  769. break;
  770. }
  771. }
  772. m_OKButton.EnableWindow(false);
  773. if(cachem->GetSize() > 0 && !cmSystemTools::GetErrorOccuredFlag())
  774. {
  775. bool enable = true;
  776. items = m_CacheEntriesList.GetItems();
  777. for(std::set<CPropertyItem*>::iterator i = items.begin();
  778. i != items.end(); ++i)
  779. {
  780. CPropertyItem* item = *i;
  781. if(item->m_NewValue)
  782. {
  783. // if one new value then disable to OK button
  784. enable = false;
  785. break;
  786. }
  787. }
  788. if(enable)
  789. {
  790. m_OKButton.EnableWindow(true);
  791. }
  792. }
  793. // redraw the list
  794. m_CacheEntriesList.SetTopIndex(0);
  795. m_CacheEntriesList.Invalidate();
  796. }
  797. // copy from the list box to the cache manager
  798. void CMakeSetupDialog::FillCacheManagerFromCacheGUI()
  799. {
  800. cmCacheManager *cachem = this->m_CMakeInstance->GetCacheManager();
  801. std::set<CPropertyItem*> items = m_CacheEntriesList.GetItems();
  802. cmCacheManager::CacheIterator it = cachem->NewIterator();
  803. for(std::set<CPropertyItem*>::iterator i = items.begin();
  804. i != items.end(); ++i)
  805. {
  806. CPropertyItem* item = *i;
  807. if ( it.Find((const char*)item->m_propName) )
  808. {
  809. // if value is enclosed in single quotes ('foo') then remove them
  810. // they were used to enforce the fact that it had 'invisible'
  811. // trailing stuff
  812. if (item->m_curValue.GetLength() >= 2 &&
  813. item->m_curValue[0] == '\'' &&
  814. item->m_curValue[item->m_curValue.GetLength() - 1] == '\'')
  815. {
  816. it.SetValue(item->m_curValue.Mid(
  817. 1, item->m_curValue.GetLength() - 2));
  818. }
  819. else
  820. {
  821. it.SetValue(item->m_curValue);
  822. }
  823. }
  824. }
  825. }
  826. //! Load cache file from m_WhereBuild and display in GUI editor
  827. void CMakeSetupDialog::LoadCacheFromDiskToGUI()
  828. {
  829. cmCacheManager *cachem = this->m_CMakeInstance->GetCacheManager();
  830. if(m_WhereBuild != "")
  831. {
  832. cachem->LoadCache(m_WhereBuild);
  833. this->FillCacheGUIFromCacheManager();
  834. cmCacheManager::CacheIterator it =
  835. cachem->GetCacheIterator("CMAKE_GENERATOR");
  836. if(!it.IsAtEnd())
  837. {
  838. std::string curGen = it.GetValue();
  839. if(m_GeneratorChoiceString != curGen.c_str())
  840. {
  841. m_GeneratorChoiceString = curGen.c_str();
  842. this->UpdateData(FALSE);
  843. }
  844. }
  845. }
  846. }
  847. //! Save GUI values to cmCacheManager and then save to disk.
  848. void CMakeSetupDialog::SaveCacheFromGUI()
  849. {
  850. cmCacheManager *cachem = this->m_CMakeInstance->GetCacheManager();
  851. this->FillCacheManagerFromCacheGUI();
  852. if(m_WhereBuild != "")
  853. {
  854. cachem->SaveCache(m_WhereBuild);
  855. }
  856. }
  857. void CMakeSetupDialog::OnSize(UINT nType, int cx, int cy)
  858. {
  859. if (nType == SIZE_MINIMIZED)
  860. {
  861. CDialog::OnSize(nType, cx, cy);
  862. return;
  863. }
  864. if (m_oldCX == -1)
  865. {
  866. m_oldCX = cx;
  867. m_oldCY = cy;
  868. }
  869. int deltax = cx - m_oldCX;
  870. int deltay = cy - m_oldCY;
  871. m_oldCX = cx;
  872. m_oldCY = cy;
  873. CDialog::OnSize(nType, cx, cy);
  874. if (deltax == 0 && deltay == 0)
  875. {
  876. return;
  877. }
  878. if(m_CacheEntriesList.m_hWnd)
  879. {
  880. // get the original sizes/positions
  881. CRect cRect;
  882. m_AdvancedValuesControl.GetWindowRect(&cRect);
  883. this->ScreenToClient(&cRect);
  884. m_AdvancedValuesControl.SetWindowPos(&wndTop, cRect.left + deltax,
  885. cRect.top,
  886. 0, 0,
  887. SWP_NOCOPYBITS |
  888. SWP_NOSIZE | SWP_NOZORDER);
  889. m_BuildForLabel.GetWindowRect(&cRect);
  890. this->ScreenToClient(&cRect);
  891. m_BuildForLabel.SetWindowPos(&wndTop, cRect.left + deltax,
  892. cRect.top,
  893. 0, 0,
  894. SWP_NOCOPYBITS | SWP_NOSIZE | SWP_NOZORDER);
  895. m_GeneratorChoice.GetWindowRect(&cRect);
  896. this->ScreenToClient(&cRect);
  897. m_GeneratorChoice.SetWindowPos(&wndTop, cRect.left + deltax,
  898. cRect.top,
  899. 0, 0,
  900. SWP_NOCOPYBITS | SWP_NOSIZE | SWP_NOZORDER);
  901. m_BrowseSource.GetWindowRect(&cRect);
  902. this->ScreenToClient(&cRect);
  903. m_BrowseSource.SetWindowPos(&wndTop, cRect.left + deltax,
  904. cRect.top,
  905. 0, 0,
  906. SWP_NOCOPYBITS | SWP_NOSIZE | SWP_NOZORDER);
  907. m_BrowseBuild.GetWindowRect(&cRect);
  908. this->ScreenToClient(&cRect);
  909. m_BrowseBuild.SetWindowPos(&wndTop, cRect.left + deltax,
  910. cRect.top,
  911. 0, 0,
  912. SWP_NOCOPYBITS | SWP_NOSIZE | SWP_NOZORDER);
  913. m_WhereSourceControl.GetWindowRect(&cRect);
  914. m_WhereSourceControl.SetWindowPos(&wndTop, cRect.left, cRect.top,
  915. cRect.Width() + deltax,
  916. cRect.Height(),
  917. SWP_NOCOPYBITS |
  918. SWP_NOMOVE | SWP_NOZORDER);
  919. m_WhereBuildControl.GetWindowRect(&cRect);
  920. m_WhereBuildControl.SetWindowPos(&wndTop, cRect.left, cRect.top,
  921. cRect.Width() + deltax,
  922. cRect.Height(),
  923. SWP_NOCOPYBITS |
  924. SWP_NOMOVE | SWP_NOZORDER);
  925. m_ListFrame.GetWindowRect(&cRect);
  926. m_ListFrame.SetWindowPos(&wndTop, cRect.left, cRect.top,
  927. cRect.Width() + deltax,
  928. cRect.Height() + deltay,
  929. SWP_NOCOPYBITS | SWP_NOMOVE | SWP_NOZORDER);
  930. m_CacheEntriesList.GetWindowRect(&cRect);
  931. m_CacheEntriesList.SetWindowPos(&wndTop, cRect.left, cRect.top,
  932. cRect.Width() + deltax,
  933. cRect.Height() + deltay,
  934. SWP_NOCOPYBITS | SWP_NOMOVE | SWP_NOZORDER);
  935. m_StatusDisplay.GetWindowRect(&cRect);
  936. this->ScreenToClient(&cRect);
  937. m_StatusDisplay.SetWindowPos(&wndBottom, cRect.left,
  938. cRect.top + deltay,
  939. cRect.Width() + deltax, cRect.Height(),
  940. SWP_NOCOPYBITS);
  941. m_MouseHelp.GetWindowRect(&cRect);
  942. this->ScreenToClient(&cRect);
  943. m_MouseHelp.SetWindowPos(&wndTop, cRect.left ,
  944. cRect.top + deltay,
  945. cRect.Width() + deltax, cRect.Height(),
  946. SWP_NOCOPYBITS | SWP_NOZORDER);
  947. deltax = int(deltax + m_deltaXRemainder);
  948. m_deltaXRemainder = float(deltax%2);
  949. m_Configure.GetWindowRect(&cRect);
  950. this->ScreenToClient(&cRect);
  951. m_Configure.SetWindowPos(&wndTop, cRect.left + deltax/2,
  952. cRect.top + deltay,
  953. 0, 0,
  954. SWP_NOCOPYBITS | SWP_NOSIZE);
  955. m_CancelButton.GetWindowRect(&cRect);
  956. this->ScreenToClient(&cRect);
  957. m_CancelButton.SetWindowPos(&wndTop, cRect.left + deltax/2,
  958. cRect.top + deltay,
  959. 0, 0,
  960. SWP_NOCOPYBITS | SWP_NOSIZE);
  961. m_OKButton.GetWindowRect(&cRect);
  962. this->ScreenToClient(&cRect);
  963. m_OKButton.SetWindowPos(&wndTop, cRect.left + deltax/2,
  964. cRect.top + deltay,
  965. 0, 0,
  966. SWP_NOCOPYBITS | SWP_NOSIZE);
  967. m_HelpButton.GetWindowRect(&cRect);
  968. this->ScreenToClient(&cRect);
  969. m_HelpButton.SetWindowPos(&wndTop, cRect.left + deltax/2,
  970. cRect.top + deltay,
  971. 0, 0,
  972. SWP_NOCOPYBITS | SWP_NOSIZE);
  973. }
  974. }
  975. void CMakeSetupDialog::OnGetMinMaxInfo( MINMAXINFO FAR* lpMMI )
  976. {
  977. lpMMI->ptMinTrackSize.x = 550;
  978. lpMMI->ptMinTrackSize.y = 272;
  979. }
  980. void CMakeSetupDialog::OnCancel()
  981. {
  982. if(m_RunningConfigure)
  983. {
  984. if(MessageBox("You are in the middle of a Configure.\n"
  985. "If you Cancel now the configure information will be lost.\n"
  986. "Are you sure you want to Cancel?", "Confirm Exit",
  987. MB_YESNO) == IDYES)
  988. {
  989. cmSystemTools::SetFatalErrorOccured();
  990. }
  991. return;
  992. }
  993. if(m_CacheEntriesList.IsDirty())
  994. {
  995. if(MessageBox("You have changed options but not rebuilt, "
  996. "are you sure you want to exit?", "Confirm Exit",
  997. MB_YESNO) == IDYES)
  998. {
  999. CDialog::OnOK();
  1000. }
  1001. }
  1002. else
  1003. {
  1004. CDialog::OnOK();
  1005. }
  1006. }
  1007. void CMakeSetupDialog::OnOk()
  1008. {
  1009. // enable error messages each time configure is pressed
  1010. cmSystemTools::EnableMessages();
  1011. m_CacheEntriesList.ClearDirty();
  1012. this->RunCMake(true);
  1013. if (!(::GetKeyState(VK_SHIFT) & 0x1000))
  1014. {
  1015. CDialog::OnOK();
  1016. }
  1017. }
  1018. void CMakeSetupDialog::OnEditchangeGenerator()
  1019. {
  1020. // TODO: Add your control notification handler code here
  1021. }
  1022. // Create a shortcut on the desktop with the current Source/Build dir.
  1023. int CMakeSetupDialog::CreateShortcut()
  1024. {
  1025. // Find the desktop folder and create the link name
  1026. HKEY hKey;
  1027. if(RegOpenKeyEx(HKEY_CURRENT_USER,
  1028. "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders",
  1029. 0, KEY_READ, &hKey) != ERROR_SUCCESS)
  1030. {
  1031. AfxMessageBox ("Create shortcut: unable to find 'Shell Folders' key in registry!");
  1032. return 1;
  1033. }
  1034. DWORD dwType, dwSize;
  1035. #define MAXPATH 1024
  1036. char link_name[MAXPATH];
  1037. dwSize = MAXPATH;
  1038. if(RegQueryValueEx(hKey,
  1039. (LPCTSTR)"Desktop",
  1040. NULL,
  1041. &dwType,
  1042. (BYTE *)link_name,
  1043. &dwSize) != ERROR_SUCCESS)
  1044. {
  1045. AfxMessageBox ("Create shortcut: unable to find 'Desktop' registry value in 'Shell Folders' key!");
  1046. return 1;
  1047. }
  1048. if(dwType != REG_SZ)
  1049. {
  1050. AfxMessageBox ("Create shortcut: 'Desktop' registry value in 'Shell Folders' key has wrong type!");
  1051. return 1;
  1052. }
  1053. strcat(link_name, "\\CMake - ");
  1054. std::string current_dir = cmSystemTools::GetFilenameName((LPCTSTR)m_WhereSource);
  1055. strcat(link_name, current_dir.c_str());
  1056. strcat(link_name, ".lnk");
  1057. // Find the path to the current executable
  1058. char path_to_current_exe[MAXPATH];
  1059. ::GetModuleFileName(NULL, path_to_current_exe, MAXPATH);
  1060. // Create the shortcut
  1061. HRESULT hres;
  1062. IShellLink *psl;
  1063. // Initialize the COM library
  1064. hres = CoInitialize(NULL);
  1065. if (! SUCCEEDED (hres))
  1066. {
  1067. AfxMessageBox ("Create shortcut: unable to initialize the COM library!");
  1068. return 1;
  1069. }
  1070. // Create an IShellLink object and get a pointer to the IShellLink
  1071. // interface (returned from CoCreateInstance).
  1072. hres = CoCreateInstance(CLSID_ShellLink,
  1073. NULL,
  1074. CLSCTX_INPROC_SERVER,
  1075. IID_IShellLink,
  1076. (void **)&psl);
  1077. if (! SUCCEEDED (hres))
  1078. {
  1079. AfxMessageBox ("Create shortcut: unable to create IShellLink instance!");
  1080. return 1;
  1081. }
  1082. IPersistFile *ppf;
  1083. // Query IShellLink for the IPersistFile interface for
  1084. // saving the shortcut in persistent storage.
  1085. hres = psl->QueryInterface(IID_IPersistFile, (void **)&ppf);
  1086. if (SUCCEEDED (hres))
  1087. {
  1088. // Set the path to the shortcut target.
  1089. hres = psl->SetPath(path_to_current_exe);
  1090. if (! SUCCEEDED (hres))
  1091. {
  1092. AfxMessageBox ("Create shortcut: SetPath failed!");
  1093. }
  1094. // Set the arguments of the shortcut.
  1095. CString args = " /H=\"" + m_WhereSource + "\" /B=\"" + m_WhereBuild + "\" /G=\"" + m_GeneratorChoiceString + "\" /A=\"" + (m_AdvancedValues ? "TRUE" : "FALSE") + "\"";
  1096. hres = psl->SetArguments(args);
  1097. if (! SUCCEEDED (hres))
  1098. {
  1099. AfxMessageBox ("Create shortcut: SetArguments failed!");
  1100. }
  1101. // Set the description of the shortcut.
  1102. hres = psl->SetDescription("Shortcut to CMakeSetup");
  1103. if (! SUCCEEDED (hres))
  1104. {
  1105. AfxMessageBox ("Create shortcut: SetDescription failed!");
  1106. }
  1107. // Ensure that the string consists of ANSI characters.
  1108. WORD wsz[MAX_PATH];
  1109. MultiByteToWideChar(CP_ACP, 0, link_name, -1, wsz, MAX_PATH);
  1110. // Save the shortcut via the IPersistFile::Save member function.
  1111. hres = ppf->Save(wsz, TRUE);
  1112. if (! SUCCEEDED (hres))
  1113. {
  1114. AfxMessageBox ("Create shortcut: Save failed!");
  1115. }
  1116. // Release the pointer to IPersistFile.
  1117. ppf->Release ();
  1118. }
  1119. // Release the pointer to IShellLink.
  1120. psl->Release ();
  1121. return 0;
  1122. }
  1123. void CMakeSetupDialog::OnHelpButton()
  1124. {
  1125. CMakeHelp dialog;
  1126. dialog.DoModal();
  1127. }
  1128. void CMakeSetupDialog::ShowAdvancedValues()
  1129. {
  1130. cmCacheManager *cachem = this->m_CMakeInstance->GetCacheManager();
  1131. for(cmCacheManager::CacheIterator i = cachem->NewIterator();
  1132. !i.IsAtEnd(); i.Next())
  1133. {
  1134. const char* key = i.GetName();
  1135. if(!i.GetPropertyAsBool("ADVANCED"))
  1136. {
  1137. continue;
  1138. }
  1139. switch(i.GetType() )
  1140. {
  1141. case cmCacheManager::BOOL:
  1142. if(cmSystemTools::IsOn(i.GetValue()))
  1143. {
  1144. m_CacheEntriesList.AddProperty(key,
  1145. "ON",
  1146. i.GetProperty("HELPSTRING"),
  1147. CPropertyList::COMBO,"ON|OFF",
  1148. true
  1149. );
  1150. }
  1151. else
  1152. {
  1153. m_CacheEntriesList.AddProperty(key,
  1154. "OFF",
  1155. i.GetProperty("HELPSTRING"),
  1156. CPropertyList::COMBO,"ON|OFF",
  1157. true
  1158. );
  1159. }
  1160. break;
  1161. case cmCacheManager::PATH:
  1162. m_CacheEntriesList.AddProperty(key,
  1163. i.GetValue(),
  1164. i.GetProperty("HELPSTRING"),
  1165. CPropertyList::PATH,"",
  1166. true
  1167. );
  1168. break;
  1169. case cmCacheManager::FILEPATH:
  1170. m_CacheEntriesList.AddProperty(key,
  1171. i.GetValue(),
  1172. i.GetProperty("HELPSTRING"),
  1173. CPropertyList::FILE,"",
  1174. true
  1175. );
  1176. break;
  1177. case cmCacheManager::STRING:
  1178. m_CacheEntriesList.AddProperty(key,
  1179. i.GetValue(),
  1180. i.GetProperty("HELPSTRING"),
  1181. CPropertyList::EDIT,"",
  1182. true
  1183. );
  1184. break;
  1185. case cmCacheManager::INTERNAL:
  1186. m_CacheEntriesList.RemoveProperty(key);
  1187. break;
  1188. }
  1189. }
  1190. }
  1191. void CMakeSetupDialog::RemoveAdvancedValues()
  1192. {
  1193. cmCacheManager *cachem = this->m_CMakeInstance->GetCacheManager();
  1194. for(cmCacheManager::CacheIterator i = cachem->NewIterator();
  1195. !i.IsAtEnd(); i.Next())
  1196. {
  1197. const char* key = i.GetName();
  1198. if(i.GetPropertyAsBool("ADVANCED"))
  1199. {
  1200. m_CacheEntriesList.RemoveProperty(key);
  1201. }
  1202. }
  1203. }
  1204. void CMakeSetupDialog::OnAdvancedValues()
  1205. {
  1206. this->UpdateData();
  1207. if(m_AdvancedValues)
  1208. {
  1209. this->ShowAdvancedValues();
  1210. }
  1211. else
  1212. {
  1213. this->RemoveAdvancedValues();
  1214. }
  1215. }
  1216. void CMakeSetupDialog::OnDoubleclickedAdvancedValues()
  1217. {
  1218. this->OnAdvancedValues();
  1219. }
  1220. // Handle param or single dropped file.
  1221. void CMakeSetupDialog::ChangeDirectoriesFromFile(const char* arg)
  1222. {
  1223. // Check if the argument refers to a CMakeCache.txt or
  1224. // CMakeLists.txt file.
  1225. std::string listPath;
  1226. std::string cachePath;
  1227. bool argIsFile = false;
  1228. if(cmSystemTools::FileIsDirectory(arg))
  1229. {
  1230. std::string path = cmSystemTools::CollapseFullPath(arg);
  1231. cmSystemTools::ConvertToUnixSlashes(path);
  1232. std::string cacheFile = path;
  1233. cacheFile += "/CMakeCache.txt";
  1234. std::string listFile = path;
  1235. listFile += "/CMakeLists.txt";
  1236. if(cmSystemTools::FileExists(cacheFile.c_str()))
  1237. {
  1238. cachePath = path;
  1239. }
  1240. if(cmSystemTools::FileExists(listFile.c_str()))
  1241. {
  1242. listPath = path;
  1243. }
  1244. }
  1245. else if(cmSystemTools::FileExists(arg))
  1246. {
  1247. argIsFile = true;
  1248. std::string fullPath = cmSystemTools::CollapseFullPath(arg);
  1249. std::string name = cmSystemTools::GetFilenameName(fullPath.c_str());
  1250. name = cmSystemTools::LowerCase(name);
  1251. if(name == "cmakecache.txt")
  1252. {
  1253. cachePath = cmSystemTools::GetFilenamePath(fullPath.c_str());
  1254. }
  1255. else if(name == "cmakelists.txt")
  1256. {
  1257. listPath = cmSystemTools::GetFilenamePath(fullPath.c_str());
  1258. }
  1259. }
  1260. // If there is a CMakeCache.txt file, use its settings.
  1261. if(cachePath.length() > 0)
  1262. {
  1263. cmCacheManager* cachem = m_CMakeInstance->GetCacheManager();
  1264. cmCacheManager::CacheIterator it = cachem->NewIterator();
  1265. if(cachem->LoadCache(cachePath.c_str()) && it.Find("CMAKE_HOME_DIRECTORY"))
  1266. {
  1267. std::string path = ConvertToWindowsPath(cachePath.c_str());
  1268. m_WhereBuild = path.c_str();
  1269. path = ConvertToWindowsPath(it.GetValue());
  1270. m_WhereSource = path.c_str();
  1271. m_GeneratorChoiceString = _T("");
  1272. return;
  1273. }
  1274. }
  1275. // If there is a CMakeLists.txt file, use it as the source tree.
  1276. if(listPath.length() > 0)
  1277. {
  1278. std::string path = ConvertToWindowsPath(listPath.c_str());
  1279. m_WhereSource = path.c_str();
  1280. if(argIsFile)
  1281. {
  1282. // Source CMakeLists.txt file given. It was probably dropped
  1283. // onto the window or executable. Default to an in-source
  1284. // build.
  1285. m_WhereBuild = path.c_str();
  1286. }
  1287. else
  1288. {
  1289. // Source directory given on command line. Use current working
  1290. // directory as build tree.
  1291. std::string cwd = cmSystemTools::GetCurrentWorkingDirectory();
  1292. path = ConvertToWindowsPath(cwd.c_str());
  1293. m_WhereBuild = path.c_str();
  1294. }
  1295. }
  1296. }
  1297. // The framework calls this member function when the user releases the
  1298. // left mouse button over a window that has registered itself as the
  1299. // recipient of dropped files.
  1300. void CMakeSetupDialog::OnDropFiles(HDROP hDropInfo)
  1301. {
  1302. UINT nb_files = DragQueryFile(hDropInfo, 0xFFFFFFFF, NULL, 0);
  1303. if (nb_files > 0)
  1304. {
  1305. UINT buffer_size = DragQueryFile(hDropInfo, 0, NULL, 0);
  1306. char *buffer = new char [buffer_size + 1];
  1307. DragQueryFile(hDropInfo, 0, buffer, buffer_size + 1);
  1308. this->ChangeDirectoriesFromFile(buffer);
  1309. delete [] buffer;
  1310. this->m_WhereSourceControl.SetWindowText(this->m_WhereSource);
  1311. this->m_WhereBuildControl.SetWindowText(this->m_WhereBuild);
  1312. this->UpdateData(FALSE);
  1313. this->OnChangeWhereSource();
  1314. this->OnChangeWhereBuild();
  1315. }
  1316. DragFinish(hDropInfo);
  1317. }
  1318. BOOL CMakeSetupDialog::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
  1319. {
  1320. ::SetCursor(m_Cursor);
  1321. return true;
  1322. }