Skip to content

Commit

Permalink
Init
Browse files Browse the repository at this point in the history
  • Loading branch information
0x5bfa committed Aug 3, 2024
1 parent 762ba7a commit dd5de42
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 62 deletions.
30 changes: 0 additions & 30 deletions .github/NOTICE.md
Original file line number Diff line number Diff line change
Expand Up @@ -645,36 +645,6 @@ A "contributor" is any person that distributes its contribution under this licen
(E) The software is licensed "as-is." You bear the risk of using it. The contributors give no express warranties, guarantees or conditions. You may have additional consumer rights under your local laws which this license cannot change. To the extent permitted under your local laws, the contributors exclude the implied warranties of merchantability, fitness for a particular purpose and non-infringement.
```

## Vanara

**Source**: [https://github.com/dahall/Vanara](https://github.com/dahall/Vanara)

### License

```
MIT License
Copyright (c) 2017 David Hall
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
```

## WinUIEx

**Source**: [https://github.com/dotMorten/WinUIEx](https://github.com/dotMorten/WinUIEx)
Expand Down
4 changes: 4 additions & 0 deletions src/Files.App/NativeMethods.txt
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,7 @@ DesktopWallpaper
SHCreateShellItemArrayFromIDLists
ILCreateFromPath
CLSIDFromString
FindWindow
SendMessage
IsWindowVisible
COPYDATASTRUCT
64 changes: 33 additions & 31 deletions src/Files.App/Services/PreviewPopupProviders/SeerProProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,47 @@
using Microsoft.Win32;
using System.IO;
using System.Runtime.InteropServices;
using Vanara.PInvoke;
using Windows.Win32;
using Windows.Win32.Foundation;
using Windows.Win32.System.DataExchange;
using static Vanara.PInvoke.AdvApi32.INSTALLSPEC;

namespace Files.App.Services.PreviewPopupProviders
{
public struct COPYDATASTRUCT
{
public IntPtr dwData;
public int cbData;
public IntPtr lpData;
}

public sealed class SeerProProvider : IPreviewPopupProvider
{
public static SeerProProvider Instance { get; } = new();

private string? CurrentPath;

public async Task TogglePreviewPopupAsync(string path)
private bool? _IsTrackSelectionSettingEnabledCache;
private bool IsTrackSelectionSettingEnabled
{
HWND Window = User32.FindWindow("SeerWindowClass", null);
COPYDATASTRUCT data = new COPYDATASTRUCT();
data.dwData = 5000;
data.cbData = (path.Length + 1) * 2;
data.lpData = Marshal.StringToHGlobalUni(path);
User32.SendMessage(Window, (uint)User32.WindowMessage.WM_COPYDATA, 0, ref data);

CurrentPath = User32.IsWindowVisible(Window) ? path : null;
get
{
_IsTrackSelectionSettingEnabledCache ??= DetectTrackSelectionSetting().Result;

return _IsTrackSelectionSettingEnabledCache.Value;
}
}

public unsafe async Task TogglePreviewPopupAsync(string path)
{
COPYDATASTRUCT data = default;
data.dwData = 5000u;
data.cbData = (uint)(path.Length + 1) * 2;
data.lpData = (void*)Marshal.StringToHGlobalUni(path);

var pData = Marshal.AllocHGlobal(Marshal.SizeOf(data));
Marshal.StructureToPtr(data, pData, false);

HWND hWnd = PInvoke.FindWindow("SeerWindowClass", null);
var result = PInvoke.SendMessage(hWnd, 0x004A /*WM_COPYDATA*/, 0, pData);

CurrentPath = PInvoke.IsWindowVisible(hWnd) ? path : null;

Marshal.FreeHGlobal((nint)data.lpData);
Marshal.FreeHGlobal(pData);
}

public async Task SwitchPreviewAsync(string path)
Expand All @@ -49,20 +63,8 @@ public async Task SwitchPreviewAsync(string path)

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;
}
var hWnd = PInvoke.FindWindow("SeerWindowClass", null).Value;
return hWnd != nint.Zero && hWnd.ToInt64() != -1;
}

private Task<bool> DetectTrackSelectionSetting()
Expand Down
1 change: 0 additions & 1 deletion src/Files.App/ViewModels/Settings/AboutViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ public AboutViewModel()
new ("https://github.com/mono/taglib-sharp", "TagLibSharp"),
new ("https://github.com/Tulpep/Active-Directory-Object-Picker", "ActiveDirectoryObjectPicker"),
new ("https://github.com/dotMorten/WinUIEx", "WinUIEx"),
new ("https://github.com/dahall/Vanara", "Vanara"),
new ("https://github.com/PowerShell/MMI", "MMI"),
new ("https://github.com/microsoft/CsWin32", "CsWin32"),
new ("https://github.com/microsoft/CsWinRT", "CsWinRT"),
Expand Down

0 comments on commit dd5de42

Please sign in to comment.