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

Win32 UI #3

Merged
merged 46 commits into from
May 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
5ce7870
Rename WPF FileSystemSearch project to FileSystemSearch_WPF.
TautvydasZilys Apr 2, 2022
a0efddc
Switch existing projects to C++20 and comformance mode.
TautvydasZilys Apr 3, 2022
84aac01
Add version info to SearchEngine.dll and SearchResultsView.dll.
TautvydasZilys Apr 3, 2022
a42741a
Add initial Win32 UI project.
TautvydasZilys Apr 3, 2022
4fc41e1
Empty search window implementation.
TautvydasZilys Apr 3, 2022
e80bd22
Complete SearchWindow layout.
TautvydasZilys Apr 3, 2022
76f6709
Made dealing with child controls a bit saner.
TautvydasZilys Apr 3, 2022
501944e
Fix SearchPathTextBox initial text for consistency with WPF version.
TautvydasZilys Apr 3, 2022
e196e38
Restrict ignoreFilesLargerThanTextBox to numbers only.
TautvydasZilys Apr 3, 2022
8c6e52c
Fix validation error strings.
TautvydasZilys Apr 3, 2022
20a325a
Implement input validation in Win32 UI.
TautvydasZilys Apr 3, 2022
cd47739
Use GetDpiForWindow instead of going through GetDpiForMonitor.
TautvydasZilys Apr 3, 2022
3f9e695
Use a single precompiled header for the whole solution.
TautvydasZilys Apr 3, 2022
225ea90
Fix formatting.
TautvydasZilys Apr 3, 2022
ea8dcf8
Hook up win32 UI to search engine.
TautvydasZilys Apr 3, 2022
2af25d7
Some code cleanup.
TautvydasZilys Apr 3, 2022
beb3db7
Barebones SearchResultWindow implementation.
TautvydasZilys Apr 4, 2022
bb5f624
Add a context pointer to search engine callbacks.
TautvydasZilys Apr 4, 2022
04f837f
Implement EventQueue type, which allows queueing callbacks onto the U…
TautvydasZilys Apr 4, 2022
483dcac
Move search initialization to SearchResultWindow and implement callba…
TautvydasZilys Apr 4, 2022
379daef
This variable is supposed to be static.
TautvydasZilys Apr 4, 2022
da2e99e
Improve experience when dragging the search window to a monitor with …
TautvydasZilys Apr 6, 2022
27773da
Add header textblock to the search window that specifies what the win…
TautvydasZilys Apr 6, 2022
bf6a537
Implement search statistics display.
TautvydasZilys Apr 6, 2022
d7c43e2
Fix text boxes limiting size length that exceeds their size.
TautvydasZilys Apr 9, 2022
cffa4e2
Implement progress bar in the search result window.
TautvydasZilys Apr 10, 2022
76151b9
Fix flickering statistics text blocks.
TautvydasZilys Apr 10, 2022
c65249a
Integrate explorer window.
TautvydasZilys Apr 10, 2022
24b183a
Fix statistics window updates getting frozen by explorer window events.
TautvydasZilys Apr 10, 2022
3443dab
Fix explorer window scaling with non 100% dpi scaling.
TautvydasZilys Apr 10, 2022
3a5fa78
Fix release build.
TautvydasZilys Apr 10, 2022
02edc7a
Add thread checks to ExplorerWindow::AddItem as it is not thread safe.
TautvydasZilys Apr 10, 2022
46941ed
Make ExplorerWindow not hit disk when displaying items.
TautvydasZilys Apr 10, 2022
f14a4d6
Dispatch results to explorer window directly on callback thread.
TautvydasZilys Apr 10, 2022
37783c7
Minor perf improvement: create event for overlapped I/O completion no…
TautvydasZilys Apr 10, 2022
6072496
Only destroy explorer window after search has been cleaned up, so tha…
TautvydasZilys Apr 10, 2022
8682e11
Localize numbers shown in search statistics.
TautvydasZilys Apr 11, 2022
0c932e3
Don't relayout search result window on minimize.
TautvydasZilys Apr 11, 2022
5ad70a0
Fix formatting.
TautvydasZilys Apr 11, 2022
21236e0
Drop 32-bit configs, they don't compile anyway.
TautvydasZilys Apr 11, 2022
73a97df
Split DCHolder into two classes: base one that just holds a DC, and a…
TautvydasZilys May 21, 2022
c24a8cf
Initial, buggy attempt at bordered textbox.
TautvydasZilys May 21, 2022
4412ca2
Add overloaded operator~ for enums.
TautvydasZilys May 22, 2022
f17f03a
Fix SearchResultWindow WndProc calling convention.
TautvydasZilys May 22, 2022
eea7249
Add a better implementation of bordered text box.
TautvydasZilys May 22, 2022
57689dd
Remove commented out include from the precompiled header.
TautvydasZilys May 22, 2022
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
21 changes: 21 additions & 0 deletions Common/HandleHolder.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,27 @@ struct HandleHolder : NonCopyable
return m_Handle != InvalidValue;
}

inline bool operator==(const HandleHolder& other) const
{
return m_Handle == other.m_Handle;
}

inline bool operator==(HANDLE other) const
{
return m_Handle == other;
}

inline HANDLE* operator&()
{
if (m_Handle != InvalidValue)
{
CloseHandle(m_Handle);
m_Handle = InvalidValue;
}

return &m_Handle;
}

HandleHolder& operator=(HANDLE handle)
{
if (m_Handle != InvalidValue)
Expand Down
2 changes: 1 addition & 1 deletion Common/NonCopyable.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

struct NonCopyable
{
NonCopyable() {}
constexpr NonCopyable() {}
NonCopyable(const NonCopyable&) = delete;
NonCopyable& operator=(const NonCopyable&) = delete;
};
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,30 @@
#define NOMINMAX

#include <Windows.h>
#include <commctrl.h>

#if USE_DSTORAGE
#include <dstorage.h>
#include <dstorageerr.h>
#endif

#include <d3d12.h>
#include <dxgi1_4.h>
#include <ShObjIdl.h>
#include <threadpoolapiset.h>
#include <wrl.h>

using Microsoft::WRL::ComPtr;

#include <algorithm>
#include <concepts>
#include <array>
#include <cmath>
#include <cstdint>
#include <map>
#include <memory>
#include <mutex>
#include <string>
#include <tuple>
#include <vector>

using Microsoft::WRL::ComPtr;

#define MAKE_BIT_OPERATORS_FOR_ENUM_CLASS(T) \
inline T operator|(T left, T right) \
{ \
Expand All @@ -45,10 +50,30 @@ using Microsoft::WRL::ComPtr;
inline void operator&=(T& left, T right) \
{ \
left = left & right; \
} \
inline T operator~(T item) \
{ \
typedef std::underlying_type<T>::type UnderlyingType; \
return static_cast<T>(~static_cast<UnderlyingType>(item)); \
}

#if _DEBUG
#define Assert(x) do { if (!(x)) __debugbreak(); } while (false, false)
#else
#define Assert(x) do { if (false, false) (void)(x); } while (false, false)
#endif

#define CONCAT_(a, b) a ## b
#define CONCAT(a, b) CONCAT_(a, b)

#if BUILDING_SEARCHENGINE
#define EXPORT_SEARCHENGINE __declspec(dllexport)
#else
#define EXPORT_SEARCHENGINE __declspec(dllimport)
#endif

#if BUILDING_SEARCHRESULTSVIEW
#define EXPORT_SEARCHRESULTSVIEW __declspec(dllexport)
#else
#define EXPORT_SEARCHRESULTSVIEW __declspec(dllimport)
#endif
72 changes: 72 additions & 0 deletions Common/ReaderWriterLock.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#pragma once

#include "NonCopyable.h"

class ReaderWriterLock : NonCopyable
{
public:
inline ReaderWriterLock()
{
InitializeSRWLock(&m_Lock);
}

struct ReaderLock : NonCopyable
{
private:
ReaderWriterLock& m_Lock;

public:
inline ReaderLock(ReaderWriterLock& lock) :
m_Lock(lock)
{
m_Lock.AcquireShared();
}

inline ~ReaderLock()
{
m_Lock.ReleaseShared();
}
};

struct WriterLock : NonCopyable
{
private:
ReaderWriterLock& m_Lock;

public:
inline WriterLock(ReaderWriterLock& lock) :
m_Lock(lock)
{
m_Lock.AcquireExclusive();
}

inline ~WriterLock()
{
m_Lock.ReleaseExclusive();
}
};

private:
inline void AcquireExclusive()
{
AcquireSRWLockExclusive(&m_Lock);
}

inline void AcquireShared()
{
AcquireSRWLockShared(&m_Lock);
}

inline void ReleaseExclusive()
{
ReleaseSRWLockExclusive(&m_Lock);
}

inline void ReleaseShared()
{
ReleaseSRWLockShared(&m_Lock);
}

SRWLOCK m_Lock;
};

Binary file added Common/Version.rc
Binary file not shown.
33 changes: 16 additions & 17 deletions FileSystemSearch.sln
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
VisualStudioVersion = 12.0.30501.0
# Visual Studio Version 16
VisualStudioVersion = 16.0.31624.102
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FileSystemSearch", "FileSystemSearch\FileSystemSearch.csproj", "{47151F80-E3E7-459B-B8A0-830BC7302F2D}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FileSystemSearch_WPF", "FileSystemSearch_WPF\FileSystemSearch_WPF.csproj", "{47151F80-E3E7-459B-B8A0-830BC7302F2D}"
ProjectSection(ProjectDependencies) = postProject
{42CB7641-3FF2-4973-B1BE-1AE94123FD10} = {42CB7641-3FF2-4973-B1BE-1AE94123FD10}
{8847E348-4C53-4017-B9F8-9201D59F1B9C} = {8847E348-4C53-4017-B9F8-9201D59F1B9C}
Expand All @@ -13,40 +13,39 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SearchEngine", "SearchEngin
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SearchResultsView", "SearchResultsView\SearchResultsView.vcxproj", "{8847E348-4C53-4017-B9F8-9201D59F1B9C}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "FileSystemSearch_Win32", "FileSystemSearch_Win32\FileSystemSearch_Win32.vcxproj", "{E3A9B0BE-0C6C-4091-BC9A-A641404C8723}"
ProjectSection(ProjectDependencies) = postProject
{42CB7641-3FF2-4973-B1BE-1AE94123FD10} = {42CB7641-3FF2-4973-B1BE-1AE94123FD10}
{8847E348-4C53-4017-B9F8-9201D59F1B9C} = {8847E348-4C53-4017-B9F8-9201D59F1B9C}
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{47151F80-E3E7-459B-B8A0-830BC7302F2D}.Debug|x64.ActiveCfg = Debug|x64
{47151F80-E3E7-459B-B8A0-830BC7302F2D}.Debug|x64.Build.0 = Debug|x64
{47151F80-E3E7-459B-B8A0-830BC7302F2D}.Debug|x86.ActiveCfg = Debug|x86
{47151F80-E3E7-459B-B8A0-830BC7302F2D}.Debug|x86.Build.0 = Debug|x86
{47151F80-E3E7-459B-B8A0-830BC7302F2D}.Release|x64.ActiveCfg = Release|x64
{47151F80-E3E7-459B-B8A0-830BC7302F2D}.Release|x64.Build.0 = Release|x64
{47151F80-E3E7-459B-B8A0-830BC7302F2D}.Release|x86.ActiveCfg = Release|x86
{47151F80-E3E7-459B-B8A0-830BC7302F2D}.Release|x86.Build.0 = Release|x86
{42CB7641-3FF2-4973-B1BE-1AE94123FD10}.Debug|x64.ActiveCfg = Debug|x64
{42CB7641-3FF2-4973-B1BE-1AE94123FD10}.Debug|x64.Build.0 = Debug|x64
{42CB7641-3FF2-4973-B1BE-1AE94123FD10}.Debug|x86.ActiveCfg = Debug|Win32
{42CB7641-3FF2-4973-B1BE-1AE94123FD10}.Debug|x86.Build.0 = Debug|Win32
{42CB7641-3FF2-4973-B1BE-1AE94123FD10}.Release|x64.ActiveCfg = Release|x64
{42CB7641-3FF2-4973-B1BE-1AE94123FD10}.Release|x64.Build.0 = Release|x64
{42CB7641-3FF2-4973-B1BE-1AE94123FD10}.Release|x86.ActiveCfg = Release|Win32
{42CB7641-3FF2-4973-B1BE-1AE94123FD10}.Release|x86.Build.0 = Release|Win32
{8847E348-4C53-4017-B9F8-9201D59F1B9C}.Debug|x64.ActiveCfg = Debug|x64
{8847E348-4C53-4017-B9F8-9201D59F1B9C}.Debug|x64.Build.0 = Debug|x64
{8847E348-4C53-4017-B9F8-9201D59F1B9C}.Debug|x86.ActiveCfg = Debug|Win32
{8847E348-4C53-4017-B9F8-9201D59F1B9C}.Debug|x86.Build.0 = Debug|Win32
{8847E348-4C53-4017-B9F8-9201D59F1B9C}.Release|x64.ActiveCfg = Release|x64
{8847E348-4C53-4017-B9F8-9201D59F1B9C}.Release|x64.Build.0 = Release|x64
{8847E348-4C53-4017-B9F8-9201D59F1B9C}.Release|x86.ActiveCfg = Release|Win32
{8847E348-4C53-4017-B9F8-9201D59F1B9C}.Release|x86.Build.0 = Release|Win32
{E3A9B0BE-0C6C-4091-BC9A-A641404C8723}.Debug|x64.ActiveCfg = Debug|x64
{E3A9B0BE-0C6C-4091-BC9A-A641404C8723}.Debug|x64.Build.0 = Debug|x64
{E3A9B0BE-0C6C-4091-BC9A-A641404C8723}.Release|x64.ActiveCfg = Release|x64
{E3A9B0BE-0C6C-4091-BC9A-A641404C8723}.Release|x64.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {2F5518D0-93A3-4F65-8C2F-AA6EB83E939C}
EndGlobalSection
EndGlobal
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<OutputType>WinExe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>FileSystemSearch</RootNamespace>
<AssemblyName>FileSystemSearch</AssemblyName>
<AssemblyName>FileSystemSearch_WPF</AssemblyName>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
Expand Down Expand Up @@ -37,26 +37,6 @@
<Prefer32Bit>true</Prefer32Bit>
<UseVSHostingProcess>false</UseVSHostingProcess>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>$(SolutionDir)build\bin\$(Platform)\$(Configuration)\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>x86</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
<OutputPath>$(SolutionDir)build\bin\$(Platform)\$(Configuration)\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x86</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Data" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
<TextBlock Text="{Binding TotalEnumeratedFilesSize}" />
</StackPanel>
<StackPanel Grid.Row="1" Grid.Column="0" Margin="20,0" Orientation="Horizontal">
<TextBlock Text="Total content searched files size: " />
<TextBlock Text="Total contents searched files size: " />
<TextBlock Text="{Binding TotalContentSearchedFilesSize}" />
</StackPanel>
<StackPanel Grid.Row="1" Grid.Column="2" Margin="20,0" Orientation="Horizontal">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ protected override async void OnClosed(EventArgs e)
resultsView.Cleanup();
}

private void OnProgressUpdated(ref SearchStatistics searchStatistics, double progress)
private void OnProgressUpdated(IntPtr context, ref SearchStatistics searchStatistics, double progress)
{
latestSearchStatistics.Set(ref searchStatistics);

Expand All @@ -87,7 +87,7 @@ private void OnProgressUpdated(ref SearchStatistics searchStatistics, double pro
}, DispatcherPriority.Input);
}

private void OnSearchDone(ref SearchStatistics searchStatistics)
private void OnSearchDone(IntPtr context, ref SearchStatistics searchStatistics)
{
latestSearchStatistics.Set(ref searchStatistics);

Expand All @@ -97,7 +97,7 @@ private void OnSearchDone(ref SearchStatistics searchStatistics)
}, DispatcherPriority.Input);
}

private void OnError(string message)
private void OnError(IntPtr context, string message)
{
Dispatcher.InvokeAsync(async () =>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ private void OnSizeChanged(object sender, SizeChangedEventArgs e)
ResizeView(childView, (int)e.NewSize.Width, (int)e.NewSize.Height);
}

public void AddItem(IntPtr findData, IntPtr itemPath)
public void AddItem(IntPtr context, IntPtr findData, IntPtr itemPath)
{
createdEvent.WaitOne();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ namespace FileSystemSearch
{
class SearchUtils
{
public delegate void FoundPathCallbackDelegate(IntPtr findData, IntPtr path);
public delegate void SearchProgressUpdatedDelegate([In] ref SearchStatistics searchStatistics, double progress);
public delegate void SearchDoneCallbackDelegate([In] ref SearchStatistics searchStatistics);
public delegate void ErrorCallbackDelegate([In] [MarshalAs(UnmanagedType.LPWStr)] string message);
public delegate void FoundPathCallbackDelegate(IntPtr context, IntPtr findData, IntPtr path);
public delegate void SearchProgressUpdatedDelegate(IntPtr context, [In] ref SearchStatistics searchStatistics, double progress);
public delegate void SearchDoneCallbackDelegate(IntPtr context, [In] ref SearchStatistics searchStatistics);
public delegate void ErrorCallbackDelegate(IntPtr context, [In] [MarshalAs(UnmanagedType.LPWStr)] string message);

public static bool ValidateSearchViewModel(SearchViewModel searchViewModel, out string validationFailedReason)
{
Expand All @@ -23,13 +23,13 @@ public static bool ValidateSearchViewModel(SearchViewModel searchViewModel, out

if (searchViewModel.SearchForFiles && !searchViewModel.SearchInFilePath && !searchViewModel.SearchInFileName && !searchViewModel.SearchInFileContents)
{
validationFailedReason = "At least one file search mode must be selected if searching for directories.";
validationFailedReason = "At least one file search mode must be selected if searching for files.";
return false;
}

if (searchViewModel.SearchInFileContents && !searchViewModel.SearchContentsAsUtf8 && !searchViewModel.SearchContentsAsUtf16)
{
validationFailedReason = "When searching file contents, either must be searched as either UTF8 and/or UTF16.";
validationFailedReason = "When searching file contents, UTF8 and/or UTF16 search must be selected.";
return false;
}

Expand Down Expand Up @@ -116,7 +116,7 @@ public static IntPtr SearchAsync(SearchViewModel searchViewModel, FoundPathCallb
if (searchViewModel.SearchUseDirectStorage)
searchFlags |= SearchFlags.UseDirectStorage;

return Search(foundPathCallback, searchProgressUpdated, searchDoneCallback, errorCallback, searchViewModel.SearchPath, searchViewModel.SearchPattern, searchViewModel.SearchString, searchFlags, searchViewModel.IgnoreFilesLargerThanInBytes);
return Search(foundPathCallback, searchProgressUpdated, searchDoneCallback, errorCallback, searchViewModel.SearchPath, searchViewModel.SearchPattern, searchViewModel.SearchString, searchFlags, searchViewModel.IgnoreFilesLargerThanInBytes, IntPtr.Zero);
}

enum SearchFlags
Expand Down Expand Up @@ -147,7 +147,8 @@ private static extern IntPtr Search(
[MarshalAs(UnmanagedType.LPWStr)]string searchPattern,
[MarshalAs(UnmanagedType.LPWStr)]string searchString,
SearchFlags searchFlags,
ulong ignoreFilesLargerThan);
ulong ignoreFilesLargerThan,
IntPtr callbackContext);

[DllImport("SearchEngine.dll")]
public static extern void CleanupSearchOperation(IntPtr searchOperation);
Expand Down
Loading