Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Added support for SeerPro's "Track selected file" setting #15339

Merged
merged 10 commits into from
May 12, 2024
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"),
yaira2 marked this conversation as resolved.
Show resolved Hide resolved
Environment.ExpandEnvironmentVariables("%USERPROFILE%\\appdata\\Local\\Packages\\CNABA5E861-AC2A-4523-B3C1.Seer-AWindowsQuickLookTo_p7t0z30wh4868\\LocalCache\\Local\\Corey\\Seer\\uwp.ini"),
yaira2 marked this conversation as resolved.
Show resolved Hide resolved
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);
}
}
}