/// <summary> /// Copy constructor /// </summary> /// <param name="original"> /// The original object /// </param> /// <param name="parentDirectory"> /// The parent directory /// </param> public ManifestDirectoryInfo( ManifestDirectoryInfo original, ManifestDirectoryInfo parentDirectory) : base(original.Name, parentDirectory) { Files = new Dictionary <string, ManifestFileInfo>(); filesStore = null; Subdirectories = new Dictionary <string, ManifestDirectoryInfo>(); subdirectoriesStore = null; foreach (String nextDirName in original.Subdirectories.Keys) { ManifestDirectoryInfo dirClone = new ManifestDirectoryInfo( original.Subdirectories[nextDirName], this); Subdirectories.Add(nextDirName, dirClone); } foreach (String nextFileName in original.Files.Keys) { ManifestFileInfo fileClone = new ManifestFileInfo( original.Files[nextFileName], this); Files.Add(nextFileName, fileClone); } }
/// <summary> /// Put an entry into this manifest corresponding to an entry in /// another manifest. Will replace an existing entry. /// </summary> /// <param name="otherManifestFile"> /// The other manifest file to be put into this manifest /// </param> /// <returns> /// The new file in this manifest /// </returns> public ManifestFileInfo PutFileFromOtherManifest( ManifestFileInfo otherManifestFile) { Stack <ManifestDirectoryInfo> stack = new Stack <ManifestDirectoryInfo>(); ManifestDirectoryInfo nextParentOther = otherManifestFile.ParentDirectory; while (nextParentOther != null) { stack.Push(nextParentOther); nextParentOther = nextParentOther.ParentDirectory; } // Start in root directory ManifestDirectoryInfo currentParentThis = RootDirectory; // Pop the root directory since we're starting there stack.Pop(); while (stack.Count > 0) { nextParentOther = stack.Pop(); if (currentParentThis.Subdirectories.Keys.Contains( nextParentOther.Name)) { currentParentThis = currentParentThis.Subdirectories[ nextParentOther.Name]; } else { ManifestDirectoryInfo newParent = new ManifestDirectoryInfo( nextParentOther.Name, currentParentThis); currentParentThis.Subdirectories[nextParentOther.Name] = newParent; currentParentThis = newParent; } } ManifestFileInfo newManifestFile = new ManifestFileInfo( otherManifestFile, currentParentThis); currentParentThis.Files[newManifestFile.Name] = newManifestFile; return(newManifestFile); }
/// <summary> /// Copy constructor /// </summary> /// <param name="original"> /// The original object /// </param> /// <param name="parentDirectory"> /// The parent directory /// </param> public ManifestFileInfo( ManifestFileInfo original, ManifestDirectoryInfo parentDirectory) : base(original.Name, parentDirectory) { FileLength = original.FileLength; LastModifiedUtc = original.LastModifiedUtc; RegisteredUtc = original.RegisteredUtc; FileHash = original.FileHash; }
/// <summary> /// Make a platform-specific relative path /// </summary> /// <param name="fileInfo"> /// The file whose path will be generated /// </param> /// <returns> /// The path /// </returns> public static String MakeNativePathString(ManifestFileInfo fileInfo) { return(Path.Combine( MakeNativePathString(fileInfo.ParentDirectory), fileInfo.Name).Normalize()); }
/// <summary> /// Make a standard UNIX-style relative path, which will not vary /// across platforms. /// </summary> /// <param name="fileInfo"> /// The file whose path will be generated /// </param> /// <returns> /// The path /// </returns> public static String MakeStandardPathString(ManifestFileInfo fileInfo) { return(MakeStandardPathString(fileInfo.ParentDirectory) + fileInfo.Name); }