Skip to content

Commit

Permalink
禁止对日志文件进行更新
Browse files Browse the repository at this point in the history
  • Loading branch information
asforest committed Jun 18, 2023
1 parent 509c0f3 commit b21b226
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/main/kotlin/mcpatch/WorkThread.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import mcpatch.gui.ChangeLogs
import mcpatch.gui.McPatchWindow
import mcpatch.localization.LangNodes
import mcpatch.localization.Localization
import mcpatch.logging.FileHandler
import mcpatch.logging.Log
import mcpatch.server.MultipleServers
import mcpatch.util.*
Expand Down Expand Up @@ -121,6 +122,16 @@ class WorkThread(
meta.newFiles.forEach { Log.debug("new files: $it") }
meta.newFolders.forEach { Log.debug("new dirs: $it") }

// 不能更新日志文件
val logFile = (Log.handlers.firstOrNull { it is FileHandler } as FileHandler?)?.logFile
var logFileUpdated = false
logFileUpdated = logFileUpdated or meta.moveFiles.removeIf { (updateDir + it.from) == logFile || (updateDir + it.to) == logFile }
logFileUpdated = logFileUpdated or meta.oldFiles.removeIf { (updateDir + it) == logFile }
logFileUpdated = logFileUpdated or meta.newFiles.removeIf { (updateDir + it.path) == logFile }

if (logFileUpdated)
Log.warn("Do not try to update the logging file of McPatchClient!")

// 处理移动,删除和创建目录
meta.moveFiles.forEach {
val from = updateDir + it.from
Expand Down
6 changes: 6 additions & 0 deletions src/main/kotlin/mcpatch/util/File2.kt
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,12 @@ class File2 : Iterable<File2>
}
}

override fun equals(other: Any?): Boolean {
if (other !is File2)
return false
return file == other.file
}

override fun iterator(): Iterator<File2>
{
return files.iterator()
Expand Down

0 comments on commit b21b226

Please # to comment.