[英]Install/Execute a CAb file[Windows Mobile application file] from C# Code?
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. 我正在为Framework 6开发Windows Mobile应用程序。我想添加功能以使用设备上当前正在运行的应用程序升级补丁。
While Windows Mobile application works, it should check asynchronously for any new version available in a server database. Windows Mobile应用程序运行时,应异步检查服务器数据库中可用的任何新版本。 If the patch exists, the program should download the .cab (Windows Mobile installer) file and install/run it automatically. 如果存在修补程序,则程序应下载.cab(Windows Mobile安装程序)文件并自动安装/运行它。
Mainly, I have doubts on these: 我主要对这些有疑问:
How could it be done? 怎么做?
Please help me on this..... 请帮我这个.....
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
: 一旦下载了已排序的部分(再次取决于存储),就可以通过调用wceload.exe
从应用程序中调用CAB安装:
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. [编辑]一些设备制造商(例如Intermec)提供了在重新启动时自动安装CAB的方法,但这是特定于设备的,因此您必须阅读相关内容。
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);
}
}
I solved this the following way: 我通过以下方式解决了这个问题:
It is not a few strings of code, however it works perfectly. 它不是几串代码,但是效果很好。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.