Ejemplo n.º 1
0
        private static bool AutoInstallService(string path)
        {
            if (!File.Exists(path))
            {
                return(false);
            }

            var root = PackageManagerSettings.CoAppRootDirectory;
            var coappBinDirectory = Path.Combine(root, "bin");

            if (!Directory.Exists(coappBinDirectory))
            {
                Directory.CreateDirectory(coappBinDirectory);
            }
            var canonicalServiceExePath = Path.Combine(coappBinDirectory, "coapp.service.exe");

            if (Symlink.IsSymlink(path))
            {
                // we found a symlink,
                if (!File.Exists(Symlink.GetActualPath(path)))
                {
                    // it is invalid anyway. trash it, try again.
                    Symlink.DeleteSymlink(path);
                }
                return(false);
            }

            try {
                Symlink.MakeFileLink(canonicalServiceExePath, path);

                // hey we found one where it's supposed to be!
                var processStartInfo = new ProcessStartInfo(canonicalServiceExePath)
                {
                    Arguments       = "--start",
                    CreateNoWindow  = true,
                    WindowStyle     = ProcessWindowStyle.Hidden,
                    UseShellExecute = false,
                };

                var process = Process.Start(processStartInfo);
                process.WaitForExit();

                // after it exits, lets see if we've got an installed service
                if (EngineServiceManager.IsServiceInstalled)
                {
                    // YAY!. We're outta here!
                    EngineServiceManager.TryToStartService();
                    return(true);
                }
            } catch {
                // hmm. not working...
            }
            return(false);
        }
Ejemplo n.º 2
0
        internal void UndoPackageComposition()
        {
            var rulesThatISuperceed = InstalledPackageFeed.Instance.FindPackages(CanonicalName.AllPackages)
                                      .Except(this.SingleItemAsEnumerable())
                                      .OrderBy(each => each, new Toolkit.Extensions.Comparer <Package>((packageA, packageB) => GeneralPackageSettings.Instance.WhoWins(packageA, packageB)))
                                      .Where(WinsVersus)
                                      .SelectMany(package => package.ResolvedRules.Select(rule => new { package, rule }))
                                      .WhereDistinct(each => each.rule.Destination)
                                      .ToArray();

            var rulesThatSuperceedMine = InstalledPackageFeed.Instance.FindPackages(CanonicalName.AllPackages).Where(package => !WinsVersus(package)).SelectMany(package => package.ResolvedRules).ToArray();

            foreach (var rule in ResolvedRules)
            {
                // there are three possibilities
                if (rule.Action == CompositionAction.DownloadFile || rule.Action == CompositionAction.InstallCommand)
                {
                    //skip these types of rules.
                    continue;
                }

                // never supercede RemoveCommand.
                if (rule.Action != CompositionAction.RemoveCommand)
                {
                    // 1. my rule was already superceded by another rule: do nothing.
                    if (rulesThatSuperceedMine.Any(each => each.Destination.Equals(rule.Destination, StringComparison.CurrentCultureIgnoreCase)))
                    {
                        continue;
                    }

                    // 2. my rule was superceding another: run that rule.
                    var runRule = rulesThatISuperceed.FirstOrDefault(each => each.rule.Destination.Equals(rule.Destination, StringComparison.CurrentCultureIgnoreCase));
                    if (runRule != null)
                    {
                        runRule.package.ApplyRule(runRule.rule);
                        continue;
                    }
                }

                // 3. my rule should be the current rule, let's undo it.
                switch (rule.Action)
                {
                case CompositionAction.Shortcut:
                    if (ShellLink.PointsTo(rule.Destination, rule.Source))
                    {
                        rule.Destination.TryHardToDelete();
                    }
                    break;

                case CompositionAction.SymlinkFile:
                    if (File.Exists(rule.Destination) && Symlink.IsSymlink(rule.Destination) && Symlink.GetActualPath(rule.Destination).Equals(rule.Source))
                    {
                        Symlink.DeleteSymlink(rule.Destination);
                    }
                    break;

                case CompositionAction.SymlinkFolder:
                    if (Symlink.IsSymlink(rule.Destination) && Symlink.GetActualPath(rule.Destination).Equals(rule.Source))
                    {
                        Symlink.DeleteSymlink(rule.Destination);
                    }
                    break;

                case CompositionAction.Registry:
                    if (CanonicalName.Architecture == Architecture.x64 && Environment.Is64BitOperatingSystem)
                    {
                        RegistryView.System["SOFTWARE"][rule.Key].StringValue = null;
                    }
                    else
                    {
                        RegistryView.System["SOFTWARE\\Wow6432Node"][rule.Key].StringValue = null;
                    }
                    break;

                case CompositionAction.EnvironmentVariable:
                    // not implemented yet.
                    break;

                case CompositionAction.RemoveCommand:
                    ExecuteCommand(rule.Source, rule.Destination);
                    break;
                }
            }
        }
Ejemplo n.º 3
0
        public static void Start()
        {
            try {
                MessageText     = "It will be just a moment while we \r\nremove old versions of the\r\nCoApp Package Manager.";
                StatusText      = "Status: Shutting down CoApp Service";
                OverallProgress = 5;
                OnPropertyChanged();


                var tsk = Task.Factory.StartNew(FilesystemExtensions.RemoveTemporaryFiles);

                // try to gracefully kill coapp.service
                try {
                    var psi = new ProcessStartInfo {
                        FileName    = "sc.exe",
                        Arguments   = @"stop  ""CoApp Package Installer Service""",
                        WindowStyle = ProcessWindowStyle.Hidden
                    };
                    var p = Process.Start(psi);
                    p.WaitForExit();
                } catch {
                    // it's ok.
                }

                // try to gracefully kill coapp.service ( new )
                try {
                    var psi = new ProcessStartInfo {
                        FileName    = "sc.exe",
                        Arguments   = @"stop  ""CoApp""",
                        WindowStyle = ProcessWindowStyle.Hidden
                    };
                    var p = Process.Start(psi);
                    p.WaitForExit();
                }
                catch {
                    // it's ok.
                }

                // let's just kill the processes if they exist
                var serviceProcs = Process.GetProcessesByName("CoApp.Service");
                if (serviceProcs.Any())
                {
                    foreach (var proc in serviceProcs)
                    {
                        try {
                            proc.Kill();
                        } catch {
                            // it's ok.
                        }
                    }
                }

                StatusText      = "Status: Removing Service";
                OverallProgress = 10;
                OnPropertyChanged();
                // remove service if it exists
                try {
                    var psi = new ProcessStartInfo {
                        FileName    = "sc.exe",
                        Arguments   = @"delete  ""CoApp Package Installer Service""",
                        WindowStyle = ProcessWindowStyle.Hidden
                    };
                    var p = Process.Start(psi);
                    p.WaitForExit();
                } catch {
                    // it's ok.
                }

                try {
                    var psi = new ProcessStartInfo {
                        FileName    = "sc.exe",
                        Arguments   = @"delete  ""CoApp""",
                        WindowStyle = ProcessWindowStyle.Hidden
                    };
                    var p = Process.Start(psi);
                    p.WaitForExit();
                }
                catch {
                    // it's ok.
                }

                MsiSetInternalUI(2, IntPtr.Zero);
                MsiSetExternalUI((context, messageType, message) => 1, 0x400, IntPtr.Zero);

                StatusText      = "Status: Finding installed packages.";
                OverallProgress = 15;
                OnPropertyChanged();

                var installedMSIs = GetInstalledCoAppMSIs().ToArray();
                StatusText      = string.Format("Status: Found {0} installed packages.", installedMSIs.Length);
                OverallProgress = 20;
                OnPropertyChanged();



                // Remove CoApp toolkit MSIs
                var toolkits = installedMSIs.Where(each => (each.ProductName.Equals("CoApp.Toolkit", StringComparison.InvariantCultureIgnoreCase) || each.ProductName.Equals("CoApp", StringComparison.InvariantCultureIgnoreCase)) && each.Manufacturer.Equals("OUTERCURVE FOUNDATION", StringComparison.CurrentCultureIgnoreCase)).ToArray();

                if (toolkits.Any())
                {
                    StatusText      = "Status: Removing CoApp Toolkit.";
                    OverallProgress = 25;
                    OnPropertyChanged();

                    foreach (var pkg in toolkits)
                    {
                        OverallProgress++;
                        OnPropertyChanged();

                        MsiInstallProduct(pkg.Path, @"REMOVE=ALL ALLUSERS=1 COAPP=1 COAPP_INSTALLED=1 REBOOT=REALLYSUPPRESS");
                    }
                }

                if (installedMSIs.Any())
                {
                    installedMSIs = GetInstalledCoAppMSIs().ToArray();

                    if (AllPackages && installedMSIs.Any())
                    {
                        var eachProgress = 45 / installedMSIs.Count();
                        StatusText      = "Status: Removing other packages.";
                        OverallProgress = 30;
                        OnPropertyChanged();

                        foreach (var pkg in installedMSIs)
                        {
                            OverallProgress += eachProgress;
                            OnPropertyChanged();

                            MsiInstallProduct(pkg.Path, @"REMOVE=ALL ALLUSERS=1 COAPP=1 COAPP_INSTALLED=1 REBOOT=REALLYSUPPRESS");
                        }
                    }
                }
                //
                // installedMSIs = GetInstalledCoAppMSIs().ToArray();
                // if (!installedMSIs.Any()) {
                StatusText      = "Status: Removing CoApp Folder.";
                OverallProgress = 75;
                OnPropertyChanged();

                // get rid of c:\windows\coapp.exe
                var coappexe = Path.Combine(Environment.GetEnvironmentVariable("SystemRoot"), "coapp.exe");
                if (File.Exists(coappexe))
                {
                    coappexe.TryHardToDelete();
                }

                // try to get rid of c:\apps
                var apps = String.Format("{0}\\apps", Environment.GetEnvironmentVariable("SystemDrive"));
                if (Symlink.IsSymlink(apps))
                {
                    Symlink.DeleteSymlink(apps);
                }
                else if (Directory.Exists(apps))
                {
                    FilesystemExtensions.TryHardToDelete(String.Format("{0}\\apps", Environment.GetEnvironmentVariable("SystemDrive")));
                }
                // no more packages installed-- remove the c:\apps directory
                var rootFolder = CoAppRootFolder.Value;

                FilesystemExtensions.TryHardToDelete(Path.Combine(rootFolder, ".cache"));
                FilesystemExtensions.TryHardToDelete(Path.Combine(rootFolder, "ReferenceAssemblies"));
                FilesystemExtensions.TryHardToDelete(Path.Combine(rootFolder, "x86"));
                FilesystemExtensions.TryHardToDelete(Path.Combine(rootFolder, "x64"));
                FilesystemExtensions.TryHardToDelete(Path.Combine(rootFolder, "bin"));
                FilesystemExtensions.TryHardToDelete(Path.Combine(rootFolder, "powershell"));
                FilesystemExtensions.TryHardToDelete(Path.Combine(rootFolder, "lib"));
                FilesystemExtensions.TryHardToDelete(Path.Combine(rootFolder, "include"));
                // FilesystemExtensions.TryHardToDelete(Path.Combine(rootFolder, "etc"));

                StatusText      = "Status: Removing Dead Links.";
                OverallProgress = 80;
                OnPropertyChanged();

                FilesystemExtensions.RemoveDeadLnks(rootFolder);

                StatusText      = "Status: Removing Empty Folders.";
                OverallProgress = 81;
                OnPropertyChanged();


                FilesystemExtensions.RemoveEssentiallyEmptyFolders(rootFolder);

                // }

                // clean out the CoApp registry keys
                try {
                    StatusText      = "Status: Removing CoApp Registry Settings.";
                    OverallProgress = 83;
                    OnPropertyChanged();

                    var registryKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64).CreateSubKey(@"Software");
                    if (registryKey != null)
                    {
                        registryKey.DeleteSubKeyTree("CoApp");
                    }
                } catch {
                }

                StatusText      = "Status: Cleaning up Temp Folder.";
                OverallProgress = 85;
                OnPropertyChanged();

                foreach (var f in Directory.EnumerateFiles(FilesystemExtensions.TempPath, "*.msi"))
                {
                    FilesystemExtensions.TryHardToDelete(f);
                }
                OverallProgress = 88;
                OnPropertyChanged();

                foreach (var f in Directory.EnumerateFiles(FilesystemExtensions.TempPath, "*.tmp"))
                {
                    FilesystemExtensions.TryHardToDelete(f);
                }

                OverallProgress = 91;
                OnPropertyChanged();

                foreach (var f in Directory.EnumerateFiles(FilesystemExtensions.TempPath, "*.exe"))
                {
                    FilesystemExtensions.TryHardToDelete(f);
                }
                OverallProgress = 93;
                OnPropertyChanged();

                foreach (var f in Directory.EnumerateFiles(FilesystemExtensions.TempPath, "*.dll"))
                {
                    FilesystemExtensions.TryHardToDelete(f);
                }

                OverallProgress = 95;
                OnPropertyChanged();


                MsiSetExternalUI(null, 0x400, IntPtr.Zero);
                FilesystemExtensions.RemoveTemporaryFiles();

                StatusText      = "Status: Complete";
                OverallProgress = 100;
                OnPropertyChanged();
            } catch {
                // meh.
            }

            Environment.Exit(0);
        }