Esempio n. 1
0
        public override ExitCode Execute()
        {
            try
            {
                switch (AdditionalArgs.Count)
                {
                case 1:
                    // Verify a directory inside the store
                    ImplementationStore.Verify(new ManifestDigest(AdditionalArgs[0]), Handler);
                    break;

                case 2:
                    // Verify an arbitrary directory
                    ImplementationStoreUtils.Verify(AdditionalArgs[0], new ManifestDigest(AdditionalArgs[1]), Handler);
                    break;
                }
            }
            catch (DigestMismatchException ex)
            {
                Handler.Output(Resources.VerifyImplementation, ex.LongMessage);
                return(ExitCode.DigestMismatch);
            }

            return(ExitCode.OK);
        }
Esempio n. 2
0
        public override ExitCode Execute()
        {
            var    manifestDigest = new ManifestDigest(AdditionalArgs[0]);
            string path           = AdditionalArgs[1];

            try
            {
                if (File.Exists(path))
                { // One or more archives (combined/overlay)
                    ImplementationStore.Add(manifestDigest, BuildImplementation);
                    return(ExitCode.OK);
                }
                else if (Directory.Exists(path))
                { // A single directory
                    if (AdditionalArgs.Count > 2)
                    {
                        throw new OptionException(Resources.TooManyArguments + Environment.NewLine + AdditionalArgs.Skip(2).JoinEscapeArguments(), null);
                    }
                    ImplementationStore.Add(manifestDigest, builder => Handler.RunTask(new ReadDirectory(Path.GetFullPath(path), builder)));
                    return(ExitCode.OK);
                }
                else
                {
                    throw new FileNotFoundException(string.Format(Resources.FileOrDirNotFound, path), path);
                }
            }
            catch (ImplementationAlreadyInStoreException ex)
            {
                Log.Warn(ex);
                return(ExitCode.NoChanges);
            }
        }
Esempio n. 3
0
        public override ExitCode Execute()
        {
            var manifestDigest = new ManifestDigest(AdditionalArgs[0]);

            try
            {
                string path = AdditionalArgs[1];
                if (Directory.Exists(path))
                {
                    if (AdditionalArgs.Count > 2)
                    {
                        throw new OptionException(Resources.TooManyArguments + Environment.NewLine + AdditionalArgs.Skip(2).JoinEscapeArguments(), null);
                    }
                    ImplementationStore.Add(manifestDigest, builder => Handler.RunTask(new ReadDirectory(Path.GetFullPath(path), builder)));
                    return(ExitCode.OK);
                }

                ImplementationStore.Add(manifestDigest, BuildImplementation);
                return(ExitCode.OK);
            }
            catch (ImplementationAlreadyInStoreException ex)
            {
                Log.Warn(ex.Message, ex);
                return(ExitCode.NoChanges);
            }
        }
Esempio n. 4
0
        public override ExitCode Execute()
        {
            bool removed = false;

            foreach (var digest in AdditionalArgs.Select(x => new ManifestDigest(x)))
            {
                removed |= ImplementationStore.Remove(digest, Handler);
            }
            return(removed ? ExitCode.OK : ExitCode.NoChanges);
        }
Esempio n. 5
0
    private void CleanImplementations(IEnumerable <ImplementationSelection> implementations)
    {
        var digestsToKeep   = implementations.Select(x => x.ManifestDigest);
        var digestsToRemove = ImplementationStore.ListAll().Except(digestsToKeep, ManifestDigestPartialEqualityComparer.Instance);

        Handler.RunTask(ForEachTask.Create(
                            name: Resources.RemovingOutdated,
                            target: digestsToRemove.ToList(),
                            work: digest => ImplementationStore.Remove(digest, Handler)));
    }
 public override ExitCode Execute()
 {
     foreach (var digest in AdditionalArgs.Select(x => new ManifestDigest(x)))
     {
         if (!ImplementationStore.Remove(digest, Handler))
         {
             throw new ImplementationNotFoundException(digest);
         }
     }
     return(ExitCode.OK);
 }
Esempio n. 7
0
 /// <summary>
 /// Deletes this implementation from the <see cref="IImplementationStore"/> it is located in.
 /// </summary>
 /// <param name="handler">A callback object used when the the user needs to be asked questions or informed about IO tasks.</param>
 /// <exception cref="KeyNotFoundException">No matching implementation could be found in the <see cref="IImplementationStore"/>.</exception>
 /// <exception cref="IOException">The implementation could not be deleted.</exception>
 /// <exception cref="UnauthorizedAccessException">Write access to the store is not permitted.</exception>
 public override void Delete(ITaskHandler handler)
 {
     try
     {
         ImplementationStore.Remove(_digest, handler);
     }
     #region Error handling
     catch (ImplementationNotFoundException ex)
     {
         throw new KeyNotFoundException(ex.Message, ex);
     }
     #endregion
 }
Esempio n. 8
0
        public override ExitCode Execute()
        {
            var digest = new ManifestDigest(AdditionalArgs[0]);

            string?path = ImplementationStore.GetPath(digest);

            if (path == null)
            {
                throw new ImplementationNotFoundException(digest);
            }
            Handler.Output(string.Format(Resources.LocalPathOf, AdditionalArgs[0]), path);
            return(ExitCode.OK);
        }
Esempio n. 9
0
 /// <summary>
 /// Deletes this implementation from the <see cref="IImplementationStore"/> it is located in.
 /// </summary>
 /// <param name="handler">A callback object used when the the user needs to be asked questions or informed about IO tasks.</param>
 /// <exception cref="KeyNotFoundException">No matching implementation could be found in the <see cref="IImplementationStore"/>.</exception>
 /// <exception cref="IOException">The implementation could not be deleted.</exception>
 /// <exception cref="UnauthorizedAccessException">Write access to the store is not permitted.</exception>
 public override void Delete(ITaskHandler handler)
 {
     try
     {
         handler.RunTask(new SimpleTask(
                             string.Format(Resources.DeletingImplementation, _digest),
                             () => ImplementationStore.Remove(_digest, handler)));
     }
     #region Error handling
     catch (ImplementationNotFoundException ex)
     {
         throw new KeyNotFoundException(ex.Message, ex);
     }
     #endregion
 }
Esempio n. 10
0
        public override ExitCode Execute()
        {
            string outputArchive = AdditionalArgs[1];
            string mimeType      = (AdditionalArgs.Count == 3) ? AdditionalArgs[3] : Archive.GuessMimeType(outputArchive);

            var    digest          = new ManifestDigest(AdditionalArgs[0]);
            string?sourceDirectory = ImplementationStore.GetPath(digest);

            if (sourceDirectory == null)
            {
                throw new ImplementationNotFoundException(digest);
            }

            using var builder = ArchiveBuilder.Create(outputArchive, mimeType);
            Handler.RunTask(new ReadDirectory(sourceDirectory, builder));

            return(ExitCode.OK);
        }
Esempio n. 11
0
            public override ExitCode Execute()
            {
                if (ZeroInstallInstance.IsRunningFromCache)
                {
                    Log.Error("This instance of Zero Install is running from a cache. There is nothing to uninstall.");
                    return(ExitCode.NoChanges);
                }

                if (MachineWide && !WindowsUtils.IsAdministrator)
                {
                    throw new NotAdminException(Resources.MustBeAdminForMachineWide);
                }

                if (!Handler.Ask(Resources.AskRemoveZeroInstall, defaultAnswer: true))
                {
                    return(ExitCode.UserCanceled);
                }

                if (ExistingDesktopIntegration(MachineWide) || ExistingDesktopIntegration(machineWide: false))
                {
                    new RemoveAllApps(Handler)
                    {
                        MachineWide = MachineWide
                    }.Execute();
                }

                if (Handler.Ask(Resources.ConfirmPurge, defaultAnswer: false))
                {
                    ImplementationStore.Purge(Handler);
                }

                if (WindowsUtils.IsWindows)
                {
                    DelegateToTempCopy();
                }
                else
                {
                    PerformRemove();
                }

                return(ExitCode.OK);
            }
Esempio n. 12
0
        public override ExitCode Execute()
        {
            string path = GetPath();

            // Init new store to ensure the target is suitable
            ImplementationStore = new ImplementationStore(path);

            var dirs = GetImplementationDirs().ToList();

            if (dirs.AddIfNew(path))
            {
                SetImplementationDirs(dirs);
                return(ExitCode.OK);
            }
            else
            {
                Log.Warn(string.Format(Resources.AlreadyInImplDirs, path));
                return(ExitCode.NoChanges);
            }
        }
Esempio n. 13
0
    private void CleanImplementations(IEnumerable <ImplementationSelection> implementations)
    {
        var digestsToKeep   = implementations.Select(x => x.ManifestDigest);
        var digestsToRemove = ImplementationStore.ListAll().Except(digestsToKeep, ManifestDigestPartialEqualityComparer.Instance);

        Handler.RunTask(ForEachTask.Create(
                            name: Resources.RemovingOutdated,
                            target: digestsToRemove.ToList(),
                            work: digest =>
        {
            try
            {
                ImplementationStore.Remove(digest, Handler);
            }
            catch (NotAdminException ex) when(ZeroInstallInstance.IsLibraryMode)
            {
                Log.Info($"Unable to remove {digest}", ex);
            }
        }
                            ));
    }
            public override ExitCode Execute()
            {
                var manifestDigest = new ManifestDigest(AdditionalArgs[0]);

                string outputArchive = AdditionalArgs[1];

                Debug.Assert(outputArchive != null);

                string?sourceDirectory = ImplementationStore.GetPath(manifestDigest);

                if (sourceDirectory == null)
                {
                    throw new ImplementationNotFoundException(manifestDigest);
                }

                string mimeType = (AdditionalArgs.Count == 3) ? AdditionalArgs[3] : Archive.GuessMimeType(outputArchive);

                using var generator = ArchiveGenerator.Create(sourceDirectory, outputArchive, mimeType);
                Handler.RunTask(generator);
                return(ExitCode.OK);
            }
Esempio n. 15
0
        private void Clean(IEnumerable <ManifestDigest> digestsToKeep)
        {
            var toDelete = ImplementationStore.ListAll().Except(digestsToKeep, ManifestDigestPartialEqualityComparer.Instance).ToList();

            Handler.RunTask(ForEachTask.Create(Resources.RemovingOutdated, toDelete, x => ImplementationStore.Remove(x, Handler)));
        }
Esempio n. 16
0
 public ImplementationStoreTest()
 {
     _handler = new MockTaskHandler();
     _tempDir = new TemporaryDirectory("0install-test-store");
     _store   = new ImplementationStore(_tempDir);
 }
Esempio n. 17
0
 /// <summary>
 /// Verify this implementation is undamaged.
 /// </summary>
 /// <param name="handler">A callback object used when the the user needs to be asked questions or informed about IO tasks.</param>
 /// <exception cref="OperationCanceledException">The user canceled the task.</exception>
 /// <exception cref="IOException">The entry's directory could not be processed.</exception>
 /// <exception cref="UnauthorizedAccessException">Read access to the entry's directory is not permitted.</exception>
 public void Verify(ITaskHandler handler) => ImplementationStore.Verify(_digest, handler);