⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wizard.c

📁 ReactOS是一些高手根据Windows XP的内核编写出的类XP。内核实现机理和API函数调用几乎相同。甚至可以兼容XP的程序。喜欢研究系统内核的人可以看一看。
💻 C
📖 第 1 页 / 共 5 页
字号:
                               FALSE,
                               &priv,
                               sizeof(previouspriv),
                               &previouspriv,
                               &PrevSize) &&
         GetLastError() == ERROR_SUCCESS)
      {
        /*
         * We successfully enabled it, we're permitted to change the system time
         * Call SetLocalTime twice to ensure correct results
         */
        Ret = SetLocalTime(&SetupData->SystemTime) &&
              SetLocalTime(&SetupData->SystemTime);

        /*
         * for the sake of security, restore the previous status again
         */
        if(previouspriv.PrivilegeCount > 0)
        {
          AdjustTokenPrivileges(hToken,
                                FALSE,
                                &previouspriv,
                                0,
                                NULL,
                                0);
        }
      }
    }
    CloseHandle(hToken);
  }

  return Ret;
}

static BOOL
WriteDateTimeSettings(HWND hwndDlg, PSETUPDATA SetupData)
{
  WCHAR Title[64];
  WCHAR ErrorLocalTime[256];
  GetLocalSystemTime(hwndDlg, SetupData);
  SetLocalTimeZone(GetDlgItem(hwndDlg, IDC_TIMEZONELIST),
                   SetupData);

  SetAutoDaylightInfo(GetDlgItem(hwndDlg, IDC_AUTODAYLIGHT));
  if(!SetSystemLocalTime(hwndDlg, SetupData))
    {
      if (0 == LoadStringW(hDllInstance, IDS_REACTOS_SETUP, Title, sizeof(Title) / sizeof(Title[0])))
      {
        wcscpy(Title, L"ReactOS Setup");
      }
      if (0 == LoadStringW(hDllInstance, IDS_WZD_LOCALTIME, ErrorLocalTime,
                           sizeof(ErrorLocalTime) / sizeof(ErrorLocalTime[0])))
      {
        wcscpy(ErrorLocalTime, L"Setup failed to set the computer name.");
      }
      MessageBox(hwndDlg, ErrorLocalTime, Title, MB_ICONWARNING | MB_OK);
      return FALSE;
    }

  return TRUE;
}

static INT_PTR CALLBACK
DateTimePageDlgProc(HWND hwndDlg,
                    UINT uMsg,
                    WPARAM wParam,
                    LPARAM lParam)
{
  PSETUPDATA SetupData;
  WCHAR Title[64];
  WCHAR ErrorLocalTime[256];

  /* Retrieve pointer to the global setup data */
  SetupData = (PSETUPDATA)GetWindowLongPtr (hwndDlg, GWL_USERDATA);

  switch (uMsg)
    {
      case WM_INITDIALOG:
        {
          /* Save pointer to the global setup data */
          SetupData = (PSETUPDATA)((LPPROPSHEETPAGE)lParam)->lParam;
          SetWindowLongPtr(hwndDlg, GWL_USERDATA, (DWORD_PTR)SetupData);

          CreateTimeZoneList(SetupData);
          
          if (SetupData->UnattendSetup)
            {
              ShowTimeZoneList(GetDlgItem(hwndDlg, IDC_TIMEZONELIST),
                               SetupData, SetupData->TimeZoneIndex);

              if (!SetupData->DisableAutoDaylightTimeSet)
                {
                  SendDlgItemMessage(hwndDlg, IDC_AUTODAYLIGHT, BM_SETCHECK, (WPARAM)BST_CHECKED, 0);
                }
            }
          else
            {
              ShowTimeZoneList(GetDlgItem(hwndDlg, IDC_TIMEZONELIST),
                               SetupData, 85 /* GMT time zone */);

              SendDlgItemMessage(hwndDlg, IDC_AUTODAYLIGHT, BM_SETCHECK, (WPARAM)BST_CHECKED, 0);
            }

        }
        break;


      case WM_NOTIFY:
        {
          LPNMHDR lpnm = (LPNMHDR)lParam;

          switch (lpnm->code)
            {
              case PSN_SETACTIVE:
                /* Enable the Back and Next buttons */
                PropSheet_SetWizButtons(GetParent(hwndDlg), PSWIZB_BACK | PSWIZB_NEXT);
                if (SetupData->UnattendSetup && WriteDateTimeSettings(hwndDlg, SetupData))
                  {
                    SetWindowLong(hwndDlg, DWL_MSGRESULT, IDD_PROCESSPAGE);
                    return TRUE;
                  }
                break;

              case PSN_WIZNEXT:
                {
                  GetLocalSystemTime(hwndDlg, SetupData);
                  SetLocalTimeZone(GetDlgItem(hwndDlg, IDC_TIMEZONELIST),
                                   SetupData);
                  SetAutoDaylightInfo(GetDlgItem(hwndDlg, IDC_AUTODAYLIGHT));
                  if(!SetSystemLocalTime(hwndDlg, SetupData))
                  {
                    if (0 == LoadStringW(hDllInstance, IDS_REACTOS_SETUP, Title, sizeof(Title) / sizeof(Title[0])))
                    {
                      wcscpy(Title, L"ReactOS Setup");
                    }
                    if (0 == LoadStringW(hDllInstance, IDS_WZD_LOCALTIME, ErrorLocalTime,
                                         sizeof(ErrorLocalTime) / sizeof(ErrorLocalTime[0])))
                    {
                      wcscpy(ErrorLocalTime, L"Setup failed to set the computer name.");
                    }
                    MessageBox(hwndDlg, ErrorLocalTime, Title, MB_ICONWARNING | MB_OK);
                  }
                }
                break;

              case PSN_WIZBACK:
                SetupData->UnattendSetup = FALSE;
                break;

              default:
                break;
            }
        }
        break;

      case WM_DESTROY:
        DestroyTimeZoneList(SetupData);
        break;

      default:
        break;
    }

  return FALSE;
}


static UINT CALLBACK
RegistrationNotificationProc(PVOID Context,
                             UINT Notification,
                             UINT_PTR Param1,
                             UINT_PTR Param2)
{
  PREGISTRATIONDATA RegistrationData;
  REGISTRATIONNOTIFY RegistrationNotify;
  PSP_REGISTER_CONTROL_STATUSW StatusInfo;
  UINT MessageID;
  WCHAR ErrorMessage[128];

  RegistrationData = (PREGISTRATIONDATA) Context;

  if (SPFILENOTIFY_STARTREGISTRATION == Notification ||
      SPFILENOTIFY_ENDREGISTRATION == Notification)
    {
      StatusInfo = (PSP_REGISTER_CONTROL_STATUSW) Param1;
      RegistrationNotify.CurrentItem = wcsrchr(StatusInfo->FileName, L'\\');
      if (NULL == RegistrationNotify.CurrentItem)
        {
          RegistrationNotify.CurrentItem = StatusInfo->FileName;
        }
      else
        {
          RegistrationNotify.CurrentItem++;
        }

      if (SPFILENOTIFY_STARTREGISTRATION == Notification)
        {
          DPRINT("Received SPFILENOTIFY_STARTREGISTRATION notification for %S\n",
                 StatusInfo->FileName);
          RegistrationNotify.ErrorMessage = NULL;
          RegistrationNotify.Progress = RegistrationData->Registered;
        }
      else
        {
          DPRINT("Received SPFILENOTIFY_ENDREGISTRATION notification for %S\n",
                 StatusInfo->FileName);
          DPRINT("Win32Error %u FailureCode %u\n", StatusInfo->Win32Error,
                 StatusInfo->FailureCode);
          if (SPREG_SUCCESS != StatusInfo->FailureCode)
            {
              switch(StatusInfo->FailureCode)
                {
                case SPREG_LOADLIBRARY:
                  MessageID = IDS_LOADLIBRARY_FAILED;
                  break;
                case SPREG_GETPROCADDR:
                  MessageID = IDS_GETPROCADDR_FAILED;
                  break;
                case SPREG_REGSVR:
                  MessageID = IDS_REGSVR_FAILED;
                  break;
                case SPREG_DLLINSTALL:
                  MessageID = IDS_DLLINSTALL_FAILED;
                  break;
                case SPREG_TIMEOUT:
                  MessageID = IDS_TIMEOUT;
                  break;
                default:
                  MessageID = IDS_REASON_UNKNOWN;
                  break;
                }
              if (0 == LoadStringW(hDllInstance, MessageID,
                                   ErrorMessage,
                                   sizeof(ErrorMessage) /
                                   sizeof(ErrorMessage[0])))
                {
                  ErrorMessage[0] = L'\0';
                }
              if (SPREG_TIMEOUT != StatusInfo->FailureCode)
                {
                  FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM, NULL,
                                 StatusInfo->Win32Error, 0, 
                                 ErrorMessage + wcslen(ErrorMessage),
                                 sizeof(ErrorMessage) / sizeof(ErrorMessage[0]) -
                                 wcslen(ErrorMessage), NULL);
                }
              RegistrationNotify.ErrorMessage = ErrorMessage;
            }
          else
            {
              RegistrationNotify.ErrorMessage = NULL;
            }
          if (RegistrationData->Registered < RegistrationData->DllCount)
            {
              RegistrationData->Registered++;
            }
        }

      RegistrationNotify.Progress = RegistrationData->Registered;
      RegistrationNotify.ActivityID = IDS_REGISTERING_COMPONENTS;
      SendMessage(RegistrationData->hwndDlg, PM_REGISTRATION_NOTIFY,
                  0, (LPARAM) &RegistrationNotify);

      return FILEOP_DOIT;
    }
  else
    {
      DPRINT1("Received unexpected notification %u\n", Notification);
      return SetupDefaultQueueCallback(RegistrationData->DefaultContext,
                                       Notification, Param1, Param2);
    }
}


static DWORD CALLBACK
RegistrationProc(LPVOID Parameter)
{
  PREGISTRATIONDATA RegistrationData;
  REGISTRATIONNOTIFY RegistrationNotify;
  DWORD LastError = NO_ERROR;
  WCHAR UnknownError[84];

  RegistrationData = (PREGISTRATIONDATA) Parameter;
  RegistrationData->Registered = 0;
  RegistrationData->DefaultContext = SetupInitDefaultQueueCallback(RegistrationData->hwndDlg);

  _SEH_TRY
    {
      if (!SetupInstallFromInfSectionW(GetParent(RegistrationData->hwndDlg),
                                       hSysSetupInf,
                                       L"RegistrationPhase2",
                                       SPINST_REGISTRY |
                                       SPINST_REGISTERCALLBACKAWARE  |
                                       SPINST_REGSVR,
                                       0,
                                       NULL,
                                       0,
                                       RegistrationNotificationProc,
                                       RegistrationData,
                                       NULL,
                                       NULL))
        {
          LastError = GetLastError();
        }
    }
  _SEH_HANDLE
    {
      DPRINT("Catching exception\n");
      LastError = RtlNtStatusToDosError(_SEH_GetExceptionCode());
    }
  _SEH_END;

  if (NO_ERROR == LastError)
    {
      RegistrationNotify.ErrorMessage = NULL;
    }
  else
    {
      DPRINT1("SetupInstallFromInfSection failed with error %u\n",
              LastError);
      if (0 == FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER |
                              FORMAT_MESSAGE_FROM_SYSTEM, NULL, LastError, 0,
                              (LPWSTR) &RegistrationNotify.ErrorMessage, 0,
                              NULL))
        {
          if (0 == LoadStringW(hDllInstance, IDS_UNKNOWN_ERROR,
                               UnknownError,
                               sizeof(UnknownError) / sizeof(UnknownError[0] -
                               20)))
            {
              wcscpy(UnknownError, L"Unknown error");
            }
          wcscat(UnknownError, L" ");
          _ultow(LastError, UnknownError + wcslen(UnknownError), 10);
          RegistrationNotify.ErrorMessage = UnknownError;
        }
    }

  RegistrationNotify.Progress = RegistrationData->DllCount;
  RegistrationNotify.ActivityID = IDS_REGISTERING_COMPONENTS;
  RegistrationNotify.CurrentItem = NULL;
  SendMessage(RegistrationData->hwndDlg, PM_REGISTRATION_NOTIFY,
              1, (LPARAM) &RegistrationNotify);
  if (NULL != RegistrationNotify.ErrorMessage &&
      UnknownError != RegistrationNotify.ErrorMessage)
    {
      LocalFree((PVOID) RegistrationNotify.ErrorMessage);
    }

  SetupTermDefaultQueueCallback(RegistrationData->DefaultContext);
  HeapFree(GetProcessHeap(), 0, RegistrationData);

  return 0;
}


static BOOL
StartComponentRegistration(HWND hwndDlg, PULONG MaxProgress)
{
  HANDLE RegistrationThread;
  LONG DllCount;
  INFCONTEXT Context;
  WCHAR SectionName[512];
  PREGISTRATIONDATA RegistrationData;
  
  DllCount = -1;
  if (! SetupFindFirstLineW(hSysSetupInf, L"RegistrationPhase2",
                            L"RegisterDlls", &Context))
    {
      DPRINT1("No RegistrationPhase2 section found\n");
      return FALSE;
    }
  if (! SetupGetStringFieldW(&Context, 1, SectionName,
                             sizeof(SectionName) / sizeof(SectionName[0]),
                             NULL))
    {
      DPRINT1("Unable to retrieve section name\n");
      return FALSE;
    }
  DllCount = SetupGetLineCountW(hSysSetupInf, SectionName);
  DPRINT("SectionName %S DllCount %ld\n", SectionName, DllCount);
  if (DllCount < 0)
    {
      SetLastError(STATUS_NOT_FOUND);
      return FALSE;
    }

  *MaxProgress = (ULONG) DllCount;

  /*
   * Create a background thread to do the actual registrations, so the
   * main thread can just run its message loop.
   */
  RegistrationThread = NULL;
  RegistrationData = HeapAlloc(GetProcessHeap(), 0,
                               sizeof(REGISTRATIONDATA));
  if (NULL != RegistrationData)
    {
      RegistrationData->hwndDlg = hwndDlg;
      RegistrationData->DllCount = DllCount;
      RegistrationThread = CreateThread(NULL, 0, RegistrationProc,
                                        (LPVOID) RegistrationData, 0, NULL);
      if (NULL != RegistrationThread)
        {
          CloseHandle(RegistrationThread);
        }
      else
        {
          DPRINT1("CreateThread failed, error %u\n", GetLastError());
          return FALSE;
        }
    }
  else
    {
      DPRINT1("HeapAlloc() failed, error %u\n", GetLastError());
      return FALSE;
    }

  return TRUE;
}


static INT_PTR CALLBACK
ProcessPageDlgProc(HWND hwndDlg,
                   UINT uMsg,
                   WPARAM wParam,
                   LPARAM lParam)
{
  PSETUPDATA SetupData;
  PREGISTRATIONNOTIFY RegistrationNotify;
  WCHAR Title[64];

  /* Retrieve pointer to the global setup data */
  SetupData = (PSETUPDATA)GetWindowLongPtr (hwndDlg, GWL_USERDATA);

  switch (uMsg)
    {
      case WM_INITDIALOG:
        {
          /* Save pointer to the global setup data */
          SetupData = (PSETUPDATA)((LPPROPSHEETPAGE)lParam)->lParam;
          SetWindowLongPtr(hwndDlg, GWL_USERDATA, (DWORD_PTR)SetupData);
        }
        break;

      case WM_NOTIFY:
        {
          LPNMHDR lpnm = (LPNMHDR)lParam;
          ULONG MaxProgress = 0;

          switch (lpnm->code)
            {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -