public IEnumerable <string> RunAppSetupInstallers(PostInstallInfo info) { var appSetups = default(IEnumerable <IAppSetup>); try { appSetups = findAppSetupsToRun(info.NewAppDirectoryRoot); } catch (UnauthorizedAccessException ex) { log.ErrorException("Failed to load IAppSetups in post-install due to access denied", ex); return(new string[0]); } ResolveEventHandler resolveAssembly = (obj, args) => { var directory = fileSystem.GetDirectoryInfo(info.NewAppDirectoryRoot); return(tryResolveAssembly(directory, args)); }; AppDomain.CurrentDomain.AssemblyResolve += resolveAssembly; var results = appSetups .Select(app => installAppVersion(app, info.NewCurrentVersion, info.ShortcutRequestsToIgnore, info.IsFirstInstall)) .Where(x => x != null) .ToArray(); AppDomain.CurrentDomain.AssemblyResolve -= resolveAssembly; return(results); }
void registerExtensionDlls(TinyIoCContainer kernel) { var di = fileSystem.GetDirectoryInfo(Path.GetDirectoryName(currentAssemblyDir)); var thisAssembly = System.Reflection.Assembly.GetExecutingAssembly().Location; var extensions = di.GetFiles("*.dll") .Where(x => x.FullName != thisAssembly) .SelectMany(x => { try { return(new[] { System.Reflection.Assembly.LoadFile(x.FullName) }); } catch (Exception ex) { this.Log().WarnException("Couldn't load " + x.Name, ex); return(Enumerable.Empty <System.Reflection.Assembly>()); } }) .SelectMany(x => x.GetModules()).SelectMany(x => x.GetTypes()) .Where(x => typeof(IWiXCustomUi).IsAssignableFrom(x) && !x.IsAbstract) .SelectMany(x => { try { return(new[] { (IWiXCustomUi)Activator.CreateInstance(x) }); } catch (Exception ex) { this.Log().WarnException("Couldn't create instance: " + x.FullName, ex); return(Enumerable.Empty <IWiXCustomUi>()); } }); foreach (var extension in extensions) { extension.RegisterTypes(kernel); } registerDefaultTypes(kernel); }
public static void BuildReleasesFile(string releasePackagesDir, IFileSystemFactory fileSystemFactory = null) { fileSystemFactory = fileSystemFactory ?? AnonFileSystem.Default; var packagesDir = fileSystemFactory.GetDirectoryInfo(releasePackagesDir); // Generate release entries for all of the local packages var entries = packagesDir.GetFiles("*.nupkg").MapReduce(x => Observable.Start(() => { using (var file = x.OpenRead()) { return(GenerateFromFile(file, x.Name)); } }, RxApp.TaskpoolScheduler)).First(); // Write the new RELEASES file to a temp file then move it into // place var tempFile = fileSystemFactory.CreateTempFile(); try { if (entries.Count > 0) { WriteReleaseFile(entries, tempFile.Item2); } } finally { tempFile.Item2.Dispose(); } var target = Path.Combine(packagesDir.FullName, "RELEASES"); if (File.Exists(target)) { File.Delete(target); } fileSystemFactory.GetFileInfo(tempFile.Item1).MoveTo(target); }
IEnumerable <IAppSetup> findAppSetupsToRun(string appDirectory) { var allExeFiles = default(FileInfoBase[]); try { allExeFiles = fileSystem.GetDirectoryInfo(appDirectory).GetFiles("*.exe"); } catch (UnauthorizedAccessException ex) { // NB: This can happen if we run into a MoveFileEx'd directory, // where we can't even get the list of files in it. log.WarnException("Couldn't search directory for IAppSetups: " + appDirectory, ex); throw; } var locatedAppSetups = allExeFiles .Select(x => loadAssemblyOrWhine(x.FullName)).Where(x => x != null) .SelectMany(x => x.GetModules()) .SelectMany(x => { try { return(x.GetTypes().Where(y => typeof(IAppSetup).IsAssignableFrom(y))); } catch (ReflectionTypeLoadException ex) { log.WarnException("Couldn't load types from module", ex); return(Enumerable.Empty <Type>()); } }) .Select(createInstanceOrWhine).Where(x => x != null) .ToArray(); return(locatedAppSetups.Length > 0 ? locatedAppSetups : allExeFiles.Select(x => new DidntFollowInstructionsAppSetup(x.FullName)).ToArray()); }
IPackage openBundledPackage() { var fi = fileSystem.GetFileInfo(Path.Combine(currentAssemblyDir, BundledRelease.Filename)); if (!fi.Exists) { this.Log().Error("The expected file '{0}' could not be found...", BundledRelease.Filename); var directoryInfo = fileSystem.GetDirectoryInfo(currentAssemblyDir); foreach (var f in directoryInfo.GetFiles("*.nupkg")) { this.Log().Info("Directory contains file: {0}", f.Name); } UserError.Throw("This installer is incorrectly configured, please contact the author", new FileNotFoundException(fi.FullName)); return(null); } return(new ZipPackage(fi.FullName)); }
IEnumerable <IAppSetup> findAppSetupsToRun(string appDirectory) { var allExeFiles = default(FileInfoBase[]); try { allExeFiles = fileSystem.GetDirectoryInfo(appDirectory).GetFiles("*.exe"); } catch (UnauthorizedAccessException ex) { // NB: This can happen if we run into a MoveFileEx'd directory, // where we can't even get the list of files in it. log.WarnException("Couldn't search directory for IAppSetups: " + appDirectory, ex); return(Enumerable.Empty <IAppSetup>()); } var locatedAppSetups = allExeFiles .Select(x => loadAssemblyOrWhine(x.FullName)).Where(x => x != null) .SelectMany(x => x.GetModules()) .SelectMany(x => { try { return(x.GetTypes().Where(y => typeof(IAppSetup).IsAssignableFrom(y))); } catch (ReflectionTypeLoadException ex) { var message = String.Format("Couldn't load types from module {0}", x.FullyQualifiedName); log.WarnException(message, ex); ex.LoaderExceptions.ForEach(le => log.WarnException("LoaderException found", le)); return(Enumerable.Empty <Type>()); } }) .Select(createInstanceOrWhine).Where(x => x != null) .ToArray(); if (!locatedAppSetups.Any()) { log.Warn("Could not find any AppSetup instances"); allExeFiles.ForEach(f => log.Info("We have an exe: {0}", f.FullName)); return(allExeFiles.Select(x => new DidntFollowInstructionsAppSetup(x.FullName)) .ToArray()); } return(locatedAppSetups); }
IObservable <UpdateInfo> checkForUpdate(bool ignoreDeltaUpdates = false, IObserver <int> progress = null) { var localReleases = Enumerable.Empty <ReleaseEntry>(); progress = progress ?? new Subject <int>(); try { var file = fileSystem.GetFileInfo(LocalReleaseFile).OpenRead(); // NB: sr disposes file using (var sr = new StreamReader(file, Encoding.UTF8)) { localReleases = ReleaseEntry.ParseReleaseFile(sr.ReadToEnd()); } } catch (Exception ex) { // Something has gone wrong, we'll start from scratch. log.WarnException("Failed to load local release list", ex); initializeClientAppDirectory(); } IObservable <string> releaseFile; // Fetch the remote RELEASES file, whether it's a local dir or an // HTTP URL try { if (isHttpUrl(updateUrlOrPath)) { log.Info("Downloading RELEASES file from {0}", updateUrlOrPath); releaseFile = urlDownloader.DownloadUrl(String.Format("{0}/{1}", updateUrlOrPath, "RELEASES"), progress) .Catch <string, TimeoutException>(ex => { log.Info("Download timed out (returning blank release list)"); return(Observable.Return(String.Empty)); }) .Catch <string, WebException>(ex => { log.InfoException("Download resulted in WebException (returning blank release list)", ex); return(Observable.Return(String.Empty)); }); } else { log.Info("Reading RELEASES file from {0}", updateUrlOrPath); if (!fileSystem.GetDirectoryInfo(updateUrlOrPath).Exists) { var message = String.Format( "The directory {0} does not exist, something is probably broken with your application", updateUrlOrPath); var ex = new SquirrelConfigurationException(message); return(Observable.Throw <UpdateInfo>(ex)); } var fi = fileSystem.GetFileInfo(Path.Combine(updateUrlOrPath, "RELEASES")); if (!fi.Exists) { var message = String.Format( "The file {0} does not exist, something is probably broken with your application", fi.FullName); log.Warn(message); var packages = fileSystem.GetDirectoryInfo(updateUrlOrPath).GetFiles("*.nupkg"); if (packages.Length == 0) { var ex = new SquirrelConfigurationException(message); return(Observable.Throw <UpdateInfo>(ex)); } // NB: Create a new RELEASES file since we've got a directory of packages ReleaseEntry.WriteReleaseFile( packages.Select(x => ReleaseEntry.GenerateFromFile(x.FullName)), fi.FullName); } using (var sr = new StreamReader(fi.OpenRead(), Encoding.UTF8)) { var text = sr.ReadToEnd(); releaseFile = Observable.Return(text); } progress.OnNext(100); progress.OnCompleted(); } } catch (Exception ex) { progress.OnCompleted(); return(Observable.Throw <UpdateInfo>(ex)); } // Return null if no updates found var ret = releaseFile .Select(ReleaseEntry.ParseReleaseFile) .SelectMany(releases => releases.Any() ? determineUpdateInfo(localReleases, releases, ignoreDeltaUpdates) : Observable.Return <UpdateInfo>(null)) .PublishLast(); ret.Connect(); return(ret); }
public static void BuildReleasesFile(string releasePackagesDir, IFileSystemFactory fileSystemFactory = null) { fileSystemFactory = fileSystemFactory ?? AnonFileSystem.Default; var packagesDir = fileSystemFactory.GetDirectoryInfo(releasePackagesDir); // Generate release entries for all of the local packages var entries = packagesDir.GetFiles("*.nupkg").MapReduce(x => Observable.Start(() => { using (var file = x.OpenRead()) { return GenerateFromFile(file, x.Name); } }, RxApp.TaskpoolScheduler)).First(); // Write the new RELEASES file to a temp file then move it into // place var tempFile = fileSystemFactory.CreateTempFile(); try { if (entries.Count > 0) WriteReleaseFile(entries, tempFile.Item2); } finally { tempFile.Item2.Dispose(); } var target = Path.Combine(packagesDir.FullName, "RELEASES"); if (File.Exists(target)) { File.Delete(target); } fileSystemFactory.GetFileInfo(tempFile.Item1).MoveTo(target); }
DirectoryInfoBase getDirectoryForRelease(Version releaseVersion) { return(fileSystem.GetDirectoryInfo(Path.Combine(rootAppDirectory, "app-" + releaseVersion))); }