Skip to content

Commit

Permalink
Merge pull request #3 from TautvydasZilys/win32-ui
Browse files Browse the repository at this point in the history
Win32 UI
  • Loading branch information
TautvydasZilys authored May 22, 2022
2 parents 9c4f98d + 57689dd commit ced8539
Show file tree
Hide file tree
Showing 72 changed files with 3,184 additions and 396 deletions.
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
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit ced8539

Please sign in to comment.