-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEverything3SDK.psm1
More file actions
172 lines (130 loc) · 7.78 KB
/
Everything3SDK.psm1
File metadata and controls
172 lines (130 loc) · 7.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
Write-Verbose "=== DEBUG: Everything3SDK.psm1 wird geladen von: $PSCommandPath ==="
Write-Verbose "PSScriptRoot: $PSScriptRoot"
$ModulePath = $PSScriptRoot
$DllPath = Join-Path $ModulePath "Everything3_x64.dll"
Write-Verbose "DLL-Pfad: $DllPath"
Write-Verbose "DLL existiert: $(Test-Path $DllPath)"
# Modul-Pfad zu PATH hinzufügen für DLL-Loading
$env:PATH = "$ModulePath;$env:PATH"
Write-Verbose "Modul-Pfad zu PATH hinzugefügt"
#region P/Invoke Definitions
# Korrigierte C# Wrapper-Klasse für Everything3 SDK
$Everything3Type = @"
using System;
using System.Runtime.InteropServices;
using System.Text;
public static class Everything3SDK
{
// Client connection functions
[DllImport("Everything3_x64.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.StdCall)]
public static extern IntPtr Everything3_ConnectW(string instanceName);
[DllImport("Everything3_x64.dll", CallingConvention = CallingConvention.StdCall)]
public static extern bool Everything3_DestroyClient(IntPtr client);
// Search state functions
[DllImport("Everything3_x64.dll", CallingConvention = CallingConvention.StdCall)]
public static extern IntPtr Everything3_CreateSearchState();
[DllImport("Everything3_x64.dll", CallingConvention = CallingConvention.StdCall)]
public static extern bool Everything3_DestroySearchState(IntPtr searchState);
[DllImport("Everything3_x64.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.StdCall)]
public static extern bool Everything3_SetSearchTextW(IntPtr searchState, string searchText);
[DllImport("Everything3_x64.dll", CallingConvention = CallingConvention.StdCall)]
public static extern bool Everything3_SetSearchViewportOffset(IntPtr searchState, uint offset);
[DllImport("Everything3_x64.dll", CallingConvention = CallingConvention.StdCall)]
public static extern bool Everything3_SetSearchViewportCount(IntPtr searchState, uint count);
[DllImport("Everything3_x64.dll", CallingConvention = CallingConvention.StdCall)]
public static extern bool Everything3_SetSearchMatchCase(IntPtr searchState, bool matchCase);
[DllImport("Everything3_x64.dll", CallingConvention = CallingConvention.StdCall)]
public static extern bool Everything3_SetSearchMatchWholeWords(IntPtr searchState, bool matchWholeWords);
[DllImport("Everything3_x64.dll", CallingConvention = CallingConvention.StdCall)]
public static extern bool Everything3_SetSearchMatchPath(IntPtr searchState, bool matchPath);
[DllImport("Everything3_x64.dll", CallingConvention = CallingConvention.StdCall)]
public static extern bool Everything3_SetSearchRegex(IntPtr searchState, bool regex);
// Search execution
[DllImport("Everything3_x64.dll", CallingConvention = CallingConvention.StdCall)]
public static extern IntPtr Everything3_Search(IntPtr client, IntPtr searchState);
[DllImport("Everything3_x64.dll", CallingConvention = CallingConvention.StdCall)]
public static extern bool Everything3_DestroyResultList(IntPtr resultList);
// Result retrieval
[DllImport("Everything3_x64.dll", CallingConvention = CallingConvention.StdCall)]
public static extern uint Everything3_GetResultListViewportCount(IntPtr resultList);
[DllImport("Everything3_x64.dll", CallingConvention = CallingConvention.StdCall)]
public static extern uint Everything3_GetResultListCount(IntPtr resultList);
[DllImport("Everything3_x64.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.StdCall)]
public static extern uint Everything3_GetResultFullPathNameW(IntPtr resultList, uint index, StringBuilder fileName, uint fileNameSize);
[DllImport("Everything3_x64.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.StdCall)]
public static extern uint Everything3_GetResultNameW(IntPtr resultList, uint index, StringBuilder fileName, uint fileNameSize);
// Property requests
[DllImport("Everything3_x64.dll", CallingConvention = CallingConvention.StdCall)]
public static extern bool Everything3_AddSearchPropertyRequest(IntPtr searchState, uint propertyId);
[DllImport("Everything3_x64.dll", CallingConvention = CallingConvention.StdCall)]
public static extern uint Everything3_GetResultPropertyTextW(IntPtr resultList, uint index, uint propertyId, StringBuilder buffer, uint bufferSize);
[DllImport("Everything3_x64.dll", CallingConvention = CallingConvention.StdCall)]
public static extern ulong Everything3_GetResultPropertyUINT64(IntPtr resultList, uint index, uint propertyId);
[DllImport("Everything3_x64.dll", CallingConvention = CallingConvention.StdCall)]
public static extern uint Everything3_GetResultPropertyDWORD(IntPtr resultList, uint index, uint propertyId);
// Sort functions
[DllImport("Everything3_x64.dll", CallingConvention = CallingConvention.StdCall)]
public static extern bool Everything3_AddSearchSort(IntPtr searchState, uint propertyId, bool ascending);
// Error handling
[DllImport("Everything3_x64.dll", CallingConvention = CallingConvention.StdCall)]
public static extern uint Everything3_GetLastError();
// Version info
[DllImport("Everything3_x64.dll", CallingConvention = CallingConvention.StdCall)]
public static extern uint Everything3_GetMajorVersion(IntPtr client);
[DllImport("Everything3_x64.dll", CallingConvention = CallingConvention.StdCall)]
public static extern uint Everything3_GetMinorVersion(IntPtr client);
// DB Status
[DllImport("Everything3_x64.dll", CallingConvention = CallingConvention.StdCall)]
public static extern bool Everything3_IsDBLoaded(IntPtr client);
}
public static class Everything3Properties
{
public const uint EVERYTHING3_PROPERTY_ID_NAME = 0;
public const uint EVERYTHING3_PROPERTY_ID_PATH = 1;
public const uint EVERYTHING3_PROPERTY_ID_SIZE = 2;
public const uint EVERYTHING3_PROPERTY_ID_EXTENSION = 3;
public const uint EVERYTHING3_PROPERTY_ID_TYPE = 4;
public const uint EVERYTHING3_PROPERTY_ID_DATE_MODIFIED = 5;
public const uint EVERYTHING3_PROPERTY_ID_DATE_CREATED = 6;
public const uint EVERYTHING3_PROPERTY_ID_DATE_ACCESSED = 7;
public const uint EVERYTHING3_PROPERTY_ID_ATTRIBUTES = 8;
public const uint EVERYTHING3_PROPERTY_ID_FULL_PATH = 240;
}
"@
$typeExists = $null -ne ([System.Management.Automation.PSTypeName]'Everything3SDK').Type
Write-Verbose "Everything3SDK Type bereits geladen: $typeExists"
$typeExists = $null -ne ([System.Management.Automation.PSTypeName]'Everything3SDK').Type
Write-Verbose "Everything3SDK Type bereits geladen: $typeExists"
if (-not $typeExists) {
try {
Write-Host "Lade native DLL explizit: $DllPath" -ForegroundColor Yellow
# Kernel32 LoadLibrary P/Invoke definieren
$Kernel32Type = @"
using System;
using System.Runtime.InteropServices;
public static class Kernel32
{
[DllImport("kernel32.dll", SetLastError = true)]
public static extern IntPtr LoadLibrary(string lpFileName);
[DllImport("kernel32.dll", SetLastError = true)]
public static extern bool FreeLibrary(IntPtr hModule);
}
"@
# Kernel32 Type laden falls noch nicht vorhanden
if (-not ([System.Management.Automation.PSTypeName]'Kernel32').Type) {
Add-Type -TypeDefinition $Kernel32Type
}
# DLL laden (Weil in VSCode es ansonsten nicht funktioniert)
$hModule = [Kernel32]::LoadLibrary($DllPath)
if ($hModule -eq [IntPtr]::Zero) {
throw "Fehler beim Laden der nativen DLL: $DllPath"
}
Write-Verbose "Native DLL erfolgreich geladen, Handle: $hModule"
Add-Type -TypeDefinition $Everything3Type -ErrorAction Stop
Write-Verbose "Everything3SDK Types über temporäre Datei geladen"
}
finally {
Write-Verbose "Finishe: Alles geladen, DLL Handle: $hModule"
}
}
#endregion