[IERNONCE] Add InitCallback function

This commit is contained in:
He Yang 2021-08-22 17:25:01 +08:00 committed by George Bișoc
parent 32340a2ae6
commit 5ce6ce18f4
No known key found for this signature in database
GPG key ID: 49452AAF629C81F3
8 changed files with 119 additions and 51 deletions

View file

@ -4,10 +4,14 @@ include_directories(include)
spec2def(iernonce.dll iernonce.spec)
add_library(iernonce MODULE
list(APPEND SOURCE
dialog.cpp
iernonce.cpp
registry.cpp
iernonce.h)
add_library(iernonce MODULE
${SOURCE}
iernonce.rc
${CMAKE_CURRENT_BINARY_DIR}/iernonce.def)
@ -15,4 +19,5 @@ set_module_type(iernonce win32dll UNICODE)
target_link_libraries(iernonce cppstl atl_classes)
set_target_cpp_properties(iernonce WITH_EXCEPTIONS)
add_importlibs(iernonce advapi32 msvcrt gdi32 ole32 shell32 shlwapi kernel32 user32 ntdll)
add_pch(iernonce iernonce.h SOURCE)
add_cd_file(TARGET iernonce DESTINATION reactos/system32 FOR all)

View file

@ -5,14 +5,9 @@
* COPYRIGHT: Copyright 2021 He Yang <1160386205@qq.com>
*/
#include <atlbase.h>
#include <atlwin.h>
#include <windowsx.h>
#include "iernonce.h"
#include <process.h>
#include "dialog.h"
#include "registry.h"
#define ITEM_VPADDING 3
#define ITEM_LEFTPADDING 22
@ -37,10 +32,7 @@ BOOL ProgressDlg::RunDialogBox()
// Show the dialog and run the items only when the list is not empty.
if (m_RunOnceExInst.m_SectionList.GetSize() != 0)
{
if (DoModal() == -1)
{
return FALSE;
}
return (DoModal() == 1);
}
return TRUE;
}
@ -220,8 +212,8 @@ ProgressDlg::ProcessWindowMessage(
{
if ((int)wParam == m_RunOnceExInst.m_SectionList.GetSize())
{
// All sections are handled.
EndDialog(0);
// All sections are handled, lParam is bSuccess.
EndDialog(lParam);
}
m_PointedItem = wParam;
InvalidateRect(NULL);

View file

@ -13,6 +13,8 @@
#include "resource.h"
#include "registry.h"
// When wParam < item count ==> wParam is item index (0 based)
// wParam = item count ==> all finished, lParam = bSuccess
#define WM_SETINDEX (WM_USER + 1)
class ProgressDlg : public CDialogImpl<ProgressDlg>

View file

@ -6,16 +6,10 @@
* Copyright 2021 He Yang <1160386205@qq.com>
*/
#define WIN32_NO_STATUS
#include <windef.h>
#include <winbase.h>
#include <windows.h>
#include "iernonce.h"
#define NDEBUG
#include <debug.h>
#include "registry.h"
#include "dialog.h"
RUNONCEEX_CALLBACK g_Callback = NULL;
BOOL g_bSilence = FALSE;
BOOL
WINAPI
@ -52,28 +46,16 @@ RunOnceExProcess(_In_ HWND hwnd,
for (UINT i = 0; i < _countof(RootKeys); ++i)
{
RunOnceExInstance Instance(RootKeys[i]);
if (!Instance.m_bSuccess)
continue;
if ((Instance.m_dwFlags & FLAGS_NO_STAT_DIALOG) || !Instance.m_bShowDialog)
{
Instance.Exec(NULL);
}
else
{
// The dialog is responsible to create a thread and execute.
ProgressDlg dlg(Instance);
dlg.RunDialogBox();
}
Instance.Run(g_bSilence);
}
CoUninitialize();
}
extern "C" VOID WINAPI
InitCallback(
_In_ PVOID Callback,
_In_ BOOL bSilence)
InitCallback(_In_ RUNONCEEX_CALLBACK Callback,
_In_ BOOL bSilence)
{
// FIXME: unimplemented
g_Callback = Callback;
g_bSilence = bSilence;
}

View file

@ -0,0 +1,24 @@
/*
* PROJECT: ReactOS system libraries
* LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
* PURPOSE: ReactOS Extended RunOnce processing with UI.
* COPYRIGHT: Copyright 2021 He Yang <1160386205@qq.com>
*/
#pragma once
#include <cassert>
#include <cstdlib>
#define WIN32_NO_STATUS
#include <windef.h>
#include <winbase.h>
#include <windowsx.h>
#include <shlwapi.h>
#include <iernonce_undoc.h>
#include <atlbase.h>
#include <atlwin.h>
#include "registry.h"
#include "dialog.h"

View file

@ -71,7 +71,11 @@ public:
BOOL CloseAndDelete(_In_ CRegKeyEx &hParentKey);
BOOL Exec();
UINT GetEntryCnt() const;
BOOL Exec(
_Inout_ UINT& iCompleteCnt,
_In_ const UINT iTotalCnt);
friend int RunOnceExSectionCmp(
_In_ const void *a,
@ -99,4 +103,5 @@ public:
RunOnceExInstance(_In_ HKEY BaseKey);
BOOL Exec(_In_opt_ HWND hwnd);
BOOL Run(_In_ BOOL bSilence);
};

View file

@ -5,15 +5,9 @@
* COPYRIGHT: Copyright 2021 He Yang <1160386205@qq.com>
*/
#include "iernonce.h"
#include <cassert>
#include <cstdlib>
#include <shlwapi.h>
#include <windows.h>
#include <winreg.h>
#include "registry.h"
#include "dialog.h"
extern RUNONCEEX_CALLBACK g_Callback;
LONG CRegKeyEx::EnumValueName(
_In_ DWORD iIndex,
@ -199,7 +193,14 @@ BOOL RunOnceExSection::CloseAndDelete(
return hParentKey.RecurseDeleteKey(m_SectionName) == ERROR_SUCCESS;
}
BOOL RunOnceExSection::Exec()
UINT RunOnceExSection::GetEntryCnt() const
{
return m_EntryList.GetSize();
}
BOOL RunOnceExSection::Exec(
_Inout_ UINT& iCompleteCnt,
_In_ const UINT iTotalCnt)
{
BOOL bSuccess = TRUE;
@ -207,6 +208,10 @@ BOOL RunOnceExSection::Exec()
{
m_EntryList[i].Delete(m_RegKey);
bSuccess &= m_EntryList[i].Exec();
iCompleteCnt++;
// TODO: the meaning of the third param is still unknown, seems it's always 0.
if (g_Callback)
g_Callback(iCompleteCnt, iTotalCnt, NULL);
}
return bSuccess;
}
@ -289,13 +294,20 @@ BOOL RunOnceExInstance::Exec(_In_opt_ HWND hwnd)
{
BOOL bSuccess = TRUE;
UINT TotalCnt = 0;
UINT CompleteCnt = 0;
for (int i = 0; i < m_SectionList.GetSize(); i++)
{
TotalCnt += m_SectionList[i].GetEntryCnt();
}
// Execute items from registry one by one, and remove them.
for (int i = 0; i < m_SectionList.GetSize(); i++)
{
if (hwnd)
SendMessageW(hwnd, WM_SETINDEX, i, 0);
bSuccess &= m_SectionList[i].Exec();
bSuccess &= m_SectionList[i].Exec(CompleteCnt, TotalCnt);
m_SectionList[i].CloseAndDelete(m_RegKey);
}
@ -304,10 +316,26 @@ BOOL RunOnceExInstance::Exec(_In_opt_ HWND hwnd)
// Notify the dialog all sections are handled.
if (hwnd)
SendMessageW(hwnd, WM_SETINDEX, m_SectionList.GetSize(), 0);
SendMessageW(hwnd, WM_SETINDEX, m_SectionList.GetSize(), bSuccess);
return bSuccess;
}
BOOL RunOnceExInstance::Run(_In_ BOOL bSilence)
{
if (bSilence ||
(m_dwFlags & FLAGS_NO_STAT_DIALOG) ||
!m_bShowDialog)
{
return Exec(NULL);
}
else
{
// The dialog is responsible to create a thread and execute.
ProgressDlg dlg(*this);
return dlg.RunDialogBox();
}
}
BOOL RunOnceExInstance::HandleSubKey(
_In_ CRegKeyEx &hKey,
_In_ const CStringW& SubKeyName)

View file

@ -0,0 +1,30 @@
#ifndef _IERNONCE_UNDOC_H_
#define _IERNONCE_UNDOC_H_
#ifdef __cplusplus
extern "C" {
#endif
typedef VOID
(CALLBACK *RUNONCEEX_CALLBACK)(
_In_ UINT CompleteCnt,
_In_ UINT TotalCnt,
_In_ DWORD_PTR dwReserved);
VOID WINAPI
InitCallback(
_In_ RUNONCEEX_CALLBACK Callback,
_In_ BOOL bSilence);
VOID WINAPI
RunOnceExProcess(
_In_ HWND hwnd,
_In_ HINSTANCE hInst,
_In_ LPCSTR pszCmdLine,
_In_ int nCmdShow);
#ifdef __cplusplus
}
#endif
#endif /* _IERNONCE_UNDOC_H_ */