Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/Files.App/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ async Task ActivateAsync()
public async Task OnActivatedAsync(AppActivationArguments activatedEventArgs)
{
var activatedEventArgsData = activatedEventArgs.Data;

// Logger may not be initialized yet due to race condition during startup
if (Logger is not null)
Logger.LogInformation($"The app is being activated. Activation type: {activatedEventArgsData.GetType().Name}");
Expand All @@ -175,6 +175,8 @@ await MainWindow.Instance.DispatcherQueue.EnqueueOrInvokeAsync(()
/// </summary>
private void Window_Activated(object sender, WindowActivatedEventArgs args)
{
Logger.LogInformation($"Window_Activated: State={args?.WindowActivationState.ToString()}");

AppModel.IsMainWindowClosed = false;

// TODO(s): Is this code still needed?
Expand Down
38 changes: 38 additions & 0 deletions src/Files.App/Helpers/LogPathHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright (c) Files Community
// Licensed under the MIT License.

using System.IO;
using System.Security.Cryptography;
using System.Text;

namespace Files.App.Helpers
{
public static class LogPathHelper
{
public static string GetPathIdentifier(string? path)
{
if (string.IsNullOrEmpty(path))
return "[Empty]";

try
{
using var md5 = MD5.Create();
var hashBytes = md5.ComputeHash(Encoding.UTF8.GetBytes(path));

//4 bytes, still low collision
var shortHash = BitConverter.ToString(hashBytes, 0, 4).Replace("-", "").ToLowerInvariant();

var extension = Path.GetExtension(path);

if (!string.IsNullOrEmpty(extension))
return $"[hash:{shortHash}{extension}]";
else
return $"[hash:{shortHash}]";
}
catch
{
return "[?]";
}
}
}
}
6 changes: 6 additions & 0 deletions src/Files.App/ViewModels/ShellViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1694,6 +1694,8 @@ private async Task RapidAddItemsToCollectionAsync(string? path, LibraryItem? lib

public void CloseWatcher()
{
App.Logger.LogInformation($"CloseWatcher: aProcessQueueAction={aProcessQueueAction?.Status.ToString()}, gitProcessQueueAction={gitProcessQueueAction?.Status.ToString()}");

watcher?.Dispose();
watcher = null;

Expand Down Expand Up @@ -2771,6 +2773,8 @@ public void CancelSearch()

public void UpdateDateDisplay(bool isFormatChange)
{
App.Logger.LogDebug($"UpdateDateDisplay: isFormatChange={isFormatChange}, itemCount={filesAndFolders?.Count}");

filesAndFolders.ToList().AsParallel().ForAll(async item =>
{
// Reassign values to update date display
Expand All @@ -2792,6 +2796,8 @@ public void UpdateDateDisplay(bool isFormatChange)
public void Dispose()
{
CancelLoadAndClearFiles();
App.Logger.LogInformation($"ShellViewModel.Dispose: CurrentFolder={LogPathHelper.GetPathIdentifier(CurrentFolder?.ItemPath)}");

StorageTrashBinService.Watcher.ItemAdded -= RecycleBinItemCreatedAsync;
StorageTrashBinService.Watcher.ItemDeleted -= RecycleBinItemDeletedAsync;
StorageTrashBinService.Watcher.RefreshRequested -= RecycleBinRefreshRequestedAsync;
Expand Down
8 changes: 7 additions & 1 deletion src/Files.App/ViewModels/UserControls/InfoPaneViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,13 @@ public bool ShowCloudItemButton
public UIElement PreviewPaneContent
{
get => previewPaneContent;
set => SetProperty(ref previewPaneContent, value);
set
{
var oldType = previewPaneContent?.GetType()?.Name;
var newType = value?.GetType()?.Name;
App.Logger.LogDebug($"PreviewPaneContent changing: {oldType} -> {newType}");
SetProperty(ref previewPaneContent, value);
}
}

public bool LoadTagsList
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// Copyright (c) Files Community
// Licensed under the MIT License.

using Files.App.Helpers;
using Files.App.ViewModels.Properties;
using Microsoft.Extensions.Logging;
using Microsoft.UI.Content;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Hosting;
Expand Down Expand Up @@ -127,6 +129,8 @@ private unsafe LRESULT WndProc(HWND hwnd, uint msg, WPARAM wParam, LPARAM lParam

public unsafe void LoadPreview(UIElement presenter)
{
App.Logger.LogInformation($"ShellPreview.LoadPreview: Item={LogPathHelper.GetPathIdentifier(Item?.ItemPath)}");

var parent = MainWindow.Instance.WindowHandle;
var hInst = PInvoke.GetModuleHandle(default(PWSTR));
var szClassName = $"{nameof(ShellPreviewViewModel)}-{Guid.NewGuid()}";
Expand Down Expand Up @@ -251,7 +255,13 @@ private unsafe bool ChildWindowToXaml(nint parent, UIElement presenter)
public void UnloadPreview()
{
if (_hWnd != HWND.Null)
{
PInvoke.DestroyWindow(_hWnd);
App.Logger.LogInformation($"ShellPreview.UnloadPreview: HWND={((nint)_hWnd)}, Item={LogPathHelper.GetPathIdentifier(Item?.ItemPath)}");
}
else
App.Logger.LogInformation($"ShellPreview.UnloadPreview: HWND=, Item={LogPathHelper.GetPathIdentifier(Item?.ItemPath)}");


_contentExternalOutputLink?.Dispose();
_contentExternalOutputLink = null;
Expand Down
2 changes: 2 additions & 0 deletions src/Files.App/Views/MainPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,8 @@ private void UpdateDateDisplayTimer_Tick(object sender, object e)
{
if (!App.AppModel.IsMainWindowClosed)
InfoPane?.ViewModel.UpdateDateDisplay();
else
App.Logger.LogWarning("UpdateDateDisplayTimer_Tick: Timer firing after window closed!");
}

private void Page_SizeChanged(object sender, SizeChangedEventArgs e)
Expand Down
3 changes: 3 additions & 0 deletions src/Files.App/Views/ShellPanesPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT License.

using Files.App.Controls;
using Microsoft.Extensions.Logging;
using Microsoft.UI.Input;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
Expand Down Expand Up @@ -766,6 +767,8 @@ private void NotifyPropertyChanged([CallerMemberName] string propertyName = "")

public void Dispose()
{
App.Logger.LogInformation($"ShellPanesPage.Dispose: PaneCount={GetPaneCount()}, ActivePane={LogPathHelper.GetPathIdentifier(ActivePane?.TabBarItemParameter?.NavigationParameter?.ToString())}");

MainWindow.Instance.SizeChanged -= MainWindow_SizeChanged;

// Dispose panes
Expand Down
Loading