private void FormMain_Load(object sender, EventArgs e) { data = new ClipboardData(); data.SaveCompleted += () => Application.Exit(); // exit when save completed string[] extensions = data.Analyze(); cboExtension.Items.AddRange(extensions); if (extensions.Length > 0) { cboExtension.Text = extensions[0] ?? ""; } else { if (MessageBox.Show(this, Resources.Strings.TipAnalyzeFailed, Resources.Strings.Title, MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes) { btnChooseLocation.Enabled = false; btnSave.Enabled = false; txtFileName.Enabled = false; cboExtension.Enabled = false; tsslCurrentLocation.Text = Resources.Strings.TxtCanOnlyUse; } else { Environment.Exit(0); } } lastAutoGeneratedFileName = PathGenerator.GenerateFileName(CurrentLocation, cboExtension.Text); txtFileName.Text = lastAutoGeneratedFileName; }
public static void QuickPasteEx(string location) { ManualResetEvent allDone = new ManualResetEvent(false); ClipboardData data = new ClipboardData(Clipboard.GetDataObject()); data.SaveCompleted += () => allDone.Set(); string[] extensions = data.Analyze(); 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 = currentLocation + GenerateFileName(currentLocation, extensions[0]) + "." + extensions[0]; 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) { data.Save(path, extensions[0]); } else if (result == DialogResult.No) { return; } } else { data.Save(path, extensions[0]); } } } else { Console.WriteLine(Resources.Strings.TipAnalyzeFailedWithoutPrompt); MessageBox.Show(Resources.Strings.TipAnalyzeFailedWithoutPrompt, Resources.Strings.Title, MessageBoxButtons.OK, MessageBoxIcon.Warning); } allDone.WaitOne(); }