ConfigurationPage.cpp 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. /****************************************************************/
  2. /* */
  3. /* ConfigurationPage.cpp */
  4. /* */
  5. /* Implementation of the CConfigurationPage class. */
  6. /* This class is a part of the FTP Server Application */
  7. /* */
  8. /* Programmed by LYFZ van der Meer */
  9. /* Copyright LYFZ Software Solutions 2002 */
  10. /* http://www.LYFZvandermeer.nl */
  11. /* */
  12. /* Last updated: 10 july 2002 */
  13. /* */
  14. /****************************************************************/
  15. #include "stdafx.h"
  16. #include "LYFZIPReceiveApp.h"
  17. #include "LYFZIPReceive.h"
  18. #include "ConfigurationPage.h"
  19. #include "UserAccountsDlg.h"
  20. #include "ApplicationDlg.h"
  21. #ifdef _DEBUG
  22. #define new DEBUG_NEW
  23. #undef THIS_FILE
  24. static char THIS_FILE[] = __FILE__;
  25. #endif
  26. extern CLYFZIPReceive theServer;
  27. extern CLYFZIPReceiveApp theApp;
  28. CConfigurationPage::CConfigurationPage() : CDialogResize(CConfigurationPage::IDD)
  29. {
  30. //{{AFX_DATA_INIT(CConfigurationPage)
  31. m_nPort = 0;
  32. m_nMaxUsers = 0;
  33. m_strGoodbyeMessage = _T("");
  34. m_bStartInTray = FALSE;
  35. m_nTimeout = 0;
  36. m_strWelcomeMessage = _T("");
  37. m_bLaunchOnStartup = FALSE;
  38. m_bAutoActivate = FALSE;
  39. m_nLogLevel = 0;
  40. m_strApplicationName = _T("");
  41. //}}AFX_DATA_INIT
  42. m_bModified = FALSE;
  43. }
  44. CConfigurationPage::~CConfigurationPage()
  45. {
  46. }
  47. void CConfigurationPage::DoDataExchange(CDataExchange* pDX)
  48. {
  49. CDialogResize::DoDataExchange(pDX);
  50. //{{AFX_DATA_MAP(CConfigurationPage)
  51. DDX_Text(pDX, IDC_PORT, m_nPort);
  52. DDX_Text(pDX, IDC_MAX_USERS, m_nMaxUsers);
  53. DDX_Text(pDX, IDC_GOODBYE_MSG, m_strGoodbyeMessage);
  54. DDX_Check(pDX, IDC_START_IN_TRAY, m_bStartInTray);
  55. DDX_Text(pDX, IDC_TIMEOUT, m_nTimeout);
  56. DDX_Text(pDX, IDC_WELCOME_MSG, m_strWelcomeMessage);
  57. DDX_Check(pDX, IDC_LAUNCH_ON_STARTUP, m_bLaunchOnStartup);
  58. DDX_Check(pDX, IDC_AUTOACTIVATE, m_bAutoActivate);
  59. DDX_CBIndex(pDX, IDC_LOGLEVEL, m_nLogLevel);
  60. DDX_Text(pDX, IDC_APPLICATIONNAME, m_strApplicationName);
  61. //}}AFX_DATA_MAP
  62. }
  63. BEGIN_MESSAGE_MAP(CConfigurationPage, CDialogResize)
  64. //{{AFX_MSG_MAP(CConfigurationPage)
  65. ON_WM_DESTROY()
  66. ON_BN_CLICKED(IDC_LAUNCH_ON_STARTUP, OnLaunchOnStartup)
  67. ON_BN_CLICKED(IDC_VIEW, OnView)
  68. ON_BN_CLICKED(IDC_CLEAR, OnClear)
  69. ON_UPDATE_COMMAND_UI(IDC_APPLY, OnUpdateApply)
  70. ON_EN_CHANGE(IDC_PORT, OnSomethingChanged)
  71. ON_BN_CLICKED(IDC_APPLY, OnApply)
  72. ON_EN_CHANGE(IDC_MAX_USERS, OnSomethingChanged)
  73. ON_EN_CHANGE(IDC_TIMEOUT, OnSomethingChanged)
  74. ON_EN_CHANGE(IDC_WELCOME_MSG, OnSomethingChanged)
  75. ON_EN_CHANGE(IDC_GOODBYE_MSG, OnSomethingChanged)
  76. ON_CBN_SELCHANGE(IDC_LOGLEVEL, OnSomethingChanged)
  77. ON_BN_CLICKED(IDC_START_IN_TRAY, OnSomethingChanged)
  78. ON_BN_CLICKED(IDC_AUTOACTIVATE, OnSomethingChanged)
  79. ON_EN_CHANGE(IDC_APPLICATIONNAME, OnSomethingChanged)
  80. //}}AFX_MSG_MAP
  81. END_MESSAGE_MAP()
  82. BEGIN_DLGRESIZE_MAP(CConfigurationPage)
  83. DLGRESIZE_CONTROL(IDC_WELCOME_MSG, DLSZ_SIZE_X)
  84. DLGRESIZE_CONTROL(IDC_GOODBYE_MSG, DLSZ_SIZE_X)
  85. DLGRESIZE_CONTROL(IDC_APPLICATIONNAME, DLSZ_SIZE_X)
  86. DLGRESIZE_CONTROL(IDC_VIEW, DLSZ_MOVE_X)
  87. DLGRESIZE_CONTROL(IDC_CLEAR, DLSZ_MOVE_X)
  88. DLGRESIZE_CONTROL(IDC_APPLY, DLSZ_MOVE_X | DLSZ_MOVE_Y)
  89. DLGRESIZE_CONTROL(IDC_IPLIST, DLSZ_SIZE_Y)
  90. END_DLGRESIZE_MAP()
  91. /********************************************************************/
  92. /* */
  93. /* Function name : OnInitDialog */
  94. /* Description : Called by the framework in response to the */
  95. /* WM_INITDIALOG message. */
  96. /* */
  97. /********************************************************************/
  98. BOOL CConfigurationPage::OnInitDialog()
  99. {
  100. CDialogResize::OnInitDialog();
  101. InitResizing(FALSE, FALSE, WS_CLIPCHILDREN);
  102. UpdateDialogControls(this, FALSE);
  103. return TRUE;
  104. }
  105. /********************************************************************/
  106. /* */
  107. /* Function name : OnDestroy */
  108. /* Description : Called by the framework in response to the */
  109. /* WM_DESTROY message. */
  110. /* */
  111. /********************************************************************/
  112. void CConfigurationPage::OnDestroy()
  113. {
  114. UpdateData();
  115. // save settings
  116. AfxGetApp()->WriteProfileInt("Settings", "Port", m_nPort);
  117. AfxGetApp()->WriteProfileInt("Settings", "MaxUsers", m_nMaxUsers);
  118. AfxGetApp()->WriteProfileInt("Settings", "Timeout", m_nTimeout);
  119. AfxGetApp()->WriteProfileString("Settings", "WelcomeMsg", m_strWelcomeMessage);
  120. AfxGetApp()->WriteProfileString("Settings", "GoodbyeMsg", m_strGoodbyeMessage);
  121. AfxGetApp()->WriteProfileInt("Settings", "LaunchOnStartup", m_bLaunchOnStartup);
  122. AfxGetApp()->WriteProfileInt("Settings", "StartInTray", m_bStartInTray);
  123. AfxGetApp()->WriteProfileInt("Settings", "AutoActivate", m_bAutoActivate);
  124. AfxGetApp()->WriteProfileInt("Settings", "LogLevel", m_nLogLevel);
  125. AfxGetApp()->WriteProfileString("Settings", "AppName", m_strApplicationName);
  126. CDialogResize::OnDestroy();
  127. }
  128. /********************************************************************/
  129. /* */
  130. /* Function name : OnLaunchOnStartup */
  131. /* Description : Launch application on startup? */
  132. /* */
  133. /********************************************************************/
  134. void CConfigurationPage::OnLaunchOnStartup()
  135. {
  136. UpdateData(TRUE);
  137. if (m_bLaunchOnStartup)
  138. {
  139. char szModuleFilename[MAX_PATH];
  140. // Get application's full path.
  141. ::GetModuleFileName(NULL, szModuleFilename, MAX_PATH);
  142. // create shortcut
  143. CreateStartMenuShortcut(szModuleFilename, "FTP Server", "Startup");
  144. }
  145. else
  146. {
  147. // remove shortcut
  148. RemoveStartMenuShortcut("FTP Server", "Startup");
  149. }
  150. OnSomethingChanged();
  151. }
  152. /********************************************************************/
  153. /* */
  154. /* Function name : OnView */
  155. /* Description : View log file contents. */
  156. /* */
  157. /********************************************************************/
  158. void CConfigurationPage::OnView()
  159. {
  160. int ExecStatus = (UINT)ShellExecute(m_hWnd, "open", "NOTEPAD.EXE", (LPCTSTR)theApp.m_LogFile.m_FileName, 0, SW_SHOW);
  161. switch(ExecStatus)
  162. {
  163. case 0:
  164. MessageBox("Systeem is out of Memory","ShellExecute Error",MB_OK | MB_ICONEXCLAMATION);
  165. break;
  166. case 2:
  167. MessageBox("'NOTEPAD.EXE' is not found !","ShellExecute Error",MB_OK | MB_ICONEXCLAMATION);
  168. break;
  169. default:
  170. if (ExecStatus <= 32)
  171. MessageBox("Problem with executing of NOTEPAD.EXE","ShellExecute Error",MB_OK | MB_ICONEXCLAMATION);
  172. break;
  173. }
  174. }
  175. /********************************************************************/
  176. /* */
  177. /* Function name : OnClear */
  178. /* Description : Clear log file contents. */
  179. /* */
  180. /********************************************************************/
  181. void CConfigurationPage::OnClear()
  182. {
  183. theApp.m_LogFile.Clear();
  184. }
  185. /********************************************************************/
  186. /* */
  187. /* Function name : OnApply */
  188. /* Description : Update FTP server settings. */
  189. /* */
  190. /********************************************************************/
  191. void CConfigurationPage::OnApply()
  192. {
  193. m_bModified = FALSE;
  194. UpdateDialogControls(this, FALSE);
  195. AfxGetMainWnd()->SendMessage(WM_COMMAND, IDC_APPLY);
  196. // save settings
  197. AfxGetApp()->WriteProfileInt("Settings", "Port", m_nPort);
  198. AfxGetApp()->WriteProfileInt("Settings", "MaxUsers", m_nMaxUsers);
  199. AfxGetApp()->WriteProfileInt("Settings", "Timeout", m_nTimeout);
  200. AfxGetApp()->WriteProfileString("Settings", "WelcomeMsg", m_strWelcomeMessage);
  201. AfxGetApp()->WriteProfileString("Settings", "GoodbyeMsg", m_strGoodbyeMessage);
  202. AfxGetApp()->WriteProfileInt("Settings", "LaunchOnStartup", m_bLaunchOnStartup);
  203. AfxGetApp()->WriteProfileInt("Settings", "StartInTray", m_bStartInTray);
  204. AfxGetApp()->WriteProfileInt("Settings", "AutoActivate", m_bAutoActivate);
  205. AfxGetApp()->WriteProfileInt("Settings", "LogLevel", m_nLogLevel);
  206. AfxGetApp()->WriteProfileString("Settings", "AppName", m_strApplicationName);
  207. }
  208. /********************************************************************/
  209. /* */
  210. /* Function name : OnUpdateApply */
  211. /* Description : Update button state. */
  212. /* */
  213. /********************************************************************/
  214. void CConfigurationPage::OnUpdateApply(CCmdUI* pCmdUI)
  215. {
  216. pCmdUI->Enable(m_bModified);
  217. }
  218. /********************************************************************/
  219. /* */
  220. /* Function name : OnSomethingChanged */
  221. /* Description : Something has changed... */
  222. /* */
  223. /********************************************************************/
  224. void CConfigurationPage::OnSomethingChanged()
  225. {
  226. m_bModified = TRUE;
  227. UpdateDialogControls(this, FALSE);
  228. }