peter9477

PlayBook MANIFEST.MF interface

Jul 24th, 2011
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package {
  2.     import flash.filesystem.File;
  3.     import flash.filesystem.FileMode;
  4.     import flash.filesystem.FileStream;
  5.  
  6.     import flash.utils.*;
  7.  
  8.     //-----------------------------------
  9.     //
  10.     public class AppUtil {
  11.  
  12.         private static var _instance:AppUtil;
  13.  
  14.         public static var date:String = '2011-07-19'; // hardcoded for now
  15.  
  16.         public static var name:String = 'ThisApp';
  17.  
  18.         public static var author:String = 'Author';
  19.  
  20.         public static var version:String = '0.0';
  21.  
  22.  
  23.         //-----------------------------------
  24.         //
  25.         public function AppUtil() {
  26.             if (AppUtil._instance)
  27.                 return;
  28.             AppUtil._instance = this;
  29.  
  30.             // The alternative to this mess is to use File.userDirectory, but I don't consider
  31.             // that guaranteed to always point to the parent of app/META-INF
  32.             var manifest:File = new File(File.applicationDirectory.nativePath).resolvePath('../META-INF/MANIFEST.MF');
  33.  
  34.             var file:FileStream = new FileStream();
  35.             file.open(manifest, FileMode.READ);
  36.             var text:String = file.readUTFBytes(Math.min(manifest.size, 1000));
  37.  
  38.             var item:String;
  39.             item = /Application-Version: (.+)/i.exec(text)[1];
  40.             //~ trace('version', item, 'old', AppUtil.version);
  41.             AppUtil.version = item;
  42.  
  43.             item = /Application-Name: (.+)/i.exec(text)[1];
  44.             //~ trace('name', item, 'old', AppUtil.name);
  45.             AppUtil.name = item;
  46.  
  47.             item = /Package-Author: (.+)/i.exec(text)[1];
  48.             //~ trace('name', item, 'old', AppUtil.author);
  49.             AppUtil.author = item;
  50.         }
  51.  
  52.  
  53.         //-----------------------------------
  54.         //
  55.         public static function initialize():AppUtil {
  56.             return AppUtil._instance || new AppUtil();
  57.         }
  58.     }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment