diff --git a/.gitignore b/.gitignore index 990e547..a6d3a11 100644 --- a/.gitignore +++ b/.gitignore @@ -12,6 +12,7 @@ obj/ *.user *.userosscache *.sln.docstates +*GPUCache/ # User-specific files (MonoDevelop/Xamarin Studio) *.userprefs diff --git a/src/DesktopMagic.Installer/DesktopMagic-Installer.exe b/src/DesktopMagic.Installer/DesktopMagic-Installer.exe index 00227d6..02ef4f5 100644 Binary files a/src/DesktopMagic.Installer/DesktopMagic-Installer.exe and b/src/DesktopMagic.Installer/DesktopMagic-Installer.exe differ diff --git a/src/DesktopMagic.Installer/Installer.iss b/src/DesktopMagic.Installer/Installer.iss index 3315a4f..14855d5 100644 --- a/src/DesktopMagic.Installer/Installer.iss +++ b/src/DesktopMagic.Installer/Installer.iss @@ -2,7 +2,7 @@ ; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES! #define MyAppName "DesktopMagic" -#define MyAppVersion "0.0.3.0" +#define MyAppVersion "0.0.3.1" #define MyAppPublisher "Stone_Red" #define MyAppExeName "DesktopMagic.exe" diff --git a/src/DesktopMagic/App.xaml.cs b/src/DesktopMagic/App.xaml.cs index e86d738..3b2842a 100644 --- a/src/DesktopMagic/App.xaml.cs +++ b/src/DesktopMagic/App.xaml.cs @@ -3,6 +3,7 @@ using Stone_Red_Utilities.Logging; using System; +using System.IO; using System.Threading; using System.Windows; @@ -18,7 +19,7 @@ namespace DesktopMagic #if DEBUG private readonly Updater updater = new Updater(TimeSpan.FromDays(1), "https://raw.githubusercontent.com/Stone-Red-Code/DesktopMagic/develop/update/updateInfo.json"); #else - private readonly Updater updater = new Updater(TimeSpan.FromHours(1), "https://raw.githubusercontent.com/Stone-Red-Code/DesktopMagic/main/update/updateInfo.json"); + private readonly Updater updater = new Updater(TimeSpan.FromDays(1), "https://raw.githubusercontent.com/Stone-Red-Code/DesktopMagic/main/update/updateInfo.json"); #endif public const string AppName = "Desktop Magic"; @@ -33,11 +34,11 @@ namespace DesktopMagic // Try to grab mutex _mutex = new Mutex(true, $"Stone_Red{AppName}", out bool createdNew); - //check if creating new was succesfull + //check if creating new was successful if (!createdNew) { Logger.Log("Shutting down because other instance already running.", "Setup"); - //Shutdown Aplication + //Shutdown Application Current.Shutdown(); } else @@ -59,7 +60,7 @@ namespace DesktopMagic private void Updater_NoUpdateAvailible() { - Logger.Log("No update avalible.", "Updater"); + Logger.Log("No update available.", "Updater"); } private void Updater_OnException(Exception exception) @@ -104,7 +105,7 @@ namespace DesktopMagic InfoConfig = new OutputConfig() { Color = ConsoleColor.White, - LogTarget = LogTarget.Console | LogTarget.File, + LogTarget = LogTarget.DebugConsole | LogTarget.File, FilePath = logFilePath }, DebugConfig = new OutputConfig() @@ -114,9 +115,24 @@ namespace DesktopMagic }, FormatConfig = new FormatConfig() { - DebugConsoleFormat = $"> {{{LogFormatType.DateTime}:hh:mm:ss}} | {{{LogFormatType.LogSeverity},-5}} | {{{LogFormatType.Message}}}\n> at {{{LogFormatType.LineNumber},3}} | {{{LogFormatType.FilePath}}}" + DebugConsoleFormat = $"> {{{LogFormatType.DateTime}:hh:mm:ss}} | {{{LogFormatType.LogSeverity},-5}} | {{{LogFormatType.Message}}}\nat {{{LogFormatType.LineNumber}}} | {{{LogFormatType.FilePath}}}" } }; + + try + { + if (!Directory.Exists(ApplicationDataPath)) + { + _ = Directory.CreateDirectory(ApplicationDataPath); + } + Logger.Log("Created ApplicationData Folder", "Main"); + } + catch (Exception ex) + { + Logger.Log(ex.Message, "Setup", LogSeverity.Error); + _ = MessageBox.Show(ex.ToString()); + } + Logger.ClearLogFile(LogSeverity.Info); Logger.Log("Log setup complete.", "Setup"); } diff --git a/src/DesktopMagic/CpuUsageWindow.xaml b/src/DesktopMagic/BuiltInWindowElements/CpuUsageWindow.xaml similarity index 58% rename from src/DesktopMagic/CpuUsageWindow.xaml rename to src/DesktopMagic/BuiltInWindowElements/CpuUsageWindow.xaml index d326c01..a1b19b6 100644 --- a/src/DesktopMagic/CpuUsageWindow.xaml +++ b/src/DesktopMagic/BuiltInWindowElements/CpuUsageWindow.xaml @@ -14,8 +14,15 @@ x:Name="window"> - - + + + + + + + + + diff --git a/src/DesktopMagic/CpuUsageWindow.xaml.cs b/src/DesktopMagic/BuiltInWindowElements/CpuUsageWindow.xaml.cs similarity index 65% rename from src/DesktopMagic/CpuUsageWindow.xaml.cs rename to src/DesktopMagic/BuiltInWindowElements/CpuUsageWindow.xaml.cs index d5afd15..db0dcce 100644 --- a/src/DesktopMagic/CpuUsageWindow.xaml.cs +++ b/src/DesktopMagic/BuiltInWindowElements/CpuUsageWindow.xaml.cs @@ -1,4 +1,6 @@ -using Microsoft.Win32; +using DesktopMagic.Helpers; + +using Microsoft.Win32; using System; using System.Diagnostics; @@ -6,12 +8,10 @@ using System.Timers; using System.Windows; using System.Windows.Interop; using System.Windows.Media; +using System.Windows.Threading; namespace DesktopMagic { - /// - /// Interaktionslogik für TimeWindow.xaml - /// public partial class CpuUsageWindow : Window { private RegistryKey key; @@ -41,7 +41,7 @@ namespace DesktopMagic Timer t = new Timer(); t.Interval = 100; - t.Elapsed += T_Elapsed; + t.Elapsed += UpdateTimer_Elapsed; t.Start(); Timer valueTimer = new Timer(); @@ -68,23 +68,37 @@ namespace DesktopMagic WindowPos.GetWindowLong(helper.Handle, WindowPos.GWL_EXSTYLE) | WindowPos.WS_EX_NOACTIVATE); } - private void T_Elapsed(object sender, ElapsedEventArgs e) + private void UpdateTimer_Elapsed(object sender, ElapsedEventArgs e) { Dispatcher.Invoke(() => { if (MainWindow.EditMode) { panel.Visibility = Visibility.Visible; + tileBar.CaptionHeight = tileBar.CaptionHeight = ActualHeight - 10 < 0 ? 0 : ActualHeight - 10; WindowPos.SetIsLocked(this, false); + ResizeMode = ResizeMode.CanResize; } else { panel.Visibility = Visibility.Collapsed; + tileBar.CaptionHeight = 0; WindowPos.SetIsLocked(this, true); + ResizeMode = ResizeMode.NoResize; } - textBlock.FontFamily = new FontFamily(MainWindow.GlobalFont); - textBlock.Foreground = MainWindow.GlobalColor; + rectangleGeometry.Rect = new Rect(0, 0, border.ActualWidth, border.ActualHeight); + border.Background = MainWindow.Theme.BackgroundBrush; + border.CornerRadius = new CornerRadius(MainWindow.Theme.CornerRadius); + viewBox.Margin = new Thickness(MainWindow.Theme.Margin); + border.Width = viewBox.ActualWidth + MainWindow.Theme.Margin * 2; + border.Height = viewBox.ActualHeight + MainWindow.Theme.Margin * 2; + textBlock.FontFamily = new FontFamily(MainWindow.Theme.Font); + textBlock.Foreground = MainWindow.Theme.PrimaryBrush; + valueTextBlock.FontFamily = new FontFamily(MainWindow.Theme.Font); + valueTextBlock.Foreground = MainWindow.Theme.PrimaryBrush; + + ClculateWidth(); }); } @@ -93,13 +107,24 @@ namespace DesktopMagic string cpuUsage = GetCpuUsage(); Dispatcher.Invoke(() => { - textBlock.Text = cpuUsage; + valueTextBlock.Text = cpuUsage; }); } + private void ClculateWidth() + { + string template = "CPU: ###%"; + double lenght = 0; + for (int i = 0; i < 9; i++) + { + lenght = Math.Max(StringUtilities.MeasureString(template.Replace('#', i.ToString()[0]), textBlock).Width, lenght); + } + dockPanel.Width = lenght; + } + private string GetCpuUsage() { - return "CPU: " + ((int)cpuCounter.NextValue()).ToString().PadLeft(3, '0') + "%"; + return $"{(int)cpuCounter.NextValue()}%"; } private void Window_LocationChanged(object sender, EventArgs e) diff --git a/src/DesktopMagic/BuiltInWindowElements/DatePlugin.cs b/src/DesktopMagic/BuiltInWindowElements/DatePlugin.cs new file mode 100644 index 0000000..06d6a57 --- /dev/null +++ b/src/DesktopMagic/BuiltInWindowElements/DatePlugin.cs @@ -0,0 +1,50 @@ +using DesktopMagicPluginAPI; + +using System; +using System.Drawing; +using System.Drawing.Text; + +namespace DesktopMagic.BuiltInWindowElements +{ + internal class DatePlugin : Plugin + { + public override int UpdateInterval => 1000; + + private DateTime oldDateTime = new DateTime(); + private Color oldColor = Color.White; + private string oldFont; + + public override Bitmap Main() + { + if (oldDateTime.Date == DateTime.Now.Date && oldColor == Application.Theme.PrimaryColor && oldFont == Application.Theme.Font) + { + return null; + } + + oldDateTime = DateTime.Now; + oldColor = Application.Theme.PrimaryColor; + oldFont = Application.Theme.Font; + + string date = DateTime.Now.ToLongDateString(); + + Font font = new Font(Application.Theme.Font, 200); + + Bitmap bmp = new Bitmap(1, 1); + bmp.SetResolution(100, 100); + using Graphics tmpGr = Graphics.FromImage(bmp); + tmpGr.TextRenderingHint = TextRenderingHint.AntiAlias; + + SizeF size = tmpGr.MeasureString(date, font); + + bmp = new Bitmap((int)size.Width, (int)size.Height); + bmp.SetResolution(100, 100); + + using Graphics gr = Graphics.FromImage(bmp); + + gr.TextRenderingHint = TextRenderingHint.AntiAlias; + gr.DrawString(date, font, new SolidBrush(Application.Theme.PrimaryColor), 0, 0); + + return bmp; + } + } +} \ No newline at end of file diff --git a/src/DesktopMagic/MusicVisualizerWindow.xaml.cs b/src/DesktopMagic/BuiltInWindowElements/MusicVisualizerPlugin.cs similarity index 57% rename from src/DesktopMagic/MusicVisualizerWindow.xaml.cs rename to src/DesktopMagic/BuiltInWindowElements/MusicVisualizerPlugin.cs index 8bb8ab9..79c8ad4 100644 --- a/src/DesktopMagic/MusicVisualizerWindow.xaml.cs +++ b/src/DesktopMagic/BuiltInWindowElements/MusicVisualizerPlugin.cs @@ -1,111 +1,33 @@ -using Microsoft.Win32; +using DesktopMagicPluginAPI; using NAudio.Wave; using System; using System.Collections.Generic; -using System.Diagnostics; using System.Drawing; -using System.Drawing.Drawing2D; -using System.Drawing.Imaging; using System.Linq; -using System.Runtime.InteropServices; -using System.Timers; -using System.Windows; -using System.Windows.Interop; -using System.Windows.Media.Imaging; -using System.Windows.Threading; -namespace DesktopMagic +namespace DesktopMagic.BuiltInWindowElements { - public partial class MusicVisualizerWindow : Window + internal class MusicVisualizerPlugin : Plugin { - [DllImport("user32.dll")] - private static extern void SetParent(IntPtr hWndChild, IntPtr hWndNewParent); - - private readonly RegistryKey key; - private readonly IWaveIn waveIn; + private IWaveIn waveIn; private const int fftLength = 1024; // NAudio fft wants powers of two! private readonly SampleAggregator sampleAggregator = new SampleAggregator(fftLength); private volatile bool calculate = true; + private Bitmap output = new Bitmap(880, 300); - public MusicVisualizerWindow() + public override int UpdateInterval => 0; + + public override void Start() { - InitializeComponent(); - - Window w = new() - { - Top = -100, - Left = -100, - Width = 0, - Height = 0, - WindowStyle = WindowStyle.ToolWindow, - ShowInTaskbar = false - }; - - w.Show(); - Owner = w; - w.Hide(); - - sampleAggregator.FftCalculated += new EventHandler(FftCalculated); + sampleAggregator.FftCalculated += FftCalculated; sampleAggregator.PerformFFT = true; waveIn = new WasapiLoopbackCapture(); waveIn.DataAvailable += OnDataAvailable; waveIn.StartRecording(); - - Timer t = new Timer(); - t.Interval = 100; - t.Elapsed += T_Elapsed; - t.Start(); - - key = Registry.CurrentUser.CreateSubKey(@"Software\" + App.AppName); - - Top = double.Parse(key.GetValue("MusicVisualizerWindowTop", 100).ToString()); - - Left = double.Parse(key.GetValue("MusicVisualizerWindowLeft", 100).ToString()); - - Height = double.Parse(key.GetValue("MusicVisualizerWindowHeight", 200).ToString()); - - Width = double.Parse(key.GetValue("MusicVisualizerWindowWidth", 500).ToString()); - - IsEnabled = false; - } - - protected override void OnSourceInitialized(EventArgs e) - { - base.OnSourceInitialized(e); - - //Set the window style to noactivate. - WindowInteropHelper helper = new WindowInteropHelper(this); - WindowPos.SetWindowLong(helper.Handle, WindowPos.GWL_EXSTYLE, - WindowPos.GetWindowLong(helper.Handle, WindowPos.GWL_EXSTYLE) | WindowPos.WS_EX_NOACTIVATE); - } - - private void T_Elapsed(object sender, ElapsedEventArgs e) - { - Dispatcher.Invoke(() => - { - if (MainWindow.EditMode) - { - panel.Visibility = Visibility.Visible; - WindowPos.SetIsLocked(this, false); - } - else - { - panel.Visibility = Visibility.Collapsed; - WindowPos.SetIsLocked(this, true); - } - if (!IsLoaded) - { - calculate = false; - } - else - { - calculate = true; - } - }); } private void OnDataAvailable(object sender, WaveInEventArgs e) @@ -134,7 +56,7 @@ namespace DesktopMagic } List fft = new List(); - for (int i = 0; i < e.Result.Length / 2 - 70; i++) + for (int i = 0; i < (e.Result.Length / 2) - 70; i++) { int v = i; if (v < 20) @@ -142,7 +64,7 @@ namespace DesktopMagic v = 20; } - int multiplier = 100 - MainWindow.AmplifierLevel * 2; + int multiplier = 100 - (MainWindow.AmplifierLevel * 2); multiplier = multiplier == 0 ? 1 : multiplier; fft.Add(Math.Abs(e.Result[i].Y * v / multiplier)); } @@ -173,7 +95,7 @@ namespace DesktopMagic { double temp = 0; int j; - for (j = i * count; j < count + i * count; j++) + for (j = i * count; j < count + (i * count); j++) { temp += fft[j]; } @@ -227,9 +149,6 @@ namespace DesktopMagic lastFft = fft; try { - Stopwatch sw = new Stopwatch(); - sw.Start(); - Bitmap bm = new Bitmap(885, 300); int offset = 0; if (!MainWindow.MirrorMode && MainWindow.SpectrumMode != 1) @@ -242,9 +161,9 @@ namespace DesktopMagic offset = 1; } - using (Graphics gr = Graphics.FromImage(bm)) + using (Graphics gr = Graphics.FromImage(output)) { - gr.SmoothingMode = SmoothingMode.None; + gr.Clear(Color.Transparent); PointF[] points = new PointF[scaledFft.Count + 2]; int fftIndex = 0; @@ -264,8 +183,8 @@ namespace DesktopMagic if (!fftIndexReverse) { - points[pointIndex + 1] = new PointF(bm.Width - 4 * pointIndex, bm.Height / 2 + value); - points[points.Length / 2 + pointIndex + 1] = new PointF(bm.Width - 4 * pointIndex, bm.Height / 2 - value); + points[pointIndex + 1] = new PointF(output.Width - (4 * pointIndex), (output.Height / 2) + value); + points[(points.Length / 2) + pointIndex + 1] = new PointF(output.Width - (4 * pointIndex), (output.Height / 2) - value); } break; @@ -274,7 +193,7 @@ namespace DesktopMagic break; default: - points[pointIndex + 1] = new PointF(2 * pointIndex, bm.Height - value - 1 + offset); + points[pointIndex + 1] = new PointF(2 * pointIndex, output.Height - value - 1 + offset); break; } @@ -296,17 +215,11 @@ namespace DesktopMagic } } - SetPoints(points, bm.Width, bm.Height, offset); + SetPoints(points, output.Width, output.Height, offset); - Brush brush; - if (MainWindow.MusicVisualzerColor == null) - { - brush = MainWindow.GlobalSystemColor; - } - else - { - brush = MainWindow.MusicVisualzerColor; - } + Brush brush = MainWindow.MusicVisualzerColor.HasValue + ? new SolidBrush(MainWindow.MusicVisualzerColor.Value) + : new SolidBrush(MainWindow.Theme.PrimaryColor); if (MainWindow.LineMode) { @@ -326,10 +239,7 @@ namespace DesktopMagic } } - Dispatcher.BeginInvoke((Action)delegate - { - image.Source = BitmapToImageSource(bm); - }); + Application.UpdateWindow(); } catch { } } @@ -340,51 +250,33 @@ namespace DesktopMagic { case 1: points[0] = new PointF(width, height / 2); - points[points.Length - 1] = new PointF(0, height / 2); + points[^1] = new PointF(0, height / 2); points[points.Length / 2] = new PointF(width, height / 2); - points[points.Length / 2 - 1] = new PointF(0, height / 2); + points[(points.Length / 2) - 1] = new PointF(0, height / 2); break; case 2: points[0] = new PointF(0, 0 - offset); - points[points.Length - 1] = new PointF(points[points.Length - 2].X, 0 - offset); + points[^1] = new PointF(points[^2].X, 0 - offset); break; default: points[0] = new PointF(0, height); - points[points.Length - 1] = new PointF(points[points.Length - 2].X, height); + points[^1] = new PointF(points[^2].X, height); break; } } - private BitmapSource BitmapToImageSource(Bitmap bitmap) + public override Bitmap Main() { - BitmapData bitmapData = bitmap.LockBits( - new Rectangle(0, 0, bitmap.Width, bitmap.Height), - ImageLockMode.ReadOnly, bitmap.PixelFormat); - - BitmapSource bitmapSource = BitmapSource.Create( - bitmapData.Width, bitmapData.Height, - bitmap.HorizontalResolution, bitmap.VerticalResolution, - System.Windows.Media.PixelFormats.Bgra32, null, - bitmapData.Scan0, bitmapData.Stride * bitmapData.Height, bitmapData.Stride); - - bitmap.UnlockBits(bitmapData); - return bitmapSource; + return output; } - private void Window_LocationChanged(object sender, EventArgs e) + public override void Stop() { - key.SetValue("MusicVisualizerWindowTop", this.Top); - key.SetValue("MusicVisualizerWindowLeft", this.Left); - } - - private void Window_SizeChanged(object sender, SizeChangedEventArgs e) - { - key.SetValue("MusicVisualizerWindowHeight", Height); - key.SetValue("MusicVisualizerWindowWidth", Width); - tileBar.CaptionHeight = ActualHeight - 10; + calculate = false; + waveIn?.StopRecording(); } } } \ No newline at end of file diff --git a/src/DesktopMagic/BuiltInWindowElements/TimePlugin.cs b/src/DesktopMagic/BuiltInWindowElements/TimePlugin.cs new file mode 100644 index 0000000..1cf8fa8 --- /dev/null +++ b/src/DesktopMagic/BuiltInWindowElements/TimePlugin.cs @@ -0,0 +1,55 @@ +using DesktopMagicPluginAPI; +using DesktopMagicPluginAPI.Drawing; +using DesktopMagicPluginAPI.Inputs; + +using System; +using System.Drawing; +using System.Drawing.Text; + +namespace DesktopMagic.BuiltInWindowElements +{ + internal class TimePlugin : Plugin + { + [Element("Display Seconds:")] + private CheckBox checkBox = new CheckBox(true); + + public override int UpdateInterval => 1000; + + public override Bitmap Main() + { + string time = checkBox.Value ? DateTime.Now.ToLongTimeString() : DateTime.Now.ToShortTimeString(); + + Font font = new Font(Application.Theme.Font, 200); + + Bitmap bmp = new Bitmap(1, 1); + using Graphics tmpGr = Graphics.FromImage(bmp); + tmpGr.TextRenderingHint = TextRenderingHint.AntiAlias; + + SizeF size = CalculateSize(tmpGr, font); + + bmp = new Bitmap((int)size.Width, (int)size.Height); + bmp.SetResolution(100, 100); + + using Graphics gr = Graphics.FromImage(bmp); + + gr.TextRenderingHint = TextRenderingHint.AntiAlias; + gr.DrawStringNoLeftPadding(time, font, new SolidBrush(Application.Theme.PrimaryColor), 0, 0); + + return bmp; + } + + private SizeF CalculateSize(Graphics graphics, Font font) + { + string template = checkBox.Value ? "##:##:##" : "##:##"; + SizeF size = new SizeF(); + for (int i = 0; i < 9; i++) + { + SizeF newSize = graphics.MeasureStringNoLeftPadding(template.Replace("#", i.ToString()), font); + + size.Width = Math.Max(size.Width, newSize.Width); + size.Height = Math.Max(size.Height, newSize.Height); + } + return size; + } + } +} \ No newline at end of file diff --git a/src/DesktopMagic/CalendarManagment.cs b/src/DesktopMagic/CalendarManagment.cs deleted file mode 100644 index 6a59223..0000000 --- a/src/DesktopMagic/CalendarManagment.cs +++ /dev/null @@ -1,91 +0,0 @@ -using Google.Apis.Auth.OAuth2; -using Google.Apis.Calendar.v3; -using Google.Apis.Calendar.v3.Data; -using Google.Apis.Services; -using Google.Apis.Util.Store; - -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.IO; -using System.Threading; - -namespace DesktopMagic -{ - internal class CalendarManagment - { - private static string[] Scopes = { CalendarService.Scope.CalendarReadonly }; - - private static string ApplicationName = "Google Calendar API .NET " + App.AppName; - - [Obsolete] - public (List, List) GetEvents() - { - List upcomingEventNames = new List(); - List upcomingEventTimes = new List(); - UserCredential credential; - - if (!File.Exists("credentials.json")) - { - return (new(), new()); - } - - using (FileStream stream = new FileStream("credentials.json", FileMode.Open, FileAccess.Read)) - { - // The file token.json stores the user's access and refresh tokens, and is created - // automatically when the authorization flow completes for the first time. - string credPath = "token.json"; - credential = GoogleWebAuthorizationBroker.AuthorizeAsync( - GoogleClientSecrets.Load(stream).Secrets, - Scopes, - "user", - CancellationToken.None, - new FileDataStore(credPath, true)).Result; - Debug.WriteLine("Credential file saved to: " + credPath); - } - - // Create Google Calendar API service. - CalendarService service = new CalendarService(new BaseClientService.Initializer() - { - HttpClientInitializer = credential, - ApplicationName = ApplicationName, - }); - - // Define parameters of request. - EventsResource.ListRequest request = service.Events.List("primary"); - request.TimeMin = DateTime.Now; - request.ShowDeleted = false; - request.SingleEvents = true; - request.MaxResults = 10; - request.OrderBy = EventsResource.ListRequest.OrderByEnum.StartTime; - - // List events. - Events events = request.Execute(); - if (events.Items != null && events.Items.Count > 0) - { - foreach (Event eventItem in events.Items) - { - if (upcomingEventNames.Count < 10) - { - string when = eventItem.Start.DateTime.ToString(); - if (string.IsNullOrEmpty(when)) - { - when = eventItem.Start.Date; - } - upcomingEventNames.Add(eventItem.Summary); - upcomingEventTimes.Add(when); - } - } - } - return (upcomingEventNames, upcomingEventTimes); - } - } - - internal class CalendarItems - { - public string eventname { get; set; } - public string dateTime { get; set; } - public string font { get; set; } - public string color { get; set; } - } -} \ No newline at end of file diff --git a/src/DesktopMagic/CalendarWindow.xaml b/src/DesktopMagic/CalendarWindow.xaml deleted file mode 100644 index 27c433c..0000000 --- a/src/DesktopMagic/CalendarWindow.xaml +++ /dev/null @@ -1,38 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/DesktopMagic/CalendarWindow.xaml.cs b/src/DesktopMagic/CalendarWindow.xaml.cs deleted file mode 100644 index 21fc554..0000000 --- a/src/DesktopMagic/CalendarWindow.xaml.cs +++ /dev/null @@ -1,159 +0,0 @@ -using Microsoft.Win32; - -using System; -using System.Collections.Generic; -using System.Threading.Tasks; -using System.Timers; -using System.Windows; -using System.Windows.Interop; -using System.Windows.Media; - -namespace DesktopMagic -{ - /// - /// Interaktionslogik für TimeWindow.xaml - /// - public partial class CalendarWindow : Window - { - private RegistryKey key; - private string oldFont = ""; - private Brush oldColor; - private List upcomingEventNames = new List(); - private List upcomingEventTimes = new List(); - - public CalendarWindow() - { - InitializeComponent(); - - Window w = new Window(); - w.Top = -100; - w.Left = -100; - w.Width = 0; - w.Height = 0; - - w.WindowStyle = WindowStyle.ToolWindow; - w.ShowInTaskbar = false; - w.Show(); - Owner = w; - w.Hide(); - - Timer t = new Timer(); - t.Interval = 100; - t.Elapsed += T_Elapsed; - t.Start(); - - Timer valueTimer = new Timer(); - valueTimer.Interval = 600000; - valueTimer.Elapsed += ValueTimer_Elapsed; - ; - valueTimer.Start(); - - key = Registry.CurrentUser.CreateSubKey(@"Software\" + App.AppName); - Top = double.Parse(key.GetValue("CalendarWindowTop", 100).ToString()); - Left = double.Parse(key.GetValue("CalendarWindowLeft", 100).ToString()); - Height = double.Parse(key.GetValue("CalendarWindowHeight", 200).ToString()); - Width = double.Parse(key.GetValue("CalendarWindowWidth", 500).ToString()); - //this.IsEnabled = false; - - Task.Run(() => - { - (upcomingEventNames, upcomingEventTimes) = new CalendarManagment().GetEvents(); - Dispatcher.Invoke(() => - { - LoadEvents(); - }); - }); - } - - protected override void OnSourceInitialized(EventArgs e) - { - base.OnSourceInitialized(e); - - //Set the window style to noactivate. - WindowInteropHelper helper = new WindowInteropHelper(this); - WindowPos.SetWindowLong(helper.Handle, WindowPos.GWL_EXSTYLE, - WindowPos.GetWindowLong(helper.Handle, WindowPos.GWL_EXSTYLE) | WindowPos.WS_EX_NOACTIVATE); - } - - private void ValueTimer_Elapsed(object sender, ElapsedEventArgs e) - { - Task.Run(() => - { - (upcomingEventNames, upcomingEventTimes) = new CalendarManagment().GetEvents(); - Dispatcher.Invoke(() => - { - LoadEvents(); - }); - }); - } - - private void T_Elapsed(object sender, ElapsedEventArgs e) - { - Dispatcher.Invoke(() => - { - if (MainWindow.EditMode) - { - panel.Visibility = Visibility.Visible; - WindowPos.SetIsLocked(this, false); - } - else - { - panel.Visibility = Visibility.Collapsed; - WindowPos.SetIsLocked(this, true); - } - if (MainWindow.GlobalFont != oldFont || MainWindow.GlobalColor != oldColor) - { - oldColor = MainWindow.GlobalColor; - oldFont = MainWindow.GlobalFont; - LoadEvents(); - } - listBox.SelectedIndex = -1; - }); - } - - private void LoadEvents() - { - listBox.Items.Clear(); - CalendarItems calendarItem = new CalendarItems(); - calendarItem.eventname = "Termine: "; - calendarItem.font = MainWindow.GlobalFont; - calendarItem.color = MainWindow.GlobalColor.ToString(); - listBox.Items.Add(calendarItem); - - for (int i = 0; i < upcomingEventNames.Count; i++) - { - DateTime dateTime = DateTime.Now; - DateTime.TryParse(upcomingEventTimes[i], out dateTime); - - calendarItem = new CalendarItems(); - calendarItem.eventname = upcomingEventNames[i]; - calendarItem.dateTime = dateTime.ToString("dd-MM-yyyy"); - calendarItem.font = MainWindow.GlobalFont; - calendarItem.color = MainWindow.GlobalColor.ToString(); - - if (dateTime < DateTime.Today.AddMonths(12) || upcomingEventTimes[i] == "-") - { - listBox.Items.Add(calendarItem); - } - } - - while (listBox.Items.Count < 10) - { - listBox.Items.Add(""); - } - } - - private void Window_LocationChanged(object sender, EventArgs e) - { - key.SetValue("CalendarWindowTop", Top); - key.SetValue("CalendarWindowLeft", Left); - } - - private void Window_SizeChanged(object sender, SizeChangedEventArgs e) - { - key.SetValue("CalendarWindowHeight", Height); - key.SetValue("CalendarWindowWidth", Width); - tileBar.CaptionHeight = ActualHeight - 10; - } - } -} \ No newline at end of file diff --git a/src/DesktopMagic/DateWindow.xaml b/src/DesktopMagic/DateWindow.xaml deleted file mode 100644 index 74d72b4..0000000 --- a/src/DesktopMagic/DateWindow.xaml +++ /dev/null @@ -1,23 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/src/DesktopMagic/DateWindow.xaml.cs b/src/DesktopMagic/DateWindow.xaml.cs deleted file mode 100644 index ad58d75..0000000 --- a/src/DesktopMagic/DateWindow.xaml.cs +++ /dev/null @@ -1,90 +0,0 @@ -using Microsoft.Win32; - -using System; -using System.Timers; -using System.Windows; -using System.Windows.Interop; -using System.Windows.Media; - -namespace DesktopMagic -{ - /// - /// Interaktionslogik für TimeWindow.xaml - /// - public partial class DateWindow : Window - { - private RegistryKey key; - - public DateWindow() - { - InitializeComponent(); - - Window w = new Window(); - w.Top = -100; - w.Left = -100; - w.Width = 0; - w.Height = 0; - - w.WindowStyle = WindowStyle.ToolWindow; - w.ShowInTaskbar = false; - w.Show(); - Owner = w; - w.Hide(); - - Timer t = new Timer(); - t.Interval = 100; - t.Elapsed += T_Elapsed; - t.Start(); - - key = Registry.CurrentUser.CreateSubKey(@"Software\" + App.AppName); - Top = double.Parse(key.GetValue("DateWindowTop", 100).ToString()); - Left = double.Parse(key.GetValue("DateWindowLeft", 100).ToString()); - Height = double.Parse(key.GetValue("DateWindowHeight", 200).ToString()); - Width = double.Parse(key.GetValue("DateWindowWidth", 500).ToString()); - IsEnabled = false; - } - - protected override void OnSourceInitialized(EventArgs e) - { - base.OnSourceInitialized(e); - - //Set the window style to noactivate. - WindowInteropHelper helper = new WindowInteropHelper(this); - WindowPos.SetWindowLong(helper.Handle, WindowPos.GWL_EXSTYLE, - WindowPos.GetWindowLong(helper.Handle, WindowPos.GWL_EXSTYLE) | WindowPos.WS_EX_NOACTIVATE); - } - - private void T_Elapsed(object sender, ElapsedEventArgs e) - { - Dispatcher.Invoke(() => - { - if (MainWindow.EditMode) - { - panel.Visibility = Visibility.Visible; - WindowPos.SetIsLocked(this, false); - } - else - { - panel.Visibility = Visibility.Collapsed; - WindowPos.SetIsLocked(this, true); - } - textBlock.FontFamily = new FontFamily(MainWindow.GlobalFont); - textBlock.Foreground = MainWindow.GlobalColor; - textBlock.Text = DateTime.Now.ToString("D"); - }); - } - - private void Window_LocationChanged(object sender, EventArgs e) - { - key.SetValue("DateWindowTop", Top); - key.SetValue("DateWindowLeft", Left); - } - - private void Window_SizeChanged(object sender, SizeChangedEventArgs e) - { - key.SetValue("DateWindowHeight", Height); - key.SetValue("DateWindowWidth", Width); - tileBar.CaptionHeight = ActualHeight - 10; - } - } -} \ No newline at end of file diff --git a/src/DesktopMagic/DesktopMagic.csproj b/src/DesktopMagic/DesktopMagic.csproj index 2e01db7..8f180ab 100644 --- a/src/DesktopMagic/DesktopMagic.csproj +++ b/src/DesktopMagic/DesktopMagic.csproj @@ -8,11 +8,11 @@ icon.ico OnBuildSuccess Stone_Red - 0.0.3.0 + 0.0.3.1 https://github.com/Stone-Red-Code/DesktopMagic https://github.com/Stone-Red-Code/DesktopMagic - 0.0.3.0 - 0.0.3.0 + 0.0.3.1 + 0.0.3.1 diff --git a/src/DesktopMagic/Dialogs/ColorDialog.xaml b/src/DesktopMagic/Dialogs/ColorDialog.xaml new file mode 100644 index 0000000..abd2ee2 --- /dev/null +++ b/src/DesktopMagic/Dialogs/ColorDialog.xaml @@ -0,0 +1,49 @@ + + + +