Example #1
0
 public void Test_GetAbsolutePath_ArgumentNullException()
 {
     Assert.Throws(typeof(ArgumentNullException), delegate {
         IRelativeFilePath p = @"..\File.txt".ToRelativeFilePath();
         var x = p.GetAbsolutePathFrom((null as string).ToAbsoluteDirectoryPath());
     });
 }
        public static string GetRelativePath(this IRelativeFilePath relativeFilePath)
        {
            string parentDirectoryPath = GetRelativeDirectoryPath(relativeFilePath.ParentDirectoryPath);

            if (string.IsNullOrEmpty(parentDirectoryPath))
            {
                return(relativeFilePath.FileName);
            }

            return(parentDirectoryPath + '/' + relativeFilePath.FileName);
        }
Example #3
0
        public void Test_GetAbsolutePathPathWithError3()
        {
            IRelativeFilePath      directoryPathTo           = @"..\..\Dir1\File.txt".ToRelativeFilePath();
            IAbsoluteDirectoryPath absoluteDirectoryPathFrom = @"C:\Dir1".ToAbsoluteDirectoryPath();

            Assert.IsFalse(directoryPathTo.CanGetAbsolutePathFrom(absoluteDirectoryPathFrom));
            string failureReason;

            Assert.IsFalse(directoryPathTo.CanGetAbsolutePathFrom(absoluteDirectoryPathFrom, out failureReason));
            Assert.IsTrue(failureReason == @"Cannot resolve pathTo.TryGetAbsolutePath(pathFrom) because there are too many parent dirs in pathTo:
   PathFrom = ""C:\Dir1""
   PathTo   = ""..\..\Dir1""");
            directoryPathTo.GetAbsolutePathFrom(absoluteDirectoryPathFrom);
        }
Example #4
0
        private List <string> FindUnregisteredFilesIterative(HashSet <string> filePathsHashSet)
        {
            List <string> unregisteredFiles = new List <string>();

            Console.WriteLine($"Start iterative operation for finding unregistered files from {mConfiguration.Value.DriveRootDirectory}");

            Queue <string> directoriesToSearch = new Queue <string>();

            directoriesToSearch.Enqueue(mConfiguration.Value.DriveRootDirectory);

            mConfiguration.Value.DriveRootDirectory.TryGetAbsoluteDirectoryPath(out IAbsoluteDirectoryPath absoluteDirectoryPath);

            while (directoriesToSearch.Count > 0)
            {
                string currentSearchDirectory = directoriesToSearch.Dequeue();
                Console.WriteLine($"Collecting from {currentSearchDirectory}");

                // Adding subdirectories to search.
                foreach (string directory in Directory.EnumerateDirectories(currentSearchDirectory))
                {
                    directoriesToSearch.Enqueue(directory);
                }

                // Search files.
                foreach (string filePath in Directory.EnumerateFiles(currentSearchDirectory))
                {
                    filePath.TryGetAbsoluteFilePath(out IAbsoluteFilePath absoluteFilePath);
                    IRelativeFilePath relativeFilePath = absoluteFilePath.GetRelativePathFrom(absoluteDirectoryPath);

                    string relativePath = relativeFilePath.GetRelativePath();
                    if (!filePathsHashSet.Contains(relativePath))
                    {
                        unregisteredFiles.Add(relativePath);
                    }
                }
            }

            Console.WriteLine($"Finished iterative operation for finding unregistered files from {mConfiguration.Value.DriveRootDirectory}");
            return(unregisteredFiles);
        }
Example #5
0
 public void Test_GetAbsolutePath_ArgumentNullException()
 {
     IRelativeFilePath p = @"..\File.txt".ToRelativeFilePath();
     var x = p.GetAbsolutePathFrom((null as string).ToAbsoluteDirectoryPath());
 }
        private void BuildFileContent(IAbsoluteDirectoryPath modPackagePath, IRelativeDirectoryPath relativeTargetPath,
            IRelativeFilePath relativePath, ICollection<RootRpf> list, ContentAction action,
            FileType type = FileType.Default)
        {
            if (_config.AudioPathsOnly && !IsAudioPath(relativeTargetPath))
                return;

            var rpfFile = RpfFile.FromPath(relativeTargetPath.GetAbsolutePathFrom(_gameDir));
            if (!rpfFile.ExternalRpfFile.Exists)
            {
                throw new Exception("Unable to find an RPF file: " + rpfFile.ExternalRpfFile);
            }

            IDirectory root = list.FirstOrDefault(x => x.FilePath.Equals(rpfFile.ExternalRpfFile));
            if (root == null)
            {
                var rootRpf = new RootRpf(rpfFile.ExternalRpfFile);
                root = rootRpf;
                list.Add(rootRpf);
            }
            foreach (var p in rpfFile.PathParts)
            {
                if (p.EndsWith(".rpf"))
                {
                    root = root.Contents.ContainsKey(p)
                        ? (InnerRpf)root.Contents[p]
                        : (InnerRpf)(root.Contents[p] = new InnerRpf());
                }
                else
                {
                    root = root.Contents.ContainsKey(p)
                        ? (InnerDirectory)root.Contents[p]
                        : (InnerDirectory)(root.Contents[p] = new InnerDirectory());
                }
            }

            var file = relativePath.FileName;
            IFileContent f;
            if (file.EndsWith(".rpf"))
                f = root.Contents.ContainsKey(file)
                    ? (InnerRpf)root.Contents[file]
                    : (InnerRpf)(root.Contents[file] = new InnerRpf());
            else
                f = root.Contents.ContainsKey(file)
                    ? (InnerFile)root.Contents[file]
                    : (InnerFile)(root.Contents[file] = new InnerFile());
            f.FilePath = relativePath.GetAbsolutePathFrom(modPackagePath);
            f.Action = action;
            f.Type = type;
        }
 ///<summary>
 ///Try get a new <see cref="IRelativeFilePath"/> object from this string.
 ///</summary>
 ///<returns><i>true</i> if <paramref name="pathString"/> is a valid relative file path and as a consequence, the returned <paramref name="relativeFilePath"/> is not null.</returns>
 ///<remarks>The path represented by this string doesn't need to exist for this operation to complete properly.</remarks>
 ///<param name="pathString">Represents the path.</param>
 ///<param name="relativeFilePath">If this method returns <i>true</i>, this is the returned path object.</param>
 public static bool TryGetRelativeFilePath(this string pathString, out IRelativeFilePath relativeFilePath) {
    string failureReasonUnused;
    return pathString.TryGetRelativeFilePath(out relativeFilePath, out failureReasonUnused);
 }
 ///<summary>
 ///Try get a new <see cref="IRelativeFilePath"/> object from this string.
 ///</summary>
 ///<returns><i>true</i> if <paramref name="pathString"/> is a valid relative file path and as a consequence, the returned <paramref name="relativeFilePath"/> is not null.</returns>
 ///<remarks>The path represented by this string doesn't need to exist for this operation to complete properly.</remarks>
 ///<param name="pathString">Represents the path.</param>
 ///<param name="relativeFilePath">If this method returns <i>true</i>, this is the returned path object.</param>
 ///<param name="failureReason">If this method returns <i>false</i>, this is the plain english description of the failure.</param>
 public static bool TryGetRelativeFilePath(this string pathString, out IRelativeFilePath relativeFilePath, out string failureReason) {
    relativeFilePath = null;
    if (pathString.IsPathStringNullOrEmpty(out failureReason)) { return false; }
    if (!pathString.IsValidRelativeFilePath(out failureReason)) { return false; }
    relativeFilePath = new RelativeFilePath(pathString);
    return true;
 }
Example #9
0
		/// <summary>
		///     Try get a new <see cref="IRelativeFilePath" /> object from this string.
		/// </summary>
		/// <returns>
		///     <i>true</i> if <paramref name="path" /> is a valid relative file path and as a consequence, the returned
		///     <paramref name="relativePath" /> is not null.
		/// </returns>
		/// <remarks>The path represented by this string doesn't need to exist for this operation to complete properly.</remarks>
		/// <param name="path">Represents the path.</param>
		/// <param name="relativePath">If this method returns <i>true</i>, this is the returned path object.</param>
		public static bool TryGetRelativeFilePath(this string path, out IRelativeFilePath relativePath)
		{
			string failureMessage;

			return path.TryGetRelativeFilePath(out relativePath, out failureMessage);
		}
 public static IRelativeFilePathExt WithExtension(this IRelativeFilePath path, FileExtension extension)
 {
     return(path.RelativeRoute.GetFilePathWithExtension(path.PathString, extension));
 }
Example #11
0
 public static bool TryGetRelativeFilePath(
     string path,
     out IRelativeFilePath relativeFilePath)
 {
     throw new NotImplementedException();
 }
Example #12
0
 public static bool SubStartsWith(this IRelativeFilePath path, string name)
 => path.ParentDirectoryPath.SubStartsWith(name);
Example #13
0
 public static bool MatchesSub(this IRelativeFilePath path, string name)
 => path.ParentDirectoryPath.MatchesSub(name);
Example #14
0
 public static IRelativeDirectoryPath GetRoot(this IRelativeFilePath path) => path.ParentDirectoryPath.GetRoot();
 public IRelativeFilePath Combine(IRelativeFilePath file) => (IRelativeFilePath)Combine((IRelativePath)file);
Example #16
0
        public void Test_PathEquality()
        {
            //
            // RelativeFilePath
            //
            IRelativeFilePath relativeFilePath1 = @"..\Dir1\File.txt".ToRelativeFilePath();
            IRelativeFilePath relativeFilePath2 = @"..\\dir1//file.TXT".ToRelativeFilePath();

            Assert.IsTrue(relativeFilePath1.Equals(relativeFilePath2));

            relativeFilePath1 = @"..\Dir1\File.txt".ToRelativeFilePath();
            relativeFilePath2 = @".\Dir1\File.txt".ToRelativeFilePath();
            Assert.IsFalse(relativeFilePath1.Equals(relativeFilePath2));

            relativeFilePath1 = @"..\Dir1\File.txt".ToRelativeFilePath();
            relativeFilePath2 = @"..\Dir1\Dir2\File.txt".ToRelativeFilePath();
            Assert.IsFalse(relativeFilePath1.Equals(relativeFilePath2));

            relativeFilePath1 = @"..\Dir1\File.txt".ToRelativeFilePath();
            relativeFilePath2 = @"..\Dir1\File.tx".ToRelativeFilePath();
            Assert.IsFalse(relativeFilePath1.Equals(relativeFilePath2));

            //
            // AbsoluteFilePath
            //
            IAbsoluteFilePath absoluteAbsoluteFilePath1 = @"C:\Dir1\File.txt".ToAbsoluteFilePath();
            IAbsoluteFilePath absoluteAbsoluteFilePath2 = @"C:\\dir1//file.TXT".ToAbsoluteFilePath();

            Assert.IsTrue(absoluteAbsoluteFilePath1.Equals(absoluteAbsoluteFilePath2));

            absoluteAbsoluteFilePath1 = @"C:\Dir1\File.txt".ToAbsoluteFilePath();
            absoluteAbsoluteFilePath2 = @"D:\Dir1\File.txt".ToAbsoluteFilePath();
            Assert.IsFalse(absoluteAbsoluteFilePath1.Equals(absoluteAbsoluteFilePath2));

            absoluteAbsoluteFilePath1 = @"C:\Dir1\File.txt".ToAbsoluteFilePath();
            absoluteAbsoluteFilePath2 = @"C:\Dir1\Dir2\File.txt".ToAbsoluteFilePath();
            Assert.IsFalse(absoluteAbsoluteFilePath1.Equals(absoluteAbsoluteFilePath2));

            absoluteAbsoluteFilePath1 = @"C:\Dir1\File.txt".ToAbsoluteFilePath();
            absoluteAbsoluteFilePath2 = @"C:\Dir1\File.tx".ToAbsoluteFilePath();
            Assert.IsFalse(absoluteAbsoluteFilePath1.Equals(absoluteAbsoluteFilePath2));

            //
            // Mix between AbsoluteFilePath and RelativeFilePath
            //
            relativeFilePath1         = @"..\Dir1\File.txt".ToRelativeFilePath();
            absoluteAbsoluteFilePath1 = @"C:\Dir1\File.txt".ToAbsoluteFilePath();
            Assert.IsFalse(absoluteAbsoluteFilePath1.Equals(relativeFilePath1));

            //
            // Mix between absoluteDirectoryPath and filePath
            //
            IAbsoluteDirectoryPath absoluteAbsoluteDirectoryPath1 = @"C:\Dir1\File".ToAbsoluteDirectoryPath();

            absoluteAbsoluteFilePath1 = @"C:\Dir1\File".ToAbsoluteFilePath();
            Assert.IsFalse(absoluteAbsoluteDirectoryPath1.Equals(absoluteAbsoluteFilePath1));
            Assert.IsFalse(absoluteAbsoluteFilePath1.Equals(absoluteAbsoluteDirectoryPath1));

            IRelativeDirectoryPath relativeRelativeDirectoryPath1 = @"..\Dir1\File".ToRelativeDirectoryPath();

            relativeFilePath1 = @"..\Dir1\File".ToRelativeFilePath();
            Assert.IsFalse(relativeRelativeDirectoryPath1.Equals(relativeFilePath1));
            Assert.IsFalse(relativeFilePath1.Equals(relativeRelativeDirectoryPath1));
        }
Example #17
0
 protected IAbsoluteFilePath GetFileInGameDirectory(IRelativeFilePath file) => file.GetAbsolutePathFrom(GetGameDirectory());
 public static IAbsoluteFilePath Combine(this IAbsoluteDirectoryPath dir, IRelativeFilePath file)
 {
     return(Combine(dir, file, dir.AbsoluteRoute.GetFilePath));
 }
Example #19
0
		/// <summary>
		///     Try get a new <see cref="IRelativeFilePath" /> object from this string.
		/// </summary>
		/// <returns>
		///     <i>true</i> if <paramref name="path" /> is a valid relative file path and as a consequence, the returned
		///     <paramref name="relativePath" /> is not null.
		/// </returns>
		/// <remarks>The path represented by this string doesn't need to exist for this operation to complete properly.</remarks>
		/// <param name="path">Represents the path.</param>
		/// <param name="relativePath">If this method returns <i>true</i>, this is the returned path object.</param>
		/// <param name="failureMessage">If this method returns <i>false</i>, this is the plain english description of the failure.</param>
		public static bool TryGetRelativeFilePath(this string path, out IRelativeFilePath relativePath, out string failureMessage)
		{
			relativePath = null;

			if (IsNullOrEmpty(() => path, out failureMessage))
			{
				return false;
			}

			if (!path.IsValidRelativeFilePath(out failureMessage))
			{
				return false;
			}

			relativePath = new RelativeFilePath(path);

			return true;
		}