Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

275 lines
7.3 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //
  7. //=============================================================================//
  8. // syncfrommirrorDlg.cpp : implementation file
  9. //
  10. #include "stdafx.h"
  11. #include "syncfrommirror.h"
  12. #include "syncfrommirrorDlg.h"
  13. #ifdef _DEBUG
  14. #define new DEBUG_NEW
  15. #undef THIS_FILE
  16. static char THIS_FILE[] = __FILE__;
  17. #endif
  18. /////////////////////////////////////////////////////////////////////////////
  19. // CSyncfrommirrorDlg dialog
  20. CSyncfrommirrorDlg::CSyncfrommirrorDlg(CWnd* pParent /*=NULL*/)
  21. : CDialog(CSyncfrommirrorDlg::IDD, pParent)
  22. {
  23. //{{AFX_DATA_INIT(CSyncfrommirrorDlg)
  24. m_WorkingFolder = _T("");
  25. m_bHL2 = FALSE;
  26. m_bTF2 = FALSE;
  27. m_bHL1Port = FALSE;
  28. m_bDOD = FALSE;
  29. m_bCSPort = FALSE;
  30. m_bMakeCommandPrompts = FALSE;
  31. //}}AFX_DATA_INIT
  32. m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  33. }
  34. void CSyncfrommirrorDlg::DoDataExchange(CDataExchange* pDX)
  35. {
  36. CDialog::DoDataExchange(pDX);
  37. //{{AFX_DATA_MAP(CSyncfrommirrorDlg)
  38. DDX_Control(pDX, IDC_EDIT1, m_Output);
  39. DDX_Text(pDX, IDC_EDIT2, m_WorkingFolder);
  40. DDX_Check(pDX, IDC_CHECK1, m_bHL2);
  41. DDX_Check(pDX, IDC_CHECK2, m_bHL1Port);
  42. DDX_Check(pDX, IDC_CHECK3, m_bCSPort);
  43. DDX_Check(pDX, IDC_CHECK4, m_bTF2);
  44. DDX_Check(pDX, IDC_MAKECOMMANDPROMPTS, m_bMakeCommandPrompts);
  45. DDX_Check(pDX, IDC_DOD, m_bDOD);
  46. //}}AFX_DATA_MAP
  47. }
  48. BEGIN_MESSAGE_MAP(CSyncfrommirrorDlg, CDialog)
  49. //{{AFX_MSG_MAP(CSyncfrommirrorDlg)
  50. ON_WM_PAINT()
  51. ON_WM_SIZE()
  52. ON_WM_QUERYDRAGICON()
  53. ON_BN_CLICKED(IDC_BUTTON1, OnStop)
  54. //}}AFX_MSG_MAP
  55. END_MESSAGE_MAP()
  56. /////////////////////////////////////////////////////////////////////////////
  57. // CSyncfrommirrorDlg message handlers
  58. BOOL CSyncfrommirrorDlg::OnInitDialog()
  59. {
  60. CDialog::OnInitDialog();
  61. SetIcon(m_hIcon, TRUE); // Set big icon
  62. SetIcon(m_hIcon, FALSE); // Set small icon
  63. m_bHL2 = AfxGetApp()->GetProfileInt( "settings", "hl2", 1 );
  64. m_bHL1Port = AfxGetApp()->GetProfileInt( "settings", "hl1", 0 );
  65. m_bCSPort = AfxGetApp()->GetProfileInt( "settings", "cstrike", 0 );
  66. m_bDOD = AfxGetApp()->GetProfileInt( "settings", "dod", 0 );
  67. m_bMakeCommandPrompts = AfxGetApp()->GetProfileInt( "settings", "makecommandprompts", 0 );
  68. m_WorkingFolder = AfxGetApp()->GetProfileString( "settings", "working_folder" );
  69. // Calculate layout info for resizing.
  70. CRect rectDlg;
  71. GetClientRect( &rectDlg );
  72. // Edit control
  73. CRect rectEdit;
  74. GetDlgItem( IDC_EDIT1 )->GetWindowRect( &rectEdit );
  75. ScreenToClient( rectEdit );
  76. m_nEditRightMargin = rectDlg.right - rectEdit.right;
  77. m_nEditBottomMargin = rectDlg.bottom - rectEdit.bottom;
  78. // Buttons
  79. CRect rectButton;
  80. GetDlgItem( IDOK )->GetWindowRect( &rectButton );
  81. ScreenToClient( rectButton );
  82. m_nButtonOffset = rectDlg.right - rectButton.left;
  83. // LoadSettings();
  84. UpdateData(false);
  85. // TODO: Add extra initialization here
  86. return TRUE; // return TRUE unless you set the focus to a control
  87. }
  88. // If you add a minimize button to your dialog, you will need the code below
  89. // to draw the icon. For MFC applications using the document/view model,
  90. // this is automatically done for you by the framework.
  91. void CSyncfrommirrorDlg::OnPaint()
  92. {
  93. if (IsIconic())
  94. {
  95. CPaintDC dc(this); // device context for painting
  96. SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
  97. // Center icon in client rectangle
  98. int cxIcon = GetSystemMetrics(SM_CXICON);
  99. int cyIcon = GetSystemMetrics(SM_CYICON);
  100. CRect rect;
  101. GetClientRect(&rect);
  102. int x = (rect.Width() - cxIcon + 1) / 2;
  103. int y = (rect.Height() - cyIcon + 1) / 2;
  104. // Draw the icon
  105. dc.DrawIcon(x, y, m_hIcon);
  106. }
  107. else
  108. {
  109. CDialog::OnPaint();
  110. }
  111. }
  112. HCURSOR CSyncfrommirrorDlg::OnQueryDragIcon()
  113. {
  114. return (HCURSOR) m_hIcon;
  115. }
  116. void CSyncfrommirrorDlg::RunSync( const char *pszType )
  117. {
  118. static const char *pszCmdLine = "cmd.exe /c \\\\hl2vss.valvesoftware.com\\hl2vss\\win32\\syncfrommirror.bat %s %s";
  119. if ( m_bMakeCommandPrompts )
  120. pszCmdLine = "cmd.exe /k \\\\hl2vss.valvesoftware.com\\hl2vss\\win32\\syncfrommirror.bat %s %s";
  121. CString strCmdLine;
  122. CString &strMain = m_WorkingFolder;
  123. strMain.TrimLeft(" \"");
  124. strMain.TrimRight(" \"");
  125. CString workingFolder;
  126. workingFolder = "\"";
  127. workingFolder += strMain;
  128. workingFolder += "\"";
  129. strCmdLine.Format(pszCmdLine, pszType, workingFolder.operator const char *() );
  130. GetDlgItem(IDOK)->EnableWindow(FALSE);
  131. GetDlgItem(IDCANCEL)->EnableWindow(FALSE);
  132. GetDlgItem(IDC_BUTTON1)->EnableWindow();
  133. if ( m_bMakeCommandPrompts )
  134. {
  135. RunCommandLine( strCmdLine, "c:\\" );
  136. }
  137. else
  138. {
  139. m_Redirector.Run( strCmdLine, &m_Output, "c:\\" );
  140. }
  141. GetDlgItem(IDOK)->EnableWindow();
  142. GetDlgItem(IDCANCEL)->EnableWindow();
  143. GetDlgItem(IDC_BUTTON1)->EnableWindow(FALSE);
  144. }
  145. void CSyncfrommirrorDlg::RunCommandLine( const char *pCmdLine, const char *pWorkingDir )
  146. {
  147. STARTUPINFO startupInfo;
  148. memset( &startupInfo, 0, sizeof( startupInfo ) );
  149. startupInfo.cb = sizeof( startupInfo );
  150. PROCESS_INFORMATION pi;
  151. memset( &pi, 0, sizeof( pi ) );
  152. CreateProcess(
  153. NULL,
  154. (char*)pCmdLine,
  155. NULL,
  156. NULL,
  157. FALSE,
  158. CREATE_NEW_CONSOLE,
  159. NULL,
  160. pWorkingDir,
  161. &startupInfo,
  162. &pi );
  163. }
  164. void CSyncfrommirrorDlg::OnOK()
  165. {
  166. UpdateData();
  167. AfxGetApp()->WriteProfileInt( "settings", "hl2", m_bHL2 );
  168. AfxGetApp()->WriteProfileInt( "settings", "hl1", m_bHL1Port );
  169. AfxGetApp()->WriteProfileInt( "settings", "dod", m_bDOD );
  170. AfxGetApp()->WriteProfileInt( "settings", "cstrike", m_bCSPort );
  171. AfxGetApp()->WriteProfileInt( "settings", "makecommandprompts", m_bMakeCommandPrompts );
  172. AfxGetApp()->WriteProfileString( "settings", "working_folder", m_WorkingFolder);
  173. if ( m_WorkingFolder.GetLength() == 0 )
  174. {
  175. MessageBox( "You must set your working folder (e.g. u:\\dev)", "Error", MB_ICONWARNING );
  176. return;
  177. }
  178. m_Output.SetSel( 0, -1 );
  179. m_Output.Clear();
  180. if (m_bHL2 && m_bHL1Port && m_bCSPort && m_bDOD )
  181. {
  182. RunSync( "all" );
  183. }
  184. else
  185. {
  186. if ( m_bHL2 )
  187. RunSync( "hl2" );
  188. if ( m_bHL1Port )
  189. RunSync( "hl1" );
  190. if ( m_bCSPort )
  191. RunSync( "cstrike" );
  192. if ( m_bDOD )
  193. RunSync( "dod" );
  194. }
  195. // If it spawned command prompts, then exit.
  196. if ( m_bMakeCommandPrompts )
  197. EndDialog( 0 );
  198. FlashWindow( TRUE );
  199. //CDialog::OnOK();
  200. }
  201. void CSyncfrommirrorDlg::OnStop()
  202. {
  203. m_Redirector.Stop();
  204. }
  205. void CSyncfrommirrorDlg::OnSize( UINT nType, int cx, int cy )
  206. {
  207. if ( GetDlgItem( IDC_EDIT1 ) )
  208. {
  209. CRect rectDlg;
  210. GetClientRect( &rectDlg );
  211. CRect rectEdit;
  212. GetDlgItem( IDC_EDIT1 )->GetWindowRect( &rectEdit );
  213. ScreenToClient( rectEdit );
  214. GetDlgItem( IDC_EDIT1 )->MoveWindow( rectEdit.left, rectEdit.top, ( rectDlg.right - m_nEditRightMargin ) - rectEdit.left, ( rectDlg.bottom - m_nEditBottomMargin ) - rectEdit.top, TRUE );
  215. CRect rectButton;
  216. GetDlgItem( IDOK )->GetWindowRect( &rectButton );
  217. ScreenToClient( rectButton );
  218. GetDlgItem( IDOK )->MoveWindow( rectDlg.right - m_nButtonOffset, rectButton.top, rectButton.Width( ), rectButton.Height( ), TRUE );
  219. GetDlgItem( IDCANCEL )->GetWindowRect( &rectButton );
  220. ScreenToClient( rectButton );
  221. GetDlgItem( IDCANCEL )->MoveWindow( rectDlg.right - m_nButtonOffset, rectButton.top, rectButton.Width( ), rectButton.Height( ), TRUE );
  222. GetDlgItem( IDC_BUTTON1 )->GetWindowRect( &rectButton );
  223. ScreenToClient( rectButton );
  224. GetDlgItem( IDC_BUTTON1 )->MoveWindow( rectDlg.right - m_nButtonOffset, rectButton.top, rectButton.Width( ), rectButton.Height( ), TRUE );
  225. }
  226. CDialog::OnSize( nType, cx, cy );
  227. }