Download and install update programmatically with install4j api

时间:2017-05-16 09:20:54

标签: java install4j

I have a little question, I am writing an application in which I want to implement some methods to download and install updates for the application.

Checking for updates is no problem and works fine. But, I have problems to implement download and install methods. I found some classes in API but "it's hard to work with".

Download works fine, too but without progress. I don't want to use "check for updates"-action on startup.

This is my current test code for downloading the update:

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);
    }
}

Now I have two questions.

1) Is it possible to get any download progress? There is a ProgressInterface interface but I don't know how to implement it correctly.

2.) How can I run the installer of the downloaded application programmatically (maybe in unattended mode, too)?

Thanks for helping

1 个答案:

答案 0 :(得分:1)

Downloader是运行时中的内部类,不是记录的API的一部分。

您应该在" Installer->屏幕&屏幕上添加更新程序。操作"步骤并以编程方式调用。 " Launcher集成的集成向导"选项卡有一个集成向导,可以为您提供启动更新程序的代码段。