예제 #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="path"></param>
        /// <param name="root"></param>
        /// <returns></returns>
        public string ToVisualPath(string path, string root)
        {
            string fs = "file";
            Match  match;

            if (!this.Config.GetBool("general.user_friendly_paths", false))
            {
                return(path);
            }

            // Parse file system
            match = Regex.Match(path, @"([a-z]+):\/\/(.+)", RegexOptions.IgnoreCase);
            if (match.Groups.Count == 3)
            {
                fs   = match.Groups[1].Value;
                path = match.Groups[2].Value;
            }

            path = this.DecryptPath(path);

            // Use specified root
            if (root != null)
            {
                if (path.IndexOf(root) == 0)
                {
                    path = path.Substring(root.Length);
                }

                if (path == "")
                {
                    path = "/";
                }

                // Re-attach fs
                if (fs != "file")
                {
                    path = fs + "://" + path;
                }

                return(this.EncryptPath(path));
            }

            // Use config roots

            // Replace root names
            foreach (string rootPath in this.rootNames.Keys)
            {
                path = path.Replace(rootPath, "/" + this.rootNames[rootPath]);
            }

            if (this.RootPaths.Count > 1)
            {
                foreach (string rootPath in this.RootPaths)
                {
                    path = path.Replace(rootPath, "/" + PathUtils.BaseName(rootPath));
                }
            }
            else
            {
                path = path.Replace(this.RootPaths[0], "/");
            }

            // Remove / in beginning to avoid //files
            if (path.StartsWith("//"))
            {
                path = path.Substring(1);
            }

            // Re-attach fs
            if (fs != "file")
            {
                path = fs + "://" + path;
            }

            return(this.EncryptPath(path));
        }