• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
Locked
0

How can you write an auto-updater for a native Windows app built with AIR?

New Here ,
Mar 16, 2016 Mar 16, 2016

Copy link to clipboard

Copied

We're trying to port a Flash game to Windows. Never targeted Windows using AIR before so this is a new experience for us.

Basically, I'm working on a game Blah that uses ADT to create a native installer (blah_installer.exe) that people can use to install our app (a multiplayer online game).

Importantly, we *need* this software to auto-update itself. You can't do anything in the software without connecting to the server, and you must be running the latest version of the software for the server to accept your connection.

Now, we can't use the built-in Adobe Air update framework, since it does not support native installers (as shown here, it does not have support for extended desktop applications). That's actually fine, because we'd rather write our own updater with its own graphics and all that.

So, we wrote our own updater. Upon starting the application (Blah.exe, which runs Blah_launcher.swf), it pings the server to see what the latest version is, downloads a new version if necessary, and then runs the main application (Blah_main.swf)


Everything was working great, until we got reports from a few testers who discovered that the updater sometimes failed on Windows. In some cases, Blah_launcher.swf was failing to overwrite Blah_main.swf when it was downloaded; the launcher was instead silently running the old version. It turns out that depending on their windows permission settings, they would need to run Blah.exe as an administrator for the updater to work, since it was trying to write a file to the application directory (which is by default c:\program files\Blah\) and Windows does not allow write permission to these directories without administrator permission.

One thing we tried is to download Blah_main.swf to the application storage directory (where we don't need admin permission) and run it from there. Unfortunately, this didn't work, it violates security! Only assets can be loaded from the application storage directory, not code.

But then how can we create an auto-updater for our software? If we can't write to the application directory, but can't run code from outside it, how do we get our program to update itself and always run the latest version?

It would be fine if an admin popup appeared when the updater ran, but I can't even figure out a way to do that. Does ADT provide any way to adjust the manifest settings so that the program can ask for admin permissions when necessary? I looked through all the documentation but I couldn't find anything.

This seems like an extremely common problem for any auto-updating native installer; is there a known solution?

TOPICS
Development

Views

443

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Mar 17, 2016 Mar 17, 2016

Copy link to clipboard

Copied

Hello, we are in exactly the same boat as you and I probably have a solution:

To overcome the security issue, we are storing all updates in the File.applicationStorageDirectory. Here you can read and write without Administrator permission. Whenever the app launches, we first try to load the app from the File.applicationStorageDirectory. If that fails we know that the latest version was shipped with the installer and we try to load from File.applicationDirectory, which is your installation directory that you can not write to.

If you feel the 2 times loading approach is inconvenient, you can also copy the game from File.applicationDirectory to File.applicationStorageDirectory on the initial launch.

Hope it helps

Bonus Tip: You should also think of a way to update the container file that is doing the update for you. It might be handy for the future. We didn't have it when we needed it and it was a tough learning. Now, if the version for the container changed, we present the user a popup with a download link for the new installer.exe

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 17, 2016 Mar 17, 2016

Copy link to clipboard

Copied

How do you get that to work?

For us, we found that if we tried to run our launcher swf (from the

application directory) and get it to load an swf from

File.applicationStorageDirectory, it gave a permission error (can't

remember the exact error text at the moment, but I can paste the error

message if that would help... am I doing something wrong?)

I remember reading somewhere on the help page that we were only allowed to

load assets, but not code, from the applicationStorageDirectory, so I

assumed the error message was just confirming that. But maybe I'm

misunderstanding something?

Or, are you doing something different with the launcher?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Mar 18, 2016 Mar 18, 2016

Copy link to clipboard

Copied

I don't know of any restrictions loading code swf files from the applicationStorageDirectory. Are you confusing that with iOS? Because there you can not remotely download code swf files. So unless this restriction has been added in a recent version of Air, you might be misinformed. I have never encountered this problem on Windows and there are no complaints from our users either.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 18, 2016 Mar 18, 2016

Copy link to clipboard

Copied

So I checked again; I still get error messages, but I was mistaken about the nature of them.

The error messages I get are NOT issues loading the swf code, they're errors connecting to our server and downloading files. Our app uses secure web sockets, and also employs regular URLLoaders to download/streams quite a number of files. When I run the main app from applicationStorageDirectory, I get a bunch of 2044 errors when I try to load files from external URLs.

Any way around that?

Our plan was actually to have 3 separate swfs (launcher/updater/main), with the launcher being permanent and essentially just downloading and running the updater, and the updater downloading and running main (so we could "update the updater" if necessary). But because of the 2044 error, updater cannot download main at all if it is run from the applicationStorageDirectory. This is in addition to all the problems encountered with main running in the applicationStorageDirectory.

(Do I need to get my launcher swf to do all the external I/O? I suppose that's doable, but that would involve migrating a lot of code over to the launcher since we have some pretty involved code to do our asset streaming, and I would then lose the ability to update that portion of the code when updating the main swf; the whole point is that launcher would never get updated).

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Mar 21, 2016 Mar 21, 2016

Copy link to clipboard

Copied

LATEST

Sorry I cant answer that because we have only 2 swf files (updater and main). But I would be surprised if that was the issue. After all, in the end the launcher is downloading the main, only that the download code was loaded from another swf that resides in the applicationStorageDirectory. So I would assume it should work.

I would recommend building a small test project and see if you get different results for loading directly from launcher and loading from applicationStorageDirectory.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines