2 Replies Latest reply on Oct 16, 2012 8:49 PM by WilMcGee

    Storing Application Specific Data Regardless of User

    WilMcGee

      Every time my application starts it sends it own "Machine ID" to my server to check and see if it has an active license associated with it, If there is a valid license available it returns a temp API Key that the application can use to access my dataservice. If not it prompts the user to register their Machine with a valid license key.

       

      The problem is coming up with a way to Get / Generate a "Machine ID" that every user on the one machine has access to. 

       

      I tried using the MAC address and it worked on my PC but on a test user's MacBook it had issues with the order of the NICS changing when calling 

       

      private function get_mac():String

      {

           var networkInterface : Object = NetworkInfo.networkInfo.findInterfaces();

           var networkInfo : Object = networkInterface[0];

           return networkInfo.hardwareAddress.toString();

      }

       

       

      so i could not reliably use this method.( I dont know if something like a wireless switch on a laptop would affect the array of NICS maybe?)

      So rethinking everything i decided i would generate my own "Machine ID" using either codegenas3 or mx.utils.UIDUtil;

       

       

      Then simply storing the "Machine ID" in a common place that every user on the machine would have access to, but I can not figure out where to place it.

       

       

      So in short where could you store a simple String either in a file or local store that every user would have access to.

       

       

       

      I thought this would work but no dice other users on machine were not able to access the wpsc.sys file.

      private function get_MachineID():String{
      
      
           var uuid:String; 
      
           var _file:File = File.applicationDirectory.resolvePath("wpsc.sys");
           var fs:FileStream = new FileStream(); 
          
            fs.open(_file, FileMode.UPDATE);
      
           if (fs.bytesAvailable == 0)     
           {
                uuid = UIDUtil.createUID();
                fs.writeUTF(uuid);
                fs.close();
           }
           else
           {
                fs.position = 0;
                uuid = fs.readUTF();
                fs.close();
           } 
      
           return uuid;
      }
      
      

       

        • 1. Re: Storing Application Specific Data Regardless of User
          WilMcGee Level 1

          Well, i was hoping for some help but i did come up with a ROUGH solution that works in my case

          private function get_String():String
           {
                var uuid:String;
                var _file:File   = getCommonFile();
                var fs:FileStream  = new FileStream(); 
                try
                {
                      if(_file.exists)
                      {
                            fs.open(_file, FileMode.READ);
                            fs.position = 0;
                            uuid = fs.readUTF();
                            fs.close();
                      }
                      else
                      {
                            fs.open(_file, FileMode.WRITE);
                            uuid = UIDUtil.createUID();
                            fs.writeUTF(uuid);
                            fs.close();
                      }
                }
                catch(err:Error)
                {
                        Alert.show(err); 
                }
           
                return uuid;
           }
          
           
           /*
             * This is what i came up with, one could easily adjust this script to cover their specific Manufacture / OS 
          
             *
             */
           
           private function getCommonFile():File
          {
                var _file:File;
                switch(Capabilities.manufacturer)
                {
                      case "Adobe Windows":
                      {
                            switch(Capabilities.os)
                            {
                                  case "Windows 7":
                                  {
                                        /* Works */
                                        _file = new File("C:\\ProgramData\\MyApp\\File.txt");
                                        break;
                                  }
                                  case "Windows Vista":
                                  {
                                        /* Not Tested */
                                        _file = new File("C:\\ProgramData\\MyApp\\File.txt");
                                        break;
                                  }
                                  case "Windows XP":
                                  {
                                        /* Works but required Admin Rights to Create File */
                                        _file = new File("C:\\Documents and Settings\\All Users\\MyApp\\File.txt");
                                        break;
                                  }
                                  default:
                                  {
                                        /* If using a Server OS or other Microsoft Product Default to a User Store */
                                        _file = File.applicationStorageDirectory.resolvePath('File.txt');
                                        break;
                                  }
                            }
                            break;
                      }
                      case "Adobe Macintosh":
                      {
                            /* Tested on OSX 10.7.5 - Works */
                            _file = new File("/Applications/MyApp/File.txt");
                            break;
                      }
                      default:
                      {
                            /* Catch any other Manufacture and default to a User Store*/
                            _file = File.applicationStorageDirectory.resolvePath('File.txt');
                            break;
                      }
                }
                /* Return the File */
                return _file;
          }
          
          
          • 2. Re: Storing Application Specific Data Regardless of User
            WilMcGee Level 1

            I made major improvements to the code above

             

            It can be found @ http://code.google.com/p/adobe-air-filex/

             

            Please feel free to check it out, I uploaded a sample air app, complied .swc and the source code