// InstallUtils.h : main header file for the InstallUtils DLL
//

#pragma once

#ifdef INSTALL_UTILS_EXPORTS
#define INSTALL_UTILS_API __declspec(dllexport)
#else
#define INSTALL_UTILS_API __declspec(dllimport)
#endif

#ifndef __AFXWIN_H__
	#error "include 'stdafx.h' before including this file for PCH"
#endif

#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")


// CInstallUtilsApp
// See InstallUtils.cpp for the implementation of this class
//

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

class CInstallUtilsApp : public CWinApp
{
public:
	CInstallUtilsApp();

// Overrides
public:
	virtual BOOL InitInstance();

	DECLARE_MESSAGE_MAP()
public:
    MSIHANDLE m_hInstallDB;
    CString m_sCopyRightDates;
    CString m_sVersionHTMLString;
    int m_nRetCode;
    CString m_sModuleFileName;
    virtual int ExitInstance();
    ULONGLONG m_qwFileVersion;
    bool m_bRebootNeed;
    HMODULE m_hDllModule;
    CString m_sModuleFolder;
    CString m_sDriverFolder;
    CString m_sInfFilePath;
    bool m_bTestModeInstalled;
    bool m_bTestModeInstalling;
    ERebootPurpose m_enRebootPurpose;
    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;
    void mfDeleteKey(
        HKEY hRootKey,
        LPCTSTR szKeyPath
        );
    ACL* m_pDeviceKeyDacl;
    HANDLE m_hProcessToken;
    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;
    bool SetProcessPrivilege(
        LPCTSTR lpszPrivilege,
        bool bEnablePrivilege
        );
    HWND m_hParentWindow;
    UINT mInstallDnsFirewallDriver(MSIHANDLE hInstall);
    UINT mUninstallServicesAndDrivers(MSIHANDLE hInstall);
    DWORD m_dwProcessID;
};

// The one and only CInstallUtilsApp object
extern CInstallUtilsApp theApp;

extern "C" INSTALL_UTILS_API UINT __stdcall  InstallDnsFirewallDriver(MSIHANDLE hInstall);
extern "C" INSTALL_UTILS_API UINT __stdcall  UninstallServicesAndDrivers(MSIHANDLE hInstall);
