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);
}
}