Skip to content

Commit

Permalink
patch (untested)
Browse files Browse the repository at this point in the history
  • Loading branch information
cubewhy committed Jul 27, 2024
1 parent 8b9fc36 commit 10db3c7
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 2 deletions.
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ import org.cubewhy.celestial.game.addon.WeaveMod
import org.cubewhy.celestial.game.addon.WeaveMod.Companion.add
import org.cubewhy.celestial.gui.GuiLauncher
import org.cubewhy.celestial.gui.layouts.VerticalFlowLayout
import org.cubewhy.celestial.utils.OSEnum
import org.cubewhy.celestial.utils.chooseFile
import org.cubewhy.celestial.utils.createButtonOpenFolder
import org.cubewhy.celestial.utils.currentJavaExec
import org.slf4j.LoggerFactory
import java.awt.Color
import java.awt.GridBagConstraints
Expand Down Expand Up @@ -613,6 +615,8 @@ class GuiAddonManager : JPanel() {
}
}

val patchLogFile = configDir.resolve("logs/patch.log")

class PatchDialog(panel: JPanel, private val patch: File): JDialog(SwingUtilities.getWindowAncestor(panel) as JFrame) {

init {
Expand All @@ -631,13 +635,44 @@ class PatchDialog(panel: JPanel, private val patch: File): JDialog(SwingUtilitie

this.add(patch.path.toJTextArea().readOnly())
this.add(f.getString("gui.addons.patch.warn").toJTextArea().readOnly())
if (!gameDir.exists()) {
val lunarJar = gameDir.resolve("lunar.jar")
if (!(gameDir.exists() || lunarJar.exists())) {
this.add(f.getString("gui.addons.patch.not-installed").toJLabel())
return
}
if (!patch.isZipFile()) {
this.add(f.getString("gui.addons.patch.not-zip").toJLabel())
}
this.add(JButton(f.getString("gui.addons.patch.confirm")))
this.add(JButton(f.getString("gui.addons.patch.confirm")).apply {
addActionListener { e ->
// java -jar patch.jar lunar.jar out.jar
val source = e.source<JButton>()
source.isEnabled = false
Thread {
val code = doPatch(lunarJar).start().waitFor()
source.text = if (code == 0) f.getString("gui.addons.patch.done") else f.getString("gui.addons.patch.fail")
}.start()
}
})
}

private fun doPatch(lunar: File): ProcessBuilder {
val builder = ProcessBuilder()
if (OSEnum.Windows.isCurrent) {
// Windows
// delete the log file
patchLogFile.delete()

builder.command(
currentJavaExec.path,
"-jar \" ${patch.path} ${lunar.path} ${lunar.path} 1>>\"%s\" 2>&1\"".format(patchLogFile.path)
)

} else {
// others
builder.command(currentJavaExec.path, "-jar", patch.path, lunar.path, lunar.path, " > \"" + patchLogFile.path + "\"")
}
println(builder.command())
return builder
}
}
2 changes: 2 additions & 0 deletions src/main/resources/languages/launcher.properties
Original file line number Diff line number Diff line change
Expand Up @@ -337,4 +337,6 @@ gui.addons.patch.not-zip=The file you dragged does not appear to be a jar (this
gui.addons.patch.warn=Warning: This is a very experimental feature, please use offline launch to play after applying the patch.\n\
The patch process is irreversible. If you are using an older version of Lunar, please back up your lunar.jar.
gui.addons.patch.confirm=Apply patch
gui.addons.patch.done=Patched OK.
gui.addons.patch.fail=Patching failed. Please see the log for more information.
2 changes: 2 additions & 0 deletions src/main/resources/languages/launcher_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -337,3 +337,5 @@ gui.addons.patch.not-zip=The file you dragged does not appear to be a jar (this
gui.addons.patch.warn=Warning: This is a very experimental feature, please use offline launch to play after applying the patch.\n\
The patch process is irreversible. If you are using an older version of Lunar, please back up your lunar.jar.
gui.addons.patch.confirm=Apply patch
gui.addons.patch.done=Patched OK.
gui.addons.patch.fail=Patching failed. Please see the log for more information.
2 changes: 2 additions & 0 deletions src/main/resources/languages/launcher_ja.properties
Original file line number Diff line number Diff line change
Expand Up @@ -345,5 +345,7 @@ gui.addons.patch.not-zip=ドラッグしたファイルは jar ではないよ
gui.addons.patch.warn=警告: これは非常に実験的な機能です。パッチを適用した後は、オフライン起動を使用してプレイしてください。\n\
パッチ適用プロセスは元に戻すことができません。古いバージョンの Lunar を使用している場合は、必ず lunar.jar をバックアップしてください。
gui.addons.patch.confirm=パッチを適用する
gui.addons.patch.done=修理完了
gui.addons.patch.fail=パッチは失敗しました。詳細についてはログを確認してください。


2 changes: 2 additions & 0 deletions src/main/resources/languages/launcher_ko.properties
Original file line number Diff line number Diff line change
Expand Up @@ -360,4 +360,6 @@ gui.addons.patch.not-zip=드래그한 파일이 jar 파일이 아닌 것 같습
gui.addons.patch.warn=경고: 이것은 매우 실험적인 기능이므로 패치를 적용한 후 오프라인 실행으로 플레이하세요.\n\
패치 과정은 되돌릴 수 없습니다. 이전 버전의 Lunar를 사용하는 경우 lunar.jar을 백업하세요.
gui.addons.patch.confirm=패치를 적용하세요
gui.addons.patch.done=수리 완료
gui.addons.patch.fail=패치가 실패했습니다. 자세한 내용은 로그를 확인하세요.

2 changes: 2 additions & 0 deletions src/main/resources/languages/launcher_zh.properties
Original file line number Diff line number Diff line change
Expand Up @@ -337,4 +337,6 @@ gui.addons.patch.not-zip=你拖拽的文件看起来不是jar (这条消息只
gui.addons.patch.warn=警告: 这是一个十分实验性的功能, 应用补丁后请使用离线启动进行游玩.\n\
补丁过程是不可逆的, 如果你在使用旧版Lunar, 请注意备份你的lunar.jar
gui.addons.patch.confirm=应用补丁
gui.addons.patch.done=修补完成
gui.addons.patch.fail=修补失败,更多信息请查看log

0 comments on commit 10db3c7

Please sign in to comment.