So I'm having trouble doing this is a semi-standard fashion:
I have a file encryptor that does something special when prompted to decrypt a file.
You pass the encrypted file as an argument to the program. The program reads the original filetype from the file (which I stored there upon encoding), and creates a temporary in some folder somewhere, where a decoded copy of the file is made.
Now, after calculating a checksum, the file is launched via ShellExecute(), or whatever function is its equivalent on the system for which I'm compiling. Then the program waits for the user to be done. It does this:
Surprisingly, this method works for most filetypes on my Windows Vista system.Code:while(!std::ofstream(path.c_str(), std::ios::app)) my::wait(5000); //now the file is ready
Once the user is done, I recalculate the checksum to see whether the user has made an changes. If they made changes, I reencrypt and overwrite the original encrypted file, then delete the temporary. If not, then I just delete the temporary.
Now -- my problems -- it's not working very consistently. For some files (i.e. Quicktime types), my program is allowed access to the file while the video is playing, and my program deletes the program form under quicktime's nose. Crash.
Other files work well, but when I go to recalculate my checksum, I get a crash (i.e. BMP).
And finally, some files (i.e. MSWord2007) are never overwritten because Word saves any changes in a temp and then does not update the original (compatibility mode?) .
So my question is, first: is there anything wrong with my concept? Can this be done is a nearly-standard manner?