diff --git a/.vs/EZCounter/DesignTimeBuild/.dtbcache.v2 b/.vs/EZCounter/DesignTimeBuild/.dtbcache.v2 index cb4580a..3565649 100644 Binary files a/.vs/EZCounter/DesignTimeBuild/.dtbcache.v2 and b/.vs/EZCounter/DesignTimeBuild/.dtbcache.v2 differ diff --git a/.vs/EZCounter/v17/.futdcache.v1 b/.vs/EZCounter/v17/.futdcache.v1 new file mode 100644 index 0000000..7681d16 Binary files /dev/null and b/.vs/EZCounter/v17/.futdcache.v1 differ diff --git a/App.xaml.cs b/App.xaml.cs index 079c1cf..27f499f 100644 --- a/App.xaml.cs +++ b/App.xaml.cs @@ -20,9 +20,14 @@ public partial class App : Application public App() { - string placementFile = Path.Combine( - Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "EZCounter"), - "placement.config"); + string Storage = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "EZCounter"); + + string placementFile = Path.Combine(Storage, "placement.config"); + + if(!Directory.Exists(Path.Combine(Storage, "Sounds"))) + { + Directory.CreateDirectory(Path.Combine(Storage, "Sounds")); + } WindowPlace = new WindowPlace(placementFile); } diff --git a/Custom.cs b/Custom.cs index 65ad3ed..efd68eb 100644 --- a/Custom.cs +++ b/Custom.cs @@ -3,6 +3,12 @@ using System.Windows; using System.Windows.Data; using System.Windows.Input; +using System.Media; +using System.Windows.Media; +using ImaginaryNarwhal; +using System.IO; +using System.Collections.ObjectModel; +using System.Collections.Generic; namespace EZCounter { @@ -83,4 +89,98 @@ public object ConvertBack(object value, Type targetType, object parameter, #endregion } + + public class TimerSounds : ICustomPropertyNotify + { + private MediaPlayer player = new MediaPlayer(); + private List _soundFiles; + private List _allSounds; + private string _selectedSound; + + public List SoundFiles + { + get => _soundFiles; + set => SetProperty(ref _soundFiles, value); + } + + public List AllSounds + { + get => _allSounds; + set => SetProperty(ref _allSounds, value); + } + + public string SelectedSound + { + get => _selectedSound; + set + { + SetProperty(ref _selectedSound, value); + if(!SelectedSound.Contains("System:")) + { + player.Close(); + player.Open(GetSoundFileFromString(value)); + } + } + } + + public TimerSounds() + { + SoundFiles = new List(); + GetSoundFiles(); + + AllSounds = new List(); + AllSounds.Add("None"); + AllSounds.Add("System: Asterisk"); + AllSounds.Add("System: Beep"); + AllSounds.Add("System: Exclamation"); + AllSounds.Add("System: Hand"); + AllSounds.Add("System: Question"); + foreach(var file in SoundFiles) + { + AllSounds.Add(Path.GetFileName(file.LocalPath)); + } + + SelectedSound = Properties.Settings.Default.timerSound; + } + + public void GetSoundFiles() + { + SoundFiles.Clear(); + + var ext = new List { "wav", "mp3", "wma" }; + + var files = Directory.EnumerateFiles(Storage.Sounds, "*.*").Where(f => ext.Contains(Path.GetExtension(f).TrimStart('.').ToLowerInvariant())).ToList(); + foreach(var file in files) + { + SoundFiles.Add(new Uri(Path.Combine(Storage.Sounds, file))); + } + } + + public Uri GetSoundFileFromString(string sound) + { + return SoundFiles.Where(x => Path.GetFileName(x.LocalPath) == sound).FirstOrDefault(); + } + + public void PlaySound() + { + switch(SelectedSound) + { + case "None": break; + case "System: Asterisk": SystemSounds.Asterisk.Play(); break; + case "System: Beep": SystemSounds.Beep.Play(); break; + case "System: Exclamation": SystemSounds.Exclamation.Play(); break; + case "System: Hand": SystemSounds.Hand.Play(); break; + case "System: Question": SystemSounds.Question.Play(); break; + default: + player.Play(); + break; + } + } + } + + public static class Storage + { + public static string Dir => Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "EZCounter"); + public static string Sounds => Path.Combine(Dir, "Sounds"); + } } diff --git a/EZCounter.csproj b/EZCounter.csproj index 5c90c98..822756e 100644 --- a/EZCounter.csproj +++ b/EZCounter.csproj @@ -6,6 +6,7 @@ true + 1.3.0 diff --git a/Properties/Settings.Designer.cs b/Properties/Settings.Designer.cs index 813a52f..0087f2f 100644 --- a/Properties/Settings.Designer.cs +++ b/Properties/Settings.Designer.cs @@ -12,7 +12,7 @@ namespace EZCounter.Properties { [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.0.1.0")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.0.2.0")] internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); @@ -82,5 +82,17 @@ public bool listOpen { this["listOpen"] = value; } } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("None")] + public string timerSound { + get { + return ((string)(this["timerSound"])); + } + set { + this["timerSound"] = value; + } + } } } diff --git a/Properties/Settings.settings b/Properties/Settings.settings index 0076cf0..d640bd4 100644 --- a/Properties/Settings.settings +++ b/Properties/Settings.settings @@ -17,5 +17,8 @@ True + + None + \ No newline at end of file diff --git a/ViewModels/MainViewModel.cs b/ViewModels/MainViewModel.cs index 1b1c13d..d1537c5 100644 --- a/ViewModels/MainViewModel.cs +++ b/ViewModels/MainViewModel.cs @@ -14,6 +14,8 @@ namespace EZCounter.ViewModels { public class MainViewModel : ICustomPropertyNotify { + public TimerSounds Sounds { get; set; } + public readonly dbContext db; private Timer cTimer; private decimal currentTime = 0; @@ -53,6 +55,7 @@ public MainViewModel() cTimer.Elapsed += new ElapsedEventHandler(OnTimerEVent); cTimer.Interval = 1000; TimerCounter = 0; + Sounds = new TimerSounds(); } private void OnTimerEVent(object sender, ElapsedEventArgs e) @@ -64,7 +67,10 @@ private void OnTimerEVent(object sender, ElapsedEventArgs e) if (currentTime == maxTime) { + var sounds = new TimerSounds(); TimerCounter = 100; + cTimer.Stop(); + sounds.PlaySound(); } else { diff --git a/Views/MainView.xaml b/Views/MainView.xaml index 6fe98e9..4b331a3 100644 --- a/Views/MainView.xaml +++ b/Views/MainView.xaml @@ -10,7 +10,7 @@ Topmost="True" Background="#121212" Height="65" Width="240" Name="TehWindow" ResizeMode="NoResize" WindowStyle="None" MouseDown="Window_MouseDown" - Loaded="Window_Loaded" LocationChanged="Moving" Closing="OnClose"> + Loaded="Window_Loaded" LocationChanged="Moving" Closing="OnClose" >