Source code of Windows XP (NT5)
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.

128 lines
3.2 KiB

  1. /****************************************************\
  2. FILE: offline.cpp
  3. DESCRIPTION:
  4. Handle 'offline' status and Dial-up UI
  5. \****************************************************/
  6. #include "priv.h"
  7. #include "util.h"
  8. #ifdef FEATURE_OFFLINE
  9. /****************************************************\
  10. FUNCTION: IsGlobalOffline
  11. DESCRIPTION:
  12. Determines whether wininet is in global offline mode
  13. PARAMETERS:
  14. None
  15. RETURN VALUE:
  16. BOOL
  17. TRUE - offline
  18. FALSE - online
  19. \****************************************************/
  20. BOOL IsGlobalOffline(VOID)
  21. {
  22. DWORD dwState = 0, dwSize = sizeof(DWORD);
  23. BOOL fRet = FALSE;
  24. if(InternetQueryOption(NULL, INTERNET_OPTION_CONNECTED_STATE, &dwState, &dwSize))
  25. {
  26. if(dwState & INTERNET_STATE_DISCONNECTED_BY_USER)
  27. fRet = TRUE;
  28. }
  29. return fRet;
  30. }
  31. /****************************************************\
  32. FUNCTION: SetOffline
  33. DESCRIPTION:
  34. Sets wininet's offline mode
  35. PARAMETERS:
  36. fOffline - online or offline
  37. RETURN VALUE:
  38. None.
  39. \****************************************************/
  40. VOID SetOffline(IN BOOL fOffline)
  41. {
  42. INTERNET_CONNECTED_INFO ci = {0};
  43. if(fOffline)
  44. {
  45. ci.dwConnectedState = INTERNET_STATE_DISCONNECTED_BY_USER;
  46. ci.dwFlags = ISO_FORCE_DISCONNECTED;
  47. }
  48. else
  49. {
  50. ci.dwConnectedState = INTERNET_STATE_CONNECTED;
  51. }
  52. InternetSetOption(NULL, INTERNET_OPTION_CONNECTED_STATE, &ci, sizeof(ci));
  53. }
  54. #endif // FEATURE_OFFLINE
  55. /****************************************************\
  56. FUNCTION: AssureNetConnection
  57. DESCRIPTION:
  58. \****************************************************/
  59. HRESULT AssureNetConnection(HINTERNET hint, HWND hwndParent, LPCWSTR pwzServerName, LPCITEMIDLIST pidl, BOOL fShowUI)
  60. {
  61. HRESULT hr = S_OK;
  62. #ifdef FEATURE_OFFLINE
  63. if (IsGlobalOffline())
  64. {
  65. // Assume we need to cancel the FTP operation because we are offline.
  66. hr = HRESULT_FROM_WIN32(ERROR_CANCELLED);
  67. // Can we prompt to go online?
  68. if (fShowUI)
  69. {
  70. TCHAR szTitle[MAX_PATH];
  71. TCHAR szPromptMsg[MAX_PATH];
  72. EVAL(LoadString(HINST_THISDLL, IDS_FTPERR_TITLE, szTitle, ARRAYSIZE(szTitle)));
  73. EVAL(LoadString(HINST_THISDLL, IDS_OFFLINE_PROMPTTOGOONLINE, szPromptMsg, ARRAYSIZE(szPromptMsg)));
  74. if (IDYES == MessageBox(hwndParent, szPromptMsg, szTitle, (MB_ICONQUESTION | MB_YESNO)))
  75. {
  76. SetOffline(FALSE);
  77. hr = S_OK;
  78. }
  79. }
  80. }
  81. #endif // FEATURE_OFFLINE
  82. #ifdef FEATURE_DIALER
  83. if (S_OK == hr)
  84. {
  85. TCHAR szUrl[MAX_URL_STRING];
  86. StrCpyN(szUrl, TEXT("ftp://"), ARRAYSIZE(szUrl));
  87. StrCatBuff(szUrl, pwzServerName, ARRAYSIZE(szUrl));
  88. // PERF: Does this value get cached?
  89. if (FALSE == InternetCheckConnection(szUrl, FLAG_ICC_FORCE_CONNECTION, 0)
  90. ||
  91. #ifdef FEATURE_TEST_DIALER
  92. (IDNO == MessageBox(hwndParent, TEXT("TEST: Do you want to dial?"), TEXT("Test Dialer"), MB_YESNO))
  93. #endif // FEATURE_TEST_DIALER
  94. )
  95. {
  96. hr = HRESULT_FROM_WIN32(ERROR_CANCELLED);
  97. }
  98. }
  99. #endif // FEATURE_DIALER
  100. return hr;
  101. }