Esempio n. 1
0
        protected void VersionDownloadCompleted(
            string displayAppName,
            VersionManifest downloadManifest,
            VersionManifest latestManifest,
            VersionData latestVersionInfo,
            InstallInfo installInfo)
        {
            if (!AskUserForInstall(displayAppName, latestVersionInfo))
            {
                return;
            }

            //Unzip downloaded version
            foreach (var item in downloadManifest.VersionItems)
            {
                var tempFile      = Path.Combine(installInfo.TempPath, item.GetItemFullPath());
                var tempFileUnzip = Path.Combine(installInfo.TempPath, item.GetUnzipItemFullPath());

                GZipCompression.DecompressFile(tempFile, tempFileUnzip);
            }

            LocationHash badLocation;

            if (!CheckHash(installInfo.TempPath, downloadManifest.VersionItems.ConvertAll(vi => vi.GetLocationHash()), out badLocation))
            {
                throw new UpdateException(UpdStr.BAD_VERSION);
            }

            //Unzip bootstrapper
            var tempInstallerPath = GetInstallerDir(installInfo.TempPath, installInfo.AppName, latestManifest.VersionNumber);

            foreach (var item in downloadManifest.BootStrapper)
            {
                var tempFile      = Path.Combine(tempInstallerPath, item.GetItemFullPath());
                var tempFileUnzip = Path.Combine(tempInstallerPath, item.GetUnzipItemFullPath());

                GZipCompression.DecompressFile(tempFile, tempFileUnzip);
            }

            if (!CheckHash(tempInstallerPath, downloadManifest.BootStrapper, out badLocation))
            {
                throw new UpdateException(UpdStr.BAD_VERSION);
            }

            //Saving latest manifest
            XmlSerializeHelper.SerializeItem(
                latestManifest,
                Path.Combine(installInfo.TempPath, VersionManifest.VersionManifestFileName));

            //Saving downloaded manifest
            XmlSerializeHelper.SerializeItem(
                downloadManifest,
                Path.Combine(installInfo.TempPath, VersionManifest.DownloadedVersionManifestFileName));

            //var installerPath = CopyInstaller(installInfo.TempPath, installInfo.AppName, latestManifest.VersionNumber, installInfo);
            var installerDir  = GetInstallerDir(installInfo.TempPath, installInfo.AppName, latestManifest.VersionNumber);
            var installerPath = Path.Combine(installerDir, "Updater.exe");

            //Saving install info
            XmlSerializeHelper.SerializeItem(
                installInfo,
                Path.Combine(installerDir, InstallInfo.InstallInfoFileName));

            //Start installing
            Process.Start(installerPath);
            //_UpdatingFlag.Close();

            InvokeUpdateCompleted(true, true, null);
            DispatcherHelper.Invoke(new SimpleMethod(OnNeedCloseApp));
        }