public string GetUriPath(string filename) { if (string.IsNullOrEmpty(Host)) { return(string.Empty); } if (HttpHomePathNoExtension) { filename = Path.GetFileNameWithoutExtension(filename); } string path; HttpHomePath = FTPHelpers.RemovePrefixes(HttpHomePath); NameParser nameParser = new NameParser(NameParserType.URL); string httpHomePath = nameParser.Parse(HttpHomePath.Replace("%host", Host)); string subFolderPath = GetSubFolderPath(); string browserProtocol = BrowserProtocol.GetDescription(); if (string.IsNullOrEmpty(httpHomePath)) { string host = Host; if (host.StartsWith("ftp.")) { host = host.Substring(4); } path = Helpers.CombineURL(host, subFolderPath, filename); } else { if (!httpHomePath.StartsWith("@")) { path = Helpers.CombineURL(httpHomePath, subFolderPath); } else { path = httpHomePath.Substring(1); } if (path.EndsWith("=")) { path += filename; } else { path = Helpers.CombineURL(path, filename); } } if (!path.StartsWith(browserProtocol)) { path = browserProtocol + path; } return(path); }
public string GetUriPath(string fileName, bool customPath) { if (string.IsNullOrEmpty(this.Host)) { return(string.Empty); } string path = string.Empty; string host = this.Host; string lHttpHomePath = GetHttpHomePath(); string lFolderPath = GetSubFolderPath(); if (HttpHomePathNoExtension) { int index = fileName.LastIndexOf('.'); if (index > -1) { fileName = fileName.Remove(index); } } if (host.StartsWith("ftp.")) { host = host.Remove(0, 4); } if (lHttpHomePath.StartsWith("@") || customPath) { lFolderPath = string.Empty; } if (string.IsNullOrEmpty(lHttpHomePath)) { path = FTPHelpers.CombineURL(host, lFolderPath, fileName); } else { string httppath = lHttpHomePath.Replace("%host", host).TrimStart('@'); path = FTPHelpers.CombineURL(httppath, lFolderPath, fileName); } if (!path.StartsWith(BrowserProtocol.GetDescription())) { switch (BrowserProtocol) { case UploadersLib.BrowserProtocol.ServerProtocol: path = FTPHelpers.CombineURL(FTPAddress, lFolderPath, fileName); break; default: path = BrowserProtocol.GetDescription() + path; break; } } return(path); }
public string GetUriPath(string filename, string subFolderPath = null) { if (string.IsNullOrEmpty(Host)) { return(""); } if (HttpHomePathNoExtension) { filename = Path.GetFileNameWithoutExtension(filename); } filename = URLHelpers.URLEncode(filename); if (subFolderPath == null) { subFolderPath = GetSubFolderPath(); } UriBuilder httpHomeUri; string httpHomePath = GetHttpHomePath(); if (string.IsNullOrEmpty(httpHomePath)) { string host = Host; if (host.StartsWith("ftp.")) { host = host.Substring(4); } httpHomeUri = new UriBuilder(URLHelpers.CombineURL(host, subFolderPath, filename)); httpHomeUri.Port = -1; //Since httpHomePath is not set, it's safe to erase UriBuilder's assumed port number } else { //Parse HttpHomePath in to host, port, path and query components int firstSlash = httpHomePath.IndexOf('/'); string httpHome = firstSlash >= 0 ? httpHomePath.Substring(0, firstSlash) : httpHomePath; int portSpecifiedAt = httpHome.LastIndexOf(':'); string httpHomeHost = portSpecifiedAt >= 0 ? httpHome.Substring(0, portSpecifiedAt) : httpHome; int httpHomePort = -1; string httpHomePathAndQuery = firstSlash >= 0 ? httpHomePath.Substring(firstSlash + 1) : ""; int querySpecifiedAt = httpHomePathAndQuery.LastIndexOf('?'); string httpHomeDir = querySpecifiedAt >= 0 ? httpHomePathAndQuery.Substring(0, querySpecifiedAt) : httpHomePathAndQuery; string httpHomeQuery = querySpecifiedAt >= 0 ? httpHomePathAndQuery.Substring(querySpecifiedAt + 1) : ""; if (portSpecifiedAt >= 0) { int.TryParse(httpHome.Substring(portSpecifiedAt + 1), out httpHomePort); } //Build URI httpHomeUri = new UriBuilder { Host = httpHomeHost, Path = httpHomeDir, Query = httpHomeQuery }; if (portSpecifiedAt >= 0) { httpHomeUri.Port = httpHomePort; } if (httpHomeUri.Query.EndsWith("=")) { //Setting URIBuilder.Query automatically prepends a ? so we must trim it first. if (HttpHomePathAutoAddSubFolderPath) { httpHomeUri.Query = URLHelpers.CombineURL(httpHomeUri.Query.Substring(1), subFolderPath, filename); } else { httpHomeUri.Query = httpHomeUri.Query.Substring(1) + filename; } } else { if (HttpHomePathAutoAddSubFolderPath) { httpHomeUri.Path = URLHelpers.CombineURL(httpHomeUri.Path, subFolderPath); } httpHomeUri.Path = URLHelpers.CombineURL(httpHomeUri.Path, filename); } } httpHomeUri.Scheme = BrowserProtocol.GetDescription(); return(httpHomeUri.Uri.AbsoluteUri); }
public string GetUriPath(string filename, string subFolderPath = null) { if (string.IsNullOrEmpty(Host)) { return(string.Empty); } if (HttpHomePathNoExtension) { filename = Path.GetFileNameWithoutExtension(filename); } filename = URLHelpers.URLEncode(filename); if (subFolderPath == null) { subFolderPath = GetSubFolderPath(); } subFolderPath = URLHelpers.URLPathEncode(subFolderPath); string httpHomePath = GetHttpHomePath(); httpHomePath = URLHelpers.URLPathEncode(httpHomePath); string path; if (string.IsNullOrEmpty(httpHomePath)) { string host = Host; if (host.StartsWith("ftp.")) { host = host.Substring(4); } path = URLHelpers.CombineURL(host, subFolderPath, filename); } else { if (HttpHomePathAutoAddSubFolderPath) { path = URLHelpers.CombineURL(httpHomePath, subFolderPath); } else { path = httpHomePath; } if (path.EndsWith("=")) { path += filename; } else { path = URLHelpers.CombineURL(path, filename); } } string browserProtocol = BrowserProtocol.GetDescription(); if (!path.StartsWith(browserProtocol)) { path = browserProtocol + path; } return(path); }
public string GetUriPath(string filename) { if (string.IsNullOrEmpty(Host)) { return(string.Empty); } if (HttpHomePathNoExtension) { filename = Path.GetFileNameWithoutExtension(filename); } filename = Helpers.URLEncode(filename); string subFolderPath = GetSubFolderPath(); subFolderPath = Helpers.URLPathEncode(subFolderPath); string httpHomePath = GetHttpHomePath(); 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 - FTP account problem", MessageBoxButtons.OK, MessageBoxIcon.Warning); warning1Showed = true; } httpHomePath = httpHomePath.Substring(1); } httpHomePath = Helpers.URLPathEncode(httpHomePath); string path; if (string.IsNullOrEmpty(httpHomePath)) { string host = Host; if (host.StartsWith("ftp.")) { host = host.Substring(4); } path = Helpers.CombineURL(host, subFolderPath, filename); } else { if (HttpHomePathAutoAddSubFolderPath) { path = Helpers.CombineURL(httpHomePath, subFolderPath); } else { path = httpHomePath; } if (path.EndsWith("=")) { path += filename; } else { path = Helpers.CombineURL(path, filename); } } string browserProtocol = BrowserProtocol.GetDescription(); if (!path.StartsWith(browserProtocol)) { path = browserProtocol + path; } return(path); }
public string GetUriPath(string filename, string subFolderPath = null) { if (string.IsNullOrEmpty(Host)) { return(string.Empty); } if (HttpHomePathNoExtension) { filename = Path.GetFileNameWithoutExtension(filename); } filename = URLHelpers.URLEncode(filename); if (subFolderPath == null) { subFolderPath = GetSubFolderPath(); } subFolderPath = URLHelpers.URLPathEncode(subFolderPath); UriBuilder httpHomeUri; var httpHomePath = GetHttpHomePath(); if (string.IsNullOrEmpty(httpHomePath)) { var host = Host; if (host.StartsWith("ftp.")) { host = host.Substring(4); } httpHomeUri = new UriBuilder(URLHelpers.CombineURL(host, subFolderPath, filename)); } else { //Parse HttpHomePath in to host, port and path components var firstSlash = httpHomePath.IndexOf('/'); var httpHome = firstSlash >= 0 ? httpHomePath.Substring(0, firstSlash) : httpHomePath; var portSpecifiedAt = httpHome.LastIndexOf(':'); var httpHomeHost = portSpecifiedAt >= 0 ? httpHome.Substring(0, portSpecifiedAt) : httpHome; var httpHomePort = -1; var httpHomeDir = httpHomePath.Substring(firstSlash + 1); if (portSpecifiedAt >= 0) { int.TryParse(httpHome.Substring(portSpecifiedAt + 1), out httpHomePort); } //Build URI httpHomeUri = new UriBuilder { Host = httpHomeHost, Path = httpHomeDir }; if (portSpecifiedAt >= 0) { httpHomeUri.Port = httpHomePort; } if (HttpHomePathAutoAddSubFolderPath) { httpHomeUri.Path = URLHelpers.CombineURL(httpHomeUri.Path, subFolderPath); } if (httpHomeUri.Query.EndsWith("=")) { httpHomeUri.Query += filename; } else { httpHomeUri.Path = URLHelpers.CombineURL(httpHomeUri.Path, filename); } } httpHomeUri.Scheme = BrowserProtocol.GetDescription(); return(httpHomeUri.Uri.ToString()); }