everything-voidtools 0.1.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- everything_voidtools-0.1.2/PKG-INFO +176 -0
- everything_voidtools-0.1.2/README.md +167 -0
- everything_voidtools-0.1.2/pyproject.toml +15 -0
- everything_voidtools-0.1.2/pyproject.toml.orig +14 -0
- everything_voidtools-0.1.2/src/everything_voidtools/__init__.py +2 -0
- everything_voidtools-0.1.2/src/everything_voidtools/dll/Everything64.dll +0 -0
- everything_voidtools-0.1.2/src/everything_voidtools/everything_search.py +549 -0
- everything_voidtools-0.1.2/src/everything_voidtools/py.typed +0 -0
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
Metadata-Version: 2.3
|
|
2
|
+
Name: everything-voidtools
|
|
3
|
+
Version: 0.1.2
|
|
4
|
+
Summary: A packaged version of a nice everything interface.
|
|
5
|
+
Author: Nicholas
|
|
6
|
+
Author-email: Nicholas <nmerryman9001@gmail.com>
|
|
7
|
+
Requires-Python: >=3.15
|
|
8
|
+
Description-Content-Type: text/markdown
|
|
9
|
+
|
|
10
|
+
# Everything
|
|
11
|
+
|
|
12
|
+
`Everything voidtools` is a type-safe Python SDK designed to interface with the `Everything` file search software for Windows. It provides a clean, object-oriented API to harness the full power of Everything's instant search capabilities.
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
## Requirements
|
|
17
|
+
|
|
18
|
+
This project uses IPC (Inter-Process Communication) to communicate with `Everything`. Therefore, you must have the **full version** of the `Everything` software installed and running in the background. The Lite version does not support IPC.
|
|
19
|
+
|
|
20
|
+
- **Download Everything**: You can download it from the [official website](https://www.voidtools.com/en-us/downloads/).
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
## Usage Example
|
|
25
|
+
|
|
26
|
+
Here is a basic example demonstrating how to use `Everything` to find the 5 most recently modified Python files on your system.
|
|
27
|
+
|
|
28
|
+
```python
|
|
29
|
+
from everything_search import Client, Request, Sort, SDKError
|
|
30
|
+
|
|
31
|
+
try:
|
|
32
|
+
# The client must be used within a 'with' statement to ensure resources are managed correctly.
|
|
33
|
+
with Client() as client:
|
|
34
|
+
print(f"Everything version: {client.version()}")
|
|
35
|
+
|
|
36
|
+
# 1. Define which fields to retrieve using Request enums.
|
|
37
|
+
search_flags = (
|
|
38
|
+
Request.FULL_PATH_AND_FILE_NAME |
|
|
39
|
+
Request.SIZE |
|
|
40
|
+
Request.DATE_MODIFIED
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
# 2. Perform the search with clear, readable parameters.
|
|
44
|
+
results = client.search(
|
|
45
|
+
keywords="*.py",
|
|
46
|
+
limit=5,
|
|
47
|
+
flags=search_flags,
|
|
48
|
+
sort=Sort.DATE_MODIFIED_DESCENDING
|
|
49
|
+
)
|
|
50
|
+
|
|
51
|
+
print("\nFound the 5 most recently modified Python files:")
|
|
52
|
+
|
|
53
|
+
# 3. The results are structured SearchResult objects.
|
|
54
|
+
for item in results:
|
|
55
|
+
size_kb = f"{item.size / 1024:.2f} KB" if item.size is not None else "N/A"
|
|
56
|
+
print(f"- Path: {item.full_path}")
|
|
57
|
+
print(f" Size: {size_kb}")
|
|
58
|
+
print(f" Modified: {item.modified_time}")
|
|
59
|
+
|
|
60
|
+
except FileNotFoundError as e:
|
|
61
|
+
print(f"Error: Could not find Everything64.dll. Please ensure it's in the correct path.\n{e}")
|
|
62
|
+
except SDKError as e:
|
|
63
|
+
# Catch specific SDK errors, e.g., if 'Everything' is not running.
|
|
64
|
+
print(f"An SDK error occurred: {e}")
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
## Key Features
|
|
70
|
+
|
|
71
|
+
### Type-Safe Enums
|
|
72
|
+
Instead of using raw integer constants, the SDK provides `Enum` classes for `Request`, `Sort`, and `FileAttribute`. This improves code readability and prevents bugs by allowing static analysis tools and IDEs to catch errors before runtime.
|
|
73
|
+
|
|
74
|
+
### Structured Results (`SearchResult` Dataclass)
|
|
75
|
+
The search methods return an iterator of `SearchResult` objects. This is a read-only `dataclass` that provides attribute-style access to results (e.g., `result.full_path`). It offers a more robust and predictable alternative to dictionaries, with full support for IDE autocompletion.
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
## API Overview
|
|
80
|
+
|
|
81
|
+
### Core Search Method
|
|
82
|
+
This is the main function for all queries. Convenience wrappers are built on top of it.
|
|
83
|
+
|
|
84
|
+
```python
|
|
85
|
+
def search(
|
|
86
|
+
self,
|
|
87
|
+
keywords: str,
|
|
88
|
+
match_path: bool = False,
|
|
89
|
+
match_case: bool = False,
|
|
90
|
+
whole_word: bool = False,
|
|
91
|
+
regex: bool = False,
|
|
92
|
+
offset: int = 0,
|
|
93
|
+
limit: int = -1,
|
|
94
|
+
flags: Request = Request.DEFAULT,
|
|
95
|
+
sort: Sort = Sort.NAME_ASCENDING
|
|
96
|
+
) -> Iterator[SearchResult]:
|
|
97
|
+
...
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### Convenience Wrappers
|
|
101
|
+
For common search tasks, you can use these helpful methods:
|
|
102
|
+
- `search_in_located(path, keywords, **kwargs)`: Search within a specific folder.
|
|
103
|
+
- `search_folder(keywords, **kwargs)`: Search for folders only.
|
|
104
|
+
- `search_ext(extensions, keywords, **kwargs)`: Search by one or more file extensions.
|
|
105
|
+
- `search_audio(keywords, **kwargs)`: Search for common audio files.
|
|
106
|
+
- `search_video(keywords, **kwargs)`: Search for common video files.
|
|
107
|
+
- `search_image(keywords, **kwargs)`: Search for common image files.
|
|
108
|
+
- `search_doc(keywords, **kwargs)`: Search for common document files.
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
## Reference
|
|
113
|
+
|
|
114
|
+
### Request Fields (`Request`)
|
|
115
|
+
Use these enum members to specify which data fields to retrieve. The default is `Request.DEFAULT`.
|
|
116
|
+
|
|
117
|
+
| Member | Description |
|
|
118
|
+
| ------------------------------------- | ------------------------------------------------ |
|
|
119
|
+
| `FILE_NAME` | File name only |
|
|
120
|
+
| `PATH` | Path without the file name |
|
|
121
|
+
| `FULL_PATH_AND_FILE_NAME` | Full path including the file name |
|
|
122
|
+
| `EXTENSION` | File extension |
|
|
123
|
+
| `SIZE` | File size in bytes |
|
|
124
|
+
| `DATE_CREATED` | Creation date |
|
|
125
|
+
| `DATE_MODIFIED` | Last modified date |
|
|
126
|
+
| `DATE_ACCESSED` | Last accessed date |
|
|
127
|
+
| `ATTRIBUTES` | File attributes (e.g., Read-only, Hidden) |
|
|
128
|
+
| `RUN_COUNT` | How many times the file has been run |
|
|
129
|
+
| `DATE_RUN` | The date the file was last run |
|
|
130
|
+
| `DATE_RECENTLY_CHANGED` | The date the file was recently changed |
|
|
131
|
+
| `HIGHLIGHTED_FILE_NAME` | Highlighted file name |
|
|
132
|
+
| `HIGHLIGHTED_PATH` | Highlighted path |
|
|
133
|
+
| `HIGHLIGHTED_FULL_PATH_AND_FILE_NAME` | Highlighted full path and file name |
|
|
134
|
+
| `DEFAULT` | A composite of `FULL_PATH_AND_FILE_NAME`, `SIZE`, and `DATE_MODIFIED` |
|
|
135
|
+
| `ALL` | A composite of all available request flags |
|
|
136
|
+
|
|
137
|
+
### Sort Orders (`Sort`)
|
|
138
|
+
Use these enum members to control the sort order of the results. The default is `Sort.NAME_ASCENDING`.
|
|
139
|
+
|
|
140
|
+
| Member | Description |
|
|
141
|
+
| ----------------------------- | ----------------------------- |
|
|
142
|
+
| `NAME_ASCENDING` / `DESCENDING` | Sort by file name |
|
|
143
|
+
| `PATH_ASCENDING` / `DESCENDING` | Sort by path |
|
|
144
|
+
| `SIZE_ASCENDING` / `DESCENDING` | Sort by size |
|
|
145
|
+
| `EXTENSION_ASCENDING` / `DESCENDING` | Sort by extension |
|
|
146
|
+
| `DATE_CREATED_ASCENDING` / `DESCENDING` | Sort by creation date |
|
|
147
|
+
| `DATE_MODIFIED_ASCENDING` / `DESCENDING` | Sort by modified date |
|
|
148
|
+
| ...and many more | (See `Sort` enum in code for a full list) |
|
|
149
|
+
|
|
150
|
+
### File Attributes (`FileAttribute`)
|
|
151
|
+
These enum members represent Windows file attributes.
|
|
152
|
+
|
|
153
|
+
| Member | Description |
|
|
154
|
+
| ----------------------- | ----------------------------------------- |
|
|
155
|
+
| `READONLY` | The file is read-only. |
|
|
156
|
+
| `HIDDEN` | The file is hidden. |
|
|
157
|
+
| `SYSTEM` | The file is a system file. |
|
|
158
|
+
| `DIRECTORY` | The item is a directory. |
|
|
159
|
+
| `ARCHIVE` | The file is marked for archive. |
|
|
160
|
+
| `COMPRESSED` | The file is compressed. |
|
|
161
|
+
| `ENCRYPTED` | The file is encrypted. |
|
|
162
|
+
| `REPARSE_POINT` | The file has an associated reparse point. |
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
## Search Syntax
|
|
167
|
+
|
|
168
|
+
This SDK supports the complete `Everything` search syntax. For advanced queries, please refer to the official documentation within the `Everything` application (Help -> Search Syntax). This includes:
|
|
169
|
+
- Operators (`!`, `|`, ` `)
|
|
170
|
+
- Wildcards (`*`, `?`)
|
|
171
|
+
- Modifiers (`file:`, `folder:`, `ext:`)
|
|
172
|
+
- Functions (`dm:`, `size:`, `attrib:`)
|
|
173
|
+
- And much more.
|
|
174
|
+
|
|
175
|
+
---
|
|
176
|
+
This package is built on top of [https://github.com/obgnail/everything_tool] and packaged for easier installation.
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
# Everything
|
|
2
|
+
|
|
3
|
+
`Everything voidtools` is a type-safe Python SDK designed to interface with the `Everything` file search software for Windows. It provides a clean, object-oriented API to harness the full power of Everything's instant search capabilities.
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
## Requirements
|
|
8
|
+
|
|
9
|
+
This project uses IPC (Inter-Process Communication) to communicate with `Everything`. Therefore, you must have the **full version** of the `Everything` software installed and running in the background. The Lite version does not support IPC.
|
|
10
|
+
|
|
11
|
+
- **Download Everything**: You can download it from the [official website](https://www.voidtools.com/en-us/downloads/).
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
## Usage Example
|
|
16
|
+
|
|
17
|
+
Here is a basic example demonstrating how to use `Everything` to find the 5 most recently modified Python files on your system.
|
|
18
|
+
|
|
19
|
+
```python
|
|
20
|
+
from everything_search import Client, Request, Sort, SDKError
|
|
21
|
+
|
|
22
|
+
try:
|
|
23
|
+
# The client must be used within a 'with' statement to ensure resources are managed correctly.
|
|
24
|
+
with Client() as client:
|
|
25
|
+
print(f"Everything version: {client.version()}")
|
|
26
|
+
|
|
27
|
+
# 1. Define which fields to retrieve using Request enums.
|
|
28
|
+
search_flags = (
|
|
29
|
+
Request.FULL_PATH_AND_FILE_NAME |
|
|
30
|
+
Request.SIZE |
|
|
31
|
+
Request.DATE_MODIFIED
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
# 2. Perform the search with clear, readable parameters.
|
|
35
|
+
results = client.search(
|
|
36
|
+
keywords="*.py",
|
|
37
|
+
limit=5,
|
|
38
|
+
flags=search_flags,
|
|
39
|
+
sort=Sort.DATE_MODIFIED_DESCENDING
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
print("\nFound the 5 most recently modified Python files:")
|
|
43
|
+
|
|
44
|
+
# 3. The results are structured SearchResult objects.
|
|
45
|
+
for item in results:
|
|
46
|
+
size_kb = f"{item.size / 1024:.2f} KB" if item.size is not None else "N/A"
|
|
47
|
+
print(f"- Path: {item.full_path}")
|
|
48
|
+
print(f" Size: {size_kb}")
|
|
49
|
+
print(f" Modified: {item.modified_time}")
|
|
50
|
+
|
|
51
|
+
except FileNotFoundError as e:
|
|
52
|
+
print(f"Error: Could not find Everything64.dll. Please ensure it's in the correct path.\n{e}")
|
|
53
|
+
except SDKError as e:
|
|
54
|
+
# Catch specific SDK errors, e.g., if 'Everything' is not running.
|
|
55
|
+
print(f"An SDK error occurred: {e}")
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
## Key Features
|
|
61
|
+
|
|
62
|
+
### Type-Safe Enums
|
|
63
|
+
Instead of using raw integer constants, the SDK provides `Enum` classes for `Request`, `Sort`, and `FileAttribute`. This improves code readability and prevents bugs by allowing static analysis tools and IDEs to catch errors before runtime.
|
|
64
|
+
|
|
65
|
+
### Structured Results (`SearchResult` Dataclass)
|
|
66
|
+
The search methods return an iterator of `SearchResult` objects. This is a read-only `dataclass` that provides attribute-style access to results (e.g., `result.full_path`). It offers a more robust and predictable alternative to dictionaries, with full support for IDE autocompletion.
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
## API Overview
|
|
71
|
+
|
|
72
|
+
### Core Search Method
|
|
73
|
+
This is the main function for all queries. Convenience wrappers are built on top of it.
|
|
74
|
+
|
|
75
|
+
```python
|
|
76
|
+
def search(
|
|
77
|
+
self,
|
|
78
|
+
keywords: str,
|
|
79
|
+
match_path: bool = False,
|
|
80
|
+
match_case: bool = False,
|
|
81
|
+
whole_word: bool = False,
|
|
82
|
+
regex: bool = False,
|
|
83
|
+
offset: int = 0,
|
|
84
|
+
limit: int = -1,
|
|
85
|
+
flags: Request = Request.DEFAULT,
|
|
86
|
+
sort: Sort = Sort.NAME_ASCENDING
|
|
87
|
+
) -> Iterator[SearchResult]:
|
|
88
|
+
...
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
### Convenience Wrappers
|
|
92
|
+
For common search tasks, you can use these helpful methods:
|
|
93
|
+
- `search_in_located(path, keywords, **kwargs)`: Search within a specific folder.
|
|
94
|
+
- `search_folder(keywords, **kwargs)`: Search for folders only.
|
|
95
|
+
- `search_ext(extensions, keywords, **kwargs)`: Search by one or more file extensions.
|
|
96
|
+
- `search_audio(keywords, **kwargs)`: Search for common audio files.
|
|
97
|
+
- `search_video(keywords, **kwargs)`: Search for common video files.
|
|
98
|
+
- `search_image(keywords, **kwargs)`: Search for common image files.
|
|
99
|
+
- `search_doc(keywords, **kwargs)`: Search for common document files.
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
## Reference
|
|
104
|
+
|
|
105
|
+
### Request Fields (`Request`)
|
|
106
|
+
Use these enum members to specify which data fields to retrieve. The default is `Request.DEFAULT`.
|
|
107
|
+
|
|
108
|
+
| Member | Description |
|
|
109
|
+
| ------------------------------------- | ------------------------------------------------ |
|
|
110
|
+
| `FILE_NAME` | File name only |
|
|
111
|
+
| `PATH` | Path without the file name |
|
|
112
|
+
| `FULL_PATH_AND_FILE_NAME` | Full path including the file name |
|
|
113
|
+
| `EXTENSION` | File extension |
|
|
114
|
+
| `SIZE` | File size in bytes |
|
|
115
|
+
| `DATE_CREATED` | Creation date |
|
|
116
|
+
| `DATE_MODIFIED` | Last modified date |
|
|
117
|
+
| `DATE_ACCESSED` | Last accessed date |
|
|
118
|
+
| `ATTRIBUTES` | File attributes (e.g., Read-only, Hidden) |
|
|
119
|
+
| `RUN_COUNT` | How many times the file has been run |
|
|
120
|
+
| `DATE_RUN` | The date the file was last run |
|
|
121
|
+
| `DATE_RECENTLY_CHANGED` | The date the file was recently changed |
|
|
122
|
+
| `HIGHLIGHTED_FILE_NAME` | Highlighted file name |
|
|
123
|
+
| `HIGHLIGHTED_PATH` | Highlighted path |
|
|
124
|
+
| `HIGHLIGHTED_FULL_PATH_AND_FILE_NAME` | Highlighted full path and file name |
|
|
125
|
+
| `DEFAULT` | A composite of `FULL_PATH_AND_FILE_NAME`, `SIZE`, and `DATE_MODIFIED` |
|
|
126
|
+
| `ALL` | A composite of all available request flags |
|
|
127
|
+
|
|
128
|
+
### Sort Orders (`Sort`)
|
|
129
|
+
Use these enum members to control the sort order of the results. The default is `Sort.NAME_ASCENDING`.
|
|
130
|
+
|
|
131
|
+
| Member | Description |
|
|
132
|
+
| ----------------------------- | ----------------------------- |
|
|
133
|
+
| `NAME_ASCENDING` / `DESCENDING` | Sort by file name |
|
|
134
|
+
| `PATH_ASCENDING` / `DESCENDING` | Sort by path |
|
|
135
|
+
| `SIZE_ASCENDING` / `DESCENDING` | Sort by size |
|
|
136
|
+
| `EXTENSION_ASCENDING` / `DESCENDING` | Sort by extension |
|
|
137
|
+
| `DATE_CREATED_ASCENDING` / `DESCENDING` | Sort by creation date |
|
|
138
|
+
| `DATE_MODIFIED_ASCENDING` / `DESCENDING` | Sort by modified date |
|
|
139
|
+
| ...and many more | (See `Sort` enum in code for a full list) |
|
|
140
|
+
|
|
141
|
+
### File Attributes (`FileAttribute`)
|
|
142
|
+
These enum members represent Windows file attributes.
|
|
143
|
+
|
|
144
|
+
| Member | Description |
|
|
145
|
+
| ----------------------- | ----------------------------------------- |
|
|
146
|
+
| `READONLY` | The file is read-only. |
|
|
147
|
+
| `HIDDEN` | The file is hidden. |
|
|
148
|
+
| `SYSTEM` | The file is a system file. |
|
|
149
|
+
| `DIRECTORY` | The item is a directory. |
|
|
150
|
+
| `ARCHIVE` | The file is marked for archive. |
|
|
151
|
+
| `COMPRESSED` | The file is compressed. |
|
|
152
|
+
| `ENCRYPTED` | The file is encrypted. |
|
|
153
|
+
| `REPARSE_POINT` | The file has an associated reparse point. |
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
## Search Syntax
|
|
158
|
+
|
|
159
|
+
This SDK supports the complete `Everything` search syntax. For advanced queries, please refer to the official documentation within the `Everything` application (Help -> Search Syntax). This includes:
|
|
160
|
+
- Operators (`!`, `|`, ` `)
|
|
161
|
+
- Wildcards (`*`, `?`)
|
|
162
|
+
- Modifiers (`file:`, `folder:`, `ext:`)
|
|
163
|
+
- Functions (`dm:`, `size:`, `attrib:`)
|
|
164
|
+
- And much more.
|
|
165
|
+
|
|
166
|
+
---
|
|
167
|
+
This package is built on top of [https://github.com/obgnail/everything_tool] and packaged for easier installation.
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "everything-voidtools"
|
|
3
|
+
version = "0.1.2"
|
|
4
|
+
description = "A packaged version of a nice everything interface."
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
requires-python = ">=3.15"
|
|
7
|
+
dependencies = []
|
|
8
|
+
|
|
9
|
+
[[project.authors]]
|
|
10
|
+
name = "Nicholas"
|
|
11
|
+
email = "nmerryman9001@gmail.com"
|
|
12
|
+
|
|
13
|
+
[build-system]
|
|
14
|
+
requires = ["uv_build>=0.13.4,<0.14.0"]
|
|
15
|
+
build-backend = "uv_build"
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "everything-voidtools"
|
|
3
|
+
version = "0.1.2"
|
|
4
|
+
description = "A packaged version of a nice everything interface."
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
authors = [
|
|
7
|
+
{ name = "Nicholas", email = "nmerryman9001@gmail.com" }
|
|
8
|
+
]
|
|
9
|
+
requires-python = ">=3.15"
|
|
10
|
+
dependencies = []
|
|
11
|
+
|
|
12
|
+
[build-system]
|
|
13
|
+
requires = ["uv_build>=0.13.4,<0.14.0"]
|
|
14
|
+
build-backend = "uv_build"
|
|
Binary file
|
|
@@ -0,0 +1,549 @@
|
|
|
1
|
+
"""
|
|
2
|
+
The Everything SDK provides a DLL and Lib interface to Everything over IPC.
|
|
3
|
+
Everything is required to run in the background.
|
|
4
|
+
|
|
5
|
+
documentation : https://www.voidtools.com/support/everything/sdk/
|
|
6
|
+
dependency (SDK): https://www.voidtools.com/Everything-SDK.zip
|
|
7
|
+
"""
|
|
8
|
+
import ctypes
|
|
9
|
+
import datetime
|
|
10
|
+
from ctypes import wintypes
|
|
11
|
+
from dataclasses import dataclass
|
|
12
|
+
from enum import IntEnum, IntFlag
|
|
13
|
+
from pathlib import Path
|
|
14
|
+
from typing import Dict, Iterable, Iterator, Final, Callable, Tuple, Optional
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def hello():
|
|
18
|
+
print("hello")
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
WINDOWS_TICKS = 10_000_000 # 100 nanoseconds
|
|
22
|
+
WINDOWS_EPOCH = datetime.datetime(1601, 1, 1)
|
|
23
|
+
POSIX_EPOCH = datetime.datetime(1970, 1, 1)
|
|
24
|
+
EPOCH_DIFFERENCE_S = (POSIX_EPOCH - WINDOWS_EPOCH).total_seconds()
|
|
25
|
+
WINDOWS_TICKS_TO_POSIX_EPOCH = EPOCH_DIFFERENCE_S * WINDOWS_TICKS
|
|
26
|
+
INVALID_FILETIME = 2 ** 64 - 1
|
|
27
|
+
MAX_PATH = 4096
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
class Request(IntFlag):
|
|
31
|
+
"""Flags for requesting specific file information."""
|
|
32
|
+
FILE_NAME = 0x00000001
|
|
33
|
+
PATH = 0x00000002
|
|
34
|
+
FULL_PATH_AND_FILE_NAME = 0x00000004
|
|
35
|
+
EXTENSION = 0x00000008
|
|
36
|
+
SIZE = 0x00000010
|
|
37
|
+
DATE_CREATED = 0x00000020
|
|
38
|
+
DATE_MODIFIED = 0x00000040
|
|
39
|
+
DATE_ACCESSED = 0x00000080
|
|
40
|
+
ATTRIBUTES = 0x00000100
|
|
41
|
+
FILE_LIST_FILE_NAME = 0x00000200
|
|
42
|
+
RUN_COUNT = 0x00000400
|
|
43
|
+
DATE_RUN = 0x00000800
|
|
44
|
+
DATE_RECENTLY_CHANGED = 0x00001000
|
|
45
|
+
HIGHLIGHTED_FILE_NAME = 0x00002000
|
|
46
|
+
HIGHLIGHTED_PATH = 0x00004000
|
|
47
|
+
HIGHLIGHTED_FULL_PATH_AND_FILE_NAME = 0x00008000
|
|
48
|
+
|
|
49
|
+
DEFAULT = FULL_PATH_AND_FILE_NAME | SIZE | DATE_MODIFIED
|
|
50
|
+
ALL = (
|
|
51
|
+
FILE_NAME | PATH | FULL_PATH_AND_FILE_NAME | EXTENSION | SIZE |
|
|
52
|
+
DATE_CREATED | DATE_MODIFIED | DATE_ACCESSED | ATTRIBUTES |
|
|
53
|
+
FILE_LIST_FILE_NAME | RUN_COUNT | DATE_RUN | DATE_RECENTLY_CHANGED |
|
|
54
|
+
HIGHLIGHTED_FILE_NAME | HIGHLIGHTED_PATH | HIGHLIGHTED_FULL_PATH_AND_FILE_NAME
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
class FileAttribute(IntFlag):
|
|
59
|
+
"""Windows file attributes constants."""
|
|
60
|
+
READONLY = 0x00000001
|
|
61
|
+
HIDDEN = 0x00000002
|
|
62
|
+
SYSTEM = 0x00000004
|
|
63
|
+
DIRECTORY = 0x00000010
|
|
64
|
+
ARCHIVE = 0x00000020
|
|
65
|
+
DEVICE = 0x00000040
|
|
66
|
+
NORMAL = 0x00000080
|
|
67
|
+
TEMPORARY = 0x00000100
|
|
68
|
+
SPARSE_FILE = 0x00000200
|
|
69
|
+
REPARSE_POINT = 0x00000400
|
|
70
|
+
COMPRESSED = 0x00000800
|
|
71
|
+
OFFLINE = 0x00001000
|
|
72
|
+
NOT_CONTENT_INDEXED = 0x00002000
|
|
73
|
+
ENCRYPTED = 0x00004000
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
ATTRIBUTE_MAP: Final[Dict[FileAttribute, str]] = {
|
|
77
|
+
FileAttribute.READONLY: 'R',
|
|
78
|
+
FileAttribute.HIDDEN: 'H',
|
|
79
|
+
FileAttribute.SYSTEM: 'S',
|
|
80
|
+
FileAttribute.DIRECTORY: 'D',
|
|
81
|
+
FileAttribute.ARCHIVE: 'A',
|
|
82
|
+
FileAttribute.DEVICE: 'D',
|
|
83
|
+
FileAttribute.NORMAL: 'N',
|
|
84
|
+
FileAttribute.TEMPORARY: 'T',
|
|
85
|
+
FileAttribute.SPARSE_FILE: 'P',
|
|
86
|
+
FileAttribute.REPARSE_POINT: 'L',
|
|
87
|
+
FileAttribute.COMPRESSED: 'C',
|
|
88
|
+
FileAttribute.OFFLINE: 'O',
|
|
89
|
+
FileAttribute.NOT_CONTENT_INDEXED: 'I',
|
|
90
|
+
FileAttribute.ENCRYPTED: 'E',
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
FILE_TYPE_GROUPS: Final[Dict[str, frozenset[str]]] = {
|
|
94
|
+
'AUDIO': frozenset({'m1a', 'dts', 'fla', 'mp3', 'xm', 'm2a', 'voc', 'cda', 'spc', 'snd', 'ac3', 'umx', 'mka',
|
|
95
|
+
'midi', 'wma', 'm3u', 'mod', 'mid', 'wav', 'aac', 'mpa', 'it', 'ogg', 'rmi', 'aif', 'mp2',
|
|
96
|
+
'm4a', 'ra', 'aiff', 'au', 'flac', 'aifc'}),
|
|
97
|
+
'VIDEO': frozenset({'m1v', 'mp2v', 'pss', 'mov', 'm4b', 'rm', 'vob', 'webm', '3gpp', 'roq', 'hdmov', 'tpr',
|
|
98
|
+
'evo', 'wmv', 'qt', 'dss', 'swf', 'rpm', 'flv', 'mpe', 'ogm', 'tp', 'f4v', '3gp', 'wm',
|
|
99
|
+
'amv', 'dsv', 'mpeg', 'bik', 'drc', 'ogv', 'ratdvd', 'mp4', 'asf', 'ts', 'wmp', 'ifo',
|
|
100
|
+
'3g2', 'm2t', 'ivf', 'm2v', 'mp4v', 'rmvb', 'avi', 'm2ts', 'mpv2', 'mpls', 'd2v', 'fli',
|
|
101
|
+
'bdmv', 'mpg', 'mkv', 'mpv4', 'flc', 'dsa', 'smil', 'm4p', 'm4v', 'vp6', 'm2p', 'pva',
|
|
102
|
+
'mts', 'rmm', 'smk', 'divx', 'ram', 'flic', '3gp2', 'dsm', 'amr'}),
|
|
103
|
+
'IMAGE': frozenset({'wmf', 'gif', 'ico', 'tga', 'tif', 'jpe', 'ani', 'jpeg', 'bmp', 'jpg', 'pcx', 'psd',
|
|
104
|
+
'tiff', 'webp', 'svg', 'png'}),
|
|
105
|
+
'DOC': frozenset({'doc', 'docx', 'pdf', 'txt', 'rtf', 'odt', 'xls', 'xlsx', 'ppt', 'pptx', 'md'}),
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
class Sort(IntEnum):
|
|
110
|
+
"""Sort types for query results."""
|
|
111
|
+
NAME_ASCENDING = 1
|
|
112
|
+
NAME_DESCENDING = 2
|
|
113
|
+
PATH_ASCENDING = 3
|
|
114
|
+
PATH_DESCENDING = 4
|
|
115
|
+
SIZE_ASCENDING = 5
|
|
116
|
+
SIZE_DESCENDING = 6
|
|
117
|
+
EXTENSION_ASCENDING = 7
|
|
118
|
+
EXTENSION_DESCENDING = 8
|
|
119
|
+
TYPE_NAME_ASCENDING = 9
|
|
120
|
+
TYPE_NAME_DESCENDING = 10
|
|
121
|
+
DATE_CREATED_ASCENDING = 11
|
|
122
|
+
DATE_CREATED_DESCENDING = 12
|
|
123
|
+
DATE_MODIFIED_ASCENDING = 13
|
|
124
|
+
DATE_MODIFIED_DESCENDING = 14
|
|
125
|
+
ATTRIBUTES_ASCENDING = 15
|
|
126
|
+
ATTRIBUTES_DESCENDING = 16
|
|
127
|
+
FILE_LIST_FILENAME_ASCENDING = 17
|
|
128
|
+
FILE_LIST_FILENAME_DESCENDING = 18
|
|
129
|
+
RUN_COUNT_ASCENDING = 19
|
|
130
|
+
RUN_COUNT_DESCENDING = 20
|
|
131
|
+
DATE_RECENTLY_CHANGED_ASCENDING = 21
|
|
132
|
+
DATE_RECENTLY_CHANGED_DESCENDING = 22
|
|
133
|
+
DATE_ACCESSED_ASCENDING = 23
|
|
134
|
+
DATE_ACCESSED_DESCENDING = 24
|
|
135
|
+
DATE_RUN_ASCENDING = 25
|
|
136
|
+
DATE_RUN_DESCENDING = 26
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
class EverythingError(IntEnum):
|
|
140
|
+
"""Error codes from Everything_GetLastError."""
|
|
141
|
+
OK = 0
|
|
142
|
+
MEMORY = 1
|
|
143
|
+
IPC = 2
|
|
144
|
+
REGISTERCLASSEX = 3
|
|
145
|
+
CREATEWINDOW = 4
|
|
146
|
+
CREATETHREAD = 5
|
|
147
|
+
INVALIDINDEX = 6
|
|
148
|
+
INVALIDCALL = 7
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
class SDKError(Exception):
|
|
152
|
+
"""Custom exception for Everything SDK errors."""
|
|
153
|
+
ERROR_MESSAGES = {
|
|
154
|
+
EverythingError.MEMORY: "Out of memory",
|
|
155
|
+
EverythingError.IPC: "IPC not available. Is 'Everything' running?",
|
|
156
|
+
EverythingError.REGISTERCLASSEX: "RegisterClassEx failed",
|
|
157
|
+
EverythingError.CREATEWINDOW: "CreateWindow failed",
|
|
158
|
+
EverythingError.CREATETHREAD: "CreateThread failed",
|
|
159
|
+
EverythingError.INVALIDINDEX: "Invalid result index",
|
|
160
|
+
EverythingError.INVALIDCALL: "Invalid call",
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
def __init__(self, error_code: EverythingError):
|
|
164
|
+
self.error_code = error_code
|
|
165
|
+
self.message = self.ERROR_MESSAGES.get(error_code, "An unknown error occurred")
|
|
166
|
+
super().__init__(f"[{self.error_code.name}] {self.message}")
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
@dataclass(frozen=True, slots=True)
|
|
170
|
+
class SearchResult:
|
|
171
|
+
"""A structured, read-only object for a single search result."""
|
|
172
|
+
full_path: Optional[str] = None
|
|
173
|
+
path: Optional[str] = None
|
|
174
|
+
name: Optional[str] = None
|
|
175
|
+
extension: Optional[str] = None
|
|
176
|
+
size: Optional[int] = None
|
|
177
|
+
created_time: Optional[datetime.datetime] = None
|
|
178
|
+
modified_time: Optional[datetime.datetime] = None
|
|
179
|
+
accessed_time: Optional[datetime.datetime] = None
|
|
180
|
+
attributes: Optional[str] = None
|
|
181
|
+
run_count: Optional[int] = None
|
|
182
|
+
date_run: Optional[datetime.datetime] = None
|
|
183
|
+
recently_changed: Optional[datetime.datetime] = None
|
|
184
|
+
highlighted_full_path: Optional[str] = None
|
|
185
|
+
highlighted_path: Optional[str] = None
|
|
186
|
+
highlighted_name: Optional[str] = None
|
|
187
|
+
file_list_file_name: Optional[str] = None
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
class Client:
|
|
191
|
+
def __init__(self, dll_path: Optional[str | Path] = None):
|
|
192
|
+
self.dll_path = str(dll_path or self._get_default_dll_path())
|
|
193
|
+
self.dll: Optional[ctypes.WinDLL] = None
|
|
194
|
+
self._buffers: Dict[str, ctypes._SimpleCData] = {}
|
|
195
|
+
self._request_func_map: Dict[Request, Tuple[str, Callable]] = {}
|
|
196
|
+
|
|
197
|
+
@property
|
|
198
|
+
def is_connected(self) -> bool:
|
|
199
|
+
"""Checks if the client is connected to the Everything DLL."""
|
|
200
|
+
return self.dll is not None
|
|
201
|
+
|
|
202
|
+
def connect(self) -> None:
|
|
203
|
+
"""Loads the Everything DLL and initializes the SDK. Does nothing if already connected."""
|
|
204
|
+
if self.is_connected:
|
|
205
|
+
return
|
|
206
|
+
try:
|
|
207
|
+
self.dll = ctypes.WinDLL(self.dll_path)
|
|
208
|
+
except FileNotFoundError as err:
|
|
209
|
+
raise FileNotFoundError(f"Could not find the Everything DLL at '{self.dll_path}'. "
|
|
210
|
+
f"Please ensure the SDK is downloaded and the path is correct.") from err
|
|
211
|
+
except OSError as err:
|
|
212
|
+
raise OSError(f"Failed to load DLL from '{self.dll_path}'. "
|
|
213
|
+
f"Ensure it's a valid DLL and matches your Python architecture.") from err
|
|
214
|
+
self._initialize_sdk()
|
|
215
|
+
|
|
216
|
+
def close(self) -> None:
|
|
217
|
+
"""Unloads the Everything DLL. Does nothing if not connected."""
|
|
218
|
+
if not self.is_connected:
|
|
219
|
+
return
|
|
220
|
+
if self.dll and hasattr(self.dll, "_handle"):
|
|
221
|
+
ctypes.windll.kernel32.FreeLibrary(self.dll._handle)
|
|
222
|
+
self.dll = None
|
|
223
|
+
|
|
224
|
+
def __enter__(self):
|
|
225
|
+
"""Context manager entry point. Connects to the SDK."""
|
|
226
|
+
self.connect()
|
|
227
|
+
return self
|
|
228
|
+
|
|
229
|
+
def __exit__(self, exc_type, exc_val, exc_tb):
|
|
230
|
+
"""Context manager exit point. Closes the connection."""
|
|
231
|
+
self.close()
|
|
232
|
+
|
|
233
|
+
@staticmethod
|
|
234
|
+
def _get_default_dll_path() -> Path:
|
|
235
|
+
"""Determines the default path for the Everything64.dll."""
|
|
236
|
+
return Path(__file__).parent / "dll" / "Everything64.dll"
|
|
237
|
+
|
|
238
|
+
@staticmethod
|
|
239
|
+
def _filetime_to_datetime(filetime: ctypes.c_ulonglong) -> Optional[datetime.datetime]:
|
|
240
|
+
"""Converts a Windows FILETIME structure to a Python datetime object."""
|
|
241
|
+
win_ticks = filetime.value
|
|
242
|
+
if win_ticks == 0 or win_ticks == INVALID_FILETIME:
|
|
243
|
+
return None
|
|
244
|
+
try:
|
|
245
|
+
posix_timestamp = (win_ticks - WINDOWS_TICKS_TO_POSIX_EPOCH) / WINDOWS_TICKS
|
|
246
|
+
return datetime.datetime.fromtimestamp(posix_timestamp)
|
|
247
|
+
except (OSError, ValueError):
|
|
248
|
+
return None
|
|
249
|
+
|
|
250
|
+
def _ensure_connected(self):
|
|
251
|
+
if not self.is_connected or not self.dll:
|
|
252
|
+
raise RuntimeError("Client is not connected. Please call connect() or use a 'with' statement.")
|
|
253
|
+
|
|
254
|
+
def _check_for_errors(self):
|
|
255
|
+
"""Centralized error checking to be called after critical operations."""
|
|
256
|
+
self._ensure_connected()
|
|
257
|
+
error_code_val = self.dll.Everything_GetLastError()
|
|
258
|
+
if error_code_val != EverythingError.OK:
|
|
259
|
+
raise SDKError(EverythingError(error_code_val))
|
|
260
|
+
|
|
261
|
+
def _initialize_sdk(self):
|
|
262
|
+
"""Prepare buffers, ctypes definitions, and function mappings."""
|
|
263
|
+
self._define_ctypes()
|
|
264
|
+
if not self.dll.Everything_IsDBLoaded():
|
|
265
|
+
self._check_for_errors()
|
|
266
|
+
self._create_buffers()
|
|
267
|
+
self._create_request_map()
|
|
268
|
+
|
|
269
|
+
def _create_buffers(self) -> None:
|
|
270
|
+
"""Pre-allocates ctypes buffers for performance."""
|
|
271
|
+
self._buffers = {
|
|
272
|
+
'full_path': ctypes.create_unicode_buffer(MAX_PATH),
|
|
273
|
+
'size': ctypes.c_ulonglong(0),
|
|
274
|
+
'accessed_time': ctypes.c_ulonglong(0),
|
|
275
|
+
'created_time': ctypes.c_ulonglong(0),
|
|
276
|
+
'modified_time': ctypes.c_ulonglong(0),
|
|
277
|
+
'recently_changed': ctypes.c_ulonglong(0),
|
|
278
|
+
'date_run': ctypes.c_ulonglong(0),
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
def _create_request_map(self) -> None:
|
|
282
|
+
"""Maps Requests to the corresponding result key and getter method."""
|
|
283
|
+
self._request_func_map = {
|
|
284
|
+
Request.HIGHLIGHTED_FULL_PATH_AND_FILE_NAME: ('highlighted_full_path', self._get_highlighted_full_path),
|
|
285
|
+
Request.HIGHLIGHTED_PATH: ('highlighted_path', self._get_highlighted_path),
|
|
286
|
+
Request.HIGHLIGHTED_FILE_NAME: ('highlighted_name', self._get_highlighted_name),
|
|
287
|
+
Request.DATE_RECENTLY_CHANGED: ('recently_changed', self._get_recently_changed),
|
|
288
|
+
Request.DATE_RUN: ('date_run', self._get_date_run),
|
|
289
|
+
Request.RUN_COUNT: ('run_count', self._get_run_count),
|
|
290
|
+
Request.FILE_LIST_FILE_NAME: ('file_list_file_name', self._get_file_list_file_name),
|
|
291
|
+
Request.ATTRIBUTES: ('attributes', self._get_attributes),
|
|
292
|
+
Request.DATE_ACCESSED: ('accessed_time', self._get_accessed_time),
|
|
293
|
+
Request.DATE_MODIFIED: ('modified_time', self._get_modified_time),
|
|
294
|
+
Request.DATE_CREATED: ('created_time', self._get_created_time),
|
|
295
|
+
Request.SIZE: ('size', self._get_size),
|
|
296
|
+
Request.EXTENSION: ('extension', self._get_extension),
|
|
297
|
+
Request.FULL_PATH_AND_FILE_NAME: ('full_path', self._get_full_path),
|
|
298
|
+
Request.PATH: ('path', self._get_path),
|
|
299
|
+
Request.FILE_NAME: ('name', self._get_name),
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
def _define_ctypes(self) -> None:
|
|
303
|
+
"""Define argument and return types for the DLL functions."""
|
|
304
|
+
if not self.dll:
|
|
305
|
+
return
|
|
306
|
+
|
|
307
|
+
BOOL = wintypes.BOOL
|
|
308
|
+
DWORD = wintypes.DWORD
|
|
309
|
+
LPCWSTR = wintypes.LPCWSTR
|
|
310
|
+
LPWSTR = wintypes.LPWSTR
|
|
311
|
+
HMODULE = wintypes.HMODULE
|
|
312
|
+
P_ULL = ctypes.POINTER(ctypes.c_ulonglong)
|
|
313
|
+
|
|
314
|
+
signatures = (
|
|
315
|
+
# Get String Results (Index -> String Pointer)
|
|
316
|
+
([DWORD], LPCWSTR, [
|
|
317
|
+
"Everything_GetResultExtensionW", "Everything_GetResultFileNameW",
|
|
318
|
+
"Everything_GetResultPathW", "Everything_GetResultHighlightedFileNameW",
|
|
319
|
+
"Everything_GetResultHighlightedPathW", "Everything_GetResultHighlightedFullPathAndFileNameW",
|
|
320
|
+
"Everything_GetResultFileListFileNameW",
|
|
321
|
+
]),
|
|
322
|
+
# Get Integer Results (Index -> Int)
|
|
323
|
+
([DWORD], DWORD, ["Everything_GetResultRunCount", "Everything_GetResultAttributes"]),
|
|
324
|
+
# Get Numeric/Time Data (Index, Output Pointer -> Void)
|
|
325
|
+
([DWORD, P_ULL], None, [
|
|
326
|
+
"Everything_GetResultDateCreated", "Everything_GetResultDateModified",
|
|
327
|
+
"Everything_GetResultDateAccessed", "Everything_GetResultSize",
|
|
328
|
+
"Everything_GetResultDateRecentlyChanged", "Everything_GetResultDateRun",
|
|
329
|
+
]),
|
|
330
|
+
# Set Boolean Options (Bool -> Void)
|
|
331
|
+
([BOOL], None, [
|
|
332
|
+
"Everything_SetMatchPath", "Everything_SetMatchCase",
|
|
333
|
+
"Everything_SetMatchWholeWord", "Everything_SetRegex",
|
|
334
|
+
]),
|
|
335
|
+
# Set Numeric Options (Int -> Void)
|
|
336
|
+
([DWORD], None, [
|
|
337
|
+
"Everything_SetRequestFlags", "Everything_SetSort",
|
|
338
|
+
"Everything_SetOffset", "Everything_SetMax",
|
|
339
|
+
]),
|
|
340
|
+
# Get Global State/Versions (Void -> Int)
|
|
341
|
+
([], DWORD, [
|
|
342
|
+
"Everything_GetMajorVersion", "Everything_GetMinorVersion",
|
|
343
|
+
"Everything_GetRevision", "Everything_GetBuildNumber",
|
|
344
|
+
"Everything_GetLastError", "Everything_GetNumResults",
|
|
345
|
+
]),
|
|
346
|
+
# Set Search String (String -> Void)
|
|
347
|
+
([LPCWSTR], None, ["Everything_SetSearchW"]),
|
|
348
|
+
# Void Actions (Void -> Void)
|
|
349
|
+
([], None, ["Everything_Reset", "Everything_Exit"]),
|
|
350
|
+
# Check DB Status (Void -> Bool)
|
|
351
|
+
([], BOOL, ["Everything_IsDBLoaded"]),
|
|
352
|
+
# Execute Query (Bool -> Bool)
|
|
353
|
+
([BOOL], BOOL, ["Everything_QueryW"]),
|
|
354
|
+
# Get Full Path into Buffer (Index, Buffer, Size -> Void)
|
|
355
|
+
([DWORD, LPWSTR, DWORD], None, ["Everything_GetResultFullPathNameW"]),
|
|
356
|
+
)
|
|
357
|
+
|
|
358
|
+
for arg_types, res_type, func_names in signatures:
|
|
359
|
+
for func_name in func_names:
|
|
360
|
+
func = getattr(self.dll, func_name, None)
|
|
361
|
+
if func:
|
|
362
|
+
func.argtypes = arg_types
|
|
363
|
+
func.restype = res_type
|
|
364
|
+
|
|
365
|
+
if hasattr(ctypes, "windll") and hasattr(ctypes.windll, "kernel32"):
|
|
366
|
+
try:
|
|
367
|
+
lib = ctypes.windll.kernel32.FreeLibrary
|
|
368
|
+
lib.argtypes = [HMODULE]
|
|
369
|
+
lib.restype = BOOL
|
|
370
|
+
except AttributeError:
|
|
371
|
+
pass
|
|
372
|
+
|
|
373
|
+
def _setup_query(
|
|
374
|
+
self, keywords: str, match_path: bool, match_case: bool,
|
|
375
|
+
whole_word: bool, regex: bool, offset: int, limit: int,
|
|
376
|
+
flags: Request, sort: Sort
|
|
377
|
+
) -> None:
|
|
378
|
+
"""Sets all query parameters before execution."""
|
|
379
|
+
self._ensure_connected()
|
|
380
|
+
self.dll.Everything_Reset()
|
|
381
|
+
self.dll.Everything_SetSearchW(keywords)
|
|
382
|
+
self.dll.Everything_SetMatchPath(match_path)
|
|
383
|
+
self.dll.Everything_SetMatchCase(match_case)
|
|
384
|
+
self.dll.Everything_SetMatchWholeWord(whole_word)
|
|
385
|
+
self.dll.Everything_SetRegex(regex)
|
|
386
|
+
self.dll.Everything_SetRequestFlags(flags.value)
|
|
387
|
+
self.dll.Everything_SetSort(sort.value)
|
|
388
|
+
if offset > 0:
|
|
389
|
+
self.dll.Everything_SetOffset(offset)
|
|
390
|
+
if limit >= 0:
|
|
391
|
+
self.dll.Everything_SetMax(limit)
|
|
392
|
+
|
|
393
|
+
def _get_name(self, idx: int) -> str:
|
|
394
|
+
return self.dll.Everything_GetResultFileNameW(idx)
|
|
395
|
+
|
|
396
|
+
def _get_path(self, idx: int) -> str:
|
|
397
|
+
return self.dll.Everything_GetResultPathW(idx)
|
|
398
|
+
|
|
399
|
+
def _get_full_path(self, idx: int) -> str:
|
|
400
|
+
buffer = self._buffers['full_path']
|
|
401
|
+
self.dll.Everything_GetResultFullPathNameW(idx, buffer, MAX_PATH)
|
|
402
|
+
return buffer.value
|
|
403
|
+
|
|
404
|
+
def _get_size(self, idx: int) -> int:
|
|
405
|
+
buffer = self._buffers['size']
|
|
406
|
+
self.dll.Everything_GetResultSize(idx, buffer)
|
|
407
|
+
return buffer.value
|
|
408
|
+
|
|
409
|
+
def _get_extension(self, idx: int) -> str:
|
|
410
|
+
return self.dll.Everything_GetResultExtensionW(idx)
|
|
411
|
+
|
|
412
|
+
def _get_run_count(self, idx: int) -> int:
|
|
413
|
+
return self.dll.Everything_GetResultRunCount(idx)
|
|
414
|
+
|
|
415
|
+
def _get_attributes(self, idx: int) -> str:
|
|
416
|
+
attr_int = self.dll.Everything_GetResultAttributes(idx)
|
|
417
|
+
if attr_int == 0:
|
|
418
|
+
return ""
|
|
419
|
+
|
|
420
|
+
attr_flags = FileAttribute(attr_int)
|
|
421
|
+
chars = [
|
|
422
|
+
ATTRIBUTE_MAP[flag]
|
|
423
|
+
for flag in attr_flags
|
|
424
|
+
if flag in ATTRIBUTE_MAP
|
|
425
|
+
]
|
|
426
|
+
return "".join(sorted(chars))
|
|
427
|
+
|
|
428
|
+
def _get_file_list_file_name(self, idx: int) -> str:
|
|
429
|
+
return self.dll.Everything_GetResultFileListFileNameW(idx)
|
|
430
|
+
|
|
431
|
+
def _get_accessed_time(self, idx: int) -> Optional[datetime.datetime]:
|
|
432
|
+
buffer = self._buffers['accessed_time']
|
|
433
|
+
self.dll.Everything_GetResultDateAccessed(idx, buffer)
|
|
434
|
+
return self._filetime_to_datetime(buffer)
|
|
435
|
+
|
|
436
|
+
def _get_created_time(self, idx: int) -> Optional[datetime.datetime]:
|
|
437
|
+
buffer = self._buffers['created_time']
|
|
438
|
+
self.dll.Everything_GetResultDateCreated(idx, buffer)
|
|
439
|
+
return self._filetime_to_datetime(buffer)
|
|
440
|
+
|
|
441
|
+
def _get_modified_time(self, idx: int) -> Optional[datetime.datetime]:
|
|
442
|
+
buffer = self._buffers['modified_time']
|
|
443
|
+
self.dll.Everything_GetResultDateModified(idx, buffer)
|
|
444
|
+
return self._filetime_to_datetime(buffer)
|
|
445
|
+
|
|
446
|
+
def _get_recently_changed(self, idx: int) -> Optional[datetime.datetime]:
|
|
447
|
+
buffer = self._buffers['recently_changed']
|
|
448
|
+
self.dll.Everything_GetResultDateRecentlyChanged(idx, buffer)
|
|
449
|
+
return self._filetime_to_datetime(buffer)
|
|
450
|
+
|
|
451
|
+
def _get_date_run(self, idx: int) -> Optional[datetime.datetime]:
|
|
452
|
+
buffer = self._buffers['date_run']
|
|
453
|
+
self.dll.Everything_GetResultDateRun(idx, buffer)
|
|
454
|
+
return self._filetime_to_datetime(buffer)
|
|
455
|
+
|
|
456
|
+
def _get_highlighted_name(self, idx: int) -> str:
|
|
457
|
+
return self.dll.Everything_GetResultHighlightedFileNameW(idx)
|
|
458
|
+
|
|
459
|
+
def _get_highlighted_path(self, idx: int) -> str:
|
|
460
|
+
return self.dll.Everything_GetResultHighlightedPathW(idx)
|
|
461
|
+
|
|
462
|
+
def _get_highlighted_full_path(self, idx: int) -> str:
|
|
463
|
+
return self.dll.Everything_GetResultHighlightedFullPathAndFileNameW(idx)
|
|
464
|
+
|
|
465
|
+
def version(self) -> str:
|
|
466
|
+
"""Returns the version of the Everything instance."""
|
|
467
|
+
self._ensure_connected()
|
|
468
|
+
return "{}.{}.{}.{}".format(
|
|
469
|
+
self.dll.Everything_GetMajorVersion(),
|
|
470
|
+
self.dll.Everything_GetMinorVersion(),
|
|
471
|
+
self.dll.Everything_GetRevision(),
|
|
472
|
+
self.dll.Everything_GetBuildNumber()
|
|
473
|
+
)
|
|
474
|
+
|
|
475
|
+
def search(
|
|
476
|
+
self,
|
|
477
|
+
keywords: str,
|
|
478
|
+
match_path: bool = False,
|
|
479
|
+
match_case: bool = False,
|
|
480
|
+
whole_word: bool = False,
|
|
481
|
+
regex: bool = False,
|
|
482
|
+
offset: int = 0,
|
|
483
|
+
limit: int = -1,
|
|
484
|
+
flags: Request = Request.DEFAULT,
|
|
485
|
+
sort: Sort = Sort.NAME_ASCENDING
|
|
486
|
+
) -> Iterator[SearchResult]:
|
|
487
|
+
"""
|
|
488
|
+
Performs a search query and yields results one by one.
|
|
489
|
+
|
|
490
|
+
:param keywords: Search query, supports Everything search syntax.
|
|
491
|
+
:param match_path: Match path instead of just the filename.
|
|
492
|
+
:param match_case: Case-sensitive search.
|
|
493
|
+
:param whole_word: Match whole words only.
|
|
494
|
+
:param regex: Enable regular expression syntax.
|
|
495
|
+
:param offset: The zero-based index of the first result to return.
|
|
496
|
+
:param limit: The maximum number of results to return. -1 means all results.
|
|
497
|
+
:param flags: A Request bitmask specifying which fields to retrieve.
|
|
498
|
+
:param sort: A Sort enum member specifying the sort order.
|
|
499
|
+
:return: An iterator yielding SearchResult objects.
|
|
500
|
+
"""
|
|
501
|
+
self._ensure_connected()
|
|
502
|
+
|
|
503
|
+
self._setup_query(keywords, match_path, match_case, whole_word, regex, offset, limit, flags, sort)
|
|
504
|
+
query_successful = self.dll.Everything_QueryW(True)
|
|
505
|
+
if not query_successful:
|
|
506
|
+
self._check_for_errors()
|
|
507
|
+
|
|
508
|
+
num_results = self.dll.Everything_GetNumResults()
|
|
509
|
+
|
|
510
|
+
active_getters = {
|
|
511
|
+
key: func
|
|
512
|
+
for flag, (key, func) in self._request_func_map.items()
|
|
513
|
+
if flag in flags
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
for i in range(num_results):
|
|
517
|
+
result_data = {key: getter(i) for key, getter in active_getters.items()}
|
|
518
|
+
yield SearchResult(**result_data)
|
|
519
|
+
|
|
520
|
+
def exit(self) -> None:
|
|
521
|
+
"""Requests the Everything service to exit."""
|
|
522
|
+
self._ensure_connected()
|
|
523
|
+
self.dll.Everything_Exit()
|
|
524
|
+
self.close()
|
|
525
|
+
|
|
526
|
+
def search_in_located(self, path: str | Path, keywords: str = '', **kwargs) -> Iterator[SearchResult]:
|
|
527
|
+
return self.search(f'path:"{path}" {keywords}', **kwargs)
|
|
528
|
+
|
|
529
|
+
def search_folder(self, keywords: str = '', **kwargs) -> Iterator[SearchResult]:
|
|
530
|
+
return self.search(f'folder: {keywords}', **kwargs)
|
|
531
|
+
|
|
532
|
+
def search_ext(self, extensions: str | Iterable[str], keywords: str = '', **kwargs) -> Iterator[SearchResult]:
|
|
533
|
+
if isinstance(extensions, str):
|
|
534
|
+
ext_str = extensions.lstrip('.')
|
|
535
|
+
else:
|
|
536
|
+
ext_str = ";".join(ext.lstrip('.') for ext in extensions)
|
|
537
|
+
return self.search(f'ext:{ext_str} {keywords}', **kwargs)
|
|
538
|
+
|
|
539
|
+
def search_audio(self, keywords: str = '', **kwargs) -> Iterator[SearchResult]:
|
|
540
|
+
return self.search_ext(FILE_TYPE_GROUPS['AUDIO'], keywords, **kwargs)
|
|
541
|
+
|
|
542
|
+
def search_video(self, keywords: str = '', **kwargs) -> Iterator[SearchResult]:
|
|
543
|
+
return self.search_ext(FILE_TYPE_GROUPS['VIDEO'], keywords, **kwargs)
|
|
544
|
+
|
|
545
|
+
def search_image(self, keywords: str = '', **kwargs) -> Iterator[SearchResult]:
|
|
546
|
+
return self.search_ext(FILE_TYPE_GROUPS['IMAGE'], keywords, **kwargs)
|
|
547
|
+
|
|
548
|
+
def search_doc(self, keywords: str = '', **kwargs) -> Iterator[SearchResult]:
|
|
549
|
+
return self.search_ext(FILE_TYPE_GROUPS['DOC'], keywords, **kwargs)
|
|
File without changes
|