开发者

WmAutoUpdate - anyone used it? Won't roll back

开发者 https://www.devze.com 2023-02-03 06:05 出处:网络
I\'ve built a Compact Framework application and I\'m using WmAutoUpdate to deploy new versions to the mobile devices (http://www.sebastianvogelsang.com/2009/09/23/wmautoupdate-a-net-compact-framework-

I've built a Compact Framework application and I'm using WmAutoUpdate to deploy new versions to the mobile devices (http://www.sebastianvogelsang.com/2009/09/23/wmautoupdate-a-net-compact-framework-auto-update-library/). Has anyone used this? It's cool but I've got a problem.

If I cause the application to crash half-way through updating it is supposed to recover by copying the backup version back into the main directory. This doesn't work because the exe file is "locked" by the operating system because it is currently in use. I can verify this is the case because I can't delete it using Windows Explorer either. The error details are:

System.IO.IOException开发者_运维技巧 was unhandled
Message="IOException"
StackTrace:
     at System.IO.__Error.WinIOError(Int32 errorCode, String str)
     at System.IO.File.Move(String sourceFileName, String destFileName)
     at WmAutoUpdate.Updater.assertPreviousUpdate()
     at WmAutoUpdate.Updater..ctor(String url)

The error occurs on this line in Updater.assertPreviousUpdate():

File.Move(f, appPath + "\\" + getFilenameFromPath(f));

The code manages to update the application exe file when it's allowed to run normally (I'm not sure how). The problem is that it doesn't work when rolling back.

Cheer

Mark


I've used WmAutoUpdate and I've found the same problem. The issue is that you can move the files of the actual running process, but you cannot overwrite them. If you check the update part, WmAutoUpdate moves the running application to a backup directory and then it writes the update version to the original directory. I have fixed the rollback part this way:

if (Directory.Exists(backupDir))
{
  string tmpDir = Path.Combine(Path.GetTempPath(),Path.GetFileNameWithoutExtension(Path.GetTempFileName()));
  Directory.Move(appPath, tmpDir);
  Directory.Move(backupDir, appPath);
}

First we move the running application files to a random directory in Temp. Then we copy the backup folder to the application original directory. Of course, this will generate a .TMP file in the Temp directory of your device, and a folder with the actual running process. You will have to delete this temporary folder once in a while in production code.

0

精彩评论

暂无评论...
验证码 换一张
取 消