diff --git a/src/DesktopMagic.Installer/DesktopMagic-Installer.exe b/src/DesktopMagic.Installer/DesktopMagic-Installer.exe index a719f83..00227d6 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 c4b6638..3315a4f 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.2.2" +#define MyAppVersion "0.0.3.0" #define MyAppPublisher "Stone_Red" #define MyAppExeName "DesktopMagic.exe" diff --git a/src/DesktopMagic.sln b/src/DesktopMagic.sln index 19346aa..9bd026d 100644 --- a/src/DesktopMagic.sln +++ b/src/DesktopMagic.sln @@ -11,11 +11,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DesktopMagicPlugin.Test", " EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DesktopMagic.Installer", "DesktopMagic.Installer\DesktopMagic.Installer.csproj", "{A06BD685-7F92-4799-846B-3EC38345108E}" EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{10A138D6-41F0-4DBB-BC39-D93467B4D982}" - ProjectSection(SolutionItems) = preProject - .editorconfig = .editorconfig - EndProjectSection -EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU diff --git a/src/DesktopMagic/App.xaml.cs b/src/DesktopMagic/App.xaml.cs index 4a87422..e86d738 100644 --- a/src/DesktopMagic/App.xaml.cs +++ b/src/DesktopMagic/App.xaml.cs @@ -1,4 +1,8 @@ -using System; +using AlwaysUpToDate; + +using Stone_Red_Utilities.Logging; + +using System; using System.Threading; using System.Windows; @@ -9,30 +13,118 @@ namespace DesktopMagic /// public partial class App : Application { - private Mutex _mutex; + private readonly string logFilePath; + private readonly Mutex _mutex; +#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"); +#endif + + public const string AppName = "Desktop Magic"; + public static string ApplicationDataPath { get; } = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\" + AppName; + + public static Logger Logger { get; } = new Logger(); public App() { + logFilePath = ApplicationDataPath + "\\Log.log"; + Setup(); // Try to grab mutex - bool createdNew; - _mutex = new Mutex(true, $"Stone_Red{DesktopMagic.MainWindow.AppName}", out createdNew); + _mutex = new Mutex(true, $"Stone_Red{AppName}", out bool createdNew); //check if creating new was succesfull if (!createdNew) { + Logger.Log("Shutting down because other instance already running.", "Setup"); //Shutdown Aplication Current.Shutdown(); } else { - // Add Event handler to exit event. Exit += CloseMutexHandler; + + updater.ProgressChanged += Updater_ProgressChanged; + updater.OnException += Updater_OnException; + updater.NoUpdateAvailible += Updater_NoUpdateAvailible; + updater.UpdateAvailible += Updater_UpdateAvailible; + updater.Start(); } } - protected virtual void CloseMutexHandler(object sender, EventArgs e) + private void Updater_UpdateAvailible(string version, string additionalInformation) + { + updater.Update(); + } + + private void Updater_NoUpdateAvailible() + { + Logger.Log("No update avalible.", "Updater"); + } + + private void Updater_OnException(Exception exception) + { + Logger.Log(exception.ToString(), "Updater"); + } + + private void Updater_ProgressChanged(long? totalFileSize, long totalBytesDownloaded, double? progressPercentage) + { + Logger.Log($"{progressPercentage}% {totalBytesDownloaded}/{totalFileSize}", "Updater"); + } + + protected void CloseMutexHandler(object sender, EventArgs e) { _mutex?.Close(); } + + private void Setup() + { + AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; + + Logger.Config = new LogConfig() + { + FatalConfig = new OutputConfig() + { + Color = ConsoleColor.DarkRed, + LogTarget = LogTarget.DebugConsole | LogTarget.File, + FilePath = logFilePath + }, + ErrorConfig = new OutputConfig() + { + Color = ConsoleColor.Red, + LogTarget = LogTarget.DebugConsole | LogTarget.File, + FilePath = logFilePath + }, + WarnConfig = new OutputConfig() + { + Color = ConsoleColor.Yellow, + LogTarget = LogTarget.DebugConsole | LogTarget.File, + FilePath = logFilePath + }, + InfoConfig = new OutputConfig() + { + Color = ConsoleColor.White, + LogTarget = LogTarget.Console | LogTarget.File, + FilePath = logFilePath + }, + DebugConfig = new OutputConfig() + { + Color = ConsoleColor.Gray, + LogTarget = LogTarget.DebugConsole, + }, + FormatConfig = new FormatConfig() + { + DebugConsoleFormat = $"> {{{LogFormatType.DateTime}:hh:mm:ss}} | {{{LogFormatType.LogSeverity},-5}} | {{{LogFormatType.Message}}}\n> at {{{LogFormatType.LineNumber},3}} | {{{LogFormatType.FilePath}}}" + } + }; + Logger.ClearLogFile(LogSeverity.Info); + Logger.Log("Log setup complete.", "Setup"); + } + + private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) + { + Exception exception = (Exception)e.ExceptionObject; + Logger.Log(exception + (e.IsTerminating ? "\t Process terminating!" : ""), exception.Source, LogSeverity.Fatal); + } } } \ No newline at end of file diff --git a/src/DesktopMagic/CalendarManagment.cs b/src/DesktopMagic/CalendarManagment.cs index 63bd82b..6a59223 100644 --- a/src/DesktopMagic/CalendarManagment.cs +++ b/src/DesktopMagic/CalendarManagment.cs @@ -3,8 +3,10 @@ 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; @@ -14,21 +16,22 @@ namespace DesktopMagic { private static string[] Scopes = { CalendarService.Scope.CalendarReadonly }; - private static string ApplicationName = "Google Calendar API .NET " + MainWindow.AppName; + 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; - Console.WriteLine("1"); if (!File.Exists("credentials.json")) - return (new(), new()); - using (var stream = - new FileStream("credentials.json", FileMode.Open, FileAccess.Read)) { - Console.WriteLine("2"); + 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"; @@ -38,19 +41,16 @@ namespace DesktopMagic "user", CancellationToken.None, new FileDataStore(credPath, true)).Result; - Console.WriteLine("Credential file saved to: " + credPath); + Debug.WriteLine("Credential file saved to: " + credPath); } - Console.WriteLine("3"); // Create Google Calendar API service. - var service = new CalendarService(new BaseClientService.Initializer() + CalendarService service = new CalendarService(new BaseClientService.Initializer() { HttpClientInitializer = credential, ApplicationName = ApplicationName, }); - Console.WriteLine("4"); - // Define parameters of request. EventsResource.ListRequest request = service.Events.List("primary"); request.TimeMin = DateTime.Now; @@ -59,14 +59,11 @@ namespace DesktopMagic request.MaxResults = 10; request.OrderBy = EventsResource.ListRequest.OrderByEnum.StartTime; - Console.WriteLine("5"); // List events. Events events = request.Execute(); - Console.WriteLine("6"); - Console.WriteLine("Upcoming events:"); if (events.Items != null && events.Items.Count > 0) { - foreach (var eventItem in events.Items) + foreach (Event eventItem in events.Items) { if (upcomingEventNames.Count < 10) { @@ -80,8 +77,6 @@ namespace DesktopMagic } } } - - Console.WriteLine("7"); return (upcomingEventNames, upcomingEventTimes); } } diff --git a/src/DesktopMagic/CalendarWindow.xaml.cs b/src/DesktopMagic/CalendarWindow.xaml.cs index 4de73dc..21fc554 100644 --- a/src/DesktopMagic/CalendarWindow.xaml.cs +++ b/src/DesktopMagic/CalendarWindow.xaml.cs @@ -1,4 +1,5 @@ using Microsoft.Win32; + using System; using System.Collections.Generic; using System.Threading.Tasks; @@ -33,7 +34,7 @@ namespace DesktopMagic w.WindowStyle = WindowStyle.ToolWindow; w.ShowInTaskbar = false; w.Show(); - this.Owner = w; + Owner = w; w.Hide(); Timer t = new Timer(); @@ -43,14 +44,15 @@ namespace DesktopMagic Timer valueTimer = new Timer(); valueTimer.Interval = 600000; - valueTimer.Elapsed += ValueTimer_Elapsed; ; + valueTimer.Elapsed += ValueTimer_Elapsed; + ; valueTimer.Start(); - key = Registry.CurrentUser.CreateSubKey(@"Software\" + MainWindow.AppName); - this.Top = double.Parse(key.GetValue("CalendarWindowTop", 100).ToString()); - this.Left = double.Parse(key.GetValue("CalendarWindowLeft", 100).ToString()); - this.Height = double.Parse(key.GetValue("CalendarWindowHeight", 200).ToString()); - this.Width = double.Parse(key.GetValue("CalendarWindowWidth", 500).ToString()); + 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(() => @@ -68,7 +70,7 @@ namespace DesktopMagic base.OnSourceInitialized(e); //Set the window style to noactivate. - var helper = new WindowInteropHelper(this); + WindowInteropHelper helper = new WindowInteropHelper(this); WindowPos.SetWindowLong(helper.Handle, WindowPos.GWL_EXSTYLE, WindowPos.GetWindowLong(helper.Handle, WindowPos.GWL_EXSTYLE) | WindowPos.WS_EX_NOACTIVATE); } @@ -92,12 +94,12 @@ namespace DesktopMagic if (MainWindow.EditMode) { panel.Visibility = Visibility.Visible; - new WindowPos().SetIsLocked(this, false); + WindowPos.SetIsLocked(this, false); } else { panel.Visibility = Visibility.Collapsed; - new WindowPos().SetIsLocked(this, true); + WindowPos.SetIsLocked(this, true); } if (MainWindow.GlobalFont != oldFont || MainWindow.GlobalColor != oldColor) { @@ -143,15 +145,15 @@ namespace DesktopMagic private void Window_LocationChanged(object sender, EventArgs e) { - key.SetValue("CalendarWindowTop", this.Top); - key.SetValue("CalendarWindowLeft", this.Left); + key.SetValue("CalendarWindowTop", Top); + key.SetValue("CalendarWindowLeft", Left); } private void Window_SizeChanged(object sender, SizeChangedEventArgs e) { - key.SetValue("CalendarWindowHeight", this.Height); - key.SetValue("CalendarWindowWidth", this.Width); - tileBar.CaptionHeight = this.ActualHeight - 10; + key.SetValue("CalendarWindowHeight", Height); + key.SetValue("CalendarWindowWidth", Width); + tileBar.CaptionHeight = ActualHeight - 10; } } } \ No newline at end of file diff --git a/src/DesktopMagic/CpuUsageWindow.xaml.cs b/src/DesktopMagic/CpuUsageWindow.xaml.cs index f3dbfdd..d5afd15 100644 --- a/src/DesktopMagic/CpuUsageWindow.xaml.cs +++ b/src/DesktopMagic/CpuUsageWindow.xaml.cs @@ -1,4 +1,5 @@ using Microsoft.Win32; + using System; using System.Diagnostics; using System.Timers; @@ -31,7 +32,7 @@ namespace DesktopMagic ShowInTaskbar = false }; w.Show(); - this.Owner = w; + Owner = w; w.Hide(); cpuCounter.CategoryName = "Processor"; @@ -45,15 +46,16 @@ namespace DesktopMagic Timer valueTimer = new Timer(); valueTimer.Interval = 1000; - valueTimer.Elapsed += ValueTimer_Elapsed; ; + valueTimer.Elapsed += ValueTimer_Elapsed; + ; valueTimer.Start(); - key = Registry.CurrentUser.CreateSubKey(@"Software\" + MainWindow.AppName); - this.Top = double.Parse(key.GetValue("CpuUsageWindowTop", 100).ToString()); - this.Left = double.Parse(key.GetValue("CpuUsageWindowLeft", 100).ToString()); - this.Height = double.Parse(key.GetValue("CpuUsageWindowHeight", 200).ToString()); - this.Width = double.Parse(key.GetValue("CpuUsageWindowWidth", 500).ToString()); - this.IsEnabled = false; + key = Registry.CurrentUser.CreateSubKey(@"Software\" + App.AppName); + Top = double.Parse(key.GetValue("CpuUsageWindowTop", 100).ToString()); + Left = double.Parse(key.GetValue("CpuUsageWindowLeft", 100).ToString()); + Height = double.Parse(key.GetValue("CpuUsageWindowHeight", 200).ToString()); + Width = double.Parse(key.GetValue("CpuUsageWindowWidth", 500).ToString()); + IsEnabled = false; } protected override void OnSourceInitialized(EventArgs e) @@ -61,7 +63,7 @@ namespace DesktopMagic base.OnSourceInitialized(e); //Set the window style to noactivate. - var helper = new WindowInteropHelper(this); + WindowInteropHelper helper = new WindowInteropHelper(this); WindowPos.SetWindowLong(helper.Handle, WindowPos.GWL_EXSTYLE, WindowPos.GetWindowLong(helper.Handle, WindowPos.GWL_EXSTYLE) | WindowPos.WS_EX_NOACTIVATE); } @@ -73,12 +75,12 @@ namespace DesktopMagic if (MainWindow.EditMode) { panel.Visibility = Visibility.Visible; - new WindowPos().SetIsLocked(this, false); + WindowPos.SetIsLocked(this, false); } else { panel.Visibility = Visibility.Collapsed; - new WindowPos().SetIsLocked(this, true); + WindowPos.SetIsLocked(this, true); } textBlock.FontFamily = new FontFamily(MainWindow.GlobalFont); @@ -88,9 +90,10 @@ namespace DesktopMagic private void ValueTimer_Elapsed(object sender, ElapsedEventArgs e) { + string cpuUsage = GetCpuUsage(); Dispatcher.Invoke(() => { - textBlock.Text = GetCpuUsage(); + textBlock.Text = cpuUsage; }); } @@ -101,15 +104,15 @@ namespace DesktopMagic private void Window_LocationChanged(object sender, EventArgs e) { - key.SetValue("CpuUsageWindowTop", this.Top); - key.SetValue("CpuUsageWindowLeft", this.Left); + key.SetValue("CpuUsageWindowTop", Top); + key.SetValue("CpuUsageWindowLeft", Left); } private void Window_SizeChanged(object sender, SizeChangedEventArgs e) { - key.SetValue("CpuUsageWindowHeight", this.Height); - key.SetValue("CpuUsageWindowWidth", this.Width); - tileBar.CaptionHeight = this.ActualHeight - 10; + key.SetValue("CpuUsageWindowHeight", Height); + key.SetValue("CpuUsageWindowWidth", Width); + tileBar.CaptionHeight = ActualHeight - 10; } } } \ No newline at end of file diff --git a/src/DesktopMagic/DateWindow.xaml.cs b/src/DesktopMagic/DateWindow.xaml.cs index a23b581..ad58d75 100644 --- a/src/DesktopMagic/DateWindow.xaml.cs +++ b/src/DesktopMagic/DateWindow.xaml.cs @@ -1,4 +1,5 @@ using Microsoft.Win32; + using System; using System.Timers; using System.Windows; @@ -27,7 +28,7 @@ namespace DesktopMagic w.WindowStyle = WindowStyle.ToolWindow; w.ShowInTaskbar = false; w.Show(); - this.Owner = w; + Owner = w; w.Hide(); Timer t = new Timer(); @@ -35,12 +36,12 @@ namespace DesktopMagic t.Elapsed += T_Elapsed; t.Start(); - key = Registry.CurrentUser.CreateSubKey(@"Software\" + MainWindow.AppName); - this.Top = double.Parse(key.GetValue("DateWindowTop", 100).ToString()); - this.Left = double.Parse(key.GetValue("DateWindowLeft", 100).ToString()); - this.Height = double.Parse(key.GetValue("DateWindowHeight", 200).ToString()); - this.Width = double.Parse(key.GetValue("DateWindowWidth", 500).ToString()); - this.IsEnabled = false; + 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) @@ -48,7 +49,7 @@ namespace DesktopMagic base.OnSourceInitialized(e); //Set the window style to noactivate. - var helper = new WindowInteropHelper(this); + WindowInteropHelper helper = new WindowInteropHelper(this); WindowPos.SetWindowLong(helper.Handle, WindowPos.GWL_EXSTYLE, WindowPos.GetWindowLong(helper.Handle, WindowPos.GWL_EXSTYLE) | WindowPos.WS_EX_NOACTIVATE); } @@ -60,12 +61,12 @@ namespace DesktopMagic if (MainWindow.EditMode) { panel.Visibility = Visibility.Visible; - new WindowPos().SetIsLocked(this, false); + WindowPos.SetIsLocked(this, false); } else { panel.Visibility = Visibility.Collapsed; - new WindowPos().SetIsLocked(this, true); + WindowPos.SetIsLocked(this, true); } textBlock.FontFamily = new FontFamily(MainWindow.GlobalFont); textBlock.Foreground = MainWindow.GlobalColor; @@ -75,15 +76,15 @@ namespace DesktopMagic private void Window_LocationChanged(object sender, EventArgs e) { - key.SetValue("DateWindowTop", this.Top); - key.SetValue("DateWindowLeft", this.Left); + key.SetValue("DateWindowTop", Top); + key.SetValue("DateWindowLeft", Left); } private void Window_SizeChanged(object sender, SizeChangedEventArgs e) { - key.SetValue("DateWindowHeight", this.Height); - key.SetValue("DateWindowWidth", this.Width); - tileBar.CaptionHeight = this.ActualHeight - 10; + 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 836e3b8..2e01db7 100644 --- a/src/DesktopMagic/DesktopMagic.csproj +++ b/src/DesktopMagic/DesktopMagic.csproj @@ -8,9 +8,15 @@ icon.ico OnBuildSuccess Stone_Red - 0.0.2.2 + 0.0.3.0 https://github.com/Stone-Red-Code/DesktopMagic https://github.com/Stone-Red-Code/DesktopMagic + 0.0.3.0 + 0.0.3.0 + + + + DEBUG;TRACE @@ -20,12 +26,12 @@ + - - + - - + + diff --git a/src/DesktopMagic/GlobalSuppressions.cs b/src/DesktopMagic/GlobalSuppressions.cs index 7ef5263..ba7f009 100644 --- a/src/DesktopMagic/GlobalSuppressions.cs +++ b/src/DesktopMagic/GlobalSuppressions.cs @@ -6,3 +6,4 @@ using System.Diagnostics.CodeAnalysis; [assembly: SuppressMessage("Performance", "CA1822:Member als statisch markieren", Justification = "", Scope = "member", Target = "~M:DesktopMagic.PluginWindow.LoadOptions(System.Object)")] +[assembly: SuppressMessage("Style", "IDE0090:Use 'new(...)'", Justification = "", Scope = "member", Target = "~M:DesktopMagic.MainWindow.GithubButton_Click(System.Object,System.Windows.RoutedEventArgs)")] \ No newline at end of file diff --git a/src/DesktopMagic/MainWindow.xaml b/src/DesktopMagic/MainWindow.xaml index 52b8869..c73257b 100644 --- a/src/DesktopMagic/MainWindow.xaml +++ b/src/DesktopMagic/MainWindow.xaml @@ -9,9 +9,9 @@ Background="{DynamicResource MaterialDesignPaper}" FontFamily="{DynamicResource MaterialDesignFont}" Height="520" - Width="550" + Width="570" MinHeight="520" - MinWidth="500" + MinWidth="570" WindowState="Minimized" StateChanged="Window_StateChanged" Loaded="Window_Loaded"> @@ -38,14 +38,14 @@ - + - + @@ -104,15 +104,20 @@ + - +