Skip to content

Commit

Permalink
1.3.22 整理代码
Browse files Browse the repository at this point in the history
  • Loading branch information
DragonKnightOfBreeze committed Sep 14, 2024
1 parent ce65a50 commit 8367017
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 24 deletions.
21 changes: 0 additions & 21 deletions src/main/kotlin/icu/windea/pls/core/StdlibExtensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,6 @@ fun String.matchesPath(other: String, acceptSelf: Boolean = true, strict: Boolea
* 规范化当前路径。将路径分隔符统一替换成"/",并去除所有作为前后缀的分隔符。
*/
fun String.normalizePath(): String {
//目前仅当必要时才调用这个方法
val builder = StringBuilder()
var separatorFlag = false
this.trim('/', '\\').forEach { c ->
Expand All @@ -584,26 +583,6 @@ fun String.normalizePath(): String {
return builder.toString().intern()
}

/**
* 规范化当前绝对路径。将路径分隔符统一替换成"/",并去除所有作为后缀的分隔符。
*/
fun String.normalizeAbsolutePath(): String {
//目前仅当必要时才调用这个方法
val builder = StringBuilder()
var separatorFlag = false
this.trimEnd('/', '\\').forEach { c ->
if(c == '/' || c == '\\') {
separatorFlag = true
} else if(separatorFlag) {
separatorFlag = false
builder.append('/').append(c)
} else {
builder.append(c)
}
}
return builder.toString().intern()
}

fun Path.exists(): Boolean {
return Files.exists(this)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class BuiltInCwtConfigGroupFileProvider : CwtConfigGroupFileProviderBase() {
class LocalCwtConfigGroupFileProvider: CwtConfigGroupFileProviderBase() {
override fun getRootDirectory(project: Project): VirtualFile? {
val directory = getSettings().localConfigDirectory
val directory0 = directory?.normalizeAbsolutePath()?.orNull() ?: return null
val directory0 = directory?.normalizePath()?.orNull() ?: return null
val path = directory0.toPathOrNull() ?: return null
val file = VfsUtil.findFile(path, true)
return file?.takeIf { it.isDirectory }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ object ParadoxCoreManager {
//* 路径合法
//* 路径对应的目录存在
//* 路径是游戏目录(可以查找到对应的launcher-settings.json)
val gameDirectory0 = gameDirectory?.normalizeAbsolutePath()?.orNull() ?: return null
val gameDirectory0 = gameDirectory?.normalizePath()?.orNull() ?: return null
val path = gameDirectory0.toPathOrNull()
if(path == null) return builder.error(PlsBundle.message("gameDirectory.error.1"))
val rootFile = VfsUtil.findFile(path, true)?.takeIf { it.exists() }
Expand All @@ -409,7 +409,7 @@ object ParadoxCoreManager {
}

fun getGameVersionFromGameDirectory(gameDirectory: String?): String? {
val gameDirectory0 = gameDirectory?.normalizeAbsolutePath()?.orNull() ?: return null
val gameDirectory0 = gameDirectory?.normalizePath()?.orNull() ?: return null
val rootFile = gameDirectory0.toVirtualFile(true)?.takeIf { it.exists() } ?: return null
val rootInfo = rootFile.rootInfo
if(rootInfo !is ParadoxGameRootInfo) return null
Expand Down

0 comments on commit 8367017

Please sign in to comment.