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);
        }
        async Task <List <string> > executeInstall(string currentAssemblyDir, IPackage bundledPackageMetadata, IObserver <int> progress = null)
        {
            var fxVersion    = determineFxVersionFromPackage(bundledPackageMetadata);
            var eigenUpdater = new UpdateManager(currentAssemblyDir, bundledPackageMetadata.Id, fxVersion, TargetRootDirectory);

            var eigenCheckProgress    = new Subject <int>();
            var eigenCopyFileProgress = new Subject <int>();
            var eigenApplyProgress    = new Subject <int>();

            var realCheckProgress    = new Subject <int>();
            var realCopyFileProgress = new Subject <int>();
            var realApplyProgress    = new Subject <int>();

            // The real update takes longer than the eigenupdate because we're
            // downloading from the Internet instead of doing everything
            // locally, so give it more weight
            Observable.Concat(
                Observable.Concat(eigenCheckProgress, eigenCopyFileProgress, eigenCopyFileProgress).Select(x => (x / 3.0) * 0.33),
                Observable.Concat(realCheckProgress, realCopyFileProgress, realApplyProgress).Select(x => (x / 3.0) * 0.67))
            .Select(x => (int)x)
            .Subscribe(progress);

            List <string> ret        = null;
            var           updateInfo = await eigenUpdater.CheckForUpdate(progress : eigenCheckProgress);

            await eigenUpdater.DownloadReleases(updateInfo.ReleasesToApply, eigenCopyFileProgress);

            ret = await eigenUpdater.ApplyReleases(updateInfo, eigenApplyProgress);

            eigenUpdater.Dispose();

            var updateUrl = bundledPackageMetadata.ProjectUrl != null?bundledPackageMetadata.ProjectUrl.ToString() : null;

            updateUrl = null; //XXX REMOVE ME
            if (updateUrl == null)
            {
                realCheckProgress.OnNext(100); realCheckProgress.OnCompleted();
                realCopyFileProgress.OnNext(100); realCopyFileProgress.OnCompleted();
                realApplyProgress.OnNext(100); realApplyProgress.OnCompleted();

                return(ret);
            }

            var realUpdater = new UpdateManager(updateUrl, bundledPackageMetadata.Id, fxVersion, TargetRootDirectory);

            try {
                updateInfo = await realUpdater.CheckForUpdate(progress : realCheckProgress);

                await realUpdater.DownloadReleases(updateInfo.ReleasesToApply, realCopyFileProgress);

                await realUpdater.ApplyReleases(updateInfo, realApplyProgress);
            } catch (Exception ex) {
                log.ErrorException("Failed to update to latest remote version", ex);
                return(new List <string>());
            }

            realUpdater.Dispose();

            return(ret);
        }
Beispiel #3
0
        void fixPinnedExecutables(Version newCurrentVersion)
        {
            if (Environment.OSVersion.Version < new Version(6, 1))
            {
                log.Warn("fixPinnedExecutables: Found OS Version '{0}', exiting...", Environment.OSVersion.VersionString);
                return;
            }

            var newCurrentFolder  = "app-" + newCurrentVersion;
            var oldAppDirectories = fileSystem.GetDirectoryInfo(rootAppDirectory).GetDirectories()
                                    .Where(x => x.Name.StartsWith("app-", StringComparison.InvariantCultureIgnoreCase))
                                    .Where(x => x.Name != newCurrentFolder)
                                    .Select(x => x.FullName)
                                    .ToArray();

            if (!oldAppDirectories.Any())
            {
                log.Info("fixPinnedExecutables: oldAppDirectories is empty, this is pointless");
                return;
            }

            var newAppPath = Path.Combine(rootAppDirectory, newCurrentFolder);

            var taskbarPath = Path.Combine(
                Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
                "Microsoft\\Internet Explorer\\Quick Launch\\User Pinned\\TaskBar");

            Func <FileInfoBase, ShellLink> resolveLink = file => {
                try {
                    return(new ShellLink(file.FullName));
                } catch (Exception ex) {
                    var message = String.Format("File '{0}' could not be converted into a valid ShellLink", file.FullName);
                    log.WarnException(message, ex);
                    return(null);
                }
            };

            var shellLinks = fileSystem.GetDirectoryInfo(taskbarPath)
                             .GetFiles("*.lnk")
                             .Select(resolveLink)
                             .Where(x => x != null)
                             .ToArray();

            foreach (var shortcut in shellLinks)
            {
                try {
                    updateLink(shortcut, oldAppDirectories, newAppPath);
                } catch (Exception ex) {
                    var message = String.Format("fixPinnedExecutables: shortcut failed: {0}", shortcut.Target);
                    log.ErrorException(message, ex);
                }
            }
        }
Beispiel #4
0
        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]);
            }

            return(appSetups
                   .Select(app => installAppVersion(app, info.NewCurrentVersion, info.ShortcutRequestsToIgnore, info.IsFirstInstall))
                   .Where(x => x != null)
                   .ToArray());
        }
Beispiel #5
0
        IEnumerable <ShortcutCreationRequest> runAppSetupCleanups(string fullDirectoryPath)
        {
            var dirName = Path.GetFileName(fullDirectoryPath);
            var ver     = new Version(dirName.Replace("app-", ""));

            var apps = default(IEnumerable <IAppSetup>);

            try {
                apps = findAppSetupsToRun(fullDirectoryPath);
            } catch (UnauthorizedAccessException ex) {
                log.ErrorException("Couldn't run cleanups", ex);
                return(Enumerable.Empty <ShortcutCreationRequest>());
            }

            var ret = apps.SelectMany(app => uninstallAppVersion(app, ver)).ToArray();

            return(ret);
        }
Beispiel #6
0
        async Task <List <string> > executeInstall(
            string currentAssemblyDir,
            IPackage bundledPackageMetadata,
            bool ignoreDeltaUpdates  = false,
            IObserver <int> progress = null)
        {
            var fxVersion = bundledPackageMetadata.DetectFrameworkVersion();

            var eigenCheckProgress    = new Subject <int>();
            var eigenCopyFileProgress = new Subject <int>();
            var eigenApplyProgress    = new Subject <int>();

            var realCheckProgress    = new Subject <int>();
            var realCopyFileProgress = new Subject <int>();
            var realApplyProgress    = new Subject <int>();

            List <string> ret = null;

            using (var eigenUpdater = new UpdateManager(
                       currentAssemblyDir,
                       bundledPackageMetadata.Id,
                       fxVersion,
                       TargetRootDirectory)) {
                // The real update takes longer than the eigenupdate because we're
                // downloading from the Internet instead of doing everything
                // locally, so give it more weight
                Observable.Concat(
                    Observable.Concat(eigenCheckProgress, eigenCopyFileProgress, eigenCopyFileProgress)
                    .Select(x => (x / 3.0) * 0.33),
                    Observable.Concat(realCheckProgress, realCopyFileProgress, realApplyProgress)
                    .Select(x => (x / 3.0) * 0.67))
                .Select(x => (int)x)
                .Subscribe(progress);

                var updateInfo = await eigenUpdater.CheckForUpdate(ignoreDeltaUpdates, eigenCheckProgress);

                log.Info("The checking of releases completed - and there was much rejoicing");

                if (!updateInfo.ReleasesToApply.Any())
                {
                    var rootDirectory = TargetRootDirectory ?? Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);

                    var version        = updateInfo.CurrentlyInstalledVersion;
                    var releaseFolder  = String.Format("app-{0}", version.Version);
                    var absoluteFolder = Path.Combine(rootDirectory, version.PackageName, releaseFolder);

                    if (!Directory.Exists(absoluteFolder))
                    {
                        log.Warn("executeInstall: the directory {0} doesn't exist - cannot find the current app?!!?");
                    }
                    else
                    {
                        return(Directory.GetFiles(absoluteFolder, "*.exe", SearchOption.TopDirectoryOnly)
                               .ToList());
                    }
                }

                foreach (var u in updateInfo.ReleasesToApply)
                {
                    log.Info("HEY! We should be applying update {0}", u.Filename);
                }

                await eigenUpdater.DownloadReleases(updateInfo.ReleasesToApply, eigenCopyFileProgress);

                log.Info("The downloading of releases completed - and there was much rejoicing");

                ret = await eigenUpdater.ApplyReleases(updateInfo, eigenApplyProgress);

                log.Info("The applying of releases completed - and there was much rejoicing");
            }

            var updateUrl = bundledPackageMetadata.ProjectUrl != null?bundledPackageMetadata.ProjectUrl.ToString() : null;

            updateUrl = null; //XXX REMOVE ME
            if (updateUrl == null)
            {
                realCheckProgress.OnNext(100); realCheckProgress.OnCompleted();
                realCopyFileProgress.OnNext(100); realCopyFileProgress.OnCompleted();
                realApplyProgress.OnNext(100); realApplyProgress.OnCompleted();

                return(ret);
            }

            using (var realUpdater = new UpdateManager(
                       updateUrl,
                       bundledPackageMetadata.Id,
                       fxVersion,
                       TargetRootDirectory)) {
                try {
                    var updateInfo = await realUpdater.CheckForUpdate(progress : realCheckProgress);

                    await realUpdater.DownloadReleases(updateInfo.ReleasesToApply, realCopyFileProgress);

                    await realUpdater.ApplyReleases(updateInfo, realApplyProgress);
                } catch (Exception ex) {
                    log.ErrorException("Failed to update to latest remote version", ex);
                    return(new List <string>());
                }
            }

            return(ret);
        }