Exemple #1
0
        protected virtual int Startup(IEnumerable <string> args)
        {
            var task = Task.Factory.StartNew(() => {
                Main(args);
            }, CancellationTokenSource.Token);

            try {
                Console.CancelKeyPress += (x, y) => {
                    if (!CancellationTokenSource.IsCancellationRequested)
                    {
                        Console.WriteLine("Operation Canceled...");
                        CancellationTokenSource.Cancel();
                        if (y.SpecialKey == ConsoleSpecialKey.ControlBreak)
                        {
                            // can't cancel so we just block on the task.
                            return;
                            // task.Wait();
                        }
                    }
                    y.Cancel = true;
                };
                task.Wait(CancellationTokenSource.Token);
            } catch (Exception e) {
                HandleException(e.Unwrap());
                return(1);
            }
            FilesystemExtensions.RemoveTemporaryFiles();
            return(0);
        }
Exemple #2
0
        private void Disconnect()
        {
            _bufferReady.Set();

            lock (this) {
                if (!Connected)
                {
                    return;
                }
                Connected = false;
            }

            Logger.Message("disposing of pipes: [{0}]-[{1}]".format(_clientId, _sessionId));
            try {
                if (_serverPipe != null)
                {
                    _serverPipe.Close();
                }
                _serverPipe = null;

                if (!_isAsychronous && _responsePipe != null)
                {
                    _responsePipe.Close();
                }
                _responsePipe = null;
            } catch (Exception e) {
                Logger.Error(e);
            }

            // clean up anything that can be cleaned up.
            FilesystemExtensions.RemoveTemporaryFiles();
        }
Exemple #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);
        }