Пример #1
0
        /// <summary>
        /// Unmerges the packages matching the given atoms.
        /// </summary>
        /// <param name="atomarr">package atoms for unmerging</param>
        public void Unmerge(Atom[] atomarr)
        {
            foreach (Atom atom in atomarr) {
                UnmergeEventArgs uae = new UnmergeEventArgs();
                uae.Package = atom;

                if (_pkgmgr.IsProtected(atom))
                    throw new ProtectedPackageException(atom.ToString());

                if (this.OnUnmerge != null)
                    this.OnUnmerge.Invoke(this, uae);

                IInstallProject installer = _pkgmgr.GetPackageInstaller(atom);

                if (installer != null && installer.HasPkgPreRmTarget) {
                    _log.Info("Executing pre-removal tasks...");
                    installer.PkgPreRm();
                }

                FileTuple[] files = _pkgmgr.QueryPackageFiles(atom)
                    .OrderByDescending(i => i.Item1)
                    .ToArray();

                IntPtr wow64oldval = IntPtr.Zero;
                if (Environment.Is64BitOperatingSystem && !Environment.Is64BitProcess) {
                    if (!Wow64DisableWow64FsRedirection(out wow64oldval))
                        throw new InstallException("Failed to disable Wow64 file system redirection.");
                }

                foreach (FileTuple ft in files) {
                    try {
                        if (ft.Item2 == FileType.Directory && this.IsProtected(ft.Item1)) {
                            _log.DebugFormat("Skipping protected directory '{0}'", ft.Item1);
                            continue;
                        }

                        if (ft.Item2 == FileType.Directory) {
                            if (Directory.GetFiles(ft.Item1).Length > 0)
                                throw new IOException();

                            Directory.Delete(ft.Item1);
                            _log.InfoFormat("Deleted directory '{0}'", ft.Item1);
                        } else {
                            File.Delete(ft.Item1);
                            _log.InfoFormat("Deleted file '{0}'", ft.Item1);
                        }
                    } catch (DirectoryNotFoundException) {
                        _log.DebugFormat("Skipping non-existant directory '{0}'", ft.Item1);
                    } catch (FileNotFoundException) {
                        _log.DebugFormat("Skipping non-existant file '{0}'", ft.Item1);
                    } catch {
                        TrashWorker.AddFile(ft.Item1, _pkgmgr);
                        _log.WarnFormat("Marked '{0}' for future removal", ft.Item1);
                    }
                }

                if (Environment.Is64BitOperatingSystem && !Environment.Is64BitProcess)
                    Wow64RevertWow64FsRedirection(wow64oldval);

                if (installer != null && installer.HasPkgPostRmTarget) {
                    _log.Info("Executing post-removal tasks...");
                    installer.PkgPostRm();
                }

                _pkgmgr.DeletePackage(atom);

                Atom worldatom = Atom.Parse(atom.PackageName, AtomParseOptions.WithoutVersion);
                if (_pkgmgr.FindPackages(worldatom).Length == 0)
                    _pkgmgr.DeselectPackage(worldatom);
            }

            if (this.OnAutoClean != null)
                this.OnAutoClean.Invoke(this, new EventArgs());

            TrashWorker.Purge(_pkgmgr);
        }
Пример #2
0
 /// <summary>
 /// Handler for the MergeWorker.OnUnmerge event.
 /// </summary>
 /// <param name="sender">the merge worker</param>
 /// <param name="e">event args</param>
 public void MergeWorker_OnUnmerge(object sender, UnmergeEventArgs e)
 {
     Console.WriteLine("\n>>> Unmerging {0}", e.Package.ToString());
 }