#pragma once
#include <winerror.h>
#include<BASETYPS.H>
#include <urlmon.h>
#pragma comment(lib, "urlmon.lib")
#include "FileCore.h"
#include "KeyVar.h"
#include <WinInet.h>
#include <tchar.h>

class DownloadProgress : public IBindStatusCallback
{

public:
    static double Currentpercentage;
    static double pro_Sum;
    static double pro_value;
    HRESULT __stdcall QueryInterface(const IID&, void**) {
        return E_NOINTERFACE;
    }
    ULONG STDMETHODCALLTYPE AddRef(void) {
        return 1;
    }
    ULONG STDMETHODCALLTYPE Release(void) {
        return 1;
    }
    HRESULT STDMETHODCALLTYPE OnStartBinding(DWORD dwReserved, IBinding* pib) {
        return E_NOTIMPL;
    }
    virtual HRESULT STDMETHODCALLTYPE GetPriority(LONG* pnPriority) {
        return E_NOTIMPL;
    }
    virtual HRESULT STDMETHODCALLTYPE OnLowResource(DWORD reserved) {
        return S_OK;
    }
    virtual HRESULT STDMETHODCALLTYPE OnStopBinding(HRESULT hresult, LPCWSTR szError) {
        return E_NOTIMPL;
    }
    virtual HRESULT STDMETHODCALLTYPE GetBindInfo(DWORD* grfBINDF, BINDINFO* pbindinfo) {
        return E_NOTIMPL;
    }
    virtual HRESULT STDMETHODCALLTYPE OnDataAvailable(DWORD grfBSCF, DWORD dwSize, FORMATETC* pformatetc, STGMEDIUM* pstgmed) {
        return E_NOTIMPL;
    }
    virtual HRESULT STDMETHODCALLTYPE OnObjectAvailable(REFIID riid, IUnknown* punk) {
        return E_NOTIMPL;
    }

    virtual HRESULT __stdcall OnProgress(ULONG ulProgress, ULONG ulProgressMax, ULONG ulStatusCode, LPCWSTR szStatusText)
    {
		if (ulProgressMax != 0)
		{

			pro_Sum = ulProgressMax;
			pro_value = ulProgress;
			double* percentage = new double(ulProgress * 1.0 / ulProgressMax * 100);
			DownloadProgress::Currentpercentage = *percentage;
			//将percentage 发送给显示
 
			delete percentage;
		}
        return S_OK;
    }
};


class CDownLoadFile
{
public:
    bool GetInstallPackage(std::wstring SaveFolder);
};

class NetWorkState
{
public:
    
    static bool IsNetWorking();//是否有网络
    
    static bool IsProxyEnable();//是否设置为LAN使用代理服务器
    
    static bool IsProxyNetError();//是否因开启代理服务器或代理参数不对，而没法联网
};