예제 #1
0
        /// <summary>
        /// Represents matching paths in project.
        /// </summary>
        /// <param name="originalPath">Original file out of project directory.</param>
        /// <param name="projectPath">Project root path.</param>
        /// <param name="root">Original file's anchor path deriving relative path.</param>
        public ManagedPath(string originalPath, string?root = null)
        {
            OriginalPath = Path.GetFullPath(originalPath);
            ProjectPath  = Path.GetFullPath(ProjectDirectory);

            if (IsInProject)
            {
                string relative = Path.GetRelativePath(ProjectPath, OriginalPath);
                relative     = Regex.Replace(relative, $"^{MetadataName}\\\\(.*?)\\.meta\\.txt$", "$1");
                relative     = Regex.Replace(relative, $"^{TranslationName}\\\\(.*?)\\.tran(?:_번역)?\\.txt$", "$1");
                relative     = Regex.Replace(relative, $"^({SourceName}|{DestinationName})\\\\", "");
                RelativePath = relative == "" ? "." : relative;
            }
            else if (root != null)
            {
                string rootPath = Path.GetFullPath(root);
                RelativePath = Path.GetRelativePath(rootPath, OriginalPath);
                if (RelativePath.Contains("..\\"))
                {
                    throw new RengexException("Incorrect file anchor.");
                }
            }
            else
            {
                RelativePath = Path.GetFileName(originalPath);
            }
        }