public static void AddInstallerForFileType(SUInstaller installer, string fileType) { if (installerCache == null) { installerCache = new Dictionary<string,SUInstaller>(); } installerCache.SetValueForKey(installer, fileType); }
public static void AddInstallerForFileType(SUInstaller installer, string fileType) { if (installerCache == null) { installerCache = new Dictionary <string, SUInstaller>(); } installerCache.SetValueForKey(installer, fileType); }
private SUUpdater(KNBundle aBundle) { KNBundle bundle = KNBundle.BundleWithAssembly(Assembly.GetAssembly(this.GetType())); if (aBundle == null) { aBundle = KNBundle.MainBundle(); } if (sharedUpdaters.ContainsKey(aBundle)) { throw new Exception("Updater for this bundle exists - use SUUpdater.UpdaterForBundle()"); } SUInstaller.AddInstallerForFileType(new SUExecutableInstaller(), ".exe"); SUInstaller.AddInstallerForFileType(new SUMSIInstaller(), ".msi"); SUUnarchiver.AddUnarchiverForFileType(new SUZipUnarchiver(), ".zip"); SUUnarchiver.AddUnarchiverForFileType(new SUExeUnarchiver(), ".exe"); SUUnarchiver.AddUnarchiverForFileType(new SUExeUnarchiver(), ".msi"); sharedUpdaters.Add(aBundle, this); host = new SUHost(aBundle); // Clean out old update files if they exist if (host.ObjectForUserDefaultsKey(SUConstants.SUExtractedFilesForCleanupKey) != null) { string path = (string)host.ObjectForUserDefaultsKey(SUConstants.SUExtractedFilesForCleanupKey); try { FileAttributes attr = File.GetAttributes(path); if ((attr & FileAttributes.Directory) == FileAttributes.Directory) { Directory.Delete(path, true); } else { File.Delete(path); } } catch { } finally { host.SetObjectForUserDefaultsKey(null, SUConstants.SUExtractedFilesForCleanupKey); } } OfferToAutomaticallyUpdateIfAppropriate(); ScheduleNextUpdateCheck(); }
protected virtual void InstallUpdate() { if (Helpers.StringIsNullOrWhiteSpace(extractedFilePath) || !(File.Exists(extractedFilePath) || Directory.Exists(extractedFilePath))) { AbortUpdateWithError(new Exception(SUConstants.SUInstallerFailedToLaunchError)); return; } SUInstaller installer = null; string installationFilePath = extractedFilePath; FileAttributes attr = File.GetAttributes(extractedFilePath); if ((attr & FileAttributes.Directory) == FileAttributes.Directory) { // Look for specified file if it exists if (updateItem.PrimaryInstallationFile != null) { installationFilePath = Path.Combine(extractedFilePath, updateItem.PrimaryInstallationFile); installer = SUInstaller.InstallerForFile(installationFilePath); } else { string[] files = Directory.GetFiles(extractedFilePath); if (files.Count() > 0) { foreach (string file in files) { string filePath = Path.Combine(extractedFilePath, file); installer = SUInstaller.InstallerForFile(filePath); if (installer != null) { installationFilePath = filePath; break; } } } } } else if (File.Exists(extractedFilePath)) { installer = SUInstaller.InstallerForFile(extractedFilePath); } if (installer != null) { if (installer.BeginInstallationOfItemFromPath(updateItem, installationFilePath)) { Host.SetObjectForUserDefaultsKey(extractedFilePath, SUConstants.SUExtractedFilesForCleanupKey); RemoveDownloadedFiles(); try { System.Windows.Application.Current.Shutdown(0); } catch (Exception) { try { Environment.Exit(0); } catch (Exception e) { // We really should never be here! AbortUpdateWithError(e); } } } else { AbortUpdateWithError(new Exception(SUConstants.SUInstallerFailedToLaunchError)); } } else { AbortUpdateWithError(new Exception(SUConstants.SUNoInstallerError)); } }