Ok…this isn’t a “spoof” post or anything like that. AIR literally deleted everything on my desktop as well as screwed something up on my OS (Vista). How did this happen? I’m glad you asked.
First off…I didn’t tell it to delete ANYTHING. I’m adding features to an app and one of the features is to save a file to a network share so I was testing it against my desktop directory. Since this is AIR I figured a simple file copy was sufficient.
Do you remember that old joke where someone sent you a spam email and opening the attachment showed your My Computer window deleting every file on your system? That’s how I felt watching my desktop directory contents leave.
I’m on Windows…just right click on Recyle Bin and restore, right? NOPE. AIR DELETED ALL OF MY FILES PERMANENTLY!!!!! Every file…gone. I open Computer and and it tells me “C:\Users\John C. Bland II\Desktop refers to a location that is unavailable. …” which is great because now I literally do not have a desktop (beyond a background image).
So, again…how did this happen? Ok…don’t get testy. I had to vent through sidebars real quick.
//Copy JSON file to web server
var file:File = File.createTempFile();
var stream:FileStream = new FileStream();
var jsonFile:File = new File(_filePath);
jsonFile.resolvePath(“live” + _Index + “.json”);
So, this all works up to the last line. Odd right? I don’t have any delete lines. _copyTo(…)_ is the culprit. Yep, copy really should be: copyAndDeleteAllContentsInTheDirectoryThenMoveFile(….). 🙁
What’s worse is the desktop directory is gone so I have NO idea if it even worked. Now I have to try it again. 🙁 This time I’m setting _filePath to _File.desktopDirectory.nativePath+”/myapp”_ so it will only delete that directory vs everything.
copyTo(…)’s overwrite explanation:
“If false, the copy will fail if the file specified by the target parameter already exists. If true, the operation will first delete any existing file or directory of the same name (however, you cannot copy a file or folder to its original path). (Note: If you set this parameter to true and the source and destination File objects point to the same path, calling this method deletes the file or directory.) ”
So…whatever it was…AIR DELETED MY DESKTOP! 🙁 Boo FLIPPIN’ hoo! 🙁
The bug is in my _resolvePath_. It should be _jsonFile = jsonFile.resolvePath(“live” + _Index + “.json”);_. So, AIR tried to copy a file to a directory which caused the directory to get nixed since it was an overwrite. The time you want Vista’s UAC to kick in…it is MIA! 🙂