1
0

CMakeSetupDialog.cpp 36 KB

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