Reputation: 213
I am developing a Windows Mobile application for Framework 6. I want to add functionality to upgrade a patch with the application currently running on a device.
While Windows Mobile application works, it should check asynchronously for any new version available in a server database. If the patch exists, the program should download the .cab (Windows Mobile installer) file and install/run it automatically.
Mainly, I have doubts on these:
How could it be done?
Please help me on this.....
Upvotes: 2
Views: 6868
Reputation: 25370
I just had to do this, it seems like the install part was answered. If anyone needs the download portion, this worked for me.
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Timeout = 10000;
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream receiveStream = response.GetResponseStream();
using (Stream file = File.OpenWrite("\\Windows\\Desktop\\file.cab"))
{
byte[] buffer = new byte[8 * 1024];
int len;
while ((len = receiveStream.Read(buffer, 0, buffer.Length)) > 0)
{
file.Write(buffer, 0, len);
}
}
Upvotes: 1
Reputation: 11
I solved this the following way:
It is not a few strings of code, however it works perfectly.
Upvotes: 1
Reputation: 2488
Downloading a file to local folder generally depends on your repository, ie. you will need slightly different code if you store it on a file share or in lets say web based one. You have to consider option of providing pre-download version check via some sort of manifest file or database record to avoid downloading entire patch just to check its version.
Once you have downloading part sorted (again, depends on storage), you can invoke CAB installation from your app by calling wceload.exe
:
Process proc = Process.Start("wceload.exe", "\"" + Path.Combine(applicationPath, updateFileName) + "\"");
proc.WaitForExit();
This will however require user to interact and press 'OK' to install new version on top of the old one.
[Edit] Some device manufacturers (like Intermec) provide ways of automatic CAB install on reboot but that's very device-specific so you'd have to read up on this.
Upvotes: 3