Skip to content

Commit

Permalink
Feature: Added support for SeerPro's "Track selected file" setting (#…
Browse files Browse the repository at this point in the history
…15339)

Co-authored-by: 0x5bfa <62196528+0x5bfa@users.noreply.github.com>
Co-authored-by: hishitetsu <66369541+hishitetsu@users.noreply.github.com>
  • Loading branch information
3 people committed May 12, 2024
1 parent 318bbb3 commit de2c165
Showing 1 changed file with 69 additions and 1 deletion.
70 changes: 69 additions & 1 deletion src/Files.App/Services/PreviewPopupProviders/SeerProProvider.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// Copyright (c) 2024 Files Community
// Licensed under the MIT License. See the LICENSE.

using Files.App.Services;
using Microsoft.Win32;
using System.IO;
using System.Runtime.InteropServices;
using Vanara.PInvoke;

Expand Down Expand Up @@ -34,6 +35,14 @@ public async Task TogglePreviewPopupAsync(string path)

public async Task SwitchPreviewAsync(string path)
{
// Close preview window is track selection setting is disabled
if (!IsTrackSelectionSettingEnabled && !string.IsNullOrEmpty(CurrentPath))
{
await TogglePreviewPopupAsync(CurrentPath);
return;
}

// Update the preview window if the path changed
if (CurrentPath is not null && path != CurrentPath)
await TogglePreviewPopupAsync(path);
}
Expand All @@ -43,5 +52,64 @@ public async Task<bool> DetectAvailability()
var handle = User32.FindWindow("SeerWindowClass", null).DangerousGetHandle();
return handle != IntPtr.Zero && handle.ToInt64() != -1;
}

private bool? _IsTrackSelectionSettingEnabledCache;
private bool IsTrackSelectionSettingEnabled
{
get
{
if (_IsTrackSelectionSettingEnabledCache is null)
_IsTrackSelectionSettingEnabledCache = DetectTrackSelectionSetting().Result;

return _IsTrackSelectionSettingEnabledCache.Value;
}
}

private Task<bool> DetectTrackSelectionSetting()
{
bool trackSelectedFile = true;

var keyName = @"HKEY_CURRENT_USER\Software\Corey\Seer";
var value = Registry.GetValue(keyName, "tracking_file", null);

if (value?.ToString() == "false")
return Task.FromResult(false);

// List of possible paths for the Seer Pro settings file
string[] paths =
{
Environment.ExpandEnvironmentVariables("%USERPROFILE%\\Documents\\Seer\\uwp.ini"),
Environment.ExpandEnvironmentVariables("%USERPROFILE%\\appdata\\Local\\Packages\\CNABA5E861-AC2A-4523-B3C1.Seer-AWindowsQuickLookTo_p7t0z30wh4868\\LocalCache\\Local\\Corey\\Seer\\uwp.ini"),
Environment.ExpandEnvironmentVariables("%USERPROFILE%\\appdata\\Local\\Corey\\Seer\\uwp.ini"),
Environment.ExpandEnvironmentVariables("%USERPROFILE%\\Documents\\Seer\\config.ini")
};

// Find the first existing path
foreach (var path in paths)
{
if (File.Exists(path))
{
// Read the settings file and look for the tracking_file setting
string[] lines = File.ReadAllLines(path);

foreach (var line in lines)
{
if (line.StartsWith("tracking_file", StringComparison.OrdinalIgnoreCase))
{
string[] keyValue = line.Split('=');
if (keyValue.Length == 2 && bool.TryParse(keyValue[1].Trim(), out bool isTrackingFile))
{
trackSelectedFile = isTrackingFile;
break;
}
}
}

break;
}
}

return Task.FromResult(trackSelectedFile);
}
}
}

0 comments on commit de2c165

Please sign in to comment.