Skip to content
Open
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
45 changes: 45 additions & 0 deletions src/Files.App/Helpers/LogPathHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Copyright (c) Files Community
// Licensed under the MIT License.

using System.IO;

namespace Files.App.Helpers
{
/// <summary>
/// Provides helper methods for formatting paths in logs.
/// </summary>
public static class LogPathHelper
{
public static string GetFileName(string? path)
{
if (string.IsNullOrEmpty(path))
return "[Empty]";

try
{
return Path.GetFileName(path) ?? "?";
}
catch
{
return "?";
}
}

public static string GetDirectoryName(string? path)
{
if (string.IsNullOrEmpty(path))
return "[Empty]";

try
{
// Trim trailing separators to ensure we get the last directory name
var trimmedPath = path.TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar);
return Path.GetFileName(trimmedPath) ?? "?";
}
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.GetDirectoryName(CurrentFolder?.ItemPath)}");
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: ShellViewModel.cs and ShellPanesPage.xaml.cs call LogPathHelper but are missing the required using Files.App.Helpers; directive, which will cause a compilation failure.
Severity: CRITICAL | Confidence: High

🔍 Detailed Analysis

The files ShellViewModel.cs and ShellPanesPage.xaml.cs both make calls to the new helper method LogPathHelper.GetDirectoryName(). However, neither file includes the necessary using Files.App.Helpers; directive to import the namespace where LogPathHelper is defined. This will result in a CS0103 compilation error ("The name 'LogPathHelper' does not exist in the current context") in both files, which will prevent the project from building.

💡 Suggested Fix

Add the line using Files.App.Helpers; to the top of both src/Files.App/ViewModels/ShellViewModel.cs and src/Files.App/Views/ShellPanesPage.xaml.cs to resolve the missing reference to the LogPathHelper class.

🤖 Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.

Location: src/Files.App/ViewModels/ShellViewModel.cs#L2799

Potential issue: The files `ShellViewModel.cs` and `ShellPanesPage.xaml.cs` both make
calls to the new helper method `LogPathHelper.GetDirectoryName()`. However, neither file
includes the necessary `using Files.App.Helpers;` directive to import the namespace
where `LogPathHelper` is defined. This will result in a CS0103 compilation error ("The
name 'LogPathHelper' does not exist in the current context") in both files, which will
prevent the project from building.

Did we get this right? 👍 / 👎 to inform future reviews.
Reference ID: 7334093


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.GetFileName(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.GetFileName(Item?.ItemPath)}");
}
else
App.Logger.LogInformation($"ShellPreview.UnloadPreview: HWND=, Item={LogPathHelper.GetFileName(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.GetDirectoryName(ActivePane?.TabBarItemParameter?.NavigationParameter?.ToString())}");

MainWindow.Instance.SizeChanged -= MainWindow_SizeChanged;

// Dispose panes
Expand Down
Loading