manjs
manjs

Reputation: 302

How to check first run of an AIR application

I want to check my AIR application is running in my system first time or not. Most of my searching lead to one answer that to write a file out side and check the file existing or not. But my requirement is different and if re install the same version again, then it should be a first run. Is there any idea to achieve that?

Upvotes: 1

Views: 988

Answers (3)

user594326
user594326

Reputation:

I am using File.applicationDirectory for several ipad apps and can confirm that all data written to that folder is wiped when the app is uninstalled. Thus being able to load a file previously saved to this folder gives you what you want.

var docDir:File = new File(File.applicationDirectory.nativePath + "/\.\./Documents");  //IOS specific
configFile = docDir.resolvePath("config.xml");
if (configFile.exists) {
  var firstRun:Boolean = false;
  configFile.addEventListener(Event.COMPLETE, onConfigLoaded);
  configFile.load();
}else {
  firstRun = true;
  var configXML:XML = new XML("<?xml version='1.0' encoding='utf-8' ?><config />");

  var fileStream:FileStream = new FileStream();
  fileStream.open(configFile, FileMode.WRITE);
  fileStream.writeUTFBytes(configXML);
  fileStream.close();
}

Upvotes: 1

manjs
manjs

Reputation: 302

I tried a method to write a file in application directory, first time I got a security error(http://forums.adobe.com/thread/209533)I got another method to overcome that and wrote a file inside the application directory. But after uninstalling that file is not deleted.My application folder retains there because i wrote an external file(That i want to store for first run check) inside the folder. Again tried to install the application an error message says folder exist.So i have to manually remove the folder to reinstall the application.if i delete that folder, then my problem is solved,I dont think its a good solution as User have to manually delete the folder for reinstall. Is there any other solution?

Upvotes: 0

John
John

Reputation: 131

Create a file in the same folder as your application installation and then when the user uninstalls the application this file is also deleted ex C:\Program Files\yourgame\myfile.txt

Upvotes: 0

Related Questions