sync
This commit is contained in:
parent
0c01e826d9
commit
1106ced049
@ -41,6 +41,14 @@ main > article > section.informations {
|
|||||||
font-family: "Roboto", sans-serif;
|
font-family: "Roboto", sans-serif;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
main > article > section.logo > h2 {
|
||||||
|
color: #ffffff;
|
||||||
|
padding: 13px 13px 13px 13px;
|
||||||
|
font-weight: bolder;
|
||||||
|
text-align: center;
|
||||||
|
font-family: "Roboto", sans-serif;
|
||||||
|
}
|
||||||
|
|
||||||
main > article > section.informations > h2 {
|
main > article > section.informations > h2 {
|
||||||
margin-bottom: 10px;
|
margin-bottom: 10px;
|
||||||
}
|
}
|
||||||
|
|||||||
28
app/loading.html
Normal file
28
app/loading.html
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<link rel="stylesheet" href="./assets/css/banned.css">
|
||||||
|
<title>Launcher banni</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<main>
|
||||||
|
<button class="close" onclick="system.call('window::close')">
|
||||||
|
<i class="fas fa-times"></i>
|
||||||
|
</button>
|
||||||
|
<article>
|
||||||
|
<section class="logo">
|
||||||
|
<img src="./assets/img/icon.png" alt="">
|
||||||
|
<h2>
|
||||||
|
Veuillez patienter
|
||||||
|
</h2>
|
||||||
|
</section>
|
||||||
|
</article>
|
||||||
|
</main>
|
||||||
|
|
||||||
|
<script src="./assets/js/banned.js"></script>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
75
main.js
75
main.js
@ -15,12 +15,13 @@ const launcher = new Client()
|
|||||||
const { io } = require("socket.io-client")
|
const { io } = require("socket.io-client")
|
||||||
const download = require("download")
|
const download = require("download")
|
||||||
const rpc = require("./modules/rpc")
|
const rpc = require("./modules/rpc")
|
||||||
|
const java = require("./modules/java")
|
||||||
const socket = io({
|
const socket = io({
|
||||||
host: config.api.websockets.base.host,
|
host: config.api.websockets.base.host,
|
||||||
port: config.api.websockets.base.port
|
port: config.api.websockets.base.port
|
||||||
})
|
})
|
||||||
|
|
||||||
let launcherWindow, auth, gamePlayable = false, launchProcess
|
let launcherWindow, defaultWindow, auth, gamePlayable = false, launchProcess
|
||||||
|
|
||||||
rpc.startRichPresence()
|
rpc.startRichPresence()
|
||||||
|
|
||||||
@ -108,6 +109,63 @@ async function createLauncherWindow() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function createDefaultWindow() {
|
||||||
|
gameOptions.initOptions(path.join(app.getPath("appData"), ".catboat", "options.txt"))
|
||||||
|
launcherSettings.initSettings(path.join(app.getPath("appData"), ".catboat"))
|
||||||
|
if (net.isOnline()) {
|
||||||
|
const isLauncherNotBanned = await checkIfIAmBanned()
|
||||||
|
try {
|
||||||
|
defaultWindow = new BrowserWindow({
|
||||||
|
frame: false,
|
||||||
|
width: 300,
|
||||||
|
height: 400,
|
||||||
|
minWidth: 300,
|
||||||
|
minHeight: 400,
|
||||||
|
titleBarStyle: "hidden",
|
||||||
|
autoHideMenuBar: true,
|
||||||
|
roundedCorners: false,
|
||||||
|
resizable: false,
|
||||||
|
webPreferences: {
|
||||||
|
nodeIntegration: false,
|
||||||
|
contextIsolation: true,
|
||||||
|
preload: path.join(__dirname, "modules", "preload.js"),
|
||||||
|
webviewTag: true,
|
||||||
|
devTools: false
|
||||||
|
}
|
||||||
|
})
|
||||||
|
if (os.platform() == "darwin") {
|
||||||
|
app.dock.setIcon(nativeImage.createFromPath(path.join(__dirname, "app", "assets", "img", "icon.png")))
|
||||||
|
}
|
||||||
|
defaultWindow.setIcon(path.join(__dirname, "app", "assets", "img", "icon.png"))
|
||||||
|
if (isLauncherNotBanned.success) {
|
||||||
|
defaultWindow.loadFile(path.join(__dirname, "app", "loading.html"))
|
||||||
|
defaultWindow.webContents.openDevTools()
|
||||||
|
try {
|
||||||
|
await java.main(path.join(app.getPath("appData"), ".catboat", "jre"))
|
||||||
|
await launchGame(false)
|
||||||
|
defaultWindow.hide()
|
||||||
|
createLauncherWindow()
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error)
|
||||||
|
defaultWindow.hide()
|
||||||
|
createLauncherWindow()
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
launcherWindow.loadFile(path.join(__dirname, "app", "banned.html"))
|
||||||
|
defaultWindow.webContents.executeJavaScript(`
|
||||||
|
setBannedBy("${isLauncherNotBanned.banned_by}")
|
||||||
|
setBannedAt("${isLauncherNotBanned.banned_at}")
|
||||||
|
setBannedBecause("${isLauncherNotBanned.reason}")
|
||||||
|
`)
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
dialog.showErrorBox("Erreur", error.toString())
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
dialog.showErrorBox("Connexion internet", "Le launcher requiert une connexion internet.")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function checkIfIAmBanned() {
|
async function checkIfIAmBanned() {
|
||||||
if (net.isOnline()) {
|
if (net.isOnline()) {
|
||||||
try {
|
try {
|
||||||
@ -145,9 +203,9 @@ async function checkCoutdown(uuid) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
app.whenReady().then(() => {
|
app.whenReady().then(() => {
|
||||||
createLauncherWindow()
|
createDefaultWindow()
|
||||||
app.on("activate", async () => {
|
app.on("activate", async () => {
|
||||||
if (BrowserWindow.getAllWindows().length === 0) await createLauncherWindow()
|
if (BrowserWindow.getAllWindows().length === 0) await createDefaultWindow()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -297,7 +355,7 @@ ipcMain.on("call", async (event, data) => {
|
|||||||
case "oculus::defaultshaderset":
|
case "oculus::defaultshaderset":
|
||||||
const oculusProperties = properties.parse(fs.readFileSync(path.join(app.getPath("appData"), ".catboat", "config", "oculus.properties")).toString())
|
const oculusProperties = properties.parse(fs.readFileSync(path.join(app.getPath("appData"), ".catboat", "config", "oculus.properties")).toString())
|
||||||
if (data.args.boolean) {
|
if (data.args.boolean) {
|
||||||
properties.setProperty(oculusProperties, "shaderPack", "Sildur%27s+Vibrant+Shaders+v1.50+Medium.zip")
|
properties.setProperty(oculusProperties, "shaderPack", "Sildurs_Vibrant_Shaders_v1.50_Medium.zip")
|
||||||
} else {
|
} else {
|
||||||
properties.setProperty(oculusProperties, "shaderPack", "")
|
properties.setProperty(oculusProperties, "shaderPack", "")
|
||||||
}
|
}
|
||||||
@ -305,14 +363,17 @@ ipcMain.on("call", async (event, data) => {
|
|||||||
break
|
break
|
||||||
case "oculus::getdefaultshaderset":
|
case "oculus::getdefaultshaderset":
|
||||||
const $oculusProperties = properties.parse(fs.readFileSync(path.join(app.getPath("appData"), ".catboat", "config", "oculus.properties")).toString())
|
const $oculusProperties = properties.parse(fs.readFileSync(path.join(app.getPath("appData"), ".catboat", "config", "oculus.properties")).toString())
|
||||||
launcherWindow.webContents.send("Response<oculus::getdefaultshaderset>", properties.getProperty($oculusProperties, "shaderPack") == "Sildur%27s+Vibrant+Shaders+v1.50+Medium.zip" ? true : false)
|
launcherWindow.webContents.send("Response<oculus::getdefaultshaderset>", properties.getProperty($oculusProperties, "shaderPack") == "Sildurs_Vibrant_Shaders_v1.50_Medium.zip" ? true : false)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
async function launchGame(restartGame) {
|
async function launchGame(restartGame) {
|
||||||
let sendToRenderer = true
|
let sendToRenderer = false
|
||||||
launcherWindow.webContents.send("Response<game::launch>", { disablePlayButton: false })
|
if (launcherWindow instanceof BrowserWindow) {
|
||||||
|
sendToRenderer = true
|
||||||
|
launcherWindow.webContents.send("Response<game::launch>", { disablePlayButton: false })
|
||||||
|
}
|
||||||
const downloadQueue = []
|
const downloadQueue = []
|
||||||
const remoteFiles = await fileManager.getRemoteFiles()
|
const remoteFiles = await fileManager.getRemoteFiles()
|
||||||
const localFiles = fs.readdirSync(path.join(app.getPath("appData"), ".catboat"), { recursive: true })
|
const localFiles = fs.readdirSync(path.join(app.getPath("appData"), ".catboat"), { recursive: true })
|
||||||
|
|||||||
233
modules/java.js
233
modules/java.js
@ -1,182 +1,79 @@
|
|||||||
const os = require("os")
|
const { execSync } = require("child_process")
|
||||||
|
const fs = require("fs")
|
||||||
const path = require("path")
|
const path = require("path")
|
||||||
const osmeta = require("./osmeta")
|
const os = require("os")
|
||||||
const { exec } = require("child_process")
|
const download = require("download")
|
||||||
const files = require("./files")
|
|
||||||
const config = require("../config.json")
|
|
||||||
const settings = require("./settings")
|
|
||||||
const { dialog, BrowserWindow, shell } = require("electron")
|
|
||||||
const AdmZip = require("adm-zip")
|
const AdmZip = require("adm-zip")
|
||||||
|
|
||||||
function isJavaInstalled() {
|
const JAVA_DOWNLOAD_URL = {
|
||||||
return new Promise((resolve, reject) => {
|
win32: "https://download.oracle.com/java/17/archive/jdk-17.0.12_windows-x64_bin.zip",
|
||||||
try {
|
darwin: "https://download.oracle.com/java/17/archive/jdk-17.0.12_macos-x64_bin.tar.gz",
|
||||||
exec(`"${settings.get("javaPath") == "" ? "java" : settings.get("javaPath")}" -version`, (error, stdout, stderr) => {
|
linux: "https://download.oracle.com/java/17/archive/jdk-17.0.12_linux-aarch64_bin.tar.gz",
|
||||||
if (error) {
|
|
||||||
reject({
|
|
||||||
java: false
|
|
||||||
})
|
|
||||||
}
|
|
||||||
const output = `${stdout}\n${stderr}`
|
|
||||||
const lines = output.split("\n")
|
|
||||||
const version = lines.filter(line => line.includes("version \""))[0]
|
|
||||||
try {
|
|
||||||
let matchRegEx
|
|
||||||
if (version.includes("_")) {
|
|
||||||
matchRegEx = /(?<major>\d+)\.(?<minor>\d+)\.(?<patch>\d+)\_(?<update>\d+)/
|
|
||||||
} else {
|
|
||||||
matchRegEx = /(?<major>\d+)\.(?<minor>\d+)\.(?<patch>\d+)/
|
|
||||||
}
|
|
||||||
const versionMatch = version.match(matchRegEx)
|
|
||||||
const { major, minor, patch, update } = versionMatch.groups
|
|
||||||
resolve({
|
|
||||||
java: true,
|
|
||||||
version: {
|
|
||||||
major: parseInt(major),
|
|
||||||
minor: parseInt(minor),
|
|
||||||
patch: parseInt(patch),
|
|
||||||
update: update ? parseInt(update) : null
|
|
||||||
}
|
|
||||||
})
|
|
||||||
} catch (error) {
|
|
||||||
reject({
|
|
||||||
java: false,
|
|
||||||
error
|
|
||||||
})
|
|
||||||
}
|
|
||||||
})
|
|
||||||
} catch (error) {
|
|
||||||
reject({
|
|
||||||
java: false,
|
|
||||||
error
|
|
||||||
})
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function showJavaErrorBox() {
|
function checkJavaVersion(requiredVersion = "17") {
|
||||||
const javaErrorBox = await dialog.showMessageBox(BrowserWindow.getFocusedWindow(), {
|
try {
|
||||||
title: "Mauvaise version de Java",
|
const javaVersionOutput = execSync("java -version", {
|
||||||
message: "Mauvaise version de Java",
|
encoding: "utf8",
|
||||||
detail: "La version de java installé sur votre ordinateur n'est pas compatible avec la version de minecraft utilisé",
|
stdio: "pipe"
|
||||||
icon: path.join(__dirname, "code/app/assets/img/java.png"),
|
})
|
||||||
buttons: [
|
const versionMatch = javaVersionOutput.match(/"(\d+\.\d+)(\.\d+)?_\d+"/)
|
||||||
"Fermer",
|
if (versionMatch) {
|
||||||
"Installer automatiquement java",
|
const installedVersion = versionMatch[1]
|
||||||
"Installer manuellement java",
|
console.log(`Java is installed. Version: ${installedVersion}`)
|
||||||
"Utilise un chemin d'accès personnalié",
|
if (parseFloat(installedVersion) >= parseFloat(requiredVersion)) {
|
||||||
],
|
console.log("Required Java version is already installed.")
|
||||||
cancelId: 0,
|
return true
|
||||||
defaultId: 1
|
|
||||||
})
|
|
||||||
return javaErrorBox
|
|
||||||
}
|
|
||||||
function installJava(dest) {
|
|
||||||
return new Promise(async (resolve, reject) => {
|
|
||||||
const response = await fetch(`${config.apiServicesURL}/api/java`)
|
|
||||||
const java = await response.json()
|
|
||||||
const arch = osmeta.arch() == "unknow" ? "x64" : osmeta.arch()
|
|
||||||
if (java.downloads[os.platform()]) {
|
|
||||||
if (java.downloads[os.platform()][arch]) {
|
|
||||||
files.downloadFile(config.apiServicesURL + java.downloads[os.platform()][arch].url, path.join(dest, "java.zip"), (error, file) => {
|
|
||||||
if (error) throw error
|
|
||||||
try {
|
|
||||||
const zip = new AdmZip(path.join(dest, "java.zip"))
|
|
||||||
zip.extractAllTo(path.join(dest, "java"), true)
|
|
||||||
files.removeFile(path.join(dest, "java.zip"))
|
|
||||||
if (os.platform() == "darwin") {
|
|
||||||
exec(`chmod +x "${path.join(dest, "java", "jre-1.8.0_411.jre", "Contents", "Home", "bin", "java")}"`, (error) => {
|
|
||||||
if (error) reject(error)
|
|
||||||
resolve(path.join(dest, "java", "jre-1.8.0_411.jre", "Contents", "Home", "bin", "java"))
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
exec(`chmod +x "${path.join(dest, "java", "bin", "java")}"`, (error) => {
|
|
||||||
if (error) reject(error)
|
|
||||||
resolve(path.join(dest, "java", "bin", "java"))
|
|
||||||
})
|
|
||||||
}
|
|
||||||
} catch (err) {
|
|
||||||
reject(err)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
} else {
|
} else {
|
||||||
reject(new Error("Java are not supported for your OS arch"))
|
console.log(`Installed Java version (${installedVersion}) is less than required version (${requiredVersion}).`)
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
reject(new Error("Java are not supported for your OS"))
|
console.log("Java is installed but version could not be determined.")
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
})
|
} catch (error) {
|
||||||
|
console.log("Java is not installed.")
|
||||||
|
return false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function main(requiredJavaVersionMinor, dest) {
|
async function downloadAndInstallJava(extractPath = null) {
|
||||||
return new Promise(async (resolve, reject) => {
|
const platform = os.platform()
|
||||||
try {
|
const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "java-installer-"))
|
||||||
const java = await isJavaInstalled()
|
|
||||||
if (java.version.minor < parseInt(requiredJavaVersionMinor)) {
|
const downloadUrl = JAVA_DOWNLOAD_URL[platform]
|
||||||
const javaErrorBox = await showJavaErrorBox()
|
if (!downloadUrl) {
|
||||||
switch (javaErrorBox.response) {
|
console.error("Unsupported platform for Java installation.")
|
||||||
case 0:
|
return
|
||||||
resolve()
|
}
|
||||||
break
|
|
||||||
case 1:
|
const zipPath = path.join(tempDir, "java-package.zip")
|
||||||
installJava(dest).then(javaPath => {
|
await download(downloadUrl, tempDir, {
|
||||||
resolve(javaPath)
|
filename: "java-package.zip"
|
||||||
})
|
|
||||||
break
|
|
||||||
case 2:
|
|
||||||
shell.openExternal(`https://www.java.com/fr/download/manual.jsp`)
|
|
||||||
resolve()
|
|
||||||
break
|
|
||||||
case 3:
|
|
||||||
const javaBinPathSelect = await dialog.showOpenDialog(BrowserWindow.getFocusedWindow(), {
|
|
||||||
filters: [
|
|
||||||
{
|
|
||||||
name: "java",
|
|
||||||
}
|
|
||||||
]
|
|
||||||
})
|
|
||||||
if (javaBinPathSelect.canceled) {
|
|
||||||
showJavaErrorBox()
|
|
||||||
} else {
|
|
||||||
resolve(javaBinPathSelect.filePaths[0])
|
|
||||||
}
|
|
||||||
break
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
resolve()
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
const javaErrorBox = await showJavaErrorBox()
|
|
||||||
switch (javaErrorBox.response) {
|
|
||||||
case 0:
|
|
||||||
resolve()
|
|
||||||
break
|
|
||||||
case 1:
|
|
||||||
installJava(dest).then(javaPath => {
|
|
||||||
resolve(javaPath)
|
|
||||||
})
|
|
||||||
break
|
|
||||||
case 2:
|
|
||||||
shell.openExternal(`https://www.java.com/fr/download/manual.jsp`)
|
|
||||||
resolve()
|
|
||||||
break
|
|
||||||
case 3:
|
|
||||||
const javaBinPathSelect = await dialog.showOpenDialog(BrowserWindow.getFocusedWindow(), {
|
|
||||||
filters: [
|
|
||||||
{
|
|
||||||
name: "java",
|
|
||||||
}
|
|
||||||
]
|
|
||||||
})
|
|
||||||
if (javaBinPathSelect.canceled) {
|
|
||||||
showJavaErrorBox()
|
|
||||||
} else {
|
|
||||||
resolve(javaBinPathSelect.filePaths[0])
|
|
||||||
}
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const extractionDir = extractPath || tempDir
|
||||||
|
const zip = new AdmZip(zipPath)
|
||||||
|
zip.extractAllTo(extractionDir, true)
|
||||||
|
|
||||||
|
fs.unlinkSync(zipPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports.java = main
|
async function main(customExtractPath) {
|
||||||
|
const requiredVersion = "17"
|
||||||
|
const isJavaInstalled = checkJavaVersion(requiredVersion)
|
||||||
|
|
||||||
|
if (!isJavaInstalled) {
|
||||||
|
|
||||||
|
if (!fs.existsSync(path.join(customExtractPath, "jdk-17.0.12", "bin", os.platform() == "win32" ? "java.exe" : "java"))) {
|
||||||
|
await downloadAndInstallJava(customExtractPath || path.join(__dirname, "..", "..", "java"))
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
console.log("No further action is required.")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
main
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user