mirror of
https://github.com/ShareX/ShareX.git
synced 2024-07-02 21:20:28 +12:00
Some code changes, using NameParser.Parse static method
This commit is contained in:
parent
af4221ff09
commit
ca698eaa63
|
@ -108,12 +108,11 @@ public class NameParser
|
|||
{
|
||||
public NameParserType Type { get; private set; }
|
||||
public int MaxNameLength { get; set; }
|
||||
public int MaxTitleLength { get; set; }
|
||||
public int AutoIncrementNumber { get; set; } // %i
|
||||
public Image Picture { get; set; } // %width, %height
|
||||
public string WindowText { get; set; } // %t
|
||||
public string ProcessName { get; set; } // %pn
|
||||
public int MaxTitleLength { get; set; }
|
||||
public DateTime CustomDate { get; set; }
|
||||
|
||||
protected NameParser()
|
||||
{
|
||||
|
@ -124,6 +123,11 @@ public NameParser(NameParserType nameParserType)
|
|||
Type = nameParserType;
|
||||
}
|
||||
|
||||
public static string Parse(NameParserType nameParserType, string pattern)
|
||||
{
|
||||
return new NameParser(nameParserType).Parse(pattern);
|
||||
}
|
||||
|
||||
public string Parse(string pattern)
|
||||
{
|
||||
if (string.IsNullOrEmpty(pattern))
|
||||
|
@ -160,10 +164,6 @@ public string Parse(string pattern)
|
|||
sb.Replace(ReplacementVariables.height.ToPrefixString(), height);
|
||||
|
||||
DateTime dt = DateTime.Now;
|
||||
if (CustomDate != DateTime.MinValue)
|
||||
{
|
||||
dt = CustomDate;
|
||||
}
|
||||
|
||||
sb.Replace(ReplacementVariables.mon2.ToPrefixString(), CultureInfo.InvariantCulture.DateTimeFormat.GetMonthName(dt.Month))
|
||||
.Replace(ReplacementVariables.mon.ToPrefixString(), CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(dt.Month))
|
||||
|
|
|
@ -916,6 +916,7 @@ private void cbFileUploadUseNamePattern_CheckedChanged(object sender, EventArgs
|
|||
private void txtNameFormatPatternActiveWindow_TextChanged(object sender, EventArgs e)
|
||||
{
|
||||
TaskSettings.UploadSettings.NameFormatPatternActiveWindow = txtNameFormatPatternActiveWindow.Text;
|
||||
|
||||
NameParser nameParser = new NameParser(NameParserType.FileName)
|
||||
{
|
||||
AutoIncrementNumber = Program.Settings.NameParserAutoIncrementNumber,
|
||||
|
@ -924,6 +925,7 @@ private void txtNameFormatPatternActiveWindow_TextChanged(object sender, EventAr
|
|||
MaxNameLength = TaskSettings.AdvancedSettings.NamePatternMaxLength,
|
||||
MaxTitleLength = TaskSettings.AdvancedSettings.NamePatternMaxTitleLength
|
||||
};
|
||||
|
||||
lblNameFormatPatternPreviewActiveWindow.Text = "Preview: " + nameParser.Parse(TaskSettings.UploadSettings.NameFormatPatternActiveWindow);
|
||||
}
|
||||
|
||||
|
@ -935,12 +937,14 @@ private void btnResetAutoIncrementNumber_Click(object sender, EventArgs e)
|
|||
private void txtNameFormatPattern_TextChanged(object sender, EventArgs e)
|
||||
{
|
||||
TaskSettings.UploadSettings.NameFormatPattern = txtNameFormatPattern.Text;
|
||||
|
||||
NameParser nameParser = new NameParser(NameParserType.FileName)
|
||||
{
|
||||
AutoIncrementNumber = Program.Settings.NameParserAutoIncrementNumber,
|
||||
MaxNameLength = TaskSettings.AdvancedSettings.NamePatternMaxLength,
|
||||
MaxTitleLength = TaskSettings.AdvancedSettings.NamePatternMaxTitleLength
|
||||
};
|
||||
|
||||
lblNameFormatPatternPreview.Text = "Preview: " + nameParser.Parse(TaskSettings.UploadSettings.NameFormatPattern);
|
||||
}
|
||||
|
||||
|
|
|
@ -211,7 +211,7 @@ public static string ScreenshotsFolder
|
|||
{
|
||||
get
|
||||
{
|
||||
string subFolderName = new NameParser(NameParserType.FolderPath).Parse(Settings.SaveImageSubFolderPattern);
|
||||
string subFolderName = NameParser.Parse(NameParserType.FolderPath, Settings.SaveImageSubFolderPattern);
|
||||
return Path.Combine(ScreenshotsParentFolder, subFolderName);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,5 +11,5 @@
|
|||
[assembly: AssemblyCulture("")]
|
||||
[assembly: ComVisible(false)]
|
||||
[assembly: Guid("82E6AC09-0FEF-4390-AD9F-0DD3F5561EFC")]
|
||||
[assembly: AssemblyVersion("9.1.0")]
|
||||
[assembly: AssemblyFileVersion("9.1.0")]
|
||||
[assembly: AssemblyVersion("9.0.0")]
|
||||
[assembly: AssemblyFileVersion("9.0.0")]
|
|
@ -806,21 +806,17 @@ public UploadResult UploadFile(Stream stream, string fileName)
|
|||
switch (fileDestination)
|
||||
{
|
||||
case FileDestination.Dropbox:
|
||||
NameParser parser = new NameParser(NameParserType.URL);
|
||||
string uploadPath = parser.Parse(Dropbox.TidyUploadPath(Program.UploadersConfig.DropboxUploadPath));
|
||||
fileUploader = new Dropbox(Program.UploadersConfig.DropboxOAuthInfo, Program.UploadersConfig.DropboxAccountInfo)
|
||||
{
|
||||
UploadPath = uploadPath,
|
||||
UploadPath = NameParser.Parse(NameParserType.URL, Dropbox.TidyUploadPath(Program.UploadersConfig.DropboxUploadPath)),
|
||||
AutoCreateShareableLink = Program.UploadersConfig.DropboxAutoCreateShareableLink,
|
||||
ShareURLType = Program.UploadersConfig.DropboxURLType
|
||||
};
|
||||
break;
|
||||
case FileDestination.Copy:
|
||||
parser = new NameParser(NameParserType.URL);
|
||||
uploadPath = parser.Parse(Copy.TidyUploadPath(Program.UploadersConfig.CopyUploadPath));
|
||||
fileUploader = new Copy(Program.UploadersConfig.CopyOAuthInfo, Program.UploadersConfig.CopyAccountInfo)
|
||||
{
|
||||
UploadPath = uploadPath
|
||||
UploadPath = NameParser.Parse(NameParserType.URL, Copy.TidyUploadPath(Program.UploadersConfig.CopyUploadPath))
|
||||
};
|
||||
break;
|
||||
case FileDestination.GoogleDrive:
|
||||
|
|
|
@ -99,9 +99,8 @@ private string CreateSignature(string secretKey, byte[] policyBytes)
|
|||
|
||||
private string GetObjectKey(string fileName)
|
||||
{
|
||||
NameParser parser = new NameParser(NameParserType.FolderPath);
|
||||
string objectPrefix = S3Settings.ObjectPrefix.Trim('/');
|
||||
return Helpers.CombineURL(parser.Parse(objectPrefix), fileName);
|
||||
string objectPrefix = NameParser.Parse(NameParserType.FolderPath, S3Settings.ObjectPrefix.Trim('/'));
|
||||
return Helpers.CombineURL(objectPrefix, fileName);
|
||||
}
|
||||
|
||||
private string GetObjectURL(string objectName)
|
||||
|
|
|
@ -38,7 +38,6 @@ public sealed class Copy : FileUploader, IOAuth
|
|||
{
|
||||
public OAuthInfo AuthInfo { get; set; }
|
||||
public CopyAccountInfo AccountInfo { get; set; }
|
||||
|
||||
public string UploadPath { get; set; }
|
||||
|
||||
private const string APIVersion = "1";
|
||||
|
@ -60,9 +59,7 @@ public sealed class Copy : FileUploader, IOAuth
|
|||
private const string URLAuthorize = "https://www.copy.com/applications/authorize";
|
||||
private const string URLAccessToken = "https://api.copy.com/oauth/access";
|
||||
|
||||
private readonly NameValueCollection APIHeaders = new NameValueCollection {
|
||||
{ "X-Api-Version", APIVersion }
|
||||
};
|
||||
private readonly NameValueCollection APIHeaders = new NameValueCollection { { "X-Api-Version", APIVersion } };
|
||||
|
||||
public Copy(OAuthInfo oauth)
|
||||
{
|
||||
|
@ -79,8 +76,7 @@ public Copy(OAuthInfo oauth, CopyAccountInfo accountInfo)
|
|||
// https://developers.copy.com/console
|
||||
public string GetAuthorizationURL()
|
||||
{
|
||||
return GetAuthorizationURL(URLRequestToken, URLAuthorize, AuthInfo
|
||||
, new Dictionary<string, string> { { "oauth_callback", Links.URL_CALLBACK } });
|
||||
return GetAuthorizationURL(URLRequestToken, URLAuthorize, AuthInfo, new Dictionary<string, string> { { "oauth_callback", Links.URL_CALLBACK } });
|
||||
}
|
||||
|
||||
public bool GetAccessToken(string verificationCode = null)
|
||||
|
@ -134,7 +130,7 @@ public bool DownloadFile(string path, Stream downloadStream)
|
|||
}*/
|
||||
|
||||
// https://developers.copy.com/documentation#api-calls/filesystem - Create File or Directory
|
||||
// POST https://api.copy.com/rest/files/PATH/TO/FILE?overwrite=true
|
||||
// POST https://api.copy.com/rest/files/PATH/TO/FILE?overwrite=true
|
||||
public UploadResult UploadFile(Stream stream, string path, string fileName)
|
||||
{
|
||||
if (!OAuthInfo.CheckOAuth(AuthInfo))
|
||||
|
@ -159,6 +155,7 @@ public UploadResult UploadFile(Stream stream, string path, string fileName)
|
|||
|
||||
if (content != null)
|
||||
{
|
||||
AllowReportProgress = false;
|
||||
result.URL = CreatePublicURL(content.objects[0].path);
|
||||
}
|
||||
}
|
||||
|
@ -343,12 +340,13 @@ public override UploadResult Upload(Stream stream, string fileName)
|
|||
return UploadFile(stream, UploadPath, fileName);
|
||||
}
|
||||
|
||||
/* Link types:
|
||||
* Shortened: http://copy.com/BWr9OswktCLl
|
||||
* Extended: http://www.copy.com/s/BWr9OswktCLl/2014-06-05_17-00-01.mp4
|
||||
* Direct: http://copy.com/BWr9OswktCLl/2014-06-05_17-00-01.mp4
|
||||
*/
|
||||
public string CreatePublicURL(string path)
|
||||
/// <summary>
|
||||
/// Link types:
|
||||
/// Shortened: http://copy.com/BWr9OswktCLl
|
||||
/// Extended: http://www.copy.com/s/BWr9OswktCLl/2014-06-05_17-00-01.mp4
|
||||
/// Direct: http://copy.com/BWr9OswktCLl/2014-06-05_17-00-01.mp4
|
||||
/// </summary>
|
||||
public string CreatePublicURL(string path) // TODO: Add link type parameter
|
||||
{
|
||||
path = path.Trim('/');
|
||||
|
||||
|
@ -360,7 +358,7 @@ public string CreatePublicURL(string path)
|
|||
publicLink.@public = true;
|
||||
publicLink.name = "ShareX";
|
||||
publicLink.paths = new string[] { path };
|
||||
|
||||
|
||||
string content = JsonConvert.SerializeObject(publicLink);
|
||||
|
||||
string response = SendRequest(HttpMethod.POST, query, content, null, ResponseType.Text, APIHeaders);
|
||||
|
@ -369,7 +367,8 @@ public string CreatePublicURL(string path)
|
|||
{
|
||||
return JsonConvert.DeserializeObject<CopyLinksInfo>(response).url_short;
|
||||
}
|
||||
return "";
|
||||
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
public string GetPublicURL(string path)
|
||||
|
@ -377,14 +376,15 @@ public string GetPublicURL(string path)
|
|||
path = path.Trim('/');
|
||||
|
||||
CopyContentInfo fileInfo = GetMetadata(path);
|
||||
foreach(CopyLinksInfo link in fileInfo.links)
|
||||
foreach (CopyLinksInfo link in fileInfo.links)
|
||||
{
|
||||
if(!link.expired)
|
||||
if (!link.expired)
|
||||
{
|
||||
return link.url_short;
|
||||
}
|
||||
}
|
||||
return "";
|
||||
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
public static string TidyUploadPath(string uploadPath)
|
||||
|
@ -437,7 +437,7 @@ public class CopyLinksInfo
|
|||
public string permissions { get; set; }
|
||||
}
|
||||
|
||||
public class CopyContentInfo //https://api.copy.com/rest/meta //also works on rest/meta/copy
|
||||
public class CopyContentInfo // https://api.copy.com/rest/meta also works on rest/meta/copy
|
||||
{
|
||||
public string id { get; set; } // Internal copy name
|
||||
public string path { get; set; } // hmm?
|
||||
|
|
|
@ -37,7 +37,6 @@ public sealed class Dropbox : FileUploader, IOAuth
|
|||
{
|
||||
public OAuthInfo AuthInfo { get; set; }
|
||||
public DropboxAccountInfo AccountInfo { get; set; }
|
||||
|
||||
public string UploadPath { get; set; }
|
||||
public bool AutoCreateShareableLink { get; set; }
|
||||
public DropboxURLType ShareURLType { get; set; }
|
||||
|
|
|
@ -140,8 +140,7 @@ public FTPAccount()
|
|||
|
||||
public string GetSubFolderPath(string filename = null)
|
||||
{
|
||||
NameParser parser = new NameParser(NameParserType.URL);
|
||||
string path = parser.Parse(SubFolderPath.Replace("%host", Host));
|
||||
string path = NameParser.Parse(NameParserType.URL, SubFolderPath.Replace("%host", Host));
|
||||
return Helpers.CombineURL(path, filename);
|
||||
}
|
||||
|
||||
|
@ -156,8 +155,7 @@ public string GetHttpHomePath()
|
|||
|
||||
HttpHomePath = URLHelpers.RemovePrefixes(HttpHomePath);
|
||||
|
||||
NameParser nameParser = new NameParser(NameParserType.URL);
|
||||
return nameParser.Parse(HttpHomePath.Replace("%host", Host));
|
||||
return NameParser.Parse(NameParserType.URL, HttpHomePath.Replace("%host", Host));
|
||||
}
|
||||
|
||||
public string GetUriPath(string filename)
|
||||
|
|
|
@ -112,8 +112,7 @@ public LocalhostAccount()
|
|||
|
||||
public string GetSubFolderPath()
|
||||
{
|
||||
NameParser parser = new NameParser(NameParserType.URL);
|
||||
return parser.Parse(SubFolderPath.Replace("%host", LocalhostRoot));
|
||||
return NameParser.Parse(NameParserType.URL, SubFolderPath.Replace("%host", LocalhostRoot));
|
||||
}
|
||||
|
||||
public string GetHttpHomePath()
|
||||
|
@ -127,8 +126,7 @@ public string GetHttpHomePath()
|
|||
|
||||
HttpHomePath = URLHelpers.RemovePrefixes(HttpHomePath);
|
||||
|
||||
NameParser parser = new NameParser(NameParserType.URL);
|
||||
return parser.Parse(HttpHomePath.Replace("%host", LocalhostRoot));
|
||||
return NameParser.Parse(NameParserType.URL, HttpHomePath.Replace("%host", LocalhostRoot));
|
||||
}
|
||||
|
||||
public string GetUriPath(string filename)
|
||||
|
|
28
UploadersLib/GUI/UploadersConfigForm.Designer.cs
generated
28
UploadersLib/GUI/UploadersConfigForm.Designer.cs
generated
|
@ -129,12 +129,12 @@ private void InitializeComponent()
|
|||
this.btnDropboxOpenAuthorize = new System.Windows.Forms.Button();
|
||||
this.txtDropboxPath = new System.Windows.Forms.TextBox();
|
||||
this.tpCopy = new System.Windows.Forms.TabPage();
|
||||
this.oAuthCopy = new UploadersLib.GUI.OAuth2Control();
|
||||
this.pbCopyLogo = new System.Windows.Forms.PictureBox();
|
||||
this.btnCopyRegister = new System.Windows.Forms.Button();
|
||||
this.lblCopyStatus = new System.Windows.Forms.Label();
|
||||
this.lblCopyPath = new System.Windows.Forms.Label();
|
||||
this.txtCopyPath = new System.Windows.Forms.TextBox();
|
||||
this.oAuthCopy = new UploadersLib.GUI.OAuth2Control();
|
||||
this.tpFTP = new System.Windows.Forms.TabPage();
|
||||
this.btnFtpClient = new System.Windows.Forms.Button();
|
||||
this.btnFTPExport = new System.Windows.Forms.Button();
|
||||
|
@ -1476,18 +1476,6 @@ private void InitializeComponent()
|
|||
this.tpCopy.Text = "Copy";
|
||||
this.tpCopy.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// oAuthCopy
|
||||
//
|
||||
this.oAuthCopy.IsRefreshable = false;
|
||||
this.oAuthCopy.Location = new System.Drawing.Point(16, 99);
|
||||
this.oAuthCopy.LoginStatus = false;
|
||||
this.oAuthCopy.Name = "oAuthCopy";
|
||||
this.oAuthCopy.Size = new System.Drawing.Size(328, 173);
|
||||
this.oAuthCopy.Status = "Status: Login required.";
|
||||
this.oAuthCopy.TabIndex = 2;
|
||||
this.oAuthCopy.OpenButtonClicked += new UploadersLib.GUI.OAuth2Control.OpenButtonClickedEventHandler(this.oAuthCopy_OpenButtonClicked);
|
||||
this.oAuthCopy.CompleteButtonClicked += new UploadersLib.GUI.OAuth2Control.CompleteButtonClickedEventHandler(this.oAuthCopy_CompleteButtonClicked);
|
||||
//
|
||||
// pbCopyLogo
|
||||
//
|
||||
this.pbCopyLogo.Cursor = System.Windows.Forms.Cursors.Hand;
|
||||
|
@ -1529,12 +1517,24 @@ private void InitializeComponent()
|
|||
//
|
||||
// txtCopyPath
|
||||
//
|
||||
this.txtCopyPath.Location = new System.Drawing.Point(81, 272);
|
||||
this.txtCopyPath.Location = new System.Drawing.Point(88, 272);
|
||||
this.txtCopyPath.Name = "txtCopyPath";
|
||||
this.txtCopyPath.Size = new System.Drawing.Size(272, 20);
|
||||
this.txtCopyPath.TabIndex = 4;
|
||||
this.txtCopyPath.TextChanged += new System.EventHandler(this.txtCopyPath_TextChanged);
|
||||
//
|
||||
// oAuthCopy
|
||||
//
|
||||
this.oAuthCopy.IsRefreshable = false;
|
||||
this.oAuthCopy.Location = new System.Drawing.Point(16, 99);
|
||||
this.oAuthCopy.LoginStatus = false;
|
||||
this.oAuthCopy.Name = "oAuthCopy";
|
||||
this.oAuthCopy.Size = new System.Drawing.Size(328, 173);
|
||||
this.oAuthCopy.Status = "Status: Login required.";
|
||||
this.oAuthCopy.TabIndex = 2;
|
||||
this.oAuthCopy.OpenButtonClicked += new UploadersLib.GUI.OAuth2Control.OpenButtonClickedEventHandler(this.oAuthCopy_OpenButtonClicked);
|
||||
this.oAuthCopy.CompleteButtonClicked += new UploadersLib.GUI.OAuth2Control.CompleteButtonClickedEventHandler(this.oAuthCopy_CompleteButtonClicked);
|
||||
//
|
||||
// tpFTP
|
||||
//
|
||||
this.tpFTP.Controls.Add(this.btnFtpClient);
|
||||
|
|
|
@ -297,14 +297,14 @@ public void LoadSettings(UploadersConfig uploadersConfig)
|
|||
|
||||
// Copy
|
||||
|
||||
txtCopyPath.Text = Config.CopyUploadPath;
|
||||
|
||||
if (OAuthInfo.CheckOAuth(Config.CopyOAuthInfo))
|
||||
{
|
||||
oAuthCopy.Status = "Login successful.";
|
||||
oAuthCopy.LoginStatus = true;
|
||||
}
|
||||
|
||||
txtCopyPath.Text = Config.CopyUploadPath;
|
||||
|
||||
// Google Drive
|
||||
|
||||
if (OAuth2Info.CheckOAuth(Config.GoogleDriveOAuth2Info))
|
||||
|
|
|
@ -541,7 +541,7 @@ private void UpdateDropboxStatus()
|
|||
|
||||
private string GetDropboxUploadPath()
|
||||
{
|
||||
return new NameParser(NameParserType.URL).Parse(Dropbox.TidyUploadPath(Config.DropboxUploadPath));
|
||||
return NameParser.Parse(NameParserType.URL, Dropbox.TidyUploadPath(Config.DropboxUploadPath));
|
||||
}
|
||||
|
||||
#endregion Dropbox
|
||||
|
@ -577,8 +577,8 @@ public void CopyAuthComplete(string code)
|
|||
{
|
||||
try
|
||||
{
|
||||
if (Config.CopyOAuthInfo != null && !string.IsNullOrEmpty(Config.CopyOAuthInfo.AuthToken)
|
||||
&& !string.IsNullOrEmpty(Config.CopyOAuthInfo.AuthSecret) && !string.IsNullOrEmpty(code))
|
||||
if (Config.CopyOAuthInfo != null && !string.IsNullOrEmpty(Config.CopyOAuthInfo.AuthToken) &&
|
||||
!string.IsNullOrEmpty(Config.CopyOAuthInfo.AuthSecret) && !string.IsNullOrEmpty(code))
|
||||
{
|
||||
Copy copy = new Copy(Config.CopyOAuthInfo);
|
||||
bool result = copy.GetAccessToken(code);
|
||||
|
@ -592,6 +592,7 @@ public void CopyAuthComplete(string code)
|
|||
Config.CopyAccountInfo = account;
|
||||
Config.CopyUploadPath = txtCopyPath.Text;
|
||||
UpdateCopyStatus();
|
||||
oAuthCopy.Status = "Login successful.";
|
||||
MessageBox.Show("Login successful.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
return;
|
||||
}
|
||||
|
@ -600,6 +601,7 @@ public void CopyAuthComplete(string code)
|
|||
}
|
||||
else
|
||||
{
|
||||
oAuthCopy.Status = "Login failed.";
|
||||
MessageBox.Show("Login failed.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
@ -638,7 +640,7 @@ private void UpdateCopyStatus()
|
|||
|
||||
private string GetCopyUploadPath()
|
||||
{
|
||||
return new NameParser(NameParserType.URL).Parse(Copy.TidyUploadPath(Config.CopyUploadPath));
|
||||
return NameParser.Parse(NameParserType.URL, Copy.TidyUploadPath(Config.CopyUploadPath));
|
||||
}
|
||||
|
||||
#endregion Copy
|
||||
|
|
|
@ -76,8 +76,7 @@ public override string ToString()
|
|||
value = value.Replace("$input$", input);
|
||||
}
|
||||
|
||||
NameParser parser = new NameParser(NameParserType.Text);
|
||||
value = parser.Parse(value);
|
||||
value = NameParser.Parse(NameParserType.Text, value);
|
||||
|
||||
arguments.Add(arg.Key, value);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue