mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-16 19:57:57 +01:00
adding logs
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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}");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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++;
|
||||
|
||||
@@ -84,6 +84,12 @@
|
||||
<PackageReference Include="ModernWpfUI" />
|
||||
<PackageReference Include="System.IO.Abstractions" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Reference Include="PowerToys.ManagedCommon">
|
||||
<HintPath>..\..\..\common\ManagedCommon\bin\x64\Debug\net8.0-windows\PowerToys.ManagedCommon.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Update="Properties\Resources.Designer.cs">
|
||||
<DesignTime>True</DesignTime>
|
||||
|
||||
@@ -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}");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user