Ejemplo n.º 1
0
        private static Manifest GenerateManifest(string path, ManifestFormat format, ITaskHandler handler)
        {
            var generator = new ManifestGenerator(path, format);

            handler.RunTask(generator);
            return(generator.Manifest);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Generates a manifest for a directory in the filesystem and writes the manifest to a file named <see cref="Manifest.ManifestFile"/> in that directory.
        /// </summary>
        /// <param name="path">The path of the directory to analyze.</param>
        /// <param name="format">The format of the manifest (which file details are listed, which digest method is used, etc.).</param>
        /// <param name="handler">A callback object used when the the user is to be informed about progress.</param>
        /// <returns>The manifest digest.</returns>
        /// <exception cref="IOException">A problem occurred while writing the file.</exception>
        /// <remarks>
        /// The exact format is specified here: https://docs.0install.net/specifications/manifest/
        /// </remarks>
        public static string CreateDotFile(string path, ManifestFormat format, ITaskHandler handler)
        {
            #region Sanity checks
            if (string.IsNullOrEmpty(path))
            {
                throw new ArgumentNullException(nameof(path));
            }
            if (format == null)
            {
                throw new ArgumentNullException(nameof(format));
            }
            if (handler == null)
            {
                throw new ArgumentNullException(nameof(handler));
            }
            #endregion

            var generator = new ManifestGenerator(path, format);
            handler.RunTask(generator);
            return(generator.Manifest.Save(Path.Combine(path, Manifest.ManifestFile)));
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Creates a new manifest.
 /// </summary>
 /// <param name="format">The format used for <see cref="Save(Stream)"/>, also specifies the algorithm used in <see cref="ManifestDirectoryElement.Digest"/>.</param>
 /// <param name="nodes">A list of all elements in the tree this manifest represents.</param>
 public Manifest(ManifestFormat format, params ManifestNode[] nodes)
 {
     Format = format ?? throw new ArgumentNullException(nameof(format));
     _nodes = nodes ?? throw new ArgumentNullException(nameof(nodes));
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Creates a new manifest.
 /// </summary>
 /// <param name="format">The format used for <see cref="Save(Stream)"/>, also specifies the algorithm used in <see cref="ManifestDirectoryElement.Digest"/>.</param>
 /// <param name="nodes">A list of all elements in the tree this manifest represents.</param>
 public Manifest(ManifestFormat format, IEnumerable <ManifestNode> nodes)
 {
     Format = format ?? throw new ArgumentNullException(nameof(format));
     _nodes = (nodes ?? throw new ArgumentNullException(nameof(nodes))).ToArray(); // Make the collection immutable
 }
 public void TestFromPrefix()
 {
     ManifestFormat.FromPrefix("sha1new=abc").Should().BeSameAs(ManifestFormat.Sha1New);
     ManifestFormat.FromPrefix("sha256=abc").Should().BeSameAs(ManifestFormat.Sha256);
     ManifestFormat.FromPrefix("sha256new_abc").Should().BeSameAs(ManifestFormat.Sha256New);
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Prepares to generate a manifest for a directory in the filesystem.
 /// </summary>
 /// <param name="sourcePath">The path of the directory to analyze.</param>
 /// <param name="format">The format of the manifest to generate.</param>
 public ManifestGenerator(string sourcePath, ManifestFormat format)
     : base(sourcePath)
 {
     Format = format ?? throw new ArgumentNullException(nameof(format));
 }