简体   繁体   English

解压缩.cab文件,然后关闭带有.net mobile 3.5的Windows CE 6.0上的运行过程

[英]Unpacking a .cab file and then closing the running process on windows CE 6.0 with .net mobile 3.5

I have a windows CE 6.0 program that uses a .cab file for installation. 我有一个Windows CE 6.0程序,该程序使用.cab文件进行安装。 it incorporates the guide from http://msdn.microsoft.com/en-us/library/aa446487.aspx to support automatic self-updates. 它并入了http://msdn.microsoft.com/zh-cn/library/aa446487.aspx中的指南,以支持自动自我更新。

the program can check for updates just fine, it downloads the update like it should, but when I try to make it unpack the .cab file it just downloaded, it fails. 该程序可以很好地检查更新,它会按应有的方式下载更新,但是当我尝试使其解压缩刚刚下载的.cab文件时,它将失败。

this is my code: 这是我的代码:

void ResponseReceived(IAsyncResult res)
{
    try
    {
        _mResp = (HttpWebResponse)_mReq.EndGetResponse(res);
    }
    catch (WebException ex)
    {
        MessageBox.Show(ex.ToString(), "Error");
        return;
    }
    // Allocate data buffer
    _dataBuffer = new byte[DataBlockSize];
    // Set up progrees bar
    _maxVal = (int)_mResp.ContentLength;
    pgbDownloadBar.Invoke(new EventHandler(SetProgressMax));
    // Open file stream to save received data
    _mFs = new FileStream(@"\Application\CCOptimizerSetup.cab",
      FileMode.Create);
    // Request the first chunk
    _mResp.GetResponseStream().BeginRead(_dataBuffer, 0, DataBlockSize,
      OnDataRead, this);
}

void OnDataRead(IAsyncResult res)
{
    // How many bytes did we get this time
    int nBytes = _mResp.GetResponseStream().EndRead(res);
    // Write buffer
    _mFs.Write(_dataBuffer, 0, nBytes);
    // Update progress bar using Invoke()
    _pbVal += nBytes;
    pgbDownloadBar.Invoke(new EventHandler(UpdateProgressValue));
    // Are we done yet?
    if (nBytes > 0)
    {
        // No, keep reading
        _mResp.GetResponseStream().BeginRead(_dataBuffer, 0,
          DataBlockSize, OnDataRead, this);
    }
    else
    {
        // Yes, perform cleanup and update UI.
        _mFs.Close();
        _mFs = null;
        Invoke(new EventHandler(AllDone));
    }
}

private void AllDone(object sender, EventArgs e)
{
    Cursor.Current = Cursors.Default;
    DialogResult dialogresult = MessageBox.Show(@"CCOptimizer has finished downloading. Open now?", "Download complete", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);
    switch (dialogresult)
    {
        case DialogResult.OK:
            Application.Exit();
            Dispose();
            Close();
            Invoke(new EventHandler(StartProcess));
            break;
        case DialogResult.Cancel:
            Form1 oForm = new Form1();
            oForm.Show();
            Hide();
            break;
    }
}

private void StartProcess(object sender, EventArgs e)
{
    Process.Start(@"\Application\CCOptimizerSetup.cab", null);
}

It doesn't work though. 虽然不行。 wherever I place the invocation of StartProcess() , either it just shuts down with no message or I get an error during unpacking that one of the files i'm trying to update is still in use. 无论我在哪里调用StartProcess() ,它要么只是关闭而没有任何消息,要么在解压缩过程中出现错误,表明我要更新的文件之一仍在使用中。 During debugging, it just stops the program. 在调试过程中,它只是停止程序。 If I try on an installed version, it very briefly flashes a window, then locks up the machine with the WaitCursor rotating and needs a reboot, although it can install just fine afterwards. 如果我尝试安装的版本,它会短暂地闪烁一个窗口,然后旋转WaitCursor锁定机器,并需要重新启动,尽管之后可以很好地安装它。

How can I close the current program and open a .cab file without having to reboot the machine? 如何关闭当前程序并打开.cab文件,而不必重新启动计算机?

You've got a flaw in your update logic, probably that the app you want to update is the thing checking for updates (it's not entirely clear from the question, but the behavior suggest this is the case). 您的更新逻辑存在缺陷,可能是您要更新的应用是检查更新的事物(问题尚不完全清楚,但行为表明确实如此)。

An application cannot directly update itself because, for what should be fairly obvious reasons, you cannot replace the assemblies that are already loaded and running. 应用程序无法直接更新自身,因为出于显而易见的原因,您不能替换已经加载并正在运行的程序集。

There are, generally speaking, two ways that I have used to get around this. 一般来说,有两种方法可以解决此问题。 Both require a second executable (which in many case I already have as a watchdog app anyway). 两者都需要第二个可执行文件(在许多情况下,无论如何我都已经拥有它作为看门狗应用程序)。

  1. Instead of directly launching your application, launch some "updater" application first. 而不是直接启动您的应用程序,而是先启动一些“更新程序”应用程序。 That application can check for updates, inform the user, download, and install/overwrite the target application because it's not yet running. 该应用程序可以检查更新,通知用户,下载以及安装/覆盖目标应用程序,因为它尚未运行。 The updater then runs the target application when it's done, or if no update steps are required. 然后,更新程序将在完成目标应用程序或不需要更新步骤的情况下运行目标应用程序。
  2. Instead of directly launching your application, launch some "bootstrap" application first. 与其直接启动您的应用程序,不如直接启动一些“ bootstrap”应用程序。 The bootstrap looks in local temporary storage for any update files, executes them if they exist, and then runs the normal application. 引导程序会在本地临时存储中查找任何更新文件,如果它们存在则执行它们,然后运行普通应用程序。 Have the application itself check for updates and pull them to the temporary storage location. 让应用程序本身检查更新并将其拉到临时存储位置。 When updates have been pulled, have it shutdown and restart the bootstrap, which then will apply the update. 提取更新后,将其关闭并重新启动引导程序,然后将应用更新。

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

相关问题 SmartDevice CAB“不是有效的Windows CE安装文件” - SmartDevice CAB “is not a valid Windows CE Setup file” 在Windows CE 6.0多线程程序(.NET 3.5 Compact Framework)中快速更新Windows窗体 - Updating Windows form rapidly in Windows CE 6.0 multi-threaded program (.NET 3.5 Compact Framework) Visual Studio 2015 - Windows CE 6.0编程(Compact Framework 3.5) - Visual Studio 2015 - programming for Windows CE 6.0 (Compact Framework 3.5) 运行.NET CF 3.5应用程序时Windows Mobile 6.5文件系统使Motorola MC55崩溃 - Windows Mobile 6.5 file system crash Motorola MC55 when running .NET CF 3.5 application 在Windows Mobile / Windows CE 6.0上逐渐增加系统卷 - Gradually Increase System Volume on Windows Mobile / Windows CE 6.0 如何从 c# 中的类文件更新窗体 GUI for windows CE (Windows Mobile 6.5.3 ) CF 3.5 设备 - How to update the form GUI from a class file in c# for windows CE (Windows Mobile 6.5.3 ) Devices with CF 3.5 .NET Compact Framework-Windows Mobile 6.5上的CAB自动更新 - .NET Compact Framework - CAB auto update on Windows Mobile 6.5 删除 Windows CE 6.0 CF.NET 2.0 上的 ARP 条目 - Delete ARP entry on Windows CE 6.0 CF.NET 2.0 Windows Embedded CE 6.0上的.Net Compact Framework开发 - .Net Compact Framework development on Windows Embedded CE 6.0 为Windows Mobile偶然连接的应用程序创建cab文件 - Creating cab file for Windows Mobile Occasionally Connected Application
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM