mirror of
https://github.com/ShareX/ShareX.git
synced 2024-09-30 01:07:21 +13:00
fixed #584: Custom sound support
This commit is contained in:
parent
23f13e0eb0
commit
3710f1d99d
7 changed files with 154 additions and 19 deletions
|
@ -529,14 +529,31 @@ public static object Clone(object obj)
|
|||
|
||||
public static void PlaySoundAsync(Stream stream)
|
||||
{
|
||||
TaskEx.Run(() =>
|
||||
if (stream != null)
|
||||
{
|
||||
using (stream)
|
||||
using (SoundPlayer soundPlayer = new SoundPlayer(stream))
|
||||
TaskEx.Run(() =>
|
||||
{
|
||||
soundPlayer.PlaySync();
|
||||
}
|
||||
});
|
||||
using (stream)
|
||||
using (SoundPlayer soundPlayer = new SoundPlayer(stream))
|
||||
{
|
||||
soundPlayer.PlaySync();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public static void PlaySoundAsync(string filepath)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(filepath) && File.Exists(filepath))
|
||||
{
|
||||
TaskEx.Run(() =>
|
||||
{
|
||||
using (SoundPlayer soundPlayer = new SoundPlayer(filepath))
|
||||
{
|
||||
soundPlayer.PlaySync();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public static bool BrowseFile(string title, TextBox tb, string initialDirectory = "")
|
||||
|
|
|
@ -284,6 +284,7 @@
|
|||
<Compile Include="Cryptographic\Translator.cs" />
|
||||
<Compile Include="Cryptographic\TranslatorHelper.cs" />
|
||||
<Compile Include="UITypeEditors\NameParserEditor.cs" />
|
||||
<Compile Include="UITypeEditors\WavFileNameEditor.cs" />
|
||||
<Compile Include="UnsafeBitmap.cs" />
|
||||
<Compile Include="UpdateChecker\GitHubUpdateChecker.cs" />
|
||||
<Compile Include="UpdateChecker\UpdateChecker.cs" />
|
||||
|
|
54
ShareX.HelpersLib/UITypeEditors/WavFileNameEditor.cs
Normal file
54
ShareX.HelpersLib/UITypeEditors/WavFileNameEditor.cs
Normal file
|
@ -0,0 +1,54 @@
|
|||
#region License Information (GPL v3)
|
||||
|
||||
/*
|
||||
ShareX - A program that allows you to take screenshots and share any file type
|
||||
Copyright (c) 2007-2015 ShareX Team
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
Optionally you can also view the license at <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#endregion License Information (GPL v3)
|
||||
|
||||
using ShareX.HelpersLib.Properties;
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Windows.Forms;
|
||||
using System.Windows.Forms.Design;
|
||||
|
||||
namespace ShareX.HelpersLib
|
||||
{
|
||||
public class WavFileNameEditor : FileNameEditor
|
||||
{
|
||||
public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
|
||||
{
|
||||
if (context == null || provider == null)
|
||||
{
|
||||
return base.EditValue(context, provider, value);
|
||||
}
|
||||
using (OpenFileDialog dlg = new OpenFileDialog())
|
||||
{
|
||||
dlg.Title = Resources.ExeFileNameEditor_EditValue_Browse_for_executable___;
|
||||
dlg.Filter = "Sound file (*.wav)|*.wav";
|
||||
if (dlg.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
value = dlg.FileName;
|
||||
}
|
||||
}
|
||||
return value;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1805,7 +1805,7 @@ private void AfterCapture(Image img, CaptureType captureType, TaskSettings taskS
|
|||
{
|
||||
if (taskSettings.GeneralSettings.PlaySoundAfterCapture)
|
||||
{
|
||||
Helpers.PlaySoundAsync(Resources.CaptureSound);
|
||||
TaskHelpers.PlayCaptureSound(taskSettings);
|
||||
}
|
||||
|
||||
if (taskSettings.ImageSettings.ImageEffectOnlyRegionCapture && !IsRegionCapture(captureType))
|
||||
|
@ -2344,4 +2344,4 @@ private void tsmiTrayLastRegion_Click(object sender, EventArgs e)
|
|||
|
||||
#endregion Hotkey/Capture codes and form events
|
||||
}
|
||||
}
|
||||
}
|
|
@ -838,5 +838,47 @@ private static void DownloaderForm_InstallRequested(string filePath)
|
|||
MessageBox.Show(Resources.ScreenRecordForm_DownloaderForm_InstallRequested_Download_of_FFmpeg_failed_, "ShareX", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
public static void PlayCaptureSound(TaskSettings taskSettings)
|
||||
{
|
||||
if (taskSettings == null) taskSettings = TaskSettings.GetDefaultTaskSettings();
|
||||
|
||||
if (taskSettings.AdvancedSettings.UseCustomCaptureSound && !string.IsNullOrEmpty(taskSettings.AdvancedSettings.CustomCaptureSoundPath))
|
||||
{
|
||||
Helpers.PlaySoundAsync(taskSettings.AdvancedSettings.CustomCaptureSoundPath);
|
||||
}
|
||||
else
|
||||
{
|
||||
Helpers.PlaySoundAsync(Resources.CaptureSound);
|
||||
}
|
||||
}
|
||||
|
||||
public static void PlayTaskCompleteSound(TaskSettings taskSettings)
|
||||
{
|
||||
if (taskSettings == null) taskSettings = TaskSettings.GetDefaultTaskSettings();
|
||||
|
||||
if (taskSettings.AdvancedSettings.UseCustomTaskCompleteSound && !string.IsNullOrEmpty(taskSettings.AdvancedSettings.CustomTaskCompleteSoundPath))
|
||||
{
|
||||
Helpers.PlaySoundAsync(taskSettings.AdvancedSettings.CustomTaskCompleteSoundPath);
|
||||
}
|
||||
else
|
||||
{
|
||||
Helpers.PlaySoundAsync(Resources.TaskCompletedSound);
|
||||
}
|
||||
}
|
||||
|
||||
public static void PlayErrorSound(TaskSettings taskSettings)
|
||||
{
|
||||
if (taskSettings == null) taskSettings = TaskSettings.GetDefaultTaskSettings();
|
||||
|
||||
if (taskSettings.AdvancedSettings.UseCustomErrorSound && !string.IsNullOrEmpty(taskSettings.AdvancedSettings.CustomErrorSoundPath))
|
||||
{
|
||||
Helpers.PlaySoundAsync(taskSettings.AdvancedSettings.CustomErrorSoundPath);
|
||||
}
|
||||
else
|
||||
{
|
||||
Helpers.PlaySoundAsync(Resources.ErrorSound);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -266,9 +266,9 @@ private static void task_UploadCompleted(UploadTask task)
|
|||
|
||||
if (!info.TaskSettings.AdvancedSettings.DisableNotifications)
|
||||
{
|
||||
if (task.Info.TaskSettings.GeneralSettings.PlaySoundAfterUpload)
|
||||
if (info.TaskSettings.GeneralSettings.PlaySoundAfterUpload)
|
||||
{
|
||||
Helpers.PlaySoundAsync(Resources.ErrorSound);
|
||||
TaskHelpers.PlayErrorSound(info.TaskSettings);
|
||||
}
|
||||
|
||||
if (info.TaskSettings.GeneralSettings.PopUpNotification != PopUpNotificationType.None && Program.MainForm.niTray.Visible && !string.IsNullOrEmpty(errors))
|
||||
|
@ -303,7 +303,7 @@ private static void task_UploadCompleted(UploadTask task)
|
|||
|
||||
if (!task.StopRequested && !string.IsNullOrEmpty(result))
|
||||
{
|
||||
if (task.Info.TaskSettings.GeneralSettings.SaveHistory)
|
||||
if (info.TaskSettings.GeneralSettings.SaveHistory)
|
||||
{
|
||||
HistoryManager.AddHistoryItemAsync(Program.HistoryFilePath, info.GetHistoryItem());
|
||||
}
|
||||
|
@ -321,9 +321,9 @@ private static void task_UploadCompleted(UploadTask task)
|
|||
|
||||
if (!info.TaskSettings.AdvancedSettings.DisableNotifications && info.Job != TaskJob.ShareURL)
|
||||
{
|
||||
if (task.Info.TaskSettings.GeneralSettings.PlaySoundAfterUpload)
|
||||
if (info.TaskSettings.GeneralSettings.PlaySoundAfterUpload)
|
||||
{
|
||||
Helpers.PlaySoundAsync(Resources.TaskCompletedSound);
|
||||
TaskHelpers.PlayTaskCompleteSound(info.TaskSettings);
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(info.TaskSettings.AdvancedSettings.BalloonTipContentFormat))
|
||||
|
|
|
@ -353,22 +353,43 @@ public class TaskSettingsAdvanced
|
|||
[Category("General"), DefaultValue(true), Description("Save text as file for tasks such as clipboard text upload, drag and drop text upload, index folder etc.")]
|
||||
public bool TextTaskSaveAsFile { get; set; }
|
||||
|
||||
[Category("Sound"), DefaultValue(false), Description("Enable/disable custom capture sound.")]
|
||||
public bool UseCustomCaptureSound { get; set; }
|
||||
|
||||
[Category("Sound"), DefaultValue(""), Description("Capture sound file path."),
|
||||
Editor(typeof(WavFileNameEditor), typeof(UITypeEditor))]
|
||||
public string CustomCaptureSoundPath { get; set; }
|
||||
|
||||
[Category("Sound"), DefaultValue(false), Description("Enable/disable custom task complete sound.")]
|
||||
public bool UseCustomTaskCompleteSound { get; set; }
|
||||
|
||||
[Category("Sound"), DefaultValue(""), Description("Task complete sound file path."),
|
||||
Editor(typeof(WavFileNameEditor), typeof(UITypeEditor))]
|
||||
public string CustomTaskCompleteSoundPath { get; set; }
|
||||
|
||||
[Category("Sound"), DefaultValue(false), Description("Enable/disable custom error sound.")]
|
||||
public bool UseCustomErrorSound { get; set; }
|
||||
|
||||
[Category("Sound"), DefaultValue(""), Description("Error sound file path."),
|
||||
Editor(typeof(WavFileNameEditor), typeof(UITypeEditor))]
|
||||
public string CustomErrorSoundPath { get; set; }
|
||||
|
||||
[Category("Image"), DefaultValue(256), Description("Preferred thumbnail width. 0 means aspect ratio will be used to adjust width according to height.")]
|
||||
public int ThumbnailPreferredWidth { get; set; }
|
||||
|
||||
[Category("Image"), DefaultValue(0), Description("Preferred thumbnail height. 0 means aspect ratio will be used to adjust height according to width.")]
|
||||
public int ThumbnailPreferredHeight { get; set; }
|
||||
|
||||
[Category("Paths"), Description("Custom capture path takes precedence over path configured in Application configuration.")]
|
||||
[Editor(typeof(DirectoryNameEditor), typeof(UITypeEditor))]
|
||||
[Category("Paths"), Description("Custom capture path takes precedence over path configured in Application configuration."),
|
||||
Editor(typeof(DirectoryNameEditor), typeof(UITypeEditor))]
|
||||
public string CapturePath { get; set; }
|
||||
|
||||
[Category("Upload"), Description("Files with these file extensions will be uploaded using image uploader.")]
|
||||
[Editor("System.Windows.Forms.Design.StringCollectionEditor,System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof(UITypeEditor))]
|
||||
[Category("Upload"), Description("Files with these file extensions will be uploaded using image uploader."),
|
||||
Editor("System.Windows.Forms.Design.StringCollectionEditor,System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof(UITypeEditor))]
|
||||
public List<string> ImageExtensions { get; set; }
|
||||
|
||||
[Category("Upload"), Description("Files with these file extensions will be uploaded using text uploader.")]
|
||||
[Editor("System.Windows.Forms.Design.StringCollectionEditor,System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof(UITypeEditor))]
|
||||
[Category("Upload"), Description("Files with these file extensions will be uploaded using text uploader."),
|
||||
Editor("System.Windows.Forms.Design.StringCollectionEditor,System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof(UITypeEditor))]
|
||||
public List<string> TextExtensions { get; set; }
|
||||
|
||||
[Category("After upload"), DefaultValue(false), Description("If result URL starts with \"http://\" then replace it with \"https://\".")]
|
||||
|
|
Loading…
Reference in a new issue