简体   繁体   English

从C#代码安装/执行CAb文件[Windows Mobile应用程序文件]?

[英]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: 我主要对这些有疑问:

  1. How to download a cab file to device's particular folder. 如何将cab文件下载到设备的特定文件夹。
  2. How to install the cab file programmatically. 如何以编程方式安装cab文件。 (Programmatically trigger cab file installation without user intervention) (以编程方式触发cab文件安装,而无需用户干预)

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: 我通过以下方式解决了这个问题:

  1. Open tcp/ip connection to desktop application. 打开与桌面应用程序的tcp / ip连接。
  2. Send from PDA application the current version number. 从PDA应用程序发送当前版本号。
  3. During compilation, add to #.inf file version field with value manually (here I could not find solution to do it automatically during compilation). 在编译过程中,手动将值添加到#.inf文件版本字段中(此处找不到在编译过程中自动执行此操作的解决方案)。
  4. Desktop application looks up available version in *.inf file and sends it back to PDA application. 桌面应用程序在* .inf文件中查找可用版本,并将其发送回PDA应用程序。
  5. PDA application receives it and compares with running version. PDA应用程序接收它并与运行版本进行比较。
  6. If version on dektop computer is higher than running version, PDA application sends request to deliver CAB file on desktop computer (here can be dialog introduced for requesting cab file). 如果dektop计算机上的版本高于运行版本,则PDA应用程序发送请求以在台式计算机上传送CAB文件(此处可以引入对话框以请求cab文件)。
  7. Desktop computer sends CAB file to PDA application. 台式计算机将CAB文件发送到PDA应用程序。
  8. PDA application receives CAB file and stores it locally. PDA应用程序接收CAB文件并将其存储在本地。
  9. Then run installation by wceload.exe with parameters /delete 1 /silent "full path of cab file" 然后通过wceload.exe使用参数/ delete 1 / silent“ cab文件的完整路径”运行安装
  10. In case succesful installation, exit application or restart PDA. 如果安装成功,请退出应用程序或重新启动PDA。
  11. If PDA application has 如果PDA应用程序具有

It is not a few strings of code, however it works perfectly. 它不是几串代码,但是效果很好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM