Leaked source code of windows server 2003
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.

229 lines
6.0 KiB

  1. // Config.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "Config.h"
  5. //#include "lstentry.h"
  6. #include "Registry.h"
  7. //
  8. // Settings for autodial
  9. //
  10. #define RAS_AUTODIAL_OPT_NONE 0x00000000 // No options
  11. #define RAS_AUTODIAL_OPT_NEVER 0x00000001 // Never Autodial
  12. #define RAS_AUTODIAL_OPT_ALWAYS 0x00000002 // Autodial regardless
  13. #define RAS_AUTODIAL_OPT_DEMAND 0x00000004 // Autodial on demand
  14. #define RAS_AUTODIAL_OPT_NOPROMPT 0x00000010 // Dial without prompting
  15. DWORD gWizardSuccess = 0x00000000;
  16. DWORD gWizardFailure = 0x00000001;
  17. DWORD gWizardCancelled = 0x00000002;
  18. DWORD gNewInstall = 0x00000001;
  19. DWORD gUpdateSettings = 0x00000002;
  20. DWORD gWizardResult; // will be set to gWizardSuccess, gWizardFailure, or gWizardCancelled
  21. const TCHAR c_szICSGeneral[] = _T("System\\CurrentControlSet\\Services\\ICSharing\\Settings\\General");
  22. /* RMR TODO: reenable
  23. void WriteDefaultConnectoidRegString ( LPTSTR lpszValue )
  24. {
  25. DWORD dwAutodialOpt;
  26. //
  27. // Default to dial on demand, no prompting
  28. //
  29. dwAutodialOpt = (RAS_AUTODIAL_OPT_DEMAND | RAS_AUTODIAL_OPT_NOPROMPT);
  30. RnaSetDefaultAutodialConnection(lpszValue, dwAutodialOpt);
  31. }
  32. void ReadDefaultConnectoidString ( LPTSTR lpszValue, DWORD dwSize )
  33. {
  34. DWORD dwAutodialOpt;
  35. //
  36. // Read the default autodial setting
  37. //
  38. RnaGetDefaultAutodialConnection((PUCHAR) lpszValue, dwSize, &dwAutodialOpt);
  39. }
  40. */
  41. /////////////////////////////////////////////////////////////////////////////
  42. // CConfig
  43. CConfig::CConfig()
  44. {
  45. m_EnableICS = TRUE;
  46. m_ShowTrayIcon = TRUE;
  47. m_nServers = 0;
  48. m_nDhcp = 0;
  49. m_nBlockOut = 0;
  50. m_nParams = 0;
  51. m_nGeneral = 0;
  52. m_OldExternalAdapterReg[0] = '\0';
  53. m_OldInternalAdapterReg[0] = '\0';
  54. m_OldDialupEntry[0] = '\0';
  55. m_bOldEnableICS = FALSE;
  56. }
  57. CConfig::~CConfig()
  58. {
  59. }
  60. /////////////////////////////////////////////////////////////////////////////
  61. // CConfig message handlers
  62. int CConfig::SaveConfig()
  63. {
  64. BOOL bBindingsNeeded = FALSE;
  65. BOOL bICSEnableToggled = FALSE;
  66. // check to see if a rebind is necessary
  67. if ( StrCmp ( m_OldExternalAdapterReg, m_ExternalAdapterReg ) != 0 )
  68. bBindingsNeeded = TRUE;
  69. if ( StrCmp( m_OldInternalAdapterReg, m_InternalAdapterReg ) != 0 )
  70. bBindingsNeeded = TRUE;
  71. // Save parameters in the [General] Section
  72. //
  73. CRegistry reg;
  74. reg.OpenKey(HKEY_LOCAL_MACHINE, c_szICSGeneral);
  75. // RMR TODO: REENABLE!!!
  76. // if ( _tcslen ( m_DialupEntry ) > 0 )
  77. // WriteDefaultConnectoidRegString ( m_DialupEntry );
  78. reg.SetStringValue(_T("HangupTimer"), m_HangupTimer);
  79. if (m_EnableDialOnDemand)
  80. reg.SetStringValue(_T("DialOnDemand"), _T("1"));
  81. else
  82. reg.SetStringValue(_T("DialOnDemand"), _T("0"));
  83. if (m_EnableDHCP)
  84. {
  85. reg.SetStringValue(_T("EnableDHCP"), _T("1"));
  86. }
  87. else
  88. {
  89. reg.SetStringValue(_T("EnableDHCP"), _T("0"));
  90. }
  91. if (m_ShowTrayIcon)
  92. reg.SetStringValue(_T("ShowTrayIcon"), _T("1"));
  93. else
  94. reg.SetStringValue(_T("ShowTrayIcon"), _T("0"));
  95. if (m_EnableICS)
  96. {
  97. if ( !m_bOldEnableICS )
  98. bICSEnableToggled = TRUE;
  99. reg.SetStringValue(_T("Enabled"), _T("1"));
  100. }
  101. else
  102. {
  103. if ( m_bOldEnableICS )
  104. bICSEnableToggled = TRUE;
  105. reg.SetStringValue(_T("Enabled"), _T("0"));
  106. }
  107. // Added for compatibility with Win98SE/legacy setup for now
  108. reg.SetStringValue(_T("RunWizard"), _T("0"));
  109. if ( bBindingsNeeded )
  110. return BINDINGS_NEEDED;
  111. else if ( bICSEnableToggled )
  112. return ICSENABLETOGGLED;
  113. else
  114. return SAVE_SUCCEDED;
  115. }
  116. void CConfig::WriteWizardCode( BOOL bWizardRun )
  117. {
  118. CRegistry reg;
  119. reg.OpenKey(HKEY_LOCAL_MACHINE, c_szICSGeneral);
  120. reg.SetBinaryValue(_T("WizardStatus"), &gWizardResult, sizeof(gWizardResult) );
  121. if ( bWizardRun )
  122. reg.SetBinaryValue(_T("WizardOptions"), &gNewInstall, sizeof(gNewInstall) );
  123. else
  124. reg.SetBinaryValue(_T("WizardOptions"), &gUpdateSettings, sizeof(gUpdateSettings) );
  125. }
  126. /*
  127. RMR TODO: REENABLE
  128. void CConfig::LoadConfig()
  129. {
  130. // Save parameters in the [General] Section
  131. //
  132. ReadGeneralRegString(_T("InternalAdapterReg"), m_InternalAdapterReg, MAX_STRLEN);
  133. ReadGeneralRegString(_T("ExternalAdapterReg"), m_ExternalAdapterReg, MAX_STRLEN);
  134. // ReadGeneralRegString(_T("DialupEntry"), m_DialupEntry, MAX_STRLEN);
  135. ReadDefaultConnectoidString ( m_DialupEntry, MAX_STRLEN );
  136. ReadGeneralRegString(_T("HangupTimer"), m_HangupTimer, MAX_STRLEN);
  137. TCHAR szBOOL[MAX_STRLEN];
  138. ReadGeneralRegString(_T("DialOnDemand"), szBOOL, MAX_STRLEN);
  139. if ( _tcscmp ( szBOOL, _T("1")) == 0 )
  140. m_EnableDialOnDemand = TRUE;
  141. else
  142. m_EnableDialOnDemand = FALSE;
  143. ReadGeneralRegString(_T("EnableDHCP"),szBOOL, MAX_STRLEN);
  144. if ( _tcscmp ( szBOOL, _T("1")) == 0 )
  145. m_EnableDHCP = TRUE;
  146. else
  147. m_EnableDHCP = FALSE;
  148. ReadGeneralRegString(_T("ShowTrayIcon"), szBOOL, MAX_STRLEN);
  149. if ( _tcscmp ( szBOOL, _T("1")) == 0 )
  150. m_ShowTrayIcon = TRUE;
  151. else
  152. m_ShowTrayIcon = FALSE;
  153. ReadGeneralRegString(_T("Enabled"), szBOOL, MAX_STRLEN);
  154. if ( _tcscmp ( szBOOL, _T("1")) == 0 )
  155. m_EnableICS = TRUE;
  156. else
  157. m_EnableICS = FALSE;
  158. // save these off to check against on a save
  159. _tcsncpy ( m_OldExternalAdapterReg, m_ExternalAdapterReg, MAX_STRLEN);
  160. _tcsncpy ( m_OldInternalAdapterReg, m_InternalAdapterReg, MAX_STRLEN);
  161. _tcsncpy ( m_OldDialupEntry, m_DialupEntry, MAX_STRLEN);
  162. m_bOldEnableICS = m_EnableICS;
  163. }
  164. */
  165. void CConfig::InitWizardResult()
  166. {
  167. gWizardResult = gWizardSuccess;
  168. }
  169. void CConfig::WizardCancelled()
  170. {
  171. gWizardResult = gWizardCancelled;
  172. }
  173. void CConfig::WizardFailed()
  174. {
  175. gWizardResult = gWizardFailure;
  176. }