CMakeSetupDialog.cpp 42 KB

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