CMakeSetupDialog.cpp 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311
  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. cmSystemTools::ResetErrorOccuredFlag();
  552. }
  553. // Callback for build projects button
  554. void CMakeSetupDialog::OnConfigure()
  555. {
  556. // enable error messages each time configure is pressed
  557. cmSystemTools::EnableMessages();
  558. this->RunCMake(false);
  559. }
  560. // callback for combo box menu where build selection
  561. void CMakeSetupDialog::OnSelendokWhereBuild()
  562. {
  563. m_WhereBuildControl.GetLBText(m_WhereBuildControl.GetCurSel(),
  564. m_WhereBuild);
  565. m_WhereBuildControl.SetWindowText( m_WhereBuild);
  566. this->UpdateData(FALSE);
  567. this->OnChangeWhereBuild();
  568. }
  569. // callback for combo box menu where source selection
  570. void CMakeSetupDialog::OnSelendokWhereSource()
  571. {
  572. m_WhereSourceControl.GetLBText(m_WhereSourceControl.GetCurSel(),
  573. m_WhereSource);
  574. this->UpdateData(FALSE);
  575. this->OnChangeWhereSource();
  576. }
  577. // callback for chaing source directory
  578. void CMakeSetupDialog::OnChangeWhereSource()
  579. {
  580. }
  581. // callback for changing the build directory
  582. void CMakeSetupDialog::OnChangeWhereBuild()
  583. {
  584. this->UpdateData();
  585. // The build dir has changed, check if there is a cache, and
  586. // grab the source dir from it
  587. std::string path = this->m_WhereBuild;
  588. cmSystemTools::ConvertToUnixSlashes(path);
  589. // adjust the cmake instance
  590. m_CMakeInstance->SetHomeOutputDirectory(m_WhereBuild);
  591. m_CMakeInstance->SetStartOutputDirectory(m_WhereBuild);
  592. std::string cache_file = path;
  593. cache_file += "/CMakeCache.txt";
  594. cmCacheManager *cachem = this->m_CMakeInstance->GetCacheManager();
  595. cmCacheManager::CacheIterator it = cachem->NewIterator();
  596. if (cmSystemTools::FileExists(cache_file.c_str()) &&
  597. cachem->LoadCache(path.c_str()) &&
  598. it.Find("CMAKE_HOME_DIRECTORY"))
  599. {
  600. path = ConvertToWindowsPath(it.GetValue());
  601. this->m_WhereSource = path.c_str();
  602. this->m_WhereSourceControl.SetWindowText(this->m_WhereSource);
  603. this->OnChangeWhereSource();
  604. }
  605. m_CacheEntriesList.RemoveAll();
  606. m_CacheEntriesList.ShowWindow(SW_SHOW);
  607. this->LoadCacheFromDiskToGUI();
  608. m_BuildPathChanged = true;
  609. }
  610. // copy from the cache manager to the cache edit list box
  611. void CMakeSetupDialog::FillCacheGUIFromCacheManager()
  612. {
  613. cmCacheManager *cachem = this->m_CMakeInstance->GetCacheManager();
  614. size_t size = m_CacheEntriesList.GetItems().size();
  615. bool reverseOrder = false;
  616. // if there are already entries in the cache, then
  617. // put the new ones in the top, so they show up first
  618. if(size)
  619. {
  620. reverseOrder = true;
  621. }
  622. // all the current values are not new any more
  623. std::set<CPropertyItem*> items = m_CacheEntriesList.GetItems();
  624. for(std::set<CPropertyItem*>::iterator i = items.begin();
  625. i != items.end(); ++i)
  626. {
  627. CPropertyItem* item = *i;
  628. item->m_NewValue = false;
  629. }
  630. for(cmCacheManager::CacheIterator i = cachem->NewIterator();
  631. !i.IsAtEnd(); i.Next())
  632. {
  633. const char* key = i.GetName();
  634. // if value has trailing space or tab, enclose it in single quotes
  635. // to enforce the fact that it has 'invisible' trailing stuff
  636. std::string value = i.GetValue();
  637. if (value.size() &&
  638. (value[value.size() - 1] == ' ' ||
  639. value[value.size() - 1] == '\t'))
  640. {
  641. value = '\'' + value + '\'';
  642. }
  643. if(!m_AdvancedValues)
  644. {
  645. if(i.GetPropertyAsBool("ADVANCED"))
  646. {
  647. m_CacheEntriesList.RemoveProperty(key);
  648. continue;
  649. }
  650. }
  651. switch(i.GetType() )
  652. {
  653. case cmCacheManager::BOOL:
  654. if(cmSystemTools::IsOn(value.c_str()))
  655. {
  656. m_CacheEntriesList.AddProperty(key,
  657. "ON",
  658. i.GetProperty("HELPSTRING"),
  659. CPropertyList::COMBO,"ON|OFF",
  660. reverseOrder
  661. );
  662. }
  663. else
  664. {
  665. m_CacheEntriesList.AddProperty(key,
  666. "OFF",
  667. i.GetProperty("HELPSTRING"),
  668. CPropertyList::COMBO,"ON|OFF",
  669. reverseOrder
  670. );
  671. }
  672. break;
  673. case cmCacheManager::PATH:
  674. m_CacheEntriesList.AddProperty(key,
  675. value.c_str(),
  676. i.GetProperty("HELPSTRING"),
  677. CPropertyList::PATH,"",
  678. reverseOrder
  679. );
  680. break;
  681. case cmCacheManager::FILEPATH:
  682. m_CacheEntriesList.AddProperty(key,
  683. value.c_str(),
  684. i.GetProperty("HELPSTRING"),
  685. CPropertyList::FILE,"",
  686. reverseOrder
  687. );
  688. break;
  689. case cmCacheManager::STRING:
  690. m_CacheEntriesList.AddProperty(key,
  691. value.c_str(),
  692. i.GetProperty("HELPSTRING"),
  693. CPropertyList::EDIT,"",
  694. reverseOrder
  695. );
  696. break;
  697. case cmCacheManager::INTERNAL:
  698. m_CacheEntriesList.RemoveProperty(key);
  699. break;
  700. }
  701. }
  702. m_OKButton.EnableWindow(false);
  703. if(cachem->GetSize() > 0 && !cmSystemTools::GetErrorOccuredFlag())
  704. {
  705. bool enable = true;
  706. items = m_CacheEntriesList.GetItems();
  707. for(std::set<CPropertyItem*>::iterator i = items.begin();
  708. i != items.end(); ++i)
  709. {
  710. CPropertyItem* item = *i;
  711. if(item->m_NewValue)
  712. {
  713. // if one new value then disable to OK button
  714. enable = false;
  715. break;
  716. }
  717. }
  718. if(enable)
  719. {
  720. m_OKButton.EnableWindow(true);
  721. }
  722. }
  723. // redraw the list
  724. m_CacheEntriesList.SetTopIndex(0);
  725. m_CacheEntriesList.Invalidate();
  726. }
  727. // copy from the list box to the cache manager
  728. void CMakeSetupDialog::FillCacheManagerFromCacheGUI()
  729. {
  730. cmCacheManager *cachem = this->m_CMakeInstance->GetCacheManager();
  731. std::set<CPropertyItem*> items = m_CacheEntriesList.GetItems();
  732. cmCacheManager::CacheIterator it = cachem->NewIterator();
  733. for(std::set<CPropertyItem*>::iterator i = items.begin();
  734. i != items.end(); ++i)
  735. {
  736. CPropertyItem* item = *i;
  737. if ( it.Find((const char*)item->m_propName) )
  738. {
  739. // if value is enclosed in single quotes ('foo') then remove them
  740. // they were used to enforce the fact that it had 'invisible'
  741. // trailing stuff
  742. if (item->m_curValue.GetLength() >= 2 &&
  743. item->m_curValue[0] == '\'' &&
  744. item->m_curValue[item->m_curValue.GetLength() - 1] == '\'')
  745. {
  746. it.SetValue(item->m_curValue.Mid(
  747. 1, item->m_curValue.GetLength() - 2));
  748. }
  749. else
  750. {
  751. it.SetValue(item->m_curValue);
  752. }
  753. }
  754. }
  755. }
  756. //! Load cache file from m_WhereBuild and display in GUI editor
  757. void CMakeSetupDialog::LoadCacheFromDiskToGUI()
  758. {
  759. cmCacheManager *cachem = this->m_CMakeInstance->GetCacheManager();
  760. if(m_WhereBuild != "")
  761. {
  762. cachem->LoadCache(m_WhereBuild);
  763. this->FillCacheGUIFromCacheManager();
  764. cmCacheManager::CacheIterator it =
  765. cachem->GetCacheIterator("CMAKE_GENERATOR");
  766. if(!it.IsAtEnd())
  767. {
  768. std::string curGen = it.GetValue();
  769. if(m_GeneratorChoiceString != curGen.c_str())
  770. {
  771. m_GeneratorChoiceString = curGen.c_str();
  772. this->UpdateData(FALSE);
  773. }
  774. }
  775. }
  776. }
  777. //! Save GUI values to cmCacheManager and then save to disk.
  778. void CMakeSetupDialog::SaveCacheFromGUI()
  779. {
  780. cmCacheManager *cachem = this->m_CMakeInstance->GetCacheManager();
  781. this->FillCacheManagerFromCacheGUI();
  782. if(m_WhereBuild != "")
  783. {
  784. cachem->SaveCache(m_WhereBuild);
  785. }
  786. }
  787. void CMakeSetupDialog::OnSize(UINT nType, int cx, int cy)
  788. {
  789. if (nType == SIZE_MINIMIZED)
  790. {
  791. CDialog::OnSize(nType, cx, cy);
  792. return;
  793. }
  794. if (m_oldCX == -1)
  795. {
  796. m_oldCX = cx;
  797. m_oldCY = cy;
  798. }
  799. int deltax = cx - m_oldCX;
  800. int deltay = cy - m_oldCY;
  801. m_oldCX = cx;
  802. m_oldCY = cy;
  803. CDialog::OnSize(nType, cx, cy);
  804. if (deltax == 0 && deltay == 0)
  805. {
  806. return;
  807. }
  808. if(m_CacheEntriesList.m_hWnd)
  809. {
  810. // get the original sizes/positions
  811. CRect cRect;
  812. m_ListFrame.GetWindowRect(&cRect);
  813. m_ListFrame.SetWindowPos(&wndTop, cRect.left, cRect.top,
  814. cRect.Width() + deltax,
  815. cRect.Height() + deltay,
  816. SWP_NOMOVE | SWP_NOZORDER);
  817. m_CacheEntriesList.GetWindowRect(&cRect);
  818. m_CacheEntriesList.SetWindowPos(&wndTop, cRect.left, cRect.top,
  819. cRect.Width() + deltax,
  820. cRect.Height() + deltay,
  821. SWP_NOMOVE | SWP_NOZORDER);
  822. m_VersionDisplay.SetWindowPos(&wndTop, 5, cy-23, 0, 0,
  823. SWP_NOSIZE | SWP_NOZORDER);
  824. deltax = int(deltax + m_deltaXRemainder);
  825. m_deltaXRemainder = float(deltax%2);
  826. m_MouseHelp.GetWindowRect(&cRect);
  827. this->ScreenToClient(&cRect);
  828. m_MouseHelp.SetWindowPos(&wndTop, cRect.left + deltax/2,
  829. cRect.top + deltay,
  830. 0, 0,
  831. SWP_NOSIZE | SWP_NOZORDER);
  832. m_Configure.GetWindowRect(&cRect);
  833. this->ScreenToClient(&cRect);
  834. m_Configure.SetWindowPos(&wndTop, cRect.left + deltax/2,
  835. cRect.top + deltay,
  836. 0, 0,
  837. SWP_NOSIZE | SWP_NOZORDER);
  838. m_CancelButton.GetWindowRect(&cRect);
  839. this->ScreenToClient(&cRect);
  840. m_CancelButton.SetWindowPos(&wndTop, cRect.left + deltax/2,
  841. cRect.top + deltay,
  842. 0, 0,
  843. SWP_NOSIZE | SWP_NOZORDER);
  844. m_OKButton.GetWindowRect(&cRect);
  845. this->ScreenToClient(&cRect);
  846. m_OKButton.SetWindowPos(&wndTop, cRect.left + deltax/2,
  847. cRect.top + deltay,
  848. 0, 0,
  849. SWP_NOSIZE | SWP_NOZORDER);
  850. m_HelpButton.GetWindowRect(&cRect);
  851. this->ScreenToClient(&cRect);
  852. m_HelpButton.SetWindowPos(&wndTop, cRect.left + deltax/2,
  853. cRect.top + deltay,
  854. 0, 0,
  855. SWP_NOSIZE | SWP_NOZORDER);
  856. }
  857. }
  858. void CMakeSetupDialog::OnGetMinMaxInfo( MINMAXINFO FAR* lpMMI )
  859. {
  860. lpMMI->ptMinTrackSize.x = 550;
  861. lpMMI->ptMinTrackSize.y = 272;
  862. }
  863. void CMakeSetupDialog::OnCancel()
  864. {
  865. if(m_CacheEntriesList.IsDirty())
  866. {
  867. if(MessageBox("You have changed options but not rebuilt, "
  868. "are you sure you want to exit?", "Confirm Exit",
  869. MB_YESNO) == IDYES)
  870. {
  871. CDialog::OnOK();
  872. }
  873. }
  874. else
  875. {
  876. CDialog::OnOK();
  877. }
  878. }
  879. void CMakeSetupDialog::OnOk()
  880. {
  881. // enable error messages each time configure is pressed
  882. cmSystemTools::EnableMessages();
  883. m_CacheEntriesList.ClearDirty();
  884. this->RunCMake(true);
  885. if (!(::GetKeyState(VK_SHIFT) & 0x1000))
  886. {
  887. CDialog::OnOK();
  888. }
  889. }
  890. void CMakeSetupDialog::OnEditchangeGenerator()
  891. {
  892. // TODO: Add your control notification handler code here
  893. }
  894. // Create a shortcut on the desktop with the current Source/Build dir.
  895. int CMakeSetupDialog::CreateShortcut()
  896. {
  897. // Find the desktop folder and create the link name
  898. HKEY hKey;
  899. if(RegOpenKeyEx(HKEY_CURRENT_USER,
  900. "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders",
  901. 0, KEY_READ, &hKey) != ERROR_SUCCESS)
  902. {
  903. AfxMessageBox ("Create shortcut: unable to find 'Shell Folders' key in registry!");
  904. return 1;
  905. }
  906. DWORD dwType, dwSize;
  907. #define MAXPATH 1024
  908. char link_name[MAXPATH];
  909. dwSize = MAXPATH;
  910. if(RegQueryValueEx(hKey,
  911. (LPCTSTR)"Desktop",
  912. NULL,
  913. &dwType,
  914. (BYTE *)link_name,
  915. &dwSize) != ERROR_SUCCESS)
  916. {
  917. AfxMessageBox ("Create shortcut: unable to find 'Desktop' registry value in 'Shell Folders' key!");
  918. return 1;
  919. }
  920. if(dwType != REG_SZ)
  921. {
  922. AfxMessageBox ("Create shortcut: 'Desktop' registry value in 'Shell Folders' key has wrong type!");
  923. return 1;
  924. }
  925. strcat(link_name, "\\CMake - ");
  926. std::string current_dir = cmSystemTools::GetFilenameName((LPCTSTR)m_WhereSource);
  927. strcat(link_name, current_dir.c_str());
  928. strcat(link_name, ".lnk");
  929. // Find the path to the current executable
  930. char path_to_current_exe[MAXPATH];
  931. ::GetModuleFileName(NULL, path_to_current_exe, MAXPATH);
  932. // Create the shortcut
  933. HRESULT hres;
  934. IShellLink *psl;
  935. // Initialize the COM library
  936. hres = CoInitialize(NULL);
  937. if (! SUCCEEDED (hres))
  938. {
  939. AfxMessageBox ("Create shortcut: unable to initialize the COM library!");
  940. return 1;
  941. }
  942. // Create an IShellLink object and get a pointer to the IShellLink
  943. // interface (returned from CoCreateInstance).
  944. hres = CoCreateInstance(CLSID_ShellLink,
  945. NULL,
  946. CLSCTX_INPROC_SERVER,
  947. IID_IShellLink,
  948. (void **)&psl);
  949. if (! SUCCEEDED (hres))
  950. {
  951. AfxMessageBox ("Create shortcut: unable to create IShellLink instance!");
  952. return 1;
  953. }
  954. IPersistFile *ppf;
  955. // Query IShellLink for the IPersistFile interface for
  956. // saving the shortcut in persistent storage.
  957. hres = psl->QueryInterface(IID_IPersistFile, (void **)&ppf);
  958. if (SUCCEEDED (hres))
  959. {
  960. // Set the path to the shortcut target.
  961. hres = psl->SetPath(path_to_current_exe);
  962. if (! SUCCEEDED (hres))
  963. {
  964. AfxMessageBox ("Create shortcut: SetPath failed!");
  965. }
  966. // Set the arguments of the shortcut.
  967. CString args = " /H=\"" + m_WhereSource + "\" /B=\"" + m_WhereBuild + "\" /G=\"" + m_GeneratorChoiceString + "\" /A=\"" + (m_AdvancedValues ? "TRUE" : "FALSE") + "\"";
  968. hres = psl->SetArguments(args);
  969. if (! SUCCEEDED (hres))
  970. {
  971. AfxMessageBox ("Create shortcut: SetArguments failed!");
  972. }
  973. // Set the description of the shortcut.
  974. hres = psl->SetDescription("Shortcut to CMakeSetup");
  975. if (! SUCCEEDED (hres))
  976. {
  977. AfxMessageBox ("Create shortcut: SetDescription failed!");
  978. }
  979. // Ensure that the string consists of ANSI characters.
  980. WORD wsz[MAX_PATH];
  981. MultiByteToWideChar(CP_ACP, 0, link_name, -1, wsz, MAX_PATH);
  982. // Save the shortcut via the IPersistFile::Save member function.
  983. hres = ppf->Save(wsz, TRUE);
  984. if (! SUCCEEDED (hres))
  985. {
  986. AfxMessageBox ("Create shortcut: Save failed!");
  987. }
  988. // Release the pointer to IPersistFile.
  989. ppf->Release ();
  990. }
  991. // Release the pointer to IShellLink.
  992. psl->Release ();
  993. return 0;
  994. }
  995. void CMakeSetupDialog::OnHelpButton()
  996. {
  997. CMakeHelp dialog;
  998. dialog.DoModal();
  999. }
  1000. void CMakeSetupDialog::ShowAdvancedValues()
  1001. {
  1002. cmCacheManager *cachem = this->m_CMakeInstance->GetCacheManager();
  1003. for(cmCacheManager::CacheIterator i = cachem->NewIterator();
  1004. !i.IsAtEnd(); i.Next())
  1005. {
  1006. const char* key = i.GetName();
  1007. if(!i.GetPropertyAsBool("ADVANCED"))
  1008. {
  1009. continue;
  1010. }
  1011. switch(i.GetType() )
  1012. {
  1013. case cmCacheManager::BOOL:
  1014. if(cmSystemTools::IsOn(i.GetValue()))
  1015. {
  1016. m_CacheEntriesList.AddProperty(key,
  1017. "ON",
  1018. i.GetProperty("HELPSTRING"),
  1019. CPropertyList::COMBO,"ON|OFF",
  1020. true
  1021. );
  1022. }
  1023. else
  1024. {
  1025. m_CacheEntriesList.AddProperty(key,
  1026. "OFF",
  1027. i.GetProperty("HELPSTRING"),
  1028. CPropertyList::COMBO,"ON|OFF",
  1029. true
  1030. );
  1031. }
  1032. break;
  1033. case cmCacheManager::PATH:
  1034. m_CacheEntriesList.AddProperty(key,
  1035. i.GetValue(),
  1036. i.GetProperty("HELPSTRING"),
  1037. CPropertyList::PATH,"",
  1038. true
  1039. );
  1040. break;
  1041. case cmCacheManager::FILEPATH:
  1042. m_CacheEntriesList.AddProperty(key,
  1043. i.GetValue(),
  1044. i.GetProperty("HELPSTRING"),
  1045. CPropertyList::FILE,"",
  1046. true
  1047. );
  1048. break;
  1049. case cmCacheManager::STRING:
  1050. m_CacheEntriesList.AddProperty(key,
  1051. i.GetValue(),
  1052. i.GetProperty("HELPSTRING"),
  1053. CPropertyList::EDIT,"",
  1054. true
  1055. );
  1056. break;
  1057. case cmCacheManager::INTERNAL:
  1058. m_CacheEntriesList.RemoveProperty(key);
  1059. break;
  1060. }
  1061. }
  1062. }
  1063. void CMakeSetupDialog::RemoveAdvancedValues()
  1064. {
  1065. cmCacheManager *cachem = this->m_CMakeInstance->GetCacheManager();
  1066. for(cmCacheManager::CacheIterator i = cachem->NewIterator();
  1067. !i.IsAtEnd(); i.Next())
  1068. {
  1069. const char* key = i.GetName();
  1070. if(i.GetPropertyAsBool("ADVANCED"))
  1071. {
  1072. m_CacheEntriesList.RemoveProperty(key);
  1073. }
  1074. }
  1075. }
  1076. void CMakeSetupDialog::OnAdvancedValues()
  1077. {
  1078. this->UpdateData();
  1079. if(m_AdvancedValues)
  1080. {
  1081. this->ShowAdvancedValues();
  1082. }
  1083. else
  1084. {
  1085. this->RemoveAdvancedValues();
  1086. }
  1087. }
  1088. void CMakeSetupDialog::OnDoubleclickedAdvancedValues()
  1089. {
  1090. this->OnAdvancedValues();
  1091. }
  1092. // Handle param or single dropped file.
  1093. // If the dropped file is a build directory or any file in a
  1094. // build directory, set the source dir from the cache file,
  1095. // otherwise set the source and build dirs to this file (or dir).
  1096. void CMakeSetupDialog::ChangeDirectoriesFromFile(const char* buffer)
  1097. {
  1098. // Get the path to this file
  1099. std::string path = buffer;
  1100. if (!cmSystemTools::FileIsDirectory(path.c_str()))
  1101. {
  1102. path = cmSystemTools::GetFilenamePath(path);
  1103. }
  1104. else
  1105. {
  1106. cmSystemTools::ConvertToUnixSlashes(path);
  1107. }
  1108. // Check if it's a build dir and grab the cache
  1109. std::string cache_file = path;
  1110. cache_file += "/CMakeCache.txt";
  1111. cmCacheManager *cachem = this->m_CMakeInstance->GetCacheManager();
  1112. cmCacheManager::CacheIterator it =
  1113. cachem->NewIterator();
  1114. if (cmSystemTools::FileExists(cache_file.c_str()) &&
  1115. cachem->LoadCache(path.c_str()) &&
  1116. it.Find("CMAKE_HOME_DIRECTORY"))
  1117. {
  1118. path = ConvertToWindowsPath(path.c_str());
  1119. this->m_WhereBuild = path.c_str();
  1120. path = ConvertToWindowsPath(it.GetName());
  1121. this->m_WhereSource = path.c_str();
  1122. }
  1123. else
  1124. {
  1125. path = ConvertToWindowsPath(path.c_str());
  1126. this->m_WhereSource = this->m_WhereBuild = path.c_str();
  1127. }
  1128. }
  1129. // The framework calls this member function when the user releases the
  1130. // left mouse button over a window that has registered itself as the
  1131. // recipient of dropped files.
  1132. void CMakeSetupDialog::OnDropFiles(HDROP hDropInfo)
  1133. {
  1134. UINT nb_files = DragQueryFile(hDropInfo, 0xFFFFFFFF, NULL, 0);
  1135. if (nb_files > 0)
  1136. {
  1137. UINT buffer_size = DragQueryFile(hDropInfo, 0, NULL, 0);
  1138. char *buffer = new char [buffer_size + 1];
  1139. DragQueryFile(hDropInfo, 0, buffer, buffer_size + 1);
  1140. this->ChangeDirectoriesFromFile(buffer);
  1141. delete [] buffer;
  1142. this->m_WhereSourceControl.SetWindowText(this->m_WhereSource);
  1143. this->m_WhereBuildControl.SetWindowText(this->m_WhereBuild);
  1144. this->UpdateData(FALSE);
  1145. this->OnChangeWhereSource();
  1146. this->OnChangeWhereBuild();
  1147. }
  1148. DragFinish(hDropInfo);
  1149. }