public object Serialize(object obj) { return(XmlSerializeHelper.SerializeItem(obj)); }
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)); }
public void CreateVersion(string dir, Version version, string location, string excludeExt, string locales, string updaterSrcDir) { if (!Directory.Exists(dir)) { throw new Exception("Source dir " + dir + " does not exist"); } if (dir.EndsWith("\\")) { dir = dir.Substring(0, dir.Length - 1); } string versionDir = dir + "_" + version; string updaterDir = dir + "_" + version + "_Updater"; if (Directory.Exists(versionDir)) { Directory.Delete(versionDir, true); } var files = GetVersionFiles(dir, excludeExt); var verManifest = new VersionManifest() { VersionNumber = version, UpdateUri = location, UpdateUriAlt = location }; char delim = PathHelper.GetPathSeparator(location); foreach (var item in files) { string newPath; string itemPath; CompressFile(item, dir, versionDir, out newPath, out itemPath); var ver = CreateVersion(version, item); verManifest.VersionItems.Add(new VersionItem() { InstallAction = InstallAction.Copy, Location = location + newPath.Replace(versionDir, String.Empty).Replace('\\', delim), Path = itemPath, VersionNumber = ver, Base64Hash = FileHash.GetBase64FileHash(item) }); } files = GetVersionFiles(updaterSrcDir, excludeExt); foreach (var item in files) { string newPath; string itemPath; CompressFile(item, updaterSrcDir, updaterDir, out newPath, out itemPath); verManifest.BootStrapper.Add(new LocationHash() { Location = location + newPath.Replace(updaterDir, String.Empty).Replace('\\', delim), Path = itemPath, Base64Hash = FileHash.GetBase64FileHash(item) }); } XmlSerializeHelper.SerializeItem( verManifest, Path.Combine(versionDir, VersionManifest.VersionManifestFileName)); string[] locs; if (String.IsNullOrEmpty(locales)) { locs = new string[] { "en" } } ; else { locs = locales.Split(','); } foreach (var item in locs) { XmlSerializeHelper.SerializeItem( new VersionData(version), Path.Combine(versionDir, String.Format(VersionManifest.VersionFileName, item)) ); } }