使用 install4j api 以编程方式下载并安装更新

Download and install update programmatically with install4j api

我有一个小问题,我正在编写一个应用程序,我想在其中实现一些方法来下载和安装应用程序的更新。

检查更新没问题,工作正常。但是,我在实施下载和安装方法时遇到问题。我在 API 中发现了一些 类 但 "it's hard to work with".

下载也正常,但没有任何进展。我不想在启动时使用 "check for updates"-action。

这是我当前用于下载更新的测试代码:

public static void downloadInstaller(UpdateDescriptorEntry descriptor)
{
    Downloader downloader = new Downloader(0, null); // Don't know what to use instead of 0
    try
    {
        downloader = downloader.connect(descriptor.getURL().toString());

        File outputFile = new File(ApplicationSettings.getCachesDirectoryWithIdentifier() + File.separator + descriptor.getFileName());

        downloader.download(outputFile,
                            descriptor.getFileSize(),
                            false);

        if (descriptor.getFileSize() == outputFile.length()) // Check if download complete
        {
            logger.info("Successful");
        }
        else
        {
            logger.error("Error in download");
        }
    }
    catch (IOException | UserCanceledException e)
    {
        logger.error(e);
    }
}

现在我有两个问题。

1) 是否可以获取下载进度?有一个ProgressInterface接口,但我不知道如何正确实现它。

2.) 如何以编程方式运行 下载应用程序的安装程序(也可能在无人值守模式下)?

感谢您的帮助

Downloader 是运行时中的内部 class,而不是记录的 API.

的一部分

您应该在 "Installer->Screens & Actions" 步骤中添加一个更新程序应用程序并以编程方式调用它。 "Launcher integration" 选项卡上的集成向导有一个集成向导,将为您提供启动更新程序的代码片段。