Skip to content

Commit

Permalink
fix JavaChecker does not work in offline mode
Browse files Browse the repository at this point in the history
  • Loading branch information
AlphaBs committed Sep 19, 2021
1 parent 7e2b48e commit f5c8d17
Showing 1 changed file with 32 additions and 20 deletions.
52 changes: 32 additions & 20 deletions CmlLib/Core/Files/JavaChecker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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[] { };
}
}

Expand Down Expand Up @@ -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<Task>[]
DownloadFile file = new DownloadFile(lzmaPath, javaUrl)
{
() => Task.Run(() =>
Name = "jre.lzma",
Type = MFile.Runtime,
AfterDownload = new Func<Task>[]
{
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)
Expand Down

0 comments on commit f5c8d17

Please sign in to comment.