consolidating old files into new launcher

This commit is contained in:
trippjoe 2022-03-27 20:15:42 -04:00
parent 41f8f274fd
commit cfb4be36fc
9 changed files with 308 additions and 2 deletions

BIN
src/assets/images/icon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

View file

@ -58,7 +58,6 @@
</div>
</div>
<script src=" https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"
integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous">
</script>

View file

@ -1,5 +1,6 @@
const { app, BrowserWindow } = require('electron');
const path = require('path');
const isDev = !app.isPackaged;
// Handle creating/removing shortcuts on Windows when installing/uninstalling.
if (require('electron-squirrel-startup')) {
@ -14,7 +15,12 @@ const createWindow = () => {
height: 800,
resizable: false,
title: "OpenGOAL Launcher",
icon: path.join(__dirname, 'assets/images/icon.png')
icon: path.join(__dirname, 'assets/images/icon.png'),
webPreferences: {
preload: path.join(__dirname, "/js/preload.js"),
nodeIntegration: true,
devTools: isDev
}
});
// and load the index.html of the app.

20
src/js/preload.js Normal file
View file

@ -0,0 +1,20 @@
const { contextBridge, ipcRenderer } = require("electron");
// Expose protected methods that allow the renderer process to use
contextBridge.exposeInMainWorld("api", {
send: (command) => {
let validCommands = ['getISO', 'checkUpdates', 'launch', 'build'];
if (validCommands.includes(command)) {
ipcRenderer.send(command);
} else {
console.log(command);
}
},
receive: (channel, func) => {
let validChannels = ["fromMain", 'status'];
if (validChannels.includes(channel)) {
// Deliberately strip event as it includes `sender`
ipcRenderer.on(channel, (event, ...args) => func(...args));
}
}
});

View file

@ -11,6 +11,8 @@ const background = document.querySelector('#background');
const model = document.querySelector('#model');
const logo = document.querySelector('#logo');
const { recieve, send } = window.api;
function openNav() {
container.style.marginLeft = "100px";
offcanvas.classList.add("show");

50
src/js/utils/gitFetch.js Normal file
View file

@ -0,0 +1,50 @@
const download = require('download-git-repo');
// const fetch = require('node-fetch');
// const Store = require('electron-store');
const { app } = require('electron');
// const store = new Store();
const userDataPath = app.getPath('userData');
// download the github repo
async function downloadRepo() {
const repoURL = "direct:https://github.com/water111/jak-project.git"
download(repoURL, `${userDataPath}/jak-project`, { clone: true }, function (err) {
console.log(err ? err : 'Success');
return;
});
}
// check the sha of the latest commit
async function fetchLatestCommitSha() {
const commitURL = "https://api.github.com/repos/water111/jak-project/commits/master";
const response = await fetch(commitURL);
let data = await response.json();
return data.sha;
}
// fetch the latest commit
async function fetchLatestCommit() {
const latestSha = await fetchLatestCommitSha();
// store.set('latest_sha', latestSha);
const currentSha = store.get('current_sha');
if (latestSha === currentSha) {
return 'NO UPDATES REQUIRED: You have the latest download from the Jak-Project github';
}
await downloadRepo()
// .then((() => store.set('current_sha', latestSha)))
.then(() => {
return 'Downloaded the latest updates from github!';
})
.catch(err => {
console.log(err)
});
}
module.exports = {
fetchLatestCommit
}

142
src/js/utils/iso.js Normal file
View file

@ -0,0 +1,142 @@
const { dialog, app, shell } = require('electron');
const fs = require('fs-extra');
const path = require('path');
const { series } = require('async');
const { exec } = require('child_process');
const { buildGame } = require('./launch');
const userDataPath = app.getPath('userData');
const isoSavePath = path.join(userDataPath, '/iso');
const isoContents = path.join(userDataPath, '/iso/jak1')
const jakprojectPath = path.join(userDataPath, '/jak-project');
const isoFolderPath = path.join(jakprojectPath, '/iso_data');
// const jak1FolderPath = path.join(jakprojectPath, '/iso_data/jak1');
function updateStatus(status) {
app.emit('status', status);
}
// get the ISO file from the user and save it
function getISOFile(callback) {
const files = dialog.showOpenDialogSync(this.mainWindow, {
message: 'Please select the Jak and Daxter ISO file',
properties: ['openFile'],
filters: [
{ name: 'ISO', extensions: ['iso', 'ISO', 'txt'] }
]
});
// if the user doesnt select an ISO file return
if (!files) {
updateStatus('Awaiting Jak ISO File');
callback('Awaiting Jak ISO File', null);
return;
}
// copying the iso file to the userdata/opengoal-launcher dir
const isoPath = files[0];
if (!fs.existsSync(isoSavePath)) {
fs.mkdirSync(path.join(userDataPath, '/iso'));
}
fs.copyFileSync(isoPath, `${isoSavePath}/jak.iso`);
updateStatus('Received Jak ISO File');
callback(null, 'Received Jak ISO File');
}
// extract the game files from the main iso and put them into the jak1 folder
function extractISOFile(callback) {
// if jak1 folder doesnt exist, then create the folder
// ideally they can put the jak1 folder into their actual repo and this entire chunk can be deleted
updateStatus('Extracting assets from ISO File');
if (!fs.existsSync(path.join(isoSavePath, '/jak1'))) {
fs.mkdirSync(path.join(isoSavePath, '/jak1'));
}
// if (!fs.existsSync(jak1FolderPath)) {
// fs.mkdirSync(path.join(jakprojectPath, '/iso_data/jak1'));
// }
// if (process.platform === 'darwin') {
// // const isoFile = path.join(isoSavePath, '/jak.iso');
// // const output = path.join(isoSavePath, '/jak1');
// // const archive = new ArchiveHdi(isoFile);
// // await archive.read(async entry => {
// // console.log(entry.path);
// // await entry.extract(`${output}/${entry.path}`);
// // });
// updateStatus('Incompatible Operating Software');
// callback('Incompatible Operating Software', null);
// return;
// }
if (process.platform === 'win32') {
const extractISOScript = path.join(__dirname, '../../src/assets/scripts/batch/extract-iso.bat');
shell.openPath(extractISOScript);
// copy the iso contents to the jak1 folder created above
setTimeout(() => {
try {
fs.copySync(isoContents, isoFolderPath);
updateStatus('ISO assests extracted successfully');
callback(null, 'ISO assests extracted successfully');
return;
} catch (err) {
updateStatus(err);
callback(err, null);
return;
}
}, 7000);
} else {
updateStatus('Linux & Mac support TBD');
callback('Linux & Mac support TBD', null);
return;
}
}
function runDecompiler(callback) {
let decompScript = null;
updateStatus('Running the ISO Decompiler');
if (process.platform === 'win32') {
decompScript = path.join(jakprojectPath, '/scripts/batch/decomp-jak1.bat');
} else if (process.platform === 'linux') {
decompScript = path.join(jakprojectPath, '/scripts/shell/decomp.sh');
} else if (process.platform === 'darwin') {
updateStatus('No Mac support for decompiling at this time');
callback('Mac support TBD', null);
return;
}
if (decompScript) {
console.log(decompScript);
updateStatus('Decompiling the ISO File');
let decomp = exec(decompScript, { shell: true, cwd: path.join(jakprojectPath, '/scripts/batch/') });
decomp.stdout.on('data', data => console.log(data));
// i see people online saying to use decomp.on('exit'), but thats triggering this listener immediately upon running
decomp.on('close', (code => {
console.log('code: ', code);
if (code === 0) {
updateStatus('ISO decompiled successfully');
callback(null, 'ISO decompiled successfully');
return;
} else {
// this else statment isnt actually doing anything because it always returns a code of 0
updateStatus('ISO decompile failed');
callback('ISO decompile failed', null);
return
}
}));
}
}
function isoSeries() {
series([getISOFile, extractISOFile, runDecompiler, buildGame], (err, result) => {
if (err) console.log(err);
if (result) console.log(result);
});
}
module.exports = {
isoSeries
}

77
src/js/utils/launch.js Normal file
View file

@ -0,0 +1,77 @@
const { app } = require('electron');
const path = require('path');
const { execFile } = require('child_process');
const stream = require('stream');
const userDataPath = app.getPath('userData');
const jakprojectPath = path.join(userDataPath, '/jak-project');
function updateStatus(status) {
app.emit('status', status);
}
function buildGame(callback) {
let compilerScript = null;
if (process.platform === 'win32') {
compilerScript = path.join(jakprojectPath, '/out/build/Release/bin/goalc.exe');
} else if (process.platform === 'linux') {
compilerScript = path.join(jakprojectPath, '/scripts/shell/gc.sh');
} else if (process.platform === 'darwin') {
console.log('No Mac support at this time');
return;
}
if (compilerScript) {
updateStatus('Building the game');
// so its not console logging the '100%' when i run it in the series, but when i run it on its own its fine.
// so im going to assume its working properly and its a problem with the way the compiler is outputting the %%%
// for now i have a timeout that will kill the compiler process after 30 seconds because the compiler should be done by then (twice the length it takes my pc at least)
let build = execFile(compilerScript, ['-v', '-auto-user'], { timeout: 30000 });
build.stdout.on('data', data => {
console.log(data.toString().trim());
if (data.includes('[100%]')) {
updateStatus('Compiled game successfully!');
callback(null, 'Compiled game successfully!');
return;
}
});
build.on('close', () => {
updateStatus('Compiled game successfully!');
callback(null, 'Compiled game successfully!');
return;
});
let stdinStream = new stream.Readable();
stdinStream.push('(mi)');
stdinStream.push(null);
stdinStream.pipe(build.stdin);
}
}
function launchGame() {
let launchScript = null;
if (process.platform === 'win32') {
launchScript = path.join(jakprojectPath, '/out/build/Release/bin/gk.exe');
} else if (process.platform === 'linux') {
launchScript = path.join(jakprojectPath, '/scripts/shell/gk.sh');
return;
} else if (process.platform === 'darwin') {
console.log('No Mac support at this time');
return;
}
console.log(launchScript);
if (launchScript) {
let launcher = execFile(launchScript, ['-boot', '-fakeiso', '-debug', '-v'], { shell: true });
launcher.stdout.on('data', data => console.log(data));
return;
}
}
module.exports = {
buildGame,
launchGame
}

10
src/js/utils/utils.js Normal file
View file

@ -0,0 +1,10 @@
const { isoSeries } = require('./iso');
const { launchGame, buildGame } = require('./launch');
const { fetchLatestCommit } = require('./gitFetch');
module.exports = {
launchGame,
buildGame,
isoSeries,
fetchLatestCommit
}