-
Notifications
You must be signed in to change notification settings - Fork 921
优化投影管理文件夹已存在提示 #6664
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
Merged
+112
−1
Merged
优化投影管理文件夹已存在提示 #6664
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
c00677a
(55) 千载注述一艘中
CiiLu a101aeb
(64) 壮士动 爷娘妻儿箪壶重
CiiLu ce789a1
hyw
CiiLu d2a070e
qwq
CiiLu 4ae1e96
新增 FileNameSet 类以优化目录文件名管理,并更新 SchematicsPage 以使用新类
Glavo 16d9d3f
优化 FileNameSet 类中的大小写敏感性判断逻辑
Glavo 173072f
优化 FileNameSet 类中的条件判断逻辑,并清理 SchematicsPage 中的未使用导入
Glavo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
HMCLCore/src/main/java/org/jackhuang/hmcl/util/FileNameSet.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| /* | ||
| * Hello Minecraft! Launcher | ||
| * Copyright (C) 2026 huangyuhui <huanghongxun2008@126.com> and contributors | ||
| * | ||
| * This program is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU General Public License as published by | ||
| * the Free Software Foundation, either version 3 of the License, or | ||
| * (at your option) any later version. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU General Public License | ||
| * along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
| */ | ||
| package org.jackhuang.hmcl.util; | ||
|
|
||
| import org.jackhuang.hmcl.util.platform.OperatingSystem; | ||
| import org.jetbrains.annotations.NotNullByDefault; | ||
| import org.jetbrains.annotations.Nullable; | ||
|
|
||
| import java.io.IOException; | ||
| import java.nio.file.FileSystems; | ||
| import java.nio.file.Files; | ||
| import java.nio.file.Path; | ||
| import java.util.HashSet; | ||
| import java.util.Locale; | ||
| import java.util.function.Predicate; | ||
|
|
||
| /// @author Glavo | ||
| @NotNullByDefault | ||
| public final class FileNameSet { | ||
| public static FileNameSet list(Path directory, @Nullable Predicate<? super Path> predicate) throws IOException { | ||
| try (var list = Files.list(directory)) { | ||
| boolean caseSensitive = OperatingSystem.CURRENT_OS != OperatingSystem.WINDOWS | ||
| || directory.getFileSystem() != FileSystems.getDefault(); | ||
| var set = new FileNameSet(caseSensitive); | ||
|
|
||
| list.forEachOrdered(path -> { | ||
| if (predicate == null || predicate.test(path)) { | ||
| set.add(path.getFileName().toString()); | ||
| } | ||
| }); | ||
|
|
||
| return set; | ||
| } | ||
| } | ||
|
|
||
| private final boolean caseSensitive; | ||
|
|
||
| private final HashSet<String> set = new HashSet<>(); | ||
|
|
||
| public FileNameSet(boolean caseSensitive) { | ||
| this.caseSensitive = caseSensitive; | ||
| } | ||
|
|
||
| public boolean add(String name) { | ||
| if (caseSensitive) { | ||
| return set.add(name); | ||
| } else { | ||
| return set.add(name.toLowerCase(Locale.ROOT)); | ||
| } | ||
| } | ||
|
|
||
| public boolean contains(String name) { | ||
| if (set.isEmpty()) | ||
| return false; | ||
|
|
||
| if (caseSensitive) { | ||
| return set.contains(name); | ||
| } else { | ||
| return set.contains(name.toLowerCase(Locale.ROOT)); | ||
| } | ||
| } | ||
|
|
||
| public boolean notContains(String name) { | ||
| return !contains(name); | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { | ||
| return Boolean.hashCode(caseSensitive) ^ set.hashCode(); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean equals(Object obj) { | ||
| return this == obj || obj instanceof FileNameSet that && this.caseSensitive == that.caseSensitive && this.set.equals(that.set); | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return set.toString(); | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
为什么要删除这一处检查?