private static void ClipboardMonitor_OnClipboardChange() { if (!Properties.Settings.Default.autoImageToFileEnabled) { return; } // 1. Analyze monitorModeData.Reload(); string[] exts = monitorModeData.Analyze(); if (exts == null || exts.Length == 0) { return; } // 2. Save image data to disk if (ImageProcessor.imageExt.Contains(exts[0])) { if (Properties.Settings.Default.autoImageToFileEnabled) { // Append FileDrop type data into clipboard string filePath = PathGenerator.GenerateMonitorAppendFilePath(exts[0]); AppendFileToClipboard(filePath); monitorModeData.SaveAsync(filePath, exts[0]); } } }
private static void ClipboardMonitor_OnClipboardChange(object sender) { // 0. Clipboard owner white-black list Process proc = Process.GetProcessById(Convert.ToInt32(sender)); CommandLine.Info("[Monitor] Clipboard Owner: " + proc.ProcessName + " - Process Id:" + proc.Id); if (ApplicationHelper.GetCurrentProcessName() == proc.ProcessName) { return; } if (!applicationCopyFilter.Bypass(proc.ProcessName)) { CommandLine.Warning("[Monitor] Intercept: " + proc.ProcessName); return; } if (!Properties.Settings.Default.autoImageToFileEnabled) { return; } // 1. Analyze monitorModeData.Reload(); string[] exts = monitorModeData.Analyze(); if (exts == null || exts.Length == 0) { return; } // 2. Save image data to disk if (ImageProcessor.imageExt.Contains(exts[0])) { if (monitorModeData.Storage.GetDataPresent(DataFormats.Bitmap)) { if (Properties.Settings.Default.autoImageToFileEnabled) { // Append FileDrop type data into clipboard string filePath = PathGenerator.GenerateMonitorAppendFilePath(exts[0]); CommandLine.Info("[Monitor] Paste pictures into files: " + filePath); AppendFileToClipboard(filePath); monitorModeData.SaveAsync(filePath, exts[0]); } } else if (monitorModeData.Storage.GetDataPresent(DataFormats.FileDrop)) { if (Properties.Settings.Default.monitorAutoSaveEnabled) { // Append FileDrop type data into clipboard string filePath = PathGenerator.GenerateMonitorAppendFilePath(exts[0]); CommandLine.Info("[Monitor] Copy pictures file into: " + filePath); monitorModeData.SaveAsync(filePath, exts[0]); } } } }
private static void ClipboardMonitor_OnClipboardChange(object sender) { // 0. Clipboard owner white-black list Process proc = Process.GetProcessById(Convert.ToInt32(sender)); Debug.WriteLine("ClipboardOwner: " + proc.ProcessName + " - " + proc.Id); if (ApplicationHelper.GetCurrentProcessName() == proc.ProcessName) { return; } if (!Properties.Settings.Default.autoImageToFileEnabled) { return; } // 1. Analyze monitorModeData.Reload(); string[] exts = monitorModeData.Analyze(); if (exts == null || exts.Length == 0) { return; } // 2. Save image data to disk if (ImageProcessor.imageExt.Contains(exts[0]) && monitorModeData.Storage.GetDataPresent(DataFormats.Bitmap)) { if (Properties.Settings.Default.autoImageToFileEnabled) { // Append FileDrop type data into clipboard string filePath = PathGenerator.GenerateMonitorAppendFilePath(exts[0]); AppendFileToClipboard(filePath); monitorModeData.SaveAsync(filePath, exts[0]); } } }
//public static void StartCollectionMode() //{ //} //public static void StopCollectionMode() //{ //} #endregion #region FastPasteMode public static void QuickPasteEx(string location, string fileName = null) { ManualResetEvent allDone = new ManualResetEvent(false); ClipboardData quickPasteData = new ClipboardData(); quickPasteData.SaveCompleted += () => allDone.Set(); string[] extensions = quickPasteData.Analyze(); if (!string.IsNullOrEmpty(fileName)) { string ext = Path.GetExtension(fileName); extensions = new string[1] { ext }; if (Array.IndexOf(extensions, ext) == -1) { // TODO // maybe need some tips } } if (extensions.Length > 0) { // why the disk root directory has '"' ?? if (location.LastIndexOf('"') == location.Length - 1) { location = location.Substring(0, location.Length - 1); } string currentLocation = location.EndsWith("\\") ? location : location + "\\"; string path = null; if (string.IsNullOrEmpty(fileName)) { path = currentLocation + PathGenerator.GenerateFileName(currentLocation, extensions[0]) + "." + extensions[0]; } else { path = currentLocation + fileName; } Console.WriteLine(fileName); if (!Directory.Exists(currentLocation)) { Console.WriteLine(Resources.Strings.TipTargetPathNotExist); MessageBox.Show(Resources.Strings.TipTargetPathNotExist, Resources.Strings.Title, MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { if (File.Exists(path)) { DialogResult result = MessageBox.Show(string.Format(Resources.Strings.TipTargetFileExisted, path), Resources.Strings.Title, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); if (result == DialogResult.Yes) { quickPasteData.Save(path, extensions[0]); } else if (result == DialogResult.No) { return; } } else { quickPasteData.Save(path, extensions[0]); } } } else { Console.WriteLine(Resources.Strings.TipAnalyzeFailedWithoutPrompt); MessageBox.Show(Resources.Strings.TipAnalyzeFailedWithoutPrompt, Resources.Strings.Title, MessageBoxButtons.OK, MessageBoxIcon.Warning); } allDone.WaitOne(); }