2 Replies Latest reply on Sep 24, 2008 6:27 AM by RogerNCPG

    Semi-Automated Update

    RogerNCPG
      I know this code is probably pretty hideous but it's an internal application communicating with an internal WAMP stack server so I don't care too much just yet. Anyway, the problem that happens is the update fails because of a corrupted download. The application checks to see if there's an updated version available. If so, it asks the user if they'd like to run the update, at which point it's supposed to connect, download the file to the app data folder, run it, then remove the archive at the next start-up. If I open the downloaded AIR file in a text editor, it stops after exactly five bytes of data, "PK" followed by three squares. What gives?

      This just downloads it as returned data from an AJAX connection:



      function writeFile(doc,str,type)
      {
      var f;

      if(type=="user")
      { f = air.File.applicationStorageDirectory.resolvePath(doc); }
      else if(type=="app")
      { f = air.File.applicationDirectory.resolvePath(doc); }
      else if(type=="home")
      { f = air.File.userDirectory.resolvePath(doc); }
      else if(type=="docs")
      { f = air.File.documentsDirectory.resolvePath(doc); }
      else if(type=="desk")
      { f = air.File.desktopDirectory.resolvePath(doc); }

      var fs = new air.FileStream();
      fs.open(f, air.FileMode.WRITE);
      fs.writeMultiByte(str,"utf-8");
      fs.close();
      }



      Help?

      Edit: Shortened to include only relevant code.
        • 1. Re: Semi-Automated Update
          Oliver Goldman Adobe Employee
          AIR files aren't text; they're binary. You're using text-based files to read/write them, which is corrupting the file.

          • 2. Re: Semi-Automated Update
            RogerNCPG Level 1
            Alright, I've researched it and found it (what was I thinking?). After that I had trouble getting the version number. It was at 0.79 and going to 0.80 but it wouldn't update because the version number given with the update command has to be the same as in the application descriptor, yet the number being given by Javascript was instead 0.8. AIR apparently does not support toFixed, so I had to convert it to a string and add the extra 0:


            var updateVersion = newVersion.toString();
            var i = updateVersion.indexOf(".");
            var dec = updateVersion.substr(i+1);

            if(dec.length==1){ updateVersion += "0"; }


            That said, it all seems to work now, thanks. Sometimes a kick in the pants is what's necessary.