From feba2e6f173f0c60316f36d62f3b7318a209d9e5 Mon Sep 17 00:00:00 2001 From: donlaci Date: Tue, 28 May 2024 18:21:30 +0200 Subject: [PATCH 1/7] adding logs --- src/modules/Projects/ProjectsEditor/App.xaml.cs | 4 ++++ .../ProjectsEditor/Models/Application.cs | 8 +++++--- .../Projects/ProjectsEditor/Models/Project.cs | 4 +++- .../ProjectsEditor/ProjectsEditor.csproj | 6 ++++++ .../ProjectsEditor/Utils/ProjectsEditorIO.cs | 10 +++++++++- .../ProjectsEditor/ViewModels/MainViewModel.cs | 16 +++++++++++++--- 6 files changed, 40 insertions(+), 8 deletions(-) diff --git a/src/modules/Projects/ProjectsEditor/App.xaml.cs b/src/modules/Projects/ProjectsEditor/App.xaml.cs index a4d1c608e2..6c38e5cfdf 100644 --- a/src/modules/Projects/ProjectsEditor/App.xaml.cs +++ b/src/modules/Projects/ProjectsEditor/App.xaml.cs @@ -4,6 +4,7 @@ using System; using System.Windows; +using ManagedCommon; using ProjectsEditor.Common; using ProjectsEditor.Utils; using ProjectsEditor.ViewModels; @@ -32,6 +33,8 @@ namespace ProjectsEditor private void OnStartup(object sender, StartupEventArgs e) { + Logger.InitializeLogger("\\Projects\\Logs"); + AppDomain.CurrentDomain.UnhandledException += OnUnhandledException; _themeManager = new ThemeManager(this); @@ -46,6 +49,7 @@ namespace ProjectsEditor string[] args = Environment.GetCommandLineArgs(); if (args != null && args.Length > 1) { + Logger.LogInfo($"Strated with a parameter: {args[1]}. Trying to launch that project."); _mainViewModel.LaunchProject(args[1]); return; } diff --git a/src/modules/Projects/ProjectsEditor/Models/Application.cs b/src/modules/Projects/ProjectsEditor/Models/Application.cs index 6d9cbb370f..6edd6fd365 100644 --- a/src/modules/Projects/ProjectsEditor/Models/Application.cs +++ b/src/modules/Projects/ProjectsEditor/Models/Application.cs @@ -13,6 +13,7 @@ using System.Linq; using System.Text.Json.Serialization; using System.Text.RegularExpressions; using System.Windows.Media.Imaging; +using ManagedCommon; namespace ProjectsEditor.Models { @@ -77,8 +78,9 @@ namespace ProjectsEditor.Models { _icon = Icon.ExtractAssociatedIcon(AppPath); } - catch (Exception) + catch (Exception e) { + Logger.LogError($"Exception while extracting icon from app path: {AppPath}. Exception message: {e.Message}"); _icon = new Icon(@"images\DefaultIcon.ico"); } } @@ -122,9 +124,9 @@ namespace ProjectsEditor.Models _iconBitmapImage = bitmapImage; } } - catch (Exception) + catch (Exception e) { - // todo + Logger.LogError($"Exception while drawing icon for app with path: {AppPath}. Exception message: {e.Message}"); } } diff --git a/src/modules/Projects/ProjectsEditor/Models/Project.cs b/src/modules/Projects/ProjectsEditor/Models/Project.cs index e1b4bb09b2..ca6382b13b 100644 --- a/src/modules/Projects/ProjectsEditor/Models/Project.cs +++ b/src/modules/Projects/ProjectsEditor/Models/Project.cs @@ -14,6 +14,7 @@ using System.Linq; using System.Text.Json.Serialization; using System.Threading.Tasks; using System.Windows.Media.Imaging; +using ManagedCommon; using ProjectsEditor.Utils; namespace ProjectsEditor.Models @@ -274,8 +275,9 @@ namespace ProjectsEditor.Models { graphics.DrawIcon(app.Icon, new Rectangle(32 * appIndex, 0, 24, 24)); } - catch (Exception) + catch (Exception e) { + Logger.LogError($"Exception while drawing the icon for app {Name}. Exception message: {e.Message}"); } appIndex++; diff --git a/src/modules/Projects/ProjectsEditor/ProjectsEditor.csproj b/src/modules/Projects/ProjectsEditor/ProjectsEditor.csproj index 8fe07bbcd5..36dbc4d01e 100644 --- a/src/modules/Projects/ProjectsEditor/ProjectsEditor.csproj +++ b/src/modules/Projects/ProjectsEditor/ProjectsEditor.csproj @@ -84,6 +84,12 @@ + + + + ..\..\..\common\ManagedCommon\bin\x64\Debug\net8.0-windows\PowerToys.ManagedCommon.dll + + True diff --git a/src/modules/Projects/ProjectsEditor/Utils/ProjectsEditorIO.cs b/src/modules/Projects/ProjectsEditor/Utils/ProjectsEditorIO.cs index b9fb02266d..e9e752b158 100644 --- a/src/modules/Projects/ProjectsEditor/Utils/ProjectsEditorIO.cs +++ b/src/modules/Projects/ProjectsEditor/Utils/ProjectsEditorIO.cs @@ -6,6 +6,7 @@ using System; using System.Collections.Generic; using System.IO; using System.Windows; +using ManagedCommon; using ProjectsEditor.Data; using ProjectsEditor.Models; using ProjectsEditor.ViewModels; @@ -25,12 +26,14 @@ namespace ProjectsEditor.Utils ProjectsData parser = new ProjectsData(); if (!File.Exists(parser.File)) { + Logger.LogWarning($"Projects storage file not found: {parser.File}"); return new ParsingResult(true); } ProjectsData.ProjectsListWrapper projects = parser.Read(parser.File); if (!SetProjects(mainViewModel, projects)) { + Logger.LogWarning($"Projects storage file content could not be set. Reason: {Properties.Resources.Error_Parsing_Message}"); return new ParsingResult(false, ProjectsEditor.Properties.Resources.Error_Parsing_Message); } @@ -38,6 +41,7 @@ namespace ProjectsEditor.Utils } catch (Exception e) { + Logger.LogError($"Exception while parsing storage file: {e.Message}"); return new ParsingResult(false, e.Message); } } @@ -50,12 +54,14 @@ namespace ProjectsEditor.Utils ProjectsData parser = new ProjectsData(); if (!File.Exists(fileName)) { + Logger.LogWarning($"ParseProject method. Projects storage file not found: {parser.File}"); return new ParsingResult(true); } ProjectsData.ProjectsListWrapper projects = parser.Read(fileName); if (!ExtractProject(projects, out project)) { + Logger.LogWarning($"ParseProject method. Projects storage file content could not be set. Reason: {Properties.Resources.Error_Parsing_Message}"); return new ParsingResult(false, ProjectsEditor.Properties.Resources.Error_Parsing_Message); } @@ -63,6 +69,7 @@ namespace ProjectsEditor.Utils } catch (Exception e) { + Logger.LogError($"ParseProject method. Exception while parsing storage file: {e.Message}"); return new ParsingResult(false, e.Message); } } @@ -207,9 +214,10 @@ namespace ProjectsEditor.Utils IOUtils ioUtils = new IOUtils(); ioUtils.WriteFile(serializer.File, serializer.Serialize(projectsWrapper)); } - catch (Exception) + catch (Exception e) { // TODO: show error + Logger.LogError($"Exception while writing storage file: {e.Message}"); } } diff --git a/src/modules/Projects/ProjectsEditor/ViewModels/MainViewModel.cs b/src/modules/Projects/ProjectsEditor/ViewModels/MainViewModel.cs index ba2eb62254..7f5052c2fd 100644 --- a/src/modules/Projects/ProjectsEditor/ViewModels/MainViewModel.cs +++ b/src/modules/Projects/ProjectsEditor/ViewModels/MainViewModel.cs @@ -12,6 +12,7 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; using System.Timers; +using ManagedCommon; using ProjectsEditor.Models; using ProjectsEditor.Utils; using Windows.ApplicationModel.Core; @@ -224,6 +225,7 @@ namespace ProjectsEditor.ViewModels { if (!Projects.Where(x => x.Id == projectId).Any()) { + Logger.LogWarning($"Project to launch not find. Id: {projectId}"); return; } @@ -242,12 +244,15 @@ namespace ProjectsEditor.ViewModels string launchParam = app.AppPath; if (string.IsNullOrEmpty(launchParam)) { + Logger.LogWarning($"Project launch. App path is empty. App name: {app.AppName}"); continue; } + // todo: app path might be different for packaged apps. if (actualSetup.Applications.Exists(x => x.AppPath.Equals(app.AppPath, StringComparison.Ordinal))) { // just move the existing window to the desired position + Logger.LogInfo($"Project launch. App exists. Moving the first app with same app path to the desired position. App name: {app.AppName}"); Application existingApp = actualSetup.Applications.Where(x => x.AppPath.Equals(app.AppPath, StringComparison.Ordinal)).First(); NativeMethods.ShowWindow(existingApp.Hwnd, app.Minimized ? NativeMethods.SW_MINIMIZE : NativeMethods.SW_NORMAL); if (!app.Minimized) @@ -267,9 +272,10 @@ namespace ProjectsEditor.ViewModels bool result = await Windows.System.Launcher.LaunchUriAsync(new Uri($"ms-settings:{args}")); newlyStartedApps.Add(app); } - catch (Exception) + catch (Exception e) { // todo exception handling + Logger.LogError($"Exception while launching the project {project.Id}. Tried to launch the settings app via LaunchUriAsync. Exception message: {e.Message}"); } } @@ -315,9 +321,10 @@ namespace ProjectsEditor.ViewModels started = true; } } - catch (Exception) + catch (Exception e) { // todo exception handling + Logger.LogError($"Exception while launching the project {project.Id}. Tried to launch a packaged app {app.AppName}. Exception message{e.Message}"); Thread.Sleep(100); } @@ -353,9 +360,10 @@ namespace ProjectsEditor.ViewModels }); newlyStartedApps.Add(app); } - catch (Exception) + catch (Exception e) { // todo exception handling + Logger.LogError($"Exception while launching the project {project.Id}. Tried to launch an exe via Process.Start: {app.AppName}. Exception message{e.Message}"); } } } @@ -369,6 +377,7 @@ namespace ProjectsEditor.ViewModels if (pkg == null) { + Logger.LogWarning($"Could not load any app for {packageFamilyName}."); return null; } @@ -437,6 +446,7 @@ namespace ProjectsEditor.ViewModels if (exitAfterLaunch) { + Logger.LogInfo($"Launched the project {project.Name}. Exiting."); Environment.Exit(0); } } From 24add7d4f846bfb5c323528c069653520da7d680 Mon Sep 17 00:00:00 2001 From: donlaci Date: Tue, 28 May 2024 19:43:32 +0200 Subject: [PATCH 2/7] adding dependent projects to the projects solution --- src/modules/Projects/Projects.sln | 68 +++++++++++++++++++ .../Projects/ProjectsEditor/App.xaml.cs | 4 +- .../ProjectsEditor/ProjectsEditor.csproj | 6 +- 3 files changed, 73 insertions(+), 5 deletions(-) diff --git a/src/modules/Projects/Projects.sln b/src/modules/Projects/Projects.sln index 0d3ab7d97f..02f58ed0bb 100644 --- a/src/modules/Projects/Projects.sln +++ b/src/modules/Projects/Projects.sln @@ -18,52 +18,120 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ProjectsLauncher", "Project EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ProjectsEditor", "ProjectsEditor\ProjectsEditor.csproj", "{5CCC8468-DEC8-4D36-99D4-5C891BEBD481}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ManagedCommon", "..\..\common\ManagedCommon\ManagedCommon.csproj", "{A881F6EB-6EDA-4674-A6B7-598F0A8E7048}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "PowerToys.Interop", "..\..\common\interop\PowerToys.Interop.vcxproj", "{F055103B-F80B-4D0C-BF48-057C55620033}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ManagedTelemetry", "..\..\common\ManagedTelemetry\Telemetry\ManagedTelemetry.csproj", "{6CE421AD-D249-4BD1-9ADA-B46DA18AADEE}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU + Debug|ARM64 = Debug|ARM64 Debug|x64 = Debug|x64 Debug|x86 = Debug|x86 Release|Any CPU = Release|Any CPU + Release|ARM64 = Release|ARM64 Release|x64 = Release|x64 Release|x86 = Release|x86 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {3D63307B-9D27-44FD-B033-B26F39245B85}.Debug|Any CPU.ActiveCfg = Debug|x64 {3D63307B-9D27-44FD-B033-B26F39245B85}.Debug|Any CPU.Build.0 = Debug|x64 + {3D63307B-9D27-44FD-B033-B26F39245B85}.Debug|ARM64.ActiveCfg = Debug|ARM64 + {3D63307B-9D27-44FD-B033-B26F39245B85}.Debug|ARM64.Build.0 = Debug|ARM64 {3D63307B-9D27-44FD-B033-B26F39245B85}.Debug|x64.ActiveCfg = Debug|x64 {3D63307B-9D27-44FD-B033-B26F39245B85}.Debug|x64.Build.0 = Debug|x64 {3D63307B-9D27-44FD-B033-B26F39245B85}.Debug|x86.ActiveCfg = Debug|Win32 {3D63307B-9D27-44FD-B033-B26F39245B85}.Debug|x86.Build.0 = Debug|Win32 {3D63307B-9D27-44FD-B033-B26F39245B85}.Release|Any CPU.ActiveCfg = Release|x64 {3D63307B-9D27-44FD-B033-B26F39245B85}.Release|Any CPU.Build.0 = Release|x64 + {3D63307B-9D27-44FD-B033-B26F39245B85}.Release|ARM64.ActiveCfg = Release|ARM64 + {3D63307B-9D27-44FD-B033-B26F39245B85}.Release|ARM64.Build.0 = Release|ARM64 {3D63307B-9D27-44FD-B033-B26F39245B85}.Release|x64.ActiveCfg = Release|x64 {3D63307B-9D27-44FD-B033-B26F39245B85}.Release|x64.Build.0 = Release|x64 {3D63307B-9D27-44FD-B033-B26F39245B85}.Release|x86.ActiveCfg = Release|Win32 {3D63307B-9D27-44FD-B033-B26F39245B85}.Release|x86.Build.0 = Release|Win32 {2CAC093E-5FCF-4102-9C2C-AC7DD5D9EB96}.Debug|Any CPU.ActiveCfg = Debug|x64 {2CAC093E-5FCF-4102-9C2C-AC7DD5D9EB96}.Debug|Any CPU.Build.0 = Debug|x64 + {2CAC093E-5FCF-4102-9C2C-AC7DD5D9EB96}.Debug|ARM64.ActiveCfg = Debug|ARM64 + {2CAC093E-5FCF-4102-9C2C-AC7DD5D9EB96}.Debug|ARM64.Build.0 = Debug|ARM64 {2CAC093E-5FCF-4102-9C2C-AC7DD5D9EB96}.Debug|x64.ActiveCfg = Debug|x64 {2CAC093E-5FCF-4102-9C2C-AC7DD5D9EB96}.Debug|x64.Build.0 = Debug|x64 {2CAC093E-5FCF-4102-9C2C-AC7DD5D9EB96}.Debug|x86.ActiveCfg = Debug|Win32 {2CAC093E-5FCF-4102-9C2C-AC7DD5D9EB96}.Debug|x86.Build.0 = Debug|Win32 {2CAC093E-5FCF-4102-9C2C-AC7DD5D9EB96}.Release|Any CPU.ActiveCfg = Release|x64 {2CAC093E-5FCF-4102-9C2C-AC7DD5D9EB96}.Release|Any CPU.Build.0 = Release|x64 + {2CAC093E-5FCF-4102-9C2C-AC7DD5D9EB96}.Release|ARM64.ActiveCfg = Release|ARM64 + {2CAC093E-5FCF-4102-9C2C-AC7DD5D9EB96}.Release|ARM64.Build.0 = Release|ARM64 {2CAC093E-5FCF-4102-9C2C-AC7DD5D9EB96}.Release|x64.ActiveCfg = Release|x64 {2CAC093E-5FCF-4102-9C2C-AC7DD5D9EB96}.Release|x64.Build.0 = Release|x64 {2CAC093E-5FCF-4102-9C2C-AC7DD5D9EB96}.Release|x86.ActiveCfg = Release|Win32 {2CAC093E-5FCF-4102-9C2C-AC7DD5D9EB96}.Release|x86.Build.0 = Release|Win32 {5CCC8468-DEC8-4D36-99D4-5C891BEBD481}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {5CCC8468-DEC8-4D36-99D4-5C891BEBD481}.Debug|Any CPU.Build.0 = Debug|Any CPU + {5CCC8468-DEC8-4D36-99D4-5C891BEBD481}.Debug|ARM64.ActiveCfg = Debug|Any CPU + {5CCC8468-DEC8-4D36-99D4-5C891BEBD481}.Debug|ARM64.Build.0 = Debug|Any CPU {5CCC8468-DEC8-4D36-99D4-5C891BEBD481}.Debug|x64.ActiveCfg = Debug|x64 {5CCC8468-DEC8-4D36-99D4-5C891BEBD481}.Debug|x64.Build.0 = Debug|x64 {5CCC8468-DEC8-4D36-99D4-5C891BEBD481}.Debug|x86.ActiveCfg = Debug|Any CPU {5CCC8468-DEC8-4D36-99D4-5C891BEBD481}.Debug|x86.Build.0 = Debug|Any CPU {5CCC8468-DEC8-4D36-99D4-5C891BEBD481}.Release|Any CPU.ActiveCfg = Release|Any CPU {5CCC8468-DEC8-4D36-99D4-5C891BEBD481}.Release|Any CPU.Build.0 = Release|Any CPU + {5CCC8468-DEC8-4D36-99D4-5C891BEBD481}.Release|ARM64.ActiveCfg = Release|Any CPU + {5CCC8468-DEC8-4D36-99D4-5C891BEBD481}.Release|ARM64.Build.0 = Release|Any CPU {5CCC8468-DEC8-4D36-99D4-5C891BEBD481}.Release|x64.ActiveCfg = Release|x64 {5CCC8468-DEC8-4D36-99D4-5C891BEBD481}.Release|x64.Build.0 = Release|x64 {5CCC8468-DEC8-4D36-99D4-5C891BEBD481}.Release|x86.ActiveCfg = Release|Any CPU {5CCC8468-DEC8-4D36-99D4-5C891BEBD481}.Release|x86.Build.0 = Release|Any CPU + {A881F6EB-6EDA-4674-A6B7-598F0A8E7048}.Debug|Any CPU.ActiveCfg = Debug|x64 + {A881F6EB-6EDA-4674-A6B7-598F0A8E7048}.Debug|Any CPU.Build.0 = Debug|x64 + {A881F6EB-6EDA-4674-A6B7-598F0A8E7048}.Debug|ARM64.ActiveCfg = Debug|ARM64 + {A881F6EB-6EDA-4674-A6B7-598F0A8E7048}.Debug|ARM64.Build.0 = Debug|ARM64 + {A881F6EB-6EDA-4674-A6B7-598F0A8E7048}.Debug|x64.ActiveCfg = Debug|x64 + {A881F6EB-6EDA-4674-A6B7-598F0A8E7048}.Debug|x64.Build.0 = Debug|x64 + {A881F6EB-6EDA-4674-A6B7-598F0A8E7048}.Debug|x86.ActiveCfg = Debug|x64 + {A881F6EB-6EDA-4674-A6B7-598F0A8E7048}.Debug|x86.Build.0 = Debug|x64 + {A881F6EB-6EDA-4674-A6B7-598F0A8E7048}.Release|Any CPU.ActiveCfg = Release|x64 + {A881F6EB-6EDA-4674-A6B7-598F0A8E7048}.Release|Any CPU.Build.0 = Release|x64 + {A881F6EB-6EDA-4674-A6B7-598F0A8E7048}.Release|ARM64.ActiveCfg = Release|ARM64 + {A881F6EB-6EDA-4674-A6B7-598F0A8E7048}.Release|ARM64.Build.0 = Release|ARM64 + {A881F6EB-6EDA-4674-A6B7-598F0A8E7048}.Release|x64.ActiveCfg = Release|x64 + {A881F6EB-6EDA-4674-A6B7-598F0A8E7048}.Release|x64.Build.0 = Release|x64 + {A881F6EB-6EDA-4674-A6B7-598F0A8E7048}.Release|x86.ActiveCfg = Release|x64 + {A881F6EB-6EDA-4674-A6B7-598F0A8E7048}.Release|x86.Build.0 = Release|x64 + {F055103B-F80B-4D0C-BF48-057C55620033}.Debug|Any CPU.ActiveCfg = Debug|x64 + {F055103B-F80B-4D0C-BF48-057C55620033}.Debug|Any CPU.Build.0 = Debug|x64 + {F055103B-F80B-4D0C-BF48-057C55620033}.Debug|ARM64.ActiveCfg = Debug|ARM64 + {F055103B-F80B-4D0C-BF48-057C55620033}.Debug|ARM64.Build.0 = Debug|ARM64 + {F055103B-F80B-4D0C-BF48-057C55620033}.Debug|x64.ActiveCfg = Debug|x64 + {F055103B-F80B-4D0C-BF48-057C55620033}.Debug|x64.Build.0 = Debug|x64 + {F055103B-F80B-4D0C-BF48-057C55620033}.Debug|x86.ActiveCfg = Debug|x64 + {F055103B-F80B-4D0C-BF48-057C55620033}.Debug|x86.Build.0 = Debug|x64 + {F055103B-F80B-4D0C-BF48-057C55620033}.Release|Any CPU.ActiveCfg = Release|x64 + {F055103B-F80B-4D0C-BF48-057C55620033}.Release|Any CPU.Build.0 = Release|x64 + {F055103B-F80B-4D0C-BF48-057C55620033}.Release|ARM64.ActiveCfg = Release|ARM64 + {F055103B-F80B-4D0C-BF48-057C55620033}.Release|ARM64.Build.0 = Release|ARM64 + {F055103B-F80B-4D0C-BF48-057C55620033}.Release|x64.ActiveCfg = Release|x64 + {F055103B-F80B-4D0C-BF48-057C55620033}.Release|x64.Build.0 = Release|x64 + {F055103B-F80B-4D0C-BF48-057C55620033}.Release|x86.ActiveCfg = Release|x64 + {F055103B-F80B-4D0C-BF48-057C55620033}.Release|x86.Build.0 = Release|x64 + {6CE421AD-D249-4BD1-9ADA-B46DA18AADEE}.Debug|Any CPU.ActiveCfg = Debug|x64 + {6CE421AD-D249-4BD1-9ADA-B46DA18AADEE}.Debug|Any CPU.Build.0 = Debug|x64 + {6CE421AD-D249-4BD1-9ADA-B46DA18AADEE}.Debug|ARM64.ActiveCfg = Debug|ARM64 + {6CE421AD-D249-4BD1-9ADA-B46DA18AADEE}.Debug|ARM64.Build.0 = Debug|ARM64 + {6CE421AD-D249-4BD1-9ADA-B46DA18AADEE}.Debug|x64.ActiveCfg = Debug|x64 + {6CE421AD-D249-4BD1-9ADA-B46DA18AADEE}.Debug|x64.Build.0 = Debug|x64 + {6CE421AD-D249-4BD1-9ADA-B46DA18AADEE}.Debug|x86.ActiveCfg = Debug|x64 + {6CE421AD-D249-4BD1-9ADA-B46DA18AADEE}.Debug|x86.Build.0 = Debug|x64 + {6CE421AD-D249-4BD1-9ADA-B46DA18AADEE}.Release|Any CPU.ActiveCfg = Release|x64 + {6CE421AD-D249-4BD1-9ADA-B46DA18AADEE}.Release|Any CPU.Build.0 = Release|x64 + {6CE421AD-D249-4BD1-9ADA-B46DA18AADEE}.Release|ARM64.ActiveCfg = Release|ARM64 + {6CE421AD-D249-4BD1-9ADA-B46DA18AADEE}.Release|ARM64.Build.0 = Release|ARM64 + {6CE421AD-D249-4BD1-9ADA-B46DA18AADEE}.Release|x64.ActiveCfg = Release|x64 + {6CE421AD-D249-4BD1-9ADA-B46DA18AADEE}.Release|x64.Build.0 = Release|x64 + {6CE421AD-D249-4BD1-9ADA-B46DA18AADEE}.Release|x86.ActiveCfg = Release|x64 + {6CE421AD-D249-4BD1-9ADA-B46DA18AADEE}.Release|x86.Build.0 = Release|x64 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/src/modules/Projects/ProjectsEditor/App.xaml.cs b/src/modules/Projects/ProjectsEditor/App.xaml.cs index 6c38e5cfdf..ce4beaa539 100644 --- a/src/modules/Projects/ProjectsEditor/App.xaml.cs +++ b/src/modules/Projects/ProjectsEditor/App.xaml.cs @@ -33,10 +33,10 @@ namespace ProjectsEditor private void OnStartup(object sender, StartupEventArgs e) { - Logger.InitializeLogger("\\Projects\\Logs"); - AppDomain.CurrentDomain.UnhandledException += OnUnhandledException; + Logger.InitializeLogger("\\Projects\\Logs"); + _themeManager = new ThemeManager(this); if (_mainViewModel == null) diff --git a/src/modules/Projects/ProjectsEditor/ProjectsEditor.csproj b/src/modules/Projects/ProjectsEditor/ProjectsEditor.csproj index 36dbc4d01e..1f84035f4b 100644 --- a/src/modules/Projects/ProjectsEditor/ProjectsEditor.csproj +++ b/src/modules/Projects/ProjectsEditor/ProjectsEditor.csproj @@ -86,9 +86,9 @@ - - ..\..\..\common\ManagedCommon\bin\x64\Debug\net8.0-windows\PowerToys.ManagedCommon.dll - + + + From 7e80c1bf73b357e04a4be5b32c21ce9f9495b4ce Mon Sep 17 00:00:00 2001 From: donlaci Date: Wed, 29 May 2024 13:51:28 +0200 Subject: [PATCH 3/7] spell checker --- src/modules/Projects/ProjectsEditor/App.xaml.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/Projects/ProjectsEditor/App.xaml.cs b/src/modules/Projects/ProjectsEditor/App.xaml.cs index ce4beaa539..568893ad0a 100644 --- a/src/modules/Projects/ProjectsEditor/App.xaml.cs +++ b/src/modules/Projects/ProjectsEditor/App.xaml.cs @@ -49,7 +49,7 @@ namespace ProjectsEditor string[] args = Environment.GetCommandLineArgs(); if (args != null && args.Length > 1) { - Logger.LogInfo($"Strated with a parameter: {args[1]}. Trying to launch that project."); + Logger.LogInfo($"Started with a parameter: {args[1]}. Trying to launch that project."); _mainViewModel.LaunchProject(args[1]); return; } From cb2a4ec6e90844ec4a7715f05c203f8a372352d1 Mon Sep 17 00:00:00 2001 From: donlaci Date: Fri, 31 May 2024 19:09:45 +0200 Subject: [PATCH 4/7] corrections in the snippet tool. extending icon handling in the editor: for packaged apps look for the exe in the current path adding shortcut icon creation. --- .../ProjectsEditor/Models/Application.cs | 41 ++++++- .../ProjectsEditor/ProjectEditorPage.xaml | 101 ++++++++++-------- .../ProjectsEditor/Utils/DrawHelper.cs | 99 +++++++++++++++++ .../ViewModels/MainViewModel.cs | 29 ++++- .../ProjectsSnapshotTool/PackagedAppUtils.cpp | 25 +++-- .../Projects/ProjectsSnapshotTool/main.cpp | 2 +- 6 files changed, 233 insertions(+), 64 deletions(-) diff --git a/src/modules/Projects/ProjectsEditor/Models/Application.cs b/src/modules/Projects/ProjectsEditor/Models/Application.cs index a67119f1ff..fec8e20b94 100644 --- a/src/modules/Projects/ProjectsEditor/Models/Application.cs +++ b/src/modules/Projects/ProjectsEditor/Models/Application.cs @@ -12,8 +12,11 @@ using System.IO; using System.Linq; using System.Text.Json.Serialization; using System.Text.RegularExpressions; +using System.Threading.Tasks; using System.Windows.Media.Imaging; using ManagedCommon; +using Windows.ApplicationModel.Core; +using Windows.Management.Deployment; namespace ProjectsEditor.Models { @@ -78,7 +81,18 @@ namespace ProjectsEditor.Models { try { - _icon = Icon.ExtractAssociatedIcon(AppPath); + if (!File.Exists(AppPath) && IsPackagedApp) + { + Task task = Task.Run(async () => await GetAppByPackageFamilyNameAsync()); + AppListEntry packApp = task.Result; + string filename = Path.GetFileName(AppPath); + string newExeLocation = Path.Combine(packApp.AppInfo.Package.InstalledPath, filename); + _icon = Icon.ExtractAssociatedIcon(newExeLocation); + } + else + { + _icon = Icon.ExtractAssociatedIcon(AppPath); + } } catch (Exception e) { @@ -91,6 +105,31 @@ namespace ProjectsEditor.Models } } + public async Task GetAppByPackageFamilyNameAsync() + { + var pkgManager = new PackageManager(); + var pkg = pkgManager.FindPackagesForUser(string.Empty, PackagedId).FirstOrDefault(); + + if (pkg == null) + { + return null; + } + + var apps = await pkg.GetAppListEntriesAsync(); + if (apps == null || apps.Count == 0) + { + return null; + } + + AppListEntry firstApp = apps[0]; + + // RandomAccessStreamReference stream = firstApp.AppInfo.DisplayInfo.GetLogo(new Windows.Foundation.Size(64, 64)); + // IRandomAccessStreamWithContentType content = await stream.OpenReadAsync(); + // BitmapImage bitmapImage = new BitmapImage(); + // bitmapImage.StreamSource = (Stream)content; + return firstApp; + } + private BitmapImage _iconBitmapImage; public BitmapImage IconBitmapImage diff --git a/src/modules/Projects/ProjectsEditor/ProjectEditorPage.xaml b/src/modules/Projects/ProjectsEditor/ProjectEditorPage.xaml index 9c8e071492..f90ad23131 100644 --- a/src/modules/Projects/ProjectsEditor/ProjectEditorPage.xaml +++ b/src/modules/Projects/ProjectsEditor/ProjectEditorPage.xaml @@ -161,6 +161,7 @@ + @@ -190,55 +191,56 @@ GotFocus="EditNameTextBox_GotFocus" KeyDown="EditNameTextBoxKeyDown" /> + + + + + + + + + + + + + + + + + + + + + + + + + + Grid.Row="3"> - - - - - - - - - - - - - - - - - - - - - - - - - @@ -251,12 +253,17 @@ - + + selectedApps = project.Applications.Where(x => x.IsSelected).ToList(); + if (selectedApps.Count > 0) + { + graphics.DrawIcon(selectedApps[0].Icon, new Rectangle(0, 0, iconSize / 2, iconSize / 2)); + } + + if (selectedApps.Count > 1) + { + graphics.DrawIcon(selectedApps[1].Icon, new Rectangle(iconSize / 2, 0, iconSize / 2, iconSize / 2)); + } + + if (selectedApps.Count > 2) + { + graphics.DrawIcon(selectedApps[2].Icon, new Rectangle(0, iconSize / 2, iconSize / 2, iconSize / 2)); + } + + if (selectedApps.Count > 3) + { + graphics.DrawIcon(selectedApps[3].Icon, new Rectangle(iconSize / 2, iconSize / 2, iconSize / 2, iconSize / 2)); + } + } + + graphics.DrawIcon(new Icon(@"images\Projects.ico"), new Rectangle(iconSize / 4, iconSize / 4, iconSize / 2, iconSize / 2)); + } + + FileStream fileStream = new FileStream(shortcutIconFilename, FileMode.OpenOrCreate); + + using (var memoryStream = new MemoryStream()) + { + bitmap.Save(memoryStream, ImageFormat.Png); + + BinaryWriter iconWriter = new BinaryWriter(fileStream); + if (fileStream != null && iconWriter != null) + { + // 0-1 reserved, 0 + iconWriter.Write((byte)0); + iconWriter.Write((byte)0); + + // 2-3 image type, 1 = icon, 2 = cursor + iconWriter.Write((short)1); + + // 4-5 number of images + iconWriter.Write((short)1); + + // image entry 1 + // 0 image width + iconWriter.Write((byte)iconSize); + + // 1 image height + iconWriter.Write((byte)iconSize); + + // 2 number of colors + iconWriter.Write((byte)0); + + // 3 reserved + iconWriter.Write((byte)0); + + // 4-5 color planes + iconWriter.Write((short)0); + + // 6-7 bits per pixel + iconWriter.Write((short)32); + + // 8-11 size of image data + iconWriter.Write((int)memoryStream.Length); + + // 12-15 offset of image data + iconWriter.Write((int)(6 + 16)); + + // write image data + // png data must contain the whole png data file + iconWriter.Write(memoryStream.ToArray()); + + iconWriter.Flush(); + } + } + + fileStream.Flush(); + fileStream.Close(); + return shortcutIconFilename; + } } } diff --git a/src/modules/Projects/ProjectsEditor/ViewModels/MainViewModel.cs b/src/modules/Projects/ProjectsEditor/ViewModels/MainViewModel.cs index d8f59626c2..af678f3728 100644 --- a/src/modules/Projects/ProjectsEditor/ViewModels/MainViewModel.cs +++ b/src/modules/Projects/ProjectsEditor/ViewModels/MainViewModel.cs @@ -7,10 +7,13 @@ using System.Collections.Generic; using System.Collections.ObjectModel; using System.ComponentModel; using System.Diagnostics; +using System.Drawing; +using System.Drawing.Imaging; using System.IO; using System.Linq; using System.Threading.Tasks; using System.Timers; +using System.Windows.Media.Imaging; using ManagedCommon; using ProjectsEditor.Models; using ProjectsEditor.Utils; @@ -131,17 +134,19 @@ namespace ProjectsEditor.ViewModels } } - private void CreateShortcut(Project editedProject) + private void CreateShortcut(Project project) { object shDesktop = (object)"Desktop"; IWshRuntimeLibrary.WshShell shell = new IWshRuntimeLibrary.WshShell(); - string shortcutAddress = (string)shell.SpecialFolders.Item(ref shDesktop) + $"\\{editedProject.Name}.lnk"; + string shortcutAddress = (string)shell.SpecialFolders.Item(ref shDesktop) + $"\\{project.Name}.lnk"; IWshRuntimeLibrary.IWshShortcut shortcut = (IWshRuntimeLibrary.IWshShortcut)shell.CreateShortcut(shortcutAddress); - shortcut.Description = $"Project Launcher {editedProject.Id}"; + shortcut.Description = $"Project Launcher {project.Id}"; string basePath = AppDomain.CurrentDomain.BaseDirectory; shortcut.TargetPath = Path.Combine(basePath, "ProjectsEditor.exe"); - shortcut.Arguments = '"' + editedProject.Id + '"'; + shortcut.Arguments = '"' + project.Id + '"'; shortcut.WorkingDirectory = basePath; + string iconFilename = DrawHelper.CreateShortcutIcon(project, out Bitmap bitmap); + shortcut.IconLocation = iconFilename; shortcut.Save(); } @@ -184,7 +189,23 @@ namespace ProjectsEditor.ViewModels projectEdited.Initialize(); } + DrawHelper.CreateShortcutIcon(selectedProject, out Bitmap bitmap); + BitmapImage bitmapImage; + using (var memory = new MemoryStream()) + { + bitmap.Save(memory, ImageFormat.Png); + memory.Position = 0; + + bitmapImage = new BitmapImage(); + bitmapImage.BeginInit(); + bitmapImage.StreamSource = memory; + bitmapImage.CacheOption = BitmapCacheOption.OnLoad; + bitmapImage.EndInit(); + bitmapImage.Freeze(); + } + editPage.DataContext = projectEdited; + editPage.IconPreview.Source = bitmapImage; _mainWindow.ShowPage(editPage); lastUpdatedTimer.Stop(); } diff --git a/src/modules/Projects/ProjectsSnapshotTool/PackagedAppUtils.cpp b/src/modules/Projects/ProjectsSnapshotTool/PackagedAppUtils.cpp index d717dc14a5..06b25fd7b9 100644 --- a/src/modules/Projects/ProjectsSnapshotTool/PackagedAppUtils.cpp +++ b/src/modules/Projects/ProjectsSnapshotTool/PackagedAppUtils.cpp @@ -144,19 +144,22 @@ namespace Utils }; } - std::wstring installPathUpper(appData.installPath); - std::transform(installPathUpper.begin(), installPathUpper.end(), installPathUpper.begin(), towupper); - - if (appPathUpper.contains(installPathUpper)) + if (!appData.installPath.empty()) { - return appData; - } + std::wstring installPathUpper(appData.installPath); + std::transform(installPathUpper.begin(), installPathUpper.end(), installPathUpper.begin(), towupper); - // edge case, some apps (e.g., Gitkraken) have different .exe files in the subfolders. - // apps list contains only one path, so in this case app is not found - if (std::filesystem::path(appPath).filename() == std::filesystem::path(appData.installPath).filename()) - { - return appData; + if (appPathUpper.contains(installPathUpper)) + { + return appData; + } + + // edge case, some apps (e.g., Gitkraken) have different .exe files in the subfolders. + // apps list contains only one path, so in this case app is not found + if (std::filesystem::path(appPath).filename() == std::filesystem::path(appData.installPath).filename()) + { + return appData; + } } } diff --git a/src/modules/Projects/ProjectsSnapshotTool/main.cpp b/src/modules/Projects/ProjectsSnapshotTool/main.cpp index 6135feca42..17c70134d4 100644 --- a/src/modules/Projects/ProjectsSnapshotTool/main.cpp +++ b/src/modules/Projects/ProjectsSnapshotTool/main.cpp @@ -124,7 +124,7 @@ int main(int argc, char* argv[]) Project::Application app { .name = data.value().name, .title = title, - .path = data.value().installPath, + .path = processPath, .packageFullName = data.value().packageFullName, .commandLineArgs = L"", .isMinimized = WindowUtils::IsMinimized(window), From af49b36d2076dcdede7e35dff8d1762df99770a1 Mon Sep 17 00:00:00 2001 From: donlaci Date: Tue, 4 Jun 2024 12:45:50 +0200 Subject: [PATCH 5/7] adding shortcut icon drawing. Minor changes --- .../Projects/ProjectsEditor/Models/Project.cs | 22 +++ .../ProjectsEditor/ProjectEditorPage.xaml | 5 - .../ProjectsEditor/Utils/DrawHelper.cs | 148 ++++++++++++++---- .../ViewModels/MainViewModel.cs | 18 +-- 4 files changed, 144 insertions(+), 49 deletions(-) diff --git a/src/modules/Projects/ProjectsEditor/Models/Project.cs b/src/modules/Projects/ProjectsEditor/Models/Project.cs index 6d443161d8..81f167988d 100644 --- a/src/modules/Projects/ProjectsEditor/Models/Project.cs +++ b/src/modules/Projects/ProjectsEditor/Models/Project.cs @@ -317,5 +317,27 @@ namespace ProjectsEditor.Models return new Rectangle((int)minX, (int)minY, (int)(maxX - minX), (int)(maxY - minY)); } + + internal string GetShortcutChars() + { + if (string.IsNullOrEmpty(Name)) + { + return "PR"; + } + + string[] words = Name.Trim().ToUpperInvariant().Split(' '); + if (words.Length > 2) + { + return $"{words[0][0]}{words[1][0]}{words[2][0]}"; + } + else if (words.Length == 2) + { + return $"{words[0][0]}{words[1][0]}"; + } + else + { + return words[0].Substring(0, Math.Min(3, words[0].Length)); + } + } } } diff --git a/src/modules/Projects/ProjectsEditor/ProjectEditorPage.xaml b/src/modules/Projects/ProjectsEditor/ProjectEditorPage.xaml index f90ad23131..149b944856 100644 --- a/src/modules/Projects/ProjectsEditor/ProjectEditorPage.xaml +++ b/src/modules/Projects/ProjectsEditor/ProjectEditorPage.xaml @@ -259,11 +259,6 @@ Content="{x:Static props:Resources.CreateShortcut}" IsChecked="{Binding IsShortcutNeeded, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" FontSize="14"/> - iconBrushes = new List + { + ////Brushes.Gold, + ////Brushes.SteelBlue, + ////Brushes.SkyBlue, + ////Brushes.DarkGoldenrod, + ////Brushes.ForestGreen, + ////Brushes.Peru, + ////Brushes.Chartreuse, + ////Brushes.LightPink, + ////Brushes.CadetBlue, + ////Brushes.DarkSalmon, + ////Brushes.Orange, + ////Brushes.DarkSeaGreen, + ////Brushes.Yellow, + ////Brushes.Green, + ////Brushes.Orange, + ////Brushes.White, + new SolidBrush(Color.FromArgb(255, 40, 101, 120)), + new SolidBrush(Color.FromArgb(255, 58, 91, 153)), + new SolidBrush(Color.FromArgb(255, 87, 88, 163)), + new SolidBrush(Color.FromArgb(255, 116, 87, 160)), + new SolidBrush(Color.FromArgb(255, 139, 82, 145)), + }; + + private static int iconBrushIndex; + public static BitmapImage DrawPreview(Project project, Rectangle bounds) { double scale = 0.1; @@ -134,7 +163,6 @@ namespace ProjectsEditor.Utils if (app.RepeatIndex > 0) { string indexString = app.RepeatIndex.ToString(CultureInfo.InvariantCulture); - System.Drawing.Font font = new System.Drawing.Font("Tahoma", 8); int indexSize = (int)(iconBounds.Width * 0.5); Rectangle indexBounds = new Rectangle(iconBounds.Right - indexSize, iconBounds.Bottom - indexSize, indexSize, indexSize); @@ -196,7 +224,6 @@ namespace ProjectsEditor.Utils if (app.RepeatIndex > 0) { string indexString = app.RepeatIndex.ToString(CultureInfo.InvariantCulture); - System.Drawing.Font font = new System.Drawing.Font("Tahoma", 8); int indexSize = (int)(iconBounds.Width * 0.5); Rectangle indexBounds = new Rectangle(iconBounds.Right - indexSize, iconBounds.Bottom - indexSize, indexSize, indexSize); @@ -252,42 +279,67 @@ namespace ProjectsEditor.Utils internal static string CreateShortcutIcon(Project project, out Bitmap bitmap) { - int iconSize = 128; object shDesktop = (object)"Desktop"; IWshRuntimeLibrary.WshShell shell = new IWshRuntimeLibrary.WshShell(); string shortcutIconFilename = (string)shell.SpecialFolders.Item(ref shDesktop) + $"\\{project.Name}.ico"; - bitmap = new Bitmap(iconSize, iconSize); + bitmap = new Bitmap(IconSize, IconSize); using (Graphics graphics = Graphics.FromImage(bitmap)) { graphics.SmoothingMode = SmoothingMode.AntiAlias; graphics.InterpolationMode = InterpolationMode.HighQualityBicubic; graphics.PixelOffsetMode = PixelOffsetMode.HighQuality; + // if (project != null) + // { + // List selectedApps = project.Applications.Where(x => x.IsSelected).ToList(); + // if (selectedApps.Count > 0) + // { + // graphics.DrawIcon(selectedApps[0].Icon, new Rectangle(0, 0, IconSize / 2, IconSize / 2)); + // } + // if (selectedApps.Count > 1) + // { + // graphics.DrawIcon(selectedApps[1].Icon, new Rectangle(IconSize / 2, 0, IconSize / 2, IconSize / 2)); + // } + // if (selectedApps.Count > 2) + // { + // graphics.DrawIcon(selectedApps[2].Icon, new Rectangle(0, IconSize / 2, IconSize / 2, IconSize / 2)); + // } + // if (selectedApps.Count > 3) + // { + // graphics.DrawIcon(selectedApps[3].Icon, new Rectangle(IconSize / 2, IconSize / 2, IconSize / 2, IconSize / 2)); + // } + // } + // graphics.FillRectangle(new System.Drawing.SolidBrush(Color.FromArgb(128, 32, 32, 32)), 0, 0, IconSize, IconSize); + graphics.FillEllipse(iconBrushes[iconBrushIndex], 0, 0, IconSize, IconSize); + + string shortcutChars = "PR"; + if (project != null) { - List selectedApps = project.Applications.Where(x => x.IsSelected).ToList(); - if (selectedApps.Count > 0) - { - graphics.DrawIcon(selectedApps[0].Icon, new Rectangle(0, 0, iconSize / 2, iconSize / 2)); - } - - if (selectedApps.Count > 1) - { - graphics.DrawIcon(selectedApps[1].Icon, new Rectangle(iconSize / 2, 0, iconSize / 2, iconSize / 2)); - } - - if (selectedApps.Count > 2) - { - graphics.DrawIcon(selectedApps[2].Icon, new Rectangle(0, iconSize / 2, iconSize / 2, iconSize / 2)); - } - - if (selectedApps.Count > 3) - { - graphics.DrawIcon(selectedApps[3].Icon, new Rectangle(iconSize / 2, iconSize / 2, iconSize / 2, iconSize / 2)); - } + shortcutChars = project.GetShortcutChars(); } - graphics.DrawIcon(new Icon(@"images\Projects.ico"), new Rectangle(iconSize / 4, iconSize / 4, iconSize / 2, iconSize / 2)); + Rectangle indexBounds; + if (shortcutChars.Length > 1) + { + indexBounds = new Rectangle(0, 0, IconSize, IconSize); + } + else + { + indexBounds = new Rectangle(IconSize / 4, 0, IconSize / 2, IconSize); + } + + var textSize = graphics.MeasureString(shortcutChars, font); + var state = graphics.Save(); + graphics.TranslateTransform(indexBounds.Left, indexBounds.Top); + graphics.ScaleTransform(indexBounds.Width / textSize.Width, indexBounds.Height / textSize.Height); + graphics.DrawString(shortcutChars, font, Brushes.White, PointF.Empty); + graphics.Restore(state); + iconBrushIndex++; + if (iconBrushIndex >= iconBrushes.Count) + { + iconBrushIndex = 0; + } } FileStream fileStream = new FileStream(shortcutIconFilename, FileMode.OpenOrCreate); @@ -311,10 +363,10 @@ namespace ProjectsEditor.Utils // image entry 1 // 0 image width - iconWriter.Write((byte)iconSize); + iconWriter.Write((byte)IconSize); // 1 image height - iconWriter.Write((byte)iconSize); + iconWriter.Write((byte)IconSize); // 2 number of colors iconWriter.Write((byte)0); @@ -346,5 +398,47 @@ namespace ProjectsEditor.Utils fileStream.Close(); return shortcutIconFilename; } + + private static void CreateExamples(Project project) + { + Bitmap bitmap = new Bitmap(IconSize + 1000, IconSize * iconBrushes.Count); + using (Graphics graphics = Graphics.FromImage(bitmap)) + { + for (int brushIndex = 0; brushIndex < iconBrushes.Count; brushIndex++) + { + graphics.SmoothingMode = SmoothingMode.AntiAlias; + graphics.InterpolationMode = InterpolationMode.HighQualityBicubic; + graphics.PixelOffsetMode = PixelOffsetMode.HighQuality; + + graphics.FillEllipse(iconBrushes[brushIndex], 0, IconSize * brushIndex, IconSize, IconSize); + + string shortcutChars = "PR"; + + Rectangle indexBounds; + indexBounds = new Rectangle(0, IconSize * brushIndex, IconSize, IconSize); + + var textSize = graphics.MeasureString(shortcutChars, font); + var state = graphics.Save(); + graphics.TranslateTransform(indexBounds.Left, indexBounds.Top); + graphics.ScaleTransform(indexBounds.Width / textSize.Width, indexBounds.Height / textSize.Height); + graphics.DrawString(shortcutChars, font, Brushes.Black, 0, 0); + graphics.Restore(state); + + var b = (SolidBrush)iconBrushes[brushIndex]; + var colorname = (from p in typeof(System.Drawing.Color).GetProperties() + where p.PropertyType.Equals(typeof(System.Drawing.Color)) + let value = (System.Drawing.Color)p.GetValue(null, null) + where value.R == b.Color.R && + value.G == b.Color.G && + value.B == b.Color.B && + value.A == b.Color.A + select p.Name).DefaultIfEmpty("unknown").First(); + + graphics.DrawString(colorname, font, Brushes.White, IconSize, IconSize * brushIndex); + } + } + + bitmap.Save(@"C:\temp\shorcutIcons.png"); + } } } diff --git a/src/modules/Projects/ProjectsEditor/ViewModels/MainViewModel.cs b/src/modules/Projects/ProjectsEditor/ViewModels/MainViewModel.cs index af678f3728..17713257b3 100644 --- a/src/modules/Projects/ProjectsEditor/ViewModels/MainViewModel.cs +++ b/src/modules/Projects/ProjectsEditor/ViewModels/MainViewModel.cs @@ -142,7 +142,7 @@ namespace ProjectsEditor.ViewModels IWshRuntimeLibrary.IWshShortcut shortcut = (IWshRuntimeLibrary.IWshShortcut)shell.CreateShortcut(shortcutAddress); shortcut.Description = $"Project Launcher {project.Id}"; string basePath = AppDomain.CurrentDomain.BaseDirectory; - shortcut.TargetPath = Path.Combine(basePath, "ProjectsEditor.exe"); + shortcut.TargetPath = Path.Combine(basePath, "ProjectsLauncher.exe"); shortcut.Arguments = '"' + project.Id + '"'; shortcut.WorkingDirectory = basePath; string iconFilename = DrawHelper.CreateShortcutIcon(project, out Bitmap bitmap); @@ -189,23 +189,7 @@ namespace ProjectsEditor.ViewModels projectEdited.Initialize(); } - DrawHelper.CreateShortcutIcon(selectedProject, out Bitmap bitmap); - BitmapImage bitmapImage; - using (var memory = new MemoryStream()) - { - bitmap.Save(memory, ImageFormat.Png); - memory.Position = 0; - - bitmapImage = new BitmapImage(); - bitmapImage.BeginInit(); - bitmapImage.StreamSource = memory; - bitmapImage.CacheOption = BitmapCacheOption.OnLoad; - bitmapImage.EndInit(); - bitmapImage.Freeze(); - } - editPage.DataContext = projectEdited; - editPage.IconPreview.Source = bitmapImage; _mainWindow.ShowPage(editPage); lastUpdatedTimer.Stop(); } From 690b537e9f593d74f8ebc66378f2b169a552d01c Mon Sep 17 00:00:00 2001 From: donlaci Date: Tue, 4 Jun 2024 12:55:05 +0200 Subject: [PATCH 6/7] spell check --- src/modules/Projects/ProjectsEditor/Utils/DrawHelper.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/modules/Projects/ProjectsEditor/Utils/DrawHelper.cs b/src/modules/Projects/ProjectsEditor/Utils/DrawHelper.cs index dabc86f425..fc42b44908 100644 --- a/src/modules/Projects/ProjectsEditor/Utils/DrawHelper.cs +++ b/src/modules/Projects/ProjectsEditor/Utils/DrawHelper.cs @@ -425,7 +425,7 @@ namespace ProjectsEditor.Utils graphics.Restore(state); var b = (SolidBrush)iconBrushes[brushIndex]; - var colorname = (from p in typeof(System.Drawing.Color).GetProperties() + var colorName = (from p in typeof(System.Drawing.Color).GetProperties() where p.PropertyType.Equals(typeof(System.Drawing.Color)) let value = (System.Drawing.Color)p.GetValue(null, null) where value.R == b.Color.R && @@ -434,11 +434,11 @@ namespace ProjectsEditor.Utils value.A == b.Color.A select p.Name).DefaultIfEmpty("unknown").First(); - graphics.DrawString(colorname, font, Brushes.White, IconSize, IconSize * brushIndex); + graphics.DrawString(colorName, font, Brushes.White, IconSize, IconSize * brushIndex); } } - bitmap.Save(@"C:\temp\shorcutIcons.png"); + bitmap.Save(@"C:\temp\shortcutIcons.png"); } } } From 449078be8e0affe4954ad5bcaea4560ddf070b6c Mon Sep 17 00:00:00 2001 From: donlaci Date: Wed, 5 Jun 2024 09:53:01 +0200 Subject: [PATCH 7/7] minor modification in light mode colors --- src/modules/Projects/ProjectsEditor/ProjectEditorPage.xaml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/modules/Projects/ProjectsEditor/ProjectEditorPage.xaml b/src/modules/Projects/ProjectsEditor/ProjectEditorPage.xaml index 149b944856..675fcc232a 100644 --- a/src/modules/Projects/ProjectsEditor/ProjectEditorPage.xaml +++ b/src/modules/Projects/ProjectsEditor/ProjectEditorPage.xaml @@ -268,17 +268,16 @@ x:Name="CancelButton" Margin="20,0,0,0" Height="36" + Background="{DynamicResource SecondaryBackgroundBrush}" AutomationProperties.Name="{x:Static props:Resources.Cancel}" Click="CancelButtonClicked">