Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 4 additions & 1 deletion src/main/java/tech/minediamond/vortex/config/AppModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import tech.minediamond.vortex.service.appConfig.AppConfigService;
import tech.minediamond.vortex.service.autoStart.MockAutoStartService;
import tech.minediamond.vortex.service.autoStart.WindowsAutoStartService;
import tech.minediamond.vortex.service.search.SearchService;
import tech.minediamond.vortex.service.ui.ShowStageListenerFactory;
import tech.minediamond.vortex.service.autoStart.IAutoStartService;
import tech.minediamond.vortex.service.i18n.I18nService;
Expand All @@ -36,6 +37,7 @@
import tech.minediamond.vortex.service.ui.TrayMenuService;
import tech.minediamond.vortex.service.ui.WindowAnimator;
import tech.minediamond.vortex.service.uncaughtExceptionHandle.GlobalUncaughtExceptionHandlerService;
import tech.minediamond.vortex.ui.component.SearchResultCardFactory;
import tech.minediamond.vortex.ui.controller.EditorPanel;
import tech.minediamond.vortex.ui.controller.MainWindow;
import tech.minediamond.vortex.ui.controller.SettingPanel;
Expand All @@ -58,6 +60,7 @@ protected void configure() {
bind(EditorPanel.class);
bind(SettingPanel.class);
bind(TrayMenuService.class);
bind(SearchService.class);

bind(WindowAnimator.class).in(Scopes.SINGLETON);

Expand All @@ -76,6 +79,6 @@ protected void configure() {
// 告诉 Guice,这个工厂的实现是基于 ShowStageListenerFactory 接口
.build(ShowStageListenerFactory.class));


install(new FactoryModuleBuilder().build(SearchResultCardFactory.class));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,31 +17,33 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

package tech.minediamond.vortex.model.search;
package tech.minediamond.vortex.model.fileData;


import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import java.util.Date;
import java.util.Objects;

@Getter
@Setter
public class EverythingResult {
private ResultType type;
@ToString
public class FileData {
private FileType type;
private String fileName;
private String extension;
private String fullPath;
private long size;
private Date dateModified;
private Date dateCreated;

public EverythingResult(){
public FileData(){

}

public EverythingResult(ResultType type, String fileName, String extension, String fullPath, long size, Date dateModified, Date dateCreated) {
public FileData(FileType type, String fileName, String extension, String fullPath, long size, Date dateModified, Date dateCreated) {
this.type = type;
this.fileName = fileName;
this.extension = extension;
Expand All @@ -51,20 +53,19 @@ public EverythingResult(ResultType type, String fileName, String extension, Stri
this.dateCreated = dateCreated;
}

@Override
public String toString() {
return "EverythingResult{" +
"type=" + type +
", fileName='" + fileName + '\'' +
", fullPath='" + fullPath + '\'' +
'}';
public String getParentPath(){
return switch (type){
case FILE-> fullPath.substring(0, fullPath.lastIndexOf('\\'));
case FOLDER-> fullPath;
};
}


@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
return Objects.equals(fullPath, ((EverythingResult) o).fullPath);
return Objects.equals(fullPath, ((FileData) o).fullPath);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

package tech.minediamond.vortex.model.search;
package tech.minediamond.vortex.model.fileData;

public enum ResultType {
public enum FileType {
FILE,
FOLDER
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@
package tech.minediamond.vortex.model.ui;

public enum ContentPanel {
EDITORPANEL("editorPanel.fxml"),
SETTINGPANEL("settingPanel.fxml");
EDITOR_PANEL("editorPanel.fxml"),
SETTING_PANEL("settingPanel.fxml"),
SEARCH_PANEL("searchPanel.fxml");

private final String fileName;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ public interface Everything3 extends StdCallLibrary {
enum PropertyType {
FILE_NAME(0),
SIZE(2),
FULL_PATH(240);
FULL_PATH(240),
IS_FOLDER(269);

final WinDef.DWORD ID;

Expand Down Expand Up @@ -166,6 +167,16 @@ class EverythingResultList extends PointerType {
*/
void Everything3_GetResultPropertyTextW(EverythingResultList resultList, WinDef.DWORD result_index, WinDef.DWORD propertyID, char[] buffer, WinDef.DWORD filename_size_in_wchars);

/**
* 根据属性值获取结果的特定属性
*
* @param resultList 结果列表句柄。
* @param result_index 结果的从零开始的索引。
* @param propertyID 需要获取的属性的属性值
* @return 返回的属性信息
*/
byte Everything3_GetResultPropertyBYTE(EverythingResultList resultList, WinDef.DWORD result_index, WinDef.DWORD propertyID);


/**
* 使用给定的客户端和搜索状态执行搜索。
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
package tech.minediamond.vortex.service.search;

import tech.minediamond.vortex.model.search.EverythingQuery;
import tech.minediamond.vortex.model.search.EverythingResult;
import tech.minediamond.vortex.model.fileData.FileData;
import tech.minediamond.vortex.model.search.SearchMode;

import java.nio.file.Path;
Expand All @@ -38,7 +38,7 @@
* <li>{@link #mode(SearchMode)} - 设置搜索模式(文件/文件夹/全部)</li>
* </ul>
* <p>
* 构建完成后,通过{@code query()}发起请求,并返回一个{@code List<EverythingResult>}
* 构建完成后,通过{@code query()}发起请求,并返回一个{@code List<FileData>}
*
* @see EverythingService
*/
Expand Down Expand Up @@ -106,7 +106,7 @@ private EverythingQuery build() {
*
* @return 搜索结果列表
*/
public List<EverythingResult> query() {
public List<FileData> query() {
if (query == null || query.trim().isEmpty()) {
return Collections.emptyList();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@
import com.sun.jna.WString;
import com.sun.jna.platform.win32.WinDef;
import lombok.extern.slf4j.Slf4j;
import tech.minediamond.vortex.model.fileData.FileType;
import tech.minediamond.vortex.model.search.EverythingQuery;
import tech.minediamond.vortex.model.search.EverythingResult;
import tech.minediamond.vortex.model.fileData.FileData;
import tech.minediamond.vortex.model.search.SearchMode;

import java.io.IOException;
Expand All @@ -49,15 +50,15 @@
* 使用示例:
* <pre>
* EverythingService service = injector.getInstance(EverythingServiceTest.class);
* List&lt;EverythingResult&gt; results = service.QueryBuilder()
* List&lt;FileData&gt; results = service.QueryBuilder()
* .searchFor("document")
* .inFolders(List.of(Path.of("C:/Users")))
* .mode(SearchMode.FILES_ONLY)
* .query();
* </pre>
*
* @see EverythingQueryBuilder
* @see EverythingResult
* @see FileData
*/
@Singleton
@Slf4j
Expand Down Expand Up @@ -150,7 +151,7 @@ public Everything3.EverythingClient LinkEverythingInstance() {
return client;
}

public List<EverythingResult> query(EverythingQuery query) {
public List<FileData> query(EverythingQuery query) {

// 防御性检查
if (client == null) {
Expand All @@ -165,12 +166,12 @@ public List<EverythingResult> query(EverythingQuery query) {

Everything3.EverythingSearchState searchState = null;
Everything3.EverythingResultList resultList = null;
List<EverythingResult> results = new ArrayList<>();
List<FileData> results = new ArrayList<>();
try {
// 创建和配置搜索条件
searchState = lib.Everything3_CreateSearchState();
if (searchState == null) {
log.error("创建搜索失败。");
log.error("无法执行查询:创建搜索失败。");
}
// 设置搜索关键字
String finalQueryString;
Expand All @@ -180,6 +181,7 @@ public List<EverythingResult> query(EverythingQuery query) {
lib.Everything3_AddSearchPropertyRequest(searchState, Everything3.PropertyType.FULL_PATH.getID());
lib.Everything3_AddSearchPropertyRequest(searchState, Everything3.PropertyType.SIZE.getID());
lib.Everything3_AddSearchPropertyRequest(searchState, Everything3.PropertyType.FILE_NAME.getID());
lib.Everything3_AddSearchPropertyRequest(searchState, Everything3.PropertyType.IS_FOLDER.getID());

//生成搜索词字符串
String queryKeywords = "\"" + query.query() + "\"";
Expand Down Expand Up @@ -220,24 +222,35 @@ public List<EverythingResult> query(EverythingQuery query) {


char[] buffer = new char[MAX_PATH];
WinDef.DWORD resultListindex = new WinDef.DWORD();
for (int i = 0; i < numResults.intValue(); i++) {
EverythingResult everythingResult = new EverythingResult();
FileData fileData = new FileData();
resultListindex.setValue(i);
//获取搜索结果的完整路径
lib.Everything3_GetResultPropertyTextW(resultList, new WinDef.DWORD(i), Everything3.PropertyType.FULL_PATH.getID(), buffer, new WinDef.DWORD(MAX_PATH));
lib.Everything3_GetResultPropertyTextW(resultList, resultListindex, Everything3.PropertyType.FULL_PATH.getID(), buffer, new WinDef.DWORD(MAX_PATH));
String pathname = Native.toString(buffer);
everythingResult.setFullPath(pathname);
fileData.setFullPath(pathname);

//获取搜索结果的名称
lib.Everything3_GetResultPropertyTextW(resultList, new WinDef.DWORD(i), Everything3.PropertyType.FILE_NAME.getID(), buffer, new WinDef.DWORD(MAX_PATH));
lib.Everything3_GetResultPropertyTextW(resultList, resultListindex, Everything3.PropertyType.FILE_NAME.getID(), buffer, new WinDef.DWORD(MAX_PATH));
String filename = Native.toString(buffer);
everythingResult.setFileName(filename);
fileData.setFileName(filename);

//获取搜索结果的大小(单位:Byte)
//这里直接将返回的无符号int64转换为long,但是考虑到无符号int64达到最大位需要文件8EB以上的大小,因此直接赋值问题不大
long size = lib.Everything3_GetResultSize(resultList, new WinDef.DWORD(i));
everythingResult.setSize(size);
long size = lib.Everything3_GetResultSize(resultList, resultListindex);
fileData.setSize(size);

results.add(everythingResult);
//获取文件的类型
byte type = lib.Everything3_GetResultPropertyBYTE(resultList, resultListindex, Everything3.PropertyType.IS_FOLDER.getID());
int intType = type & 0xFF;
if (intType != 0) {
fileData.setType(FileType.FOLDER);
} else {
fileData.setType(FileType.FILE);
}

results.add(fileData);
}
} finally {
if (resultList != null) {
Expand All @@ -258,14 +271,14 @@ private String buildPathQueryPart(EverythingQuery query) {
.map(Path::toString)
.collect(Collectors.joining("|"));
String pathQueryPart = "ancestor:" + body;
log.debug("pathQueryPart: {}",pathQueryPart);
log.debug("搜索路径关键词: {}",pathQueryPart);
return pathQueryPart;
}

//构建搜索描述部分字符串
private String buildSearchModeQueryPart(EverythingQuery query) {
SearchMode searchMode = query.searchMode().orElse(SearchMode.ALL);
log.debug("searchModeQueryPart: {}",searchMode.getQueryPrefix());
log.debug("searchMode关键词: {}",searchMode.getQueryPrefix());
return searchMode.getQueryPrefix();
}

Expand Down
Loading
Loading