Localhost changes

This commit is contained in:
Jaex 2014-04-21 01:17:54 +03:00
parent 8f9767c313
commit 62d95a0cf4
2 changed files with 67 additions and 40 deletions

View file

@ -154,7 +154,7 @@ private void InitializeComponent()
this.tcSettings.Location = new System.Drawing.Point(3, 3);
this.tcSettings.Name = "tcSettings";
this.tcSettings.SelectedIndex = 0;
this.tcSettings.Size = new System.Drawing.Size(618, 395);
this.tcSettings.Size = new System.Drawing.Size(618, 396);
this.tcSettings.TabIndex = 0;
//
// tpGeneral
@ -171,7 +171,7 @@ private void InitializeComponent()
this.tpGeneral.Location = new System.Drawing.Point(4, 22);
this.tpGeneral.Name = "tpGeneral";
this.tpGeneral.Padding = new System.Windows.Forms.Padding(3);
this.tpGeneral.Size = new System.Drawing.Size(610, 369);
this.tpGeneral.Size = new System.Drawing.Size(610, 370);
this.tpGeneral.TabIndex = 0;
this.tpGeneral.Text = "General";
this.tpGeneral.UseVisualStyleBackColor = true;
@ -1061,7 +1061,7 @@ private void InitializeComponent()
this.tpAdvanced.Location = new System.Drawing.Point(4, 22);
this.tpAdvanced.Name = "tpAdvanced";
this.tpAdvanced.Padding = new System.Windows.Forms.Padding(3);
this.tpAdvanced.Size = new System.Drawing.Size(610, 369);
this.tpAdvanced.Size = new System.Drawing.Size(610, 370);
this.tpAdvanced.TabIndex = 5;
this.tpAdvanced.Text = "Advanced";
this.tpAdvanced.UseVisualStyleBackColor = true;
@ -1072,15 +1072,16 @@ private void InitializeComponent()
this.pgSettings.Location = new System.Drawing.Point(3, 3);
this.pgSettings.Name = "pgSettings";
this.pgSettings.PropertySort = System.Windows.Forms.PropertySort.Categorized;
this.pgSettings.Size = new System.Drawing.Size(604, 363);
this.pgSettings.Size = new System.Drawing.Size(604, 364);
this.pgSettings.TabIndex = 0;
this.pgSettings.ToolbarVisible = false;
//
// ApplicationSettingsForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackColor = System.Drawing.Color.White;
this.ClientSize = new System.Drawing.Size(624, 401);
this.ClientSize = new System.Drawing.Size(624, 402);
this.Controls.Add(this.tcSettings);
this.MinimumSize = new System.Drawing.Size(640, 440);
this.Name = "ApplicationSettingsForm";

View file

@ -29,6 +29,7 @@
using System.Drawing.Design;
using System.IO;
using System.Web;
using System.Windows.Forms;
namespace UploadersLib
{
@ -53,9 +54,15 @@ public class LocalhostAccount
[Category("Localhost"), Description("Localhost Sub-folder Path, e.g. screenshots, %y = year, %mo = month. SubFolderPath will be automatically appended to HttpHomePath if HttpHomePath does not start with @"), DefaultValue("")]
public string SubFolderPath { get; set; }
[Category("Localhost"), Description("HTTP Home Path, %host = Host e.g. google.com without http:// because you choose that in Remote Protocol.\nURL = HttpHomePath (+ SubFolderPath, if HttpHomePath does not start with @) + FileName\nURL = Host + SubFolderPath + FileName (if HttpHomePath is empty)"), DefaultValue("")]
[Category("Localhost"), Description("HTTP Home Path, %host = Host e.g. google.com without http:// because you choose that in Remote Protocol.\nURL = HttpHomePath + SubFolderPath + FileName\nURL = Host + SubFolderPath + FileName (if HttpHomePath is empty)"), DefaultValue("")]
public string HttpHomePath { get; set; }
[Category("Localhost"), Description("Automatically add sub folder path to end of http home path"), DefaultValue(true)]
public bool HttpHomePathAutoAddSubFolderPath { get; set; }
[Category("Localhost"), Description("Don't add file extension to URL"), DefaultValue(false)]
public bool HttpHomePathNoExtension { get; set; }
[Category("Localhost"), Description("Choose an appropriate protocol to be accessed by the browser. Use 'file' for Shared Folders. RemoteProtocol will always be 'file' if HTTP Home Path is empty. "), DefaultValue(BrowserProtocol.File)]
public BrowserProtocol RemoteProtocol { get; set; }
@ -93,6 +100,8 @@ public string PreviewRemotePath
}
}
private static bool warning1Showed = false;
public LocalhostAccount()
{
this.ApplyDefaultPropertyValues();
@ -117,51 +126,68 @@ public string GetHttpHomePath()
return parser.Parse(HttpHomePath);
}
public string GetUriPath(string fileName)
{
return GetUriPath(fileName, false);
}
public string GetUriPath(string fileName, bool customPath)
public string GetUriPath(string filename)
{
if (string.IsNullOrEmpty(LocalhostRoot))
{
return string.Empty;
}
fileName = HttpUtility.UrlEncode(fileName).Replace("+", "%20");
string httppath;
string lHttpHomePath = GetHttpHomePath();
if (string.IsNullOrEmpty(lHttpHomePath))
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;
}
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://", "");
path = LocalUri.Replace("file://", "");
}
else
{
httppath = lHttpHomePath.Replace("%host", LocalhostRoot).TrimStart('@');
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;
}
string path = Helpers.CombineURL(Port == 80 ? httppath : string.Format("{0}:{1}", httppath, Port), lFolderPath, fileName);
if (!path.StartsWith(RemoteProtocol.GetDescription()))
if (Port != 80)
{
path = RemoteProtocol.GetDescription() + path;
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;
@ -178,14 +204,14 @@ public string GetLocalhostPath(string fileName)
public string GetLocalhostUri(string fileName)
{
string LocalhostAddress = LocalUri;
string localhostAddress = LocalUri;
if (string.IsNullOrEmpty(LocalhostAddress))
if (string.IsNullOrEmpty(localhostAddress))
{
return string.Empty;
}
return Helpers.CombineURL(LocalhostAddress, GetSubFolderPath(), fileName);
return Helpers.CombineURL(localhostAddress, GetSubFolderPath(), fileName);
}
public override string ToString()