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 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) == "." + s) { imagesList.Add(image); break; } } } 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 = NameParser.Convert(new NameParserInfo(NameParserType.SaveFolder, Engine.conf.SaveFolderPattern) { CustomDate = time }); newFolderPath = Path.Combine(Engine.RootImagesDir, newFolderPath); if (!Directory.Exists(newFolderPath)) { Directory.CreateDirectory(newFolderPath); } movePath = Path.Combine(newFolderPath, Path.GetFileName(image)); File.Move(image, movePath); } } } return(true); } return(false); }
public string GetSubFolderPath() { NameParser parser = new NameParser { Host = this.Host, IsFolderPath = true }; return(parser.Convert(this.SubFolderPath)); }
public string GetHttpHomePath() { NameParser parser = new NameParser { Host = this.Host, IsFolderPath = true }; HttpHomePath = parser.RemovePrefixes(HttpHomePath); return(parser.Convert(HttpHomePath)); }
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); }
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); }
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)); }
/// <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)); } }
/// <summary>Get Image with Watermark</summary> public static Image ApplyWatermark(Image img, WatermarkType watermarkType) { switch (watermarkType) { default: case WatermarkType.NONE: return(img); case WatermarkType.TEXT: return(DrawWatermark(img, NameParser.Convert(new NameParserInfo(NameParserType.Watermark, Engine.conf.WatermarkText) { IsPreview = true, Picture = img }))); case WatermarkType.IMAGE: return(DrawImageWatermark(img, Engine.conf.WatermarkImageLocation)); } }
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); }
/// <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(); } } }