From 3d9107a7f12d25117d34980258f66b4c607ba514 Mon Sep 17 00:00:00 2001 From: CakeLancelot Date: Wed, 8 Feb 2023 15:21:35 -0600 Subject: [PATCH] Install Unity Web Player through Electron rather than the bat file This method is a lot more reliable, as the bat file was known to not work in certain configurations of Windows and on Wine --- build/utils/installUnity.bat | 5 ----- index.js | 40 +++++++++++++++++++++++++++++------- 2 files changed, 33 insertions(+), 12 deletions(-) delete mode 100644 build/utils/installUnity.bat diff --git a/build/utils/installUnity.bat b/build/utils/installUnity.bat deleted file mode 100644 index 2cc269f..0000000 --- a/build/utils/installUnity.bat +++ /dev/null @@ -1,5 +0,0 @@ -PUSHD %~dp0 -.\UnityWebPlayer.exe /quiet /S -robocopy WebPlayer "%USERPROFILE%\AppData\LocalLow\Unity\WebPlayer" /s /e -del "%USERPROFILE%\AppData\LocalLow\Unity\WebPlayer\UnityBugReporter.exe" -POPD \ No newline at end of file diff --git a/index.js b/index.js index 89a8abe..c5db6e2 100644 --- a/index.js +++ b/index.js @@ -9,6 +9,38 @@ var mainWindow = null; app.commandLine.appendSwitch("--enable-npapi"); +function verifyUnity() { + console.log("Unimplemented!"); + return false; +} + +function installUnity(callback) { + var utilsdir = __dirname + "\\..\\..\\utils"; + + // if running in non-packaged / development mode, this dir will be slightly different + if (process.env.npm_node_execpath) { + utilsdir = app.getAppPath() + "\\build\\utils"; + } + + // run the installer silently + var child = require("child_process").spawn( + utilsdir + "\\UnityWebPlayer.exe", + ["/quiet", "/S"] + ); + child.on("exit", function () { + // overwrite 3.5.2 loader/player with FF's custom version + var dstfolder = + process.env.USERPROFILE + "\\AppData\\LocalLow\\Unity\\WebPlayer"; + fs.copySync(utilsdir + "\\WebPlayer", dstfolder, { + clobber: true, + }); + // avoids error reporter popping up when closing Electron + fs.removeSync(dstfolder + "\\UnityBugReporter.exe"); + console.log("Unity Web Player installed successfully."); + callback(); + }); +} + function initialSetup(firstTime) { // Display a small window to inform the user that the app is working setupWindow = new BrowserWindow({ @@ -19,13 +51,7 @@ function initialSetup(firstTime) { frame: false, }); setupWindow.loadUrl("file://" + __dirname + "/initialsetup.html"); - // Exec installUnity.bat and wait for it to finish. - var child = require("child_process").spawn("cmd.exe", [ - "/c", - "utils\\installUnity.bat", - ]); - child.on("exit", function () { - console.log("Unity installed."); + installUnity(function () { if (!firstTime) { // migration from pre-1.4 // Back everything up, just in case