public override ExitCode Execute() { var manifestDigest = new ManifestDigest(AdditionalArgs[0]); string path = AdditionalArgs[1]; try { if (File.Exists(path)) { // One or more archives (combined/overlayed) Store.AddArchives(GetArchiveFileInfos(), manifestDigest, Handler); 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); } Store.AddDirectory(Path.GetFullPath(path), manifestDigest, Handler); return(ExitCode.OK); } else { throw new FileNotFoundException(string.Format(Resources.FileOrDirNotFound, path), path); } } catch (ImplementationAlreadyInStoreException ex) { Log.Warn(ex); return(ExitCode.NoChanges); } }
/// <summary> /// Imports implementation archives into the <see cref="IStore"/>. /// </summary> private void ImportArchives() { foreach (string path in Directory.GetFiles(_contentDir)) { Debug.Assert(path != null); var digest = new ManifestDigest(); digest.ParseID(Path.GetFileNameWithoutExtension(path)); if (digest.Best != null && !Store.Contains(digest)) { try { Store.AddArchives(new[] { new ArchiveFileInfo { Path = path, MimeType = Archive.GuessMimeType(path) } }, digest, Handler); } #region Error handling catch (ImplementationAlreadyInStoreException) {} #endregion } } }
private ExitCode Add() { if (AdditionalArgs.Count < 3) { throw new OptionException(Resources.MissingArguments + Environment.NewLine + "add DIGEST (DIRECTORY | (ARCHIVE [EXTRACT [MIME-TYPE [...]]))", ""); } var manifestDigest = new ManifestDigest(AdditionalArgs[1]); string path = AdditionalArgs[2]; try { if (File.Exists(path)) { // One or more archives (combined/overlayed) Store.AddArchives(GetArchiveFileInfos(), manifestDigest, Handler); return(ExitCode.OK); } else if (Directory.Exists(path)) { // A single directory if (AdditionalArgs.Count > 3) { throw new OptionException(Resources.TooManyArguments + Environment.NewLine + "add DIGEST (DIRECTORY | (ARCHIVE [EXTRACT [MIME-TYPE [...]]))", ""); } Store.AddDirectory(Path.GetFullPath(path), manifestDigest, Handler); return(ExitCode.OK); } else { throw new FileNotFoundException(string.Format(Resources.NoSuchFileOrDirectory, path), path); } } catch (ImplementationAlreadyInStoreException ex) { Log.Warn(ex); return(ExitCode.NoChanges); } }