/// <summary>Get Image with Watermark</summary> public Image ApplyWatermark(Image img, NameParser parser = null) { if (parser == null) { parser = new NameParser(NameParserType.Watermark) { IsPreview = true, Picture = img }; } return ApplyWatermark(img, parser, Config.WatermarkMode); }
/// <summary>Get Image with Watermark</summary> public Image ApplyWatermark(Image img, NameParser parser, WatermarkType watermarkType) { switch (watermarkType) { default: case WatermarkType.NONE: return img; case WatermarkType.TEXT: return DrawWatermark(img, parser.Convert(Config.WatermarkText)); case WatermarkType.IMAGE: return DrawImageWatermark(img, Config.WatermarkImageLocation); } }
public static string PrepareFilename(Workflow workflow, Image img, EImageFormat imageFormat, NameParser parser) { string ext = "png"; switch (imageFormat) { case EImageFormat.PNG: ext = "png"; break; case EImageFormat.JPEG: ext = "jpg"; break; case EImageFormat.GIF: ext = "gif"; break; case EImageFormat.BMP: ext = "bmp"; break; case EImageFormat.TIFF: ext = "tif"; break; } string pattern = workflow.ConfigFileNaming.EntireScreenPattern; switch (parser.Type) { case NameParserType.ActiveWindow: pattern = workflow.ConfigFileNaming.ActiveWindowPattern; break; default: pattern = workflow.ConfigFileNaming.EntireScreenPattern; break; } string fn = parser.Convert(pattern); if (Engine.ConfigWorkflow != null) { Engine.ConfigWorkflow.ConfigFileNaming.AutoIncrement = parser.AutoIncrementNumber; // issue 577; Engine.Workflow.AutoIncrement has to be updated } string fileName = string.Format("{0}.{1}", fn, ext); return FileSystem.GetUniqueFileName(workflow, fileName); }
private static string PrepareFilename(EImageFormat imageFormat, Image img) { string ext = "png"; switch (imageFormat) { case EImageFormat.PNG: ext = "png"; break; case EImageFormat.JPEG: ext = "jpg"; break; case EImageFormat.GIF: ext = "gif"; break; case EImageFormat.BMP: ext = "bmp"; break; case EImageFormat.TIFF: ext = "tif"; break; } NameParser parser = new NameParser { Picture = img }; return string.Format("{0}.{1}", parser.Convert(Program.Settings.NameFormatPattern), ext); }
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 string GetHttpHomePath() { HttpHomePath = FTPHelpers.RemovePrefixes(HttpHomePath); NameParser nameParser = new NameParser(NameParserType.URL); return nameParser.Parse(HttpHomePath.Replace("%host", Host)); }
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; }
private void txtActiveWindow_TextChanged(object sender, EventArgs e) { Config.ActiveWindowPattern = txtActiveWindow.Text; var parser = new NameParser(NameParserType.ActiveWindow) { CustomProductName = Application.ProductName, IsPreview = true, MaxNameLength = Config.MaxNameLength }; lblActiveWindowPreview.Text = parser.Convert(Config.ActiveWindowPattern); }
public string GetHttpHomePath() { NameParser parser = new NameParser(NameParserType.URL); HttpHomePath = FTPHelpers.RemovePrefixes(HttpHomePath.Replace("%host", LocalhostRoot)); return parser.Parse(HttpHomePath); }
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 bool ManageImageFolders(string path) { if (!string.IsNullOrEmpty(path) && Directory.Exists(path)) { string[] images = Directory.GetFiles(path); List<string> imagesList = new List<string>(); foreach (string image in images) { foreach (string s in Engine.zImageFileTypes) { if (Path.HasExtension(image) && Path.GetExtension(image.ToLower()) == "." + s) { imagesList.Add(image); break; } } } DebugHelper.WriteLine(string.Format("Found {0} images to move to sub-folders", imagesList.Count)); if (imagesList.Count > 0) { if (MessageBox.Show(string.Format("{0} files found in {1}\nPlease wait until all the files are moved...", imagesList.Count, path), Application.ProductName, MessageBoxButtons.OKCancel, MessageBoxIcon.Information) == DialogResult.Cancel) { return false; } DateTime time; string newFolderPath; string movePath; foreach (string image in imagesList) { if (File.Exists(image)) { time = File.GetCreationTime(image); newFolderPath = new NameParser(NameParserType.SaveFolder) { CustomDate = time }.Convert(Engine.ConfigWorkflow.SaveFolderPattern); newFolderPath = Path.Combine(path, newFolderPath); if (!Directory.Exists(newFolderPath)) { Directory.CreateDirectory(newFolderPath); } movePath = FileSystem.GetUniqueFileName(Engine.ConfigWorkflow, Path.Combine(newFolderPath, Path.GetFileName(image))); File.Move(image, movePath); } } } return true; } return false; }
public string GetHttpHomePath() { NameParser parser = new NameParser { Host = this.LocalhostRoot, IsFolderPath = true }; HttpHomePath = parser.RemovePrefixes(HttpHomePath); return parser.Convert(HttpHomePath); }
public string GetSubFolderPath() { NameParser parser = new NameParser { Host = this.LocalhostRoot, IsFolderPath = true }; return parser.Convert(this.SubFolderPath); }
/// <summary> /// Sets Clipboard text and returns the content /// </summary> /// <returns></returns> public static void ShowUploadResults(WorkerTask task, bool showDialog) { if (!task.WorkflowConfig.ClipboardOverwrite && !Clipboard.ContainsFileDropList() && !Clipboard.ContainsImage() && !Clipboard.ContainsText() || task.WorkflowConfig.ClipboardOverwrite) { if (task.UploadResults.Count > 0) { if (task.WorkflowConfig.DestConfig.TaskClipboardContent.Count > 1 || Engine.ConfigUI.ShowUploadResultsWindow || showDialog) { ClipboardOptions cmp = new ClipboardOptions(task); cmp.Icon = Resources.zss_main; if (showDialog) { cmp.ShowDialog(); } else { NativeMethods.ShowWindow(cmp.Handle, (int)WindowShowStyle.ShowNoActivate); } showDialog = true; } } if (task.WorkflowConfig.DestConfig.Outputs.Contains(OutputEnum.Clipboard)) { StringBuilder clipboardText = new StringBuilder(); if (task.JobIsImageToClipboard()) { Adapter.CopyImageToClipboard(task.TempImage, task.WorkflowConfig.ClipboardForceBmp); } else if (task.WorkflowConfig.DestConfig.TaskClipboardContent.Contains(ClipboardContentEnum.Local)) { foreach (UploadResult ur in task.UploadResults) { if (Engine.ConfigUI.ConfLinkFormat.Count > 0) { clipboardText.AppendLine(ur.GetUrlByType((LinkFormatEnum)task.WorkflowConfig.DestConfig.LinkFormat[0], ur.LocalFilePath)); } if (!Engine.ConfigUI.ClipboardAppendMultipleLinks && clipboardText.Length > 0) { break; } } } else if (task.WorkflowConfig.DestConfig.TaskClipboardContent.Contains(ClipboardContentEnum.OCR)) { if (!string.IsNullOrEmpty(task.OCRText)) { clipboardText.Append(task.OCRText); } } // If the user requests for the full image URL, preference is given for the Shortened URL is exists else if (task.Job1 == EDataType.Image && task.WorkflowConfig.DestConfig.LinkFormat.Contains((int)LinkFormatEnum.FULL)) { if (task.Job3 == WorkerTask.JobLevel3.ShortenURL && !string.IsNullOrEmpty(task.UploadResults[0].ShortenedURL)) { foreach (UploadResult ur in task.UploadResults) { if (!string.IsNullOrEmpty(ur.ShortenedURL)) { clipboardText.AppendLine(ur.ShortenedURL); if (!Engine.ConfigUI.ClipboardAppendMultipleLinks && clipboardText.Length > 0) { break; } } } } // If no shortened URL exists then default full URL will be used else { foreach (UploadResult ur in task.UploadResults) { if (!string.IsNullOrEmpty(ur.URL)) { clipboardText.AppendLine(FileSystem.GetBrowserFriendlyUrl(ur.URL)); if (!Engine.ConfigUI.ClipboardAppendMultipleLinks && clipboardText.Length > 0) { break; } } } if (clipboardText.Length == 0 && task.WorkflowConfig.DestConfig.TaskClipboardContent.Contains(ClipboardContentEnum.Local)) { foreach (UploadResult ur in task.UploadResults) { if (!string.IsNullOrEmpty(ur.LocalFilePath)) { clipboardText.AppendLine(ur.LocalFilePath); if (!Engine.ConfigUI.ClipboardAppendMultipleLinks && clipboardText.Length > 0) { break; } } } } } } else { // From this point onwards app needs to respect all other Clipboard URL modes for Images if (task.UploadResults.Count > 0 && task.Job1 == EDataType.Image) { foreach (UploadResult ur in task.UploadResults) { if (task.WorkflowConfig.DestConfig.LinkFormat.Count > 0) { clipboardText.AppendLine(ur.GetUrlByType((LinkFormatEnum)task.WorkflowConfig.DestConfig.LinkFormat[0], ur.URL)); } if (!Engine.ConfigUI.ClipboardAppendMultipleLinks && clipboardText.Length > 0) { break; } } } // Text and File catagories are still left to process. Exception for Google Translate else if (task.Job1 == EDataType.Text && task.Job2 == WorkerTask.JobLevel2.Translate) { if (task.TranslationInfo != null) { clipboardText.AppendLine(task.TranslationInfo.Result); } } // Text and File catagories are still left to process. If shortened URL exists, preference is given to that else if (task.UploadResults.Count > 0 && task.Job3 == WorkerTask.JobLevel3.ShortenURL && !string.IsNullOrEmpty(task.UploadResults[0].ShortenedURL)) { foreach (UploadResult ur in task.UploadResults) { if (!string.IsNullOrEmpty(ur.ShortenedURL)) { clipboardText.AppendLine(ur.ShortenedURL); break; } } } // Otherwise full URL for Text or File is used else if (task.UploadResults.Count > 0) { clipboardText.AppendLine(FileSystem.GetBrowserFriendlyUrl(task.UploadResults[0].URL)); } } if (clipboardText.Length > 0) { bool bClipboardFormatOnLongUrl = Engine.ConfigUI.EnableClipboardFormatForLongURLs && task.Job1 == EDataType.URL; bool bClipboardFormat = bClipboardFormatOnLongUrl || task.Job1 != EDataType.URL; var np = new NameParser(NameParserType.Clipboard) { Link = clipboardText.ToString().Trim(), FileSize = task.Info.FileSize, FileName = task.Info.FileName }; if (bClipboardFormat) { np.WindowText = task.Info.WindowTitleText; } string tempText = bClipboardFormat ? np.Convert(Engine.ConfigUI.ClipboardFormat) : clipboardText.ToString().Trim(); if (!string.IsNullOrEmpty(tempText)) { DebugHelper.WriteLine("Setting Clipboard with URL: " + tempText); Clipboard.SetText(tempText); // auto Engine.zPreviousSetClipboardText = tempText; Engine.IsClipboardUploading = false; // optional deletion link if (task.UploadResults != null) { foreach (UploadResult ur in task.UploadResults) { string linkdel = ur.DeletionURL; if (!string.IsNullOrEmpty(linkdel)) { DebugHelper.WriteLine("Deletion Link: " + linkdel); } } } } } } if (!showDialog) { task.Dispose(); } } }
public UploadResult UploadFile(Stream stream, string fileName) { FileUploader fileUploader = null; switch (UploadManager.FileUploader) { case FileDestination.Dropbox: NameParser parser = new NameParser { IsFolderPath = true }; string uploadPath = parser.Convert(Dropbox.TidyUploadPath(Program.UploadersConfig.DropboxUploadPath)); fileUploader = new Dropbox(Program.UploadersConfig.DropboxOAuthInfo, uploadPath, Program.UploadersConfig.DropboxAccountInfo) { AutoCreateShareableLink = Program.UploadersConfig.DropboxAutoCreateShareableLink }; break; case FileDestination.RapidShare: fileUploader = new RapidShare(Program.UploadersConfig.RapidShareUsername, Program.UploadersConfig.RapidSharePassword, Program.UploadersConfig.RapidShareFolderID); break; case FileDestination.SendSpace: fileUploader = new SendSpace(ZKeys.SendSpaceKey); switch (Program.UploadersConfig.SendSpaceAccountType) { case AccountType.Anonymous: SendSpaceManager.PrepareUploadInfo(ZKeys.SendSpaceKey); break; case AccountType.User: SendSpaceManager.PrepareUploadInfo(ZKeys.SendSpaceKey, Program.UploadersConfig.SendSpaceUsername, Program.UploadersConfig.SendSpacePassword); break; } break; case FileDestination.Minus: fileUploader = new Minus(Program.UploadersConfig.MinusConfig, new OAuthInfo(ZKeys.MinusConsumerKey, ZKeys.MinusConsumerSecret)); break; case FileDestination.Box: fileUploader = new Box(ZKeys.BoxKey) { AuthToken = Program.UploadersConfig.BoxAuthToken, FolderID = Program.UploadersConfig.BoxFolderID, Share = Program.UploadersConfig.BoxShare }; break; case FileDestination.CustomUploader: if (Program.UploadersConfig.CustomUploadersList.HasValidIndex(Program.UploadersConfig.CustomUploaderSelected)) { fileUploader = new CustomUploader(Program.UploadersConfig.CustomUploadersList[Program.UploadersConfig.CustomUploaderSelected]); } break; case FileDestination.FTP: int index = Program.UploadersConfig.GetFtpIndex(Info.DataType); if (Program.UploadersConfig.FTPAccountList2.HasValidIndex(index)) { fileUploader = new FTPUploader(Program.UploadersConfig.FTPAccountList2[index]); } break; case FileDestination.Email: using (EmailForm emailForm = new EmailForm(Program.UploadersConfig.EmailRememberLastTo ? Program.UploadersConfig.EmailLastTo : string.Empty, Program.UploadersConfig.EmailDefaultSubject, Program.UploadersConfig.EmailDefaultBody)) { 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; } if (fileUploader != null) { PrepareUploader(fileUploader); return fileUploader.Upload(stream, fileName); } return null; }
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; }
private void UploadFile(FileDestination fileUploaderType, Stream data) { FileUploader fileUploader = null; switch (fileUploaderType) { case FileDestination.FTP: if (Engine.ConfigUI.ShowFTPSettingsBeforeUploading) { var ucf = new UploadersConfigForm(Engine.ConfigUploaders, Engine.ConfigUI.ApiKeysConfig); ucf.Icon = Resources.zss_main; ucf.tcUploaders.SelectedTab = ucf.tpFileUploaders; ucf.tcFileUploaders.SelectedTab = ucf.tpFTP; ucf.ShowDialog(); } switch (Job1) { case EDataType.Text: UploadToFTP(Engine.ConfigUploaders.FTPSelectedText, data); break; case EDataType.Image: UploadToFTP(Engine.ConfigUploaders.FTPSelectedImage, data); break; default: case EDataType.File: UploadToFTP(Engine.ConfigUploaders.FTPSelectedFile, data); break; } break; case FileDestination.Minus: fileUploader = new Minus(Engine.ConfigUploaders.MinusConfig, new OAuthInfo(Engine.ConfigUI.ApiKeysConfig.MinusConsumerKey, Engine.ConfigUI.ApiKeysConfig.MinusConsumerSecret)); break; case FileDestination.Dropbox: string uploadPath = new NameParser { IsFolderPath = true }.Convert(Dropbox.TidyUploadPath(Engine.ConfigUploaders.DropboxUploadPath)); fileUploader = new Dropbox(Engine.ConfigUploaders.DropboxOAuthInfo, uploadPath, Engine.ConfigUploaders.DropboxAccountInfo) { AutoCreateShareableLink = Engine.ConfigUploaders.DropboxAutoCreateShareableLink }; break; case FileDestination.Box: fileUploader = new Box(ZKeys.BoxKey) { AuthToken = Engine.ConfigUploaders.BoxAuthToken, FolderID = Engine.ConfigUploaders.BoxFolderID, Share = Engine.ConfigUploaders.BoxShare }; break; case FileDestination.SendSpace: fileUploader = new SendSpace(Engine.ConfigUI.ApiKeysConfig.SendSpaceKey); switch (Engine.ConfigUploaders.SendSpaceAccountType) { case AccountType.Anonymous: SendSpaceManager.PrepareUploadInfo(Engine.ConfigUI.ApiKeysConfig.SendSpaceKey); break; case AccountType.User: SendSpaceManager.PrepareUploadInfo(Engine.ConfigUI.ApiKeysConfig.SendSpaceKey, Engine.ConfigUploaders.SendSpaceUsername, Engine.ConfigUploaders.SendSpacePassword); break; } break; case FileDestination.RapidShare: fileUploader = new RapidShare(Engine.ConfigUploaders.RapidShareUsername, Engine.ConfigUploaders.RapidSharePassword, Engine.ConfigUploaders.RapidShareFolderID); break; case FileDestination.CustomUploader: fileUploader = new CustomUploader(Engine.ConfigUploaders.CustomUploadersList[Engine.ConfigUploaders.CustomUploaderSelected]); break; } if (fileUploader != null) { MyWorker.ReportProgress((int)ProgressType.UpdateProgressMax, TaskbarProgressBarState.Indeterminate); DestinationName = fileUploaderType.GetDescription(); DebugHelper.WriteLine("Initialized " + DestinationName); fileUploader.ProgressChanged += UploadProgressChanged; UploadResult ur_remote_file = fileUploader.Upload(data, Info.FileName); if (ur_remote_file != null) { ur_remote_file.Host = fileUploaderType.GetDescription(); ur_remote_file.LocalFilePath = Info.LocalFilePath; AddUploadResult(ur_remote_file); } Errors = fileUploader.Errors; } }
public void UploadToSharedFolder(int id) { if (Engine.ConfigUploaders.LocalhostAccountList.HasValidIndex(id)) { LocalhostAccount acc = Engine.ConfigUploaders.LocalhostAccountList[id]; string fn = string.Empty; if (File.Exists(Info.LocalFilePath)) { fn = Path.GetFileName(Info.LocalFilePath); string destFile = acc.GetLocalhostPath(fn); string destDir = Path.GetDirectoryName(destFile); if (!Directory.Exists(destDir)) { Directory.CreateDirectory(destDir); } File.Copy(Info.LocalFilePath, destFile, true); UpdateLocalFilePath(destFile); } else if (TempImage != null) { EImageFormat imageFormat; Data = WorkerTaskHelper.PrepareImage(WorkflowConfig, Engine.ConfigOptions, TempImage, out imageFormat); fn = WorkerTaskHelper.PrepareFilename(WorkflowConfig, TempImage, imageFormat, GetNameParser()); string fp = acc.GetLocalhostPath(fn); FileSystem.WriteImage(fp, Data); } else if (!string.IsNullOrEmpty(TempText)) { fn = new NameParser(NameParserType.EntireScreen).Convert(WorkflowConfig.ConfigFileNaming.EntireScreenPattern) + ".txt"; string destFile = acc.GetLocalhostPath(fn); FileSystem.WriteText(destFile, TempText); } var ur = new UploadResult { Host = OutputEnum.SharedFolder.GetDescription(), URL = acc.GetUriPath(fn), LocalFilePath = Info.LocalFilePath }; UploadResults.Add(ur); } }
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 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 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 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 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 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 string GetSubFolderPath() { NameParser parser = new NameParser(NameParserType.URL); return parser.Parse(SubFolderPath.Replace("%host", LocalhostRoot)); }
private void txtEntireScreen_TextChanged(object sender, EventArgs e) { Config.EntireScreenPattern = txtEntireScreen.Text; var parser = new NameParser(NameParserType.EntireScreen) { CustomProductName = Application.ProductName, IsPreview = true, MaxNameLength = Config.MaxNameLength }; lblEntireScreenPreview.Text = parser.Convert(Config.EntireScreenPattern); }