public string GetHttpHomePath() { NameParser parser = new NameParser(NameParserType.URL); HttpHomePath = FTPHelpers.RemovePrefixes(HttpHomePath.Replace("%host", LocalhostRoot)); return parser.Parse(HttpHomePath); }
public string GetSubFolderPath() { NameParser parser = new NameParser(NameParserType.URL); return parser.Parse(SubFolderPath.Replace("%host", LocalhostRoot)); }
public static string GetFilename(TaskSettings taskSettings, string extension = "") { NameParser nameParser = new NameParser(NameParserType.FileName) { AutoIncrementNumber = Program.Settings.NameParserAutoIncrementNumber, MaxNameLength = taskSettings.AdvancedSettings.NamePatternMaxLength, MaxTitleLength = taskSettings.AdvancedSettings.NamePatternMaxTitleLength }; string filename = nameParser.Parse(taskSettings.UploadSettings.NameFormatPattern); if (!string.IsNullOrEmpty(extension)) { filename += "." + extension.TrimStart('.'); } Program.Settings.NameParserAutoIncrementNumber = nameParser.AutoIncrementNumber; return filename; }
public static string GetImageFilename(TaskSettings taskSettings, Image image) { string filename; NameParser nameParser = new NameParser(NameParserType.FileName) { Picture = image, AutoIncrementNumber = Program.Settings.NameParserAutoIncrementNumber, MaxNameLength = taskSettings.AdvancedSettings.NamePatternMaxLength, MaxTitleLength = taskSettings.AdvancedSettings.NamePatternMaxTitleLength }; ImageTag imageTag = image.Tag as ImageTag; if (imageTag != null) { nameParser.WindowText = imageTag.ActiveWindowTitle; nameParser.ProcessName = imageTag.ActiveProcessName; } if (string.IsNullOrEmpty(nameParser.WindowText)) { filename = nameParser.Parse(taskSettings.UploadSettings.NameFormatPattern) + ".bmp"; } else { filename = nameParser.Parse(taskSettings.UploadSettings.NameFormatPatternActiveWindow) + ".bmp"; } Program.Settings.NameParserAutoIncrementNumber = nameParser.AutoIncrementNumber; return filename; }
public UploadResult UploadFile(Stream stream, string fileName) { FileUploader fileUploader = null; FileDestination fileDestination; switch (Info.DataType) { case EDataType.Image: fileDestination = Info.TaskSettings.ImageFileDestination; break; case EDataType.Text: fileDestination = Info.TaskSettings.TextFileDestination; break; default: case EDataType.File: fileDestination = Info.TaskSettings.FileDestination; break; } 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, AutoCreateShareableLink = Program.UploadersConfig.DropboxAutoCreateShareableLink, ShareURLType = Program.UploadersConfig.DropboxURLType }; break; case FileDestination.GoogleDrive: fileUploader = new GoogleDrive(Program.UploadersConfig.GoogleDriveOAuth2Info) { IsPublic = Program.UploadersConfig.GoogleDriveIsPublic }; break; case FileDestination.RapidShare: fileUploader = new RapidShare(Program.UploadersConfig.RapidShareUsername, Program.UploadersConfig.RapidSharePassword, Program.UploadersConfig.RapidShareFolderID); break; case FileDestination.SendSpace: fileUploader = new SendSpace(APIKeys.SendSpaceKey); switch (Program.UploadersConfig.SendSpaceAccountType) { case AccountType.Anonymous: SendSpaceManager.PrepareUploadInfo(APIKeys.SendSpaceKey); break; case AccountType.User: SendSpaceManager.PrepareUploadInfo(APIKeys.SendSpaceKey, Program.UploadersConfig.SendSpaceUsername, Program.UploadersConfig.SendSpacePassword); break; } break; case FileDestination.Minus: fileUploader = new Minus(Program.UploadersConfig.MinusConfig, Program.UploadersConfig.MinusOAuth2Info); break; case FileDestination.Box: fileUploader = new Box(Program.UploadersConfig.BoxOAuth2Info) { FolderID = Program.UploadersConfig.BoxSelectedFolder.id, Share = Program.UploadersConfig.BoxShare }; break; case FileDestination.Ge_tt: if (Program.UploadersConfig.IsActive(FileDestination.Ge_tt)) { fileUploader = new Ge_tt(APIKeys.Ge_ttKey) { AccessToken = Program.UploadersConfig.Ge_ttLogin.AccessToken }; } break; case FileDestination.Localhostr: fileUploader = new Hostr(Program.UploadersConfig.LocalhostrEmail, Program.UploadersConfig.LocalhostrPassword) { DirectURL = Program.UploadersConfig.LocalhostrDirectURL }; break; case FileDestination.CustomFileUploader: if (Program.UploadersConfig.CustomUploadersList.IsValidIndex(Program.UploadersConfig.CustomFileUploaderSelected)) { fileUploader = new CustomFileUploader(Program.UploadersConfig.CustomUploadersList[Program.UploadersConfig.CustomFileUploaderSelected]); } break; case FileDestination.FTP: int index = Info.TaskSettings.OverrideFTP ? Info.TaskSettings.FTPIndex.BetweenOrDefault(0, Program.UploadersConfig.FTPAccountList.Count - 1) : Program.UploadersConfig.GetFTPIndex(Info.DataType); FTPAccount account = Program.UploadersConfig.FTPAccountList.ReturnIfValidIndex(index); if (account != null) { if (account.Protocol == FTPProtocol.SFTP) { fileUploader = new SFTP(account); } else { fileUploader = new FTPUploader(account); } } break; case FileDestination.SharedFolder: int idLocalhost = Program.UploadersConfig.GetLocalhostIndex(Info.DataType); if (Program.UploadersConfig.LocalhostAccountList.IsValidIndex(idLocalhost)) { fileUploader = new SharedFolderUploader(Program.UploadersConfig.LocalhostAccountList[idLocalhost]); } break; case FileDestination.Email: using (EmailForm emailForm = new EmailForm(Program.UploadersConfig.EmailRememberLastTo ? Program.UploadersConfig.EmailLastTo : string.Empty, Program.UploadersConfig.EmailDefaultSubject, Program.UploadersConfig.EmailDefaultBody)) { emailForm.Icon = ShareXResources.Icon; if (emailForm.ShowDialog() == DialogResult.OK) { if (Program.UploadersConfig.EmailRememberLastTo) { Program.UploadersConfig.EmailLastTo = emailForm.ToEmail; } fileUploader = new Email { SmtpServer = Program.UploadersConfig.EmailSmtpServer, SmtpPort = Program.UploadersConfig.EmailSmtpPort, FromEmail = Program.UploadersConfig.EmailFrom, Password = Program.UploadersConfig.EmailPassword, ToEmail = emailForm.ToEmail, Subject = emailForm.Subject, Body = emailForm.Body }; } else { IsStopped = true; } } break; case FileDestination.Jira: fileUploader = new Jira(Program.UploadersConfig.JiraHost, Program.UploadersConfig.JiraOAuthInfo, Program.UploadersConfig.JiraIssuePrefix); break; case FileDestination.Mega: fileUploader = new Mega(Program.UploadersConfig.MegaAuthInfos, Program.UploadersConfig.MegaParentNodeId); break; case FileDestination.AmazonS3: fileUploader = new AmazonS3(Program.UploadersConfig.AmazonS3Settings); break; case FileDestination.Pushbullet: fileUploader = new Pushbullet(Program.UploadersConfig.PushbulletSettings); break; case FileDestination.MediaCrush: fileUploader = new MediaCrushUploader(); break; } if (fileUploader != null) { PrepareUploader(fileUploader); return fileUploader.Upload(stream, fileName); } return null; }
public string GetHttpHomePath() { // @ deprecated if (HttpHomePath.StartsWith("@")) { HttpHomePath = HttpHomePath.Substring(1); HttpHomePathAutoAddSubFolderPath = false; } HttpHomePath = FTPHelpers.RemovePrefixes(HttpHomePath); NameParser parser = new NameParser(NameParserType.URL); return parser.Parse(HttpHomePath.Replace("%host", LocalhostRoot)); }
public string GetHttpHomePath() { HttpHomePath = FTPHelpers.RemovePrefixes(HttpHomePath); NameParser nameParser = new NameParser(NameParserType.URL); return nameParser.Parse(HttpHomePath.Replace("%host", Host)); }
public string GetSubFolderPath(string filename = null) { NameParser parser = new NameParser(NameParserType.URL); string path = parser.Parse(SubFolderPath.Replace("%host", Host)); return Helpers.CombineURL(path, filename); }
public Dictionary<string, string> ParseArguments(string input = null) { Dictionary<string, string> arguments = new Dictionary<string, string>(); foreach (KeyValuePair<string, string> arg in Arguments) { string value = arg.Value; if (!string.IsNullOrEmpty(input)) { value = value.Replace("%input", input); value = value.Replace("$input$", input); } NameParser parser = new NameParser(NameParserType.Text); value = parser.Parse(value); arguments.Add(arg.Key, value); } return arguments; }
public override Image Apply(Image img) { if (string.IsNullOrEmpty(Text)) { return img; } using (Font textFont = TextFont) { if (textFont == null || textFont.Size < 1) { return img; } NameParser parser = new NameParser(NameParserType.Text) { Picture = img }; string parsedText = parser.Parse(Text); Size textSize = Helpers.MeasureText(parsedText, textFont); Size watermarkSize = new Size(textSize.Width + BackgroundPadding * 2, textSize.Height + BackgroundPadding * 2); Point watermarkPosition = Helpers.GetPosition(Placement, Offset, img.Size, watermarkSize); Rectangle watermarkRectangle = new Rectangle(watermarkPosition, watermarkSize); if (AutoHide && !new Rectangle(0, 0, img.Width, img.Height).Contains(watermarkRectangle)) { return img; } using (Bitmap bmpWatermark = new Bitmap(watermarkSize.Width, watermarkSize.Height)) using (Graphics gWatermark = Graphics.FromImage(bmpWatermark)) { gWatermark.SetHighQuality(); if (DrawBackground) { Rectangle backgroundRect = new Rectangle(0, 0, watermarkSize.Width, watermarkSize.Height); Brush backgroundBrush = null; try { if (UseCustomGradient && Gradient != null && Gradient.IsValid) { backgroundBrush = new LinearGradientBrush(backgroundRect, Color.Transparent, Color.Transparent, Gradient.Type); ColorBlend colorBlend = new ColorBlend(); IEnumerable<GradientStop> gradient = Gradient.Colors.OrderBy(x => x.Location); colorBlend.Colors = gradient.Select(x => x.Color).ToArray(); colorBlend.Positions = gradient.Select(x => x.Location / 100).ToArray(); ((LinearGradientBrush)backgroundBrush).InterpolationColors = colorBlend; } else if (UseGradient) { backgroundBrush = new LinearGradientBrush(backgroundRect, BackgroundColor, BackgroundColor2, GradientType); } else { backgroundBrush = new SolidBrush(BackgroundColor); } using (Pen borderPen = new Pen(BorderColor)) { gWatermark.DrawRoundedRectangle(backgroundBrush, borderPen, backgroundRect, CornerRadius); } } finally { if (backgroundBrush != null) backgroundBrush.Dispose(); } } gWatermark.TextRenderingHint = TextRenderingHint.AntiAliasGridFit; using (StringFormat sf = new StringFormat { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center }) { float centerX = bmpWatermark.Width / 2f; float centerY = bmpWatermark.Height / 2f; if (DrawTextShadow) { using (Brush textShadowBrush = new SolidBrush(TextShadowColor)) { gWatermark.DrawString(parsedText, textFont, textShadowBrush, centerX + TextShadowOffset.X, centerY + TextShadowOffset.Y, sf); } } using (Brush textBrush = new SolidBrush(TextColor)) { gWatermark.DrawString(parsedText, textFont, textBrush, centerX, centerY, sf); } } using (Graphics gResult = Graphics.FromImage(img)) { gResult.SetHighQuality(); gResult.DrawImage(bmpWatermark, watermarkRectangle); } } } return img; }
public Image ApplyWatermark(Image img) { switch (Config.WatermarkMode) { case WatermarkType.TEXT: NameParser parser = new NameParser(NameParserType.Text) { Picture = img }; return DrawWatermarkText(img, parser.Parse(Config.WatermarkText)); case WatermarkType.IMAGE: return DrawWatermarkImage(img, Config.WatermarkImageLocation); } return img; }
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 override Image Apply(Image img) { if (string.IsNullOrEmpty(Text)) { return img; } using (Font textFont = TextFont) { if (textFont == null || textFont.Size < 1) { return img; } NameParser parser = new NameParser(NameParserType.Text) { Picture = img }; string parsedText = parser.Parse(Text); Size textSize = Helpers.MeasureText(parsedText, textFont); Size watermarkSize = new Size(textSize.Width + BackgroundPadding * 2, textSize.Height + BackgroundPadding * 2); if (AutoHide && ((watermarkSize.Width + Offset > img.Width) || (watermarkSize.Height + Offset > img.Height))) { return img; } using (Bitmap bmpWatermark = new Bitmap(watermarkSize.Width, watermarkSize.Height)) using (Graphics gWatermark = Graphics.FromImage(bmpWatermark)) { gWatermark.SetHighQuality(); if (DrawBackground) { using (GraphicsPath backgroundPath = new GraphicsPath()) { Rectangle backgroundRect = new Rectangle(0, 0, watermarkSize.Width, watermarkSize.Height); backgroundPath.AddRoundedRectangle(backgroundRect, CornerRadius); Brush backgroundBrush = null; try { if (UseGradient) { backgroundBrush = new LinearGradientBrush(backgroundRect, BackgroundColor, BackgroundColor2, GradientType); if (UseCustomGradient && CustomGradientList != null && CustomGradientList.Count > 1) { ColorBlend colorBlend = new ColorBlend(); IEnumerable<GradientStop> gradient = CustomGradientList.OrderBy(x => x.Offset); colorBlend.Colors = gradient.Select(x => x.Color).ToArray(); colorBlend.Positions = gradient.Select(x => x.Offset).ToArray(); ((LinearGradientBrush)backgroundBrush).InterpolationColors = colorBlend; } } else { backgroundBrush = new SolidBrush(BackgroundColor); } gWatermark.FillPath(backgroundBrush, backgroundPath); } finally { if (backgroundBrush != null) backgroundBrush.Dispose(); } using (Pen borderPen = new Pen(BorderColor)) { gWatermark.DrawPath(borderPen, backgroundPath); } } } gWatermark.TextRenderingHint = TextRenderingHint.AntiAliasGridFit; using (Brush textBrush = new SolidBrush(TextColor)) using (StringFormat sf = new StringFormat { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center }) { gWatermark.DrawString(parsedText, textFont, textBrush, bmpWatermark.Width / 2f, bmpWatermark.Height / 2f, sf); } using (Graphics gResult = Graphics.FromImage(img)) { gResult.SetHighQuality(); Point labelPosition = Helpers.GetPosition(Position, Offset, img.Size, watermarkSize); gResult.DrawImage(bmpWatermark, labelPosition.X, labelPosition.Y, bmpWatermark.Width, bmpWatermark.Height); } } } return img; }