コード例 #1
0
        public string GetUriPath(string fileName)
        {
            if (string.IsNullOrEmpty(LocalhostRoot))
            {
                return("");
            }

            if (HttpHomePathNoExtension)
            {
                fileName = Path.GetFileNameWithoutExtension(fileName);
            }

            fileName = URLHelpers.URLEncode(fileName);

            string subFolderPath = GetSubFolderPath();

            subFolderPath = URLHelpers.URLEncode(subFolderPath, true);

            string httpHomePath = GetHttpHomePath();

            string path;

            if (string.IsNullOrEmpty(httpHomePath))
            {
                RemoteProtocol = BrowserProtocol.file;
                path           = LocalUri.Replace("file://", "");
            }
            else
            {
                path = URLHelpers.URLEncode(httpHomePath, true);
            }

            if (Port != 80)
            {
                path = string.Format("{0}:{1}", path, Port);
            }

            if (HttpHomePathAutoAddSubFolderPath)
            {
                path = URLHelpers.CombineURL(path, subFolderPath);
            }

            path = URLHelpers.CombineURL(path, fileName);

            string remoteProtocol = RemoteProtocol.GetDescription();

            if (!path.StartsWith(remoteProtocol))
            {
                path = remoteProtocol + path;
            }

            return(path);
        }
コード例 #2
0
        public string GetUriPath(string fileName, bool customPath)
        {
            if (string.IsNullOrEmpty(LocalhostRoot))
            {
                return(string.Empty);
            }

            fileName = HttpUtility.UrlEncode(fileName).Replace("+", "%20");
            string httppath;
            string lHttpHomePath = GetHttpHomePath();

            if (string.IsNullOrEmpty(lHttpHomePath))
            {
                RemoteProtocol = BrowserProtocol.File;
            }
            else if (!string.IsNullOrEmpty(lHttpHomePath) && RemoteProtocol == BrowserProtocol.File)
            {
                RemoteProtocol = BrowserProtocol.Http;
            }

            string lFolderPath = GetSubFolderPath();

            if (lHttpHomePath.StartsWith("@") || customPath)
            {
                lFolderPath = string.Empty;
            }

            if (string.IsNullOrEmpty(lHttpHomePath))
            {
                httppath = LocalUri.Replace("file://", "");
            }
            else
            {
                httppath = lHttpHomePath.Replace("%host", LocalhostRoot).TrimStart('@');
            }

            string path = Helpers.CombineURL(Port == 80 ? httppath : string.Format("{0}:{1}", httppath, Port), lFolderPath, fileName);

            if (!path.StartsWith(RemoteProtocol.GetDescription()))
            {
                path = RemoteProtocol.GetDescription() + path;
            }

            return(path);
        }
コード例 #3
0
        public string GetUriPath(string filename)
        {
            if (string.IsNullOrEmpty(LocalhostRoot))
            {
                return(string.Empty);
            }

            if (HttpHomePathNoExtension)
            {
                filename = Path.GetFileNameWithoutExtension(filename);
            }

            filename = Helpers.URLEncode(filename);

            string subFolderPath = GetSubFolderPath();

            subFolderPath = Helpers.URLPathEncode(subFolderPath);

            string httpHomePath = GetHttpHomePath();

            string path;

            if (string.IsNullOrEmpty(httpHomePath))
            {
                RemoteProtocol = BrowserProtocol.File;
                path           = LocalUri.Replace("file://", "");
            }
            else
            {
                if (httpHomePath.StartsWith("@"))
                {
                    if (!warning1Showed)
                    {
                        // TODO: Remove this warning 2 release later.
                        MessageBox.Show("Please use 'HttpHomePathAutoAddSubFolderPath' setting instead adding @ character in beginning of 'HttpHomePath' setting.", "ShareX - Localhost account problem",
                                        MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        warning1Showed = true;
                    }

                    httpHomePath = httpHomePath.Substring(1);
                }

                httpHomePath = Helpers.URLPathEncode(httpHomePath);
                path         = httpHomePath;
            }

            if (Port != 80)
            {
                path = string.Format("{0}:{1}", path, Port);
            }

            if (HttpHomePathAutoAddSubFolderPath)
            {
                path = Helpers.CombineURL(path, subFolderPath);
            }

            path = Helpers.CombineURL(path, filename);

            string remoteProtocol = RemoteProtocol.GetDescription();

            if (!path.StartsWith(remoteProtocol))
            {
                path = remoteProtocol + path;
            }

            return(path);
        }