/*
 * Copyright 2015 Jacek Caban for CodeWeavers
 * Copyright 2016 Michael Müller
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
 */

#ifndef __WIDL__
#define threading(model)
#endif

cpp_quote("#if 0")
import "unknwn.idl";
cpp_quote("#endif")

interface IStream;

cpp_quote("#define MAX_ID_LENGTH            48")
cpp_quote("#define MAX_DISPLAYNAME_LENGTH   128")

cpp_quote("#define URLF_DEFAULT                 0x0")
cpp_quote("#define URLF_EXTRACT                 0x1")
cpp_quote("#define URLF_RELATIVEURL             0x2")
cpp_quote("#define URLF_DELETE_AFTER_EXTRACT    0x4")

cpp_quote("#define ENGINESTATUS_NOTREADY    0x0")
cpp_quote("#define ENGINESTATUS_LOADING     0x1")
cpp_quote("#define ENGINESTATUS_INSTALLING  0x2")
cpp_quote("#define ENGINESTATUS_READY       0x3")

cpp_quote("#define SETACTION_NONE       0x0")
cpp_quote("#define SETACTION_INSTALL    0x1")

cpp_quote("#define INSTALLOPTIONS_NOCACHE               0x01")
cpp_quote("#define INSTALLOPTIONS_DOWNLOAD              0x02")
cpp_quote("#define INSTALLOPTIONS_INSTALL               0x04")
cpp_quote("#define INSTALLOPTIONS_DONTALLOWXPLATFORM    0x08")
cpp_quote("#define INSTALLOPTIONS_FORCEDEPENDENCIES     0x10")

cpp_quote("#define EXECUTEJOB_SILENT                0x01")
cpp_quote("#define EXECUTEJOB_DELETE_JOB            0x02")
cpp_quote("#define EXECUTEJOB_VERIFYFILES           0x08")
cpp_quote("#define EXECUTEJOB_IGNORETRUST           0x10")
cpp_quote("#define EXECUTEJOB_IGNOREDOWNLOADERROR   0x20")
cpp_quote("#define EXECUTEJOB_DONTALLOWCANCEL       0x40")

cpp_quote("#define ENGINEPROBLEM_DOWNLOADFAIL   0x1")

cpp_quote("#define PLATFORM_WIN95       0x01")
cpp_quote("#define PLATFORM_WIN98       0x02")
cpp_quote("#define PLATFORM_NT4         0x04")
cpp_quote("#define PLATFORM_NT5         0x08")
cpp_quote("#define PLATFORM_NT4ALPHA    0x10")
cpp_quote("#define PLATFORM_NT5ALPHA    0x20")
cpp_quote("#define PLATFORM_MILLEN      0x40")
cpp_quote("#define PLATFORM_ALL         (PLATFORM_WIN95 | PLATFORM_WIN98 | PLATFORM_NT4 | PLATFORM_NT5 | PLATFORM_NT4ALPHA | PLATFORM_NT5ALPHA | PLATFORM_MILLEN)")

enum InstallStatus
{
    INSTALLSTATUS_INITIALIZING,
    INSTALLSTATUS_DEPENDENCY,
    INSTALLSTATUS_DOWNLOADING,
    INSTALLSTATUS_COPYING,
    INSTALLSTATUS_RETRYING,
    INSTALLSTATUS_CHECKINGTRUST,
    INSTALLSTATUS_EXTRACTING,
    INSTALLSTATUS_RUNNING,
    INSTALLSTATUS_FINISHED,
    INSTALLSTATUS_DOWNLOADFINISHED,
};

enum ComponentAction
{
    ActionNone,
    ActionInstall,
    ActionUninstall,
};

[
    object,
    local,
    pointer_default(unique)
]
interface ICifComponent
{
    HRESULT GetID(char *id, DWORD size);
    HRESULT GetGUID(char *guid, DWORD size);
    HRESULT GetDescription(char *desc, DWORD size);
    HRESULT GetDetails(char *details, DWORD size);
    HRESULT GetUrl(UINT index, char *url, DWORD size, DWORD *flags);
    HRESULT GetFileExtractList(UINT index, char *extract, DWORD size);
    HRESULT GetUrlCheckRange(UINT index, DWORD *min, DWORD *max);
    HRESULT GetCommand(UINT index, char *cmd, DWORD cmd_size, char *switches, DWORD switch_size, DWORD *type);
    HRESULT GetVersion(DWORD *version, DWORD *build);
    HRESULT GetLocale(char *pszLocale, DWORD size);
    HRESULT GetUninstallKey(char *key, DWORD size);
    HRESULT GetInstalledSize(DWORD *win, DWORD *app);
    DWORD GetDownloadSize();
    DWORD GetExtractSize();
    HRESULT GetSuccessKey(char *key, DWORD size);
    HRESULT GetProgressKeys(char *progress, DWORD progress_size, char *cancel, DWORD cancel_size);
    HRESULT IsActiveSetupAware();
    HRESULT IsRebootRequired();
    HRESULT RequiresAdminRights();
    DWORD GetPriority();
    HRESULT GetDependency(UINT index, char *id, DWORD buf, char *type, DWORD *ver, DWORD *build);
    DWORD GetPlatform();
    HRESULT GetMode(UINT index, char *mode, DWORD size);
    HRESULT GetGroup(char *id, DWORD size);
    HRESULT IsUIVisible();
    HRESULT GetPatchID(char *id, DWORD size);
    HRESULT GetDetVersion(char *dll, DWORD dll_size, char *entry, DWORD entry_size);
    HRESULT GetTreatAsOneComponents(UINT index, char *id, DWORD buf);
    HRESULT GetCustomData(char *key, char *data, DWORD size);
    DWORD IsComponentInstalled();
    HRESULT IsComponentDownloaded();
    DWORD IsThisVersionInstalled(DWORD version, DWORD build, DWORD *ret_version, DWORD *ret_build);
    DWORD GetInstallQueueState();
    HRESULT SetInstallQueueState(DWORD state);
    DWORD GetActualDownloadSize();
    DWORD GetCurrentPriority();
    HRESULT SetCurrentPriority(DWORD priority);
};

[
    object,
    local,
    pointer_default(unique)
]
interface ICifRWComponent : ICifComponent
{
    HRESULT SetGUID(const char *guid);
    HRESULT SetDescription(const char *desc);
    HRESULT SetUrl(UINT index, const char *url, DWORD url_flags);
    HRESULT SetCommand(UINT index, const char *cmd, const char *switches, DWORD type);
    HRESULT SetVersion(const char *version);
    HRESULT SetUninstallKey(const char *key);
    HRESULT SetInstalledSize(DWORD win, DWORD app);
    HRESULT SetDownloadSize(DWORD size);
    HRESULT SetExtractSize(DWORD size);
    HRESULT DeleteDependency(const char *id, char type);
    HRESULT AddDependency(const char *id, char type);
    HRESULT SetUIVisible(BOOL visible);
    HRESULT SetGroup(const char *id);
    HRESULT SetPlatform(DWORD platform);
    HRESULT SetPriority(DWORD priority);
    HRESULT SetReboot(BOOL reboot);
    HRESULT DeleteFromModes(const char *mode);
    HRESULT AddToMode(const char *mode);
    HRESULT SetModes(const char *mode);
    HRESULT CopyComponent(const char *ciffile);
    HRESULT AddToTreatAsOne(const char *compid);
    HRESULT SetDetails(const char *desc);
};

[
    object,
    local,
    pointer_default(unique)
]
interface IEnumCifComponents : IUnknown
{
    HRESULT Next(ICifComponent **);
    HRESULT Reset();
};

[
    object,
    local,
    pointer_default(unique)
]
interface ICifGroup
{
    HRESULT GetID(char *id, DWORD size);
    HRESULT GetDescription(char *desc, DWORD size);
    DWORD GetPriority();

    HRESULT EnumComponents(IEnumCifComponents **, DWORD filter, void *pv);
    DWORD GetCurrentPriority();
};

[
    object,
    local,
    pointer_default(unique)
]
interface ICifRWGroup : ICifGroup
{
   HRESULT SetDescription(const char *desc);
   HRESULT SetPriority(DWORD priority);
   HRESULT SetDetails(const char *details);
};

[
    object,
    local,
    pointer_default(unique)
]
interface IEnumCifGroups : IUnknown
{
    HRESULT Next(ICifGroup **);
    HRESULT Reset();
};

[
    object,
    local,
    pointer_default(unique)
]
interface ICifMode
{
    HRESULT GetID(char *id, DWORD size);
    HRESULT GetDescription(char *desc, DWORD size);
    HRESULT GetDetails(char *details, DWORD size);

    HRESULT EnumComponents(IEnumCifComponents **, DWORD filter, void *pv);
};

[
    object,
    local,
    pointer_default(unique)
]
interface ICifRWMode : ICifMode
{
    HRESULT SetDescription(const char *desc);
    HRESULT SetDetails(const char *details);
};

[
    object,
    local,
    pointer_default(unique)
]
interface IEnumCifModes : IUnknown
{
    HRESULT Next(ICifMode **);
    HRESULT Reset();
};

typedef struct
{
    DWORD cbSize;
    DWORD dwInstallSize;
    DWORD dwWinDriveSize;
    DWORD dwDownloadSize;
    DWORD dwDependancySize;
    DWORD dwInstallDriveReq;
    DWORD dwWinDriveReq;
    DWORD dwDownloadDriveReq;
    char chWinDrive;
    char chInstallDrive;
    char chDownloadDrive;
    DWORD dwTotalDownloadSize;
} COMPONENT_SIZES;

typedef struct
{
    DWORD cbSize;
    DWORD dwDownloadKBRemaining;
    DWORD dwInstallKBRemaining;
    DWORD dwDownloadSecsRemaining;
    DWORD dwInstallSecsRemaining;
} INSTALLPROGRESS;

[
    uuid(6e449688-c509-11cf-aafa-00aa00b6015c),
    local
]
interface ICifFile : IUnknown
{
    HRESULT EnumComponents(IEnumCifComponents **enum_components, DWORD filter, void *pv);
    HRESULT FindComponent(const char *id, ICifComponent **p);
    HRESULT EnumGroups(IEnumCifGroups **enum_groups, DWORD filter, void *pv);
    HRESULT FindGroup(const char *id, ICifGroup **p);
    HRESULT EnumModes(IEnumCifModes **cuf_modes, DWORD filter, void *pv);
    HRESULT FindMode(const char *id, ICifMode **p);
    HRESULT GetDescription(char *desc, DWORD size);
    HRESULT GetDetDlls(char *dlls, DWORD size);
}

[
    object,
    local,
    pointer_default(unique)
]
interface ICifRWFile : ICifFile
{
    HRESULT SetDescription(const char *desc);
    HRESULT CreateComponent(const char *id, ICifRWComponent **p);
    HRESULT CreateGroup(const char *id, ICifRWGroup **p);
    HRESULT CreateMode(const char *id, ICifRWMode **p);
    HRESULT DeleteComponent(const char *id);
    HRESULT DeleteGroup(const char *id);
    HRESULT DeleteMode(const char *id);
    HRESULT Flush();
}

[
    uuid(6e449685-c509-11cf-aafa-00aa00b6015c),
    local
]
interface IInstallEngineCallback : IUnknown
{
   HRESULT OnEngineStatusChange(DWORD status, DWORD substatus);
   HRESULT OnStartInstall(DWORD dl_size, DWORD install_size);
   HRESULT OnStartComponent(const char *id, DWORD dl_size, DWORD install_size, const char *string);
   HRESULT OnComponentProgress(const char *id, DWORD phrase, const char *string,
           const char *msg_string, ULONG progress, ULONG max);
   HRESULT OnStopComponent(const char *id, HRESULT error, DWORD phrase, const char *string, DWORD status);
   HRESULT OnStopInstall(HRESULT error, const char *error_string, DWORD status);
   HRESULT OnEngineProblem(DWORD problem, DWORD *action);
}

[
    uuid(6e449684-c509-11cf-aafa-00aa00b6015c),
    local
]
interface IInstallEngine : IUnknown
{
   HRESULT GetEngineStatus(DWORD *status);
   HRESULT SetCifFile(const char *cab_name, const char *cif_name);
   HRESULT DownloadComponents(DWORD flags);
   HRESULT InstallComponents(DWORD flags);
   HRESULT EnumInstallIDs(UINT index, char **id);
   HRESULT EnumDownloadIDs(UINT index, char **id);
   HRESULT IsComponentInstalled(const char *id, DWORD *status);
   HRESULT RegisterInstallEngineCallback(IInstallEngineCallback *callback);
   HRESULT UnregisterInstallEngineCallback();
   HRESULT SetAction(const char *id, DWORD action, DWORD priority);
   HRESULT GetSizes(const char *id, COMPONENT_SIZES *sizes);
   HRESULT LaunchExtraCommand(const char *inf_name, const char *section);
   HRESULT GetDisplayName(const char *id, const char *name);
   HRESULT SetBaseUrl(const char *base_name);
   HRESULT SetDownloadDir(const char *download_dir);
   HRESULT SetInstallDrive(char drive);
   HRESULT SetInstallOptions(DWORD flags);
   HRESULT SetHWND(HWND hwnd);
   HRESULT SetIStream(IStream *stream);
   HRESULT Abort(DWORD flags);
   HRESULT Suspend();
   HRESULT Resume();
}

[
    uuid(6e449689-c509-11cf-aafa-00aa00b6015c),
    local
]
interface IInstallEngine2 : IInstallEngine
{
    HRESULT SetLocalCif(const char *cif);
    HRESULT GetICifFile(ICifFile **cif_file);
}

[
    uuid(6e449687-c509-11cf-aafa-00aa00b6015c),
    local
]
interface IInstallEngineTiming : IUnknown
{
    HRESULT GetRates(DWORD *download, DWORD *install);
    HRESULT GetInstallProgress(INSTALLPROGRESS *progress);
}

[
    helpstring("Microsoft Active Setup Engine"),
    threading(apartment),
    uuid(6e449686-c509-11cf-aafa-00aa00b6015c)
]
coclass InstallEngine { }

[
    helpstring("Download Site Manager"),
    threading(apartment),
    uuid(bfc880f1-7484-11d0-8309-00aa00b6015c)
]
coclass DownloadSiteMgr { }

cpp_quote("HRESULT WINAPI GetICifFileFromFile(ICifFile **, const char *);")
cpp_quote("HRESULT WINAPI GetICifRWFileFromFile(ICifRWFile **, const char *);")
