Home > OS >  Launch Inno Setup Update from within AIR
Launch Inno Setup Update from within AIR

Time:09-17

I am using Inno Setup to create my installer for a desktop AIR app. I have my desktop app check my database for an app version number to let the user know if there is an update ready to install. I would like to have a pretty seamless update process for the user, so if they want to update, I would like for AIR to download the EXE and then run it.

1.) How do you download big files like an EXE from the web in AIR and do you need to place it someplace specific? 2.) Once the file is downloaded, how do I get AIR to execute the EXE?

Thanks!

CodePudding user response:

public static function download(sourceURL:String, destinationPath:String, complete:Function = null, progress:Function = null, error:Function = null):void
{
    var urlReq:URLRequest = new URLRequest(sourceURL);
    var urlStream:URLStream = new URLStream();
    var fileData:ByteArray = new ByteArray();

    if(progress != null) urlStream.addEventListener(ProgressEvent.PROGRESS, progress);
    if(error != null) urlStream.addEventListener(IOErrorEvent.IO_ERROR, error);
    urlStream.addEventListener(Event.COMPLETE, loaded);
    urlStream.load(urlReq);

    function loaded(event:*):void
    {
        urlStream.readBytes(fileData, 0, urlStream.bytesAvailable);
        writeFile();
    }

    function writeFile():void
    {
        var file:File = new File(destinationPath   sourceURL.slice(sourceURL.lastIndexOf("/"), sourceURL.length));
        var fileStream:FileStream = new FileStream();
        fileStream.open(file, FileMode.WRITE);
        fileStream.writeBytes(fileData, 0, fileData.length);
        fileStream.close();

            if(complete != null) complete();
    }
}

var nativeProcessStartupInfo:NativeProcessStartupInfo = new NativeProcessStartupInfo();
nativeProcessStartupInfo.executable = file;
process = new NativeProcess();
process.closeInput();
process.start(nativeProcessStartupInfo);
  • Related