
#pragma once

#include "resource.h"		// main symbols

#define WDF_SECTION_NAME L"dnsfirewall_Device.NT.Wdf"
#define SERVICE_SECTION_NAME _T("dnsfirewall_Device.NT.Services")
#define SERVICE_DELETE_SECTION_NAME _T("dnsfirewall_Device.NT.Services.Delete")
#define DRIVER_SERVICE_NAME _T("dnsfirewall")
#define DEVICE_KEY _T("SYSTEM\\CurrentControlSet\\Enum\\Root\\LEGACY_DNSFIREWALL")
#define DEVICE_KEY_INSTANCE _T("Root\\LEGACY_DNSFIREWALL\\0000")
#define DEVICE_ID_HARDWARE _T("Root\\dnsfirewall")


static const TCHAR* c_sUsageStr = _T(
"\
Синтаксис командной строки:\n\
    PostInstallUtils -h    >\n\
                           > получение справки\n\
    PostInstallUtils -?    >\n\
    PostInstallUtils -install   > инсталляция драйвера \"dnsfirewall.sys\"\n\
    PostInstallUtils -uninstall > деинсталляция драйвера \"dnsfirewall.sys\" и сервиса \"Public DNS WS System\"\n\
");


// CPostInstallUtilsApp

enum ERebootPurpose : int
{
    enNoReboot = 0,
    enSetTesting,
    enWdfInstall,
    enDriverStore,
    enDriverService,
    enStopPluginService,
    enDeletePluginService,
    enStopDriverService,
    enDeleteDriverService,
    enDeleteDriverFile
};

class CPostInstallUtilsApp : public CWinApp
{
	DECLARE_DYNCREATE(CPostInstallUtilsApp)

public:
	CPostInstallUtilsApp();
	virtual ~CPostInstallUtilsApp();

public:
	virtual BOOL InitInstance();
	virtual int ExitInstance();

protected:
	DECLARE_MESSAGE_MAP()
public:
    bool m_bInstallDriver;
    bool m_bUninstallDriver;
    bool m_bUsageOut;
    bool m_bParseError;
    int m_nRetCode;
    CString m_sModuleFileName;
    CString m_sModuleFolder;
    CString m_sDriverFolder;
    CString m_sInfFilePath;
    ULONGLONG m_qwFileVersion;
    CString m_sVersionHTMLString;
    SID* m_pAdminsSid;
    BYTE m_abAdminsSidBuffer[SECURITY_MAX_SID_SIZE];
    DWORD m_dwAdminsSidSize;
    SID* m_pWorldSid;
    BYTE m_abWorldSidBuffer[SECURITY_MAX_SID_SIZE];
    DWORD m_dwWorldSidSize;
    HANDLE m_hProcessToken;
    bool SetProcessPrivilege(
        LPCTSTR lpszPrivilege,
        bool bEnablePrivilege
        );
    ACL* m_pDeviceKeyDacl;
    bool m_bRebootNeed;
    bool m_bTestModeInstalling;
    ERebootPurpose m_enRebootPurpose;
    bool m_bTestModeInstalled;
    bool m_bRootCertExist;
    bool m_bRootCertInstalled;
    bool m_bTrustedPublisherCertExist;
    bool m_bTrustedPublisherCertInstalled;
    CString m_sCoInstallerPath;
    HMODULE m_hCoInatallerModule;
    PFN_WDFPREDEVICEINSTALL m_pfnWdfPreDeviceInstall;
    PFN_WDFPOSTDEVICEINSTALL m_pfnWdfPostDeviceInstall;
    PFN_WDFPREDEVICEINSTALLEX m_pfnWdfPreDeviceInstallEx;
    PFN_WDFPREDEVICEREMOVE m_pfnWdfPreDeviceRemove;
    PFN_WDFPOSTDEVICEREMOVE m_pfnWdfPostDeviceRemove;
    CString m_sOEMInfFile;
    CString m_sDriversFolder;
    CString m_sCopyRightDates;
    void mfDeleteKey(
        HKEY hRootKey,
        LPCTSTR szKeyPath
        );
    HWND m_hParentWindow;
};

extern CPostInstallUtilsApp theApp;
