From f5c8d17227521f7bcb01c2ff53362556500c8f5b Mon Sep 17 00:00:00 2001 From: AlphaBs Date: Mon, 20 Sep 2021 01:09:37 +0900 Subject: [PATCH] fix JavaChecker does not work in offline mode --- CmlLib/Core/Files/JavaChecker.cs | 52 ++++++++++++++++++++------------ 1 file changed, 32 insertions(+), 20 deletions(-) diff --git a/CmlLib/Core/Files/JavaChecker.cs b/CmlLib/Core/Files/JavaChecker.cs index 2fb2e49..331ee1c 100644 --- a/CmlLib/Core/Files/JavaChecker.cs +++ b/CmlLib/Core/Files/JavaChecker.cs @@ -71,7 +71,11 @@ private DownloadFile[] internalCheckFile(string javaVersion, MinecraftPath path, catch (Exception e) { Debug.WriteLine(e); - return legacyJavaChecker(path, out binPath); + + if (string.IsNullOrEmpty(binPath)) + return legacyJavaChecker(path, out binPath); + else + return new DownloadFile[] { }; } } @@ -205,32 +209,40 @@ private DownloadFile[] legacyJavaChecker(MinecraftPath path, out string binPath) MJava mJava = new MJava(legacyJavaPath); binPath = mJava.GetBinaryPath(); - if (mJava.CheckJavaExistence()) - return new DownloadFile[] {}; + try + { + if (mJava.CheckJavaExistence()) + return new DownloadFile[] {}; - string javaUrl = mJava.GetJavaUrl(); - string lzmaPath = Path.Combine(Path.GetTempPath(), "jre.lzma"); - string zipPath = Path.Combine(Path.GetTempPath(), "jre.zip"); + string javaUrl = mJava.GetJavaUrl(); + string lzmaPath = Path.Combine(Path.GetTempPath(), "jre.lzma"); + string zipPath = Path.Combine(Path.GetTempPath(), "jre.zip"); - DownloadFile file = new DownloadFile(lzmaPath, javaUrl) - { - Name = "jre.lzma", - Type = MFile.Runtime, - AfterDownload = new Func[] + DownloadFile file = new DownloadFile(lzmaPath, javaUrl) { - () => Task.Run(() => + Name = "jre.lzma", + Type = MFile.Runtime, + AfterDownload = new Func[] { - SevenZipWrapper.DecompressFileLZMA(lzmaPath, zipPath); + () => Task.Run(() => + { + SevenZipWrapper.DecompressFileLZMA(lzmaPath, zipPath); - var z = new SharpZip(zipPath); - z.Unzip(legacyJavaPath); + var z = new SharpZip(zipPath); + z.Unzip(legacyJavaPath); - tryChmod755(mJava.GetBinaryPath()); - }) - } - }; + tryChmod755(mJava.GetBinaryPath()); + }) + } + }; - return new[] {file}; + return new[] {file}; + } + catch (Exception e) + { + Debug.WriteLine(e); + return new DownloadFile[] {}; + } } private void tryChmod755(string path)