Skip to content
This repository has been archived by the owner. It is now read-only.

Commit

Permalink
updates to installer
Browse files Browse the repository at this point in the history
  • Loading branch information
SushyDev committed Dec 20, 2020
1 parent 3697db1 commit c2490a8
Showing 1 changed file with 54 additions and 36 deletions.
90 changes: 54 additions & 36 deletions app/js/installed.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,48 +119,69 @@ function gameListExec(gameTitle, targetFolder, fileName, launchDefault) {
});
}

getDirectories(gameFolder).forEach((folderName) => {
const subFolder = path.join(localStorage.getItem('downloadDir'), fileName.slice(0, -4), folderName);

//Open dialog with executable list

fs.readdirSync(subFolder).forEach((file) => {
if (file.substr(file.length - 3) == 'exe') {
var executable = path.join(subFolder, file);

var buttonRow = document.createElement('div');
buttonRow.classList = 'buttonrow';
buttonRow.id = `${executable}-row`;
//Create exec button
var execButton = document.createElement('button');
execButton.className = 'mdc-button mdc-button--raised';
execButton.setAttribute('data-mdc-auto-init', 'MDCRipple');
execButton.setAttribute('onclick', `gamePlay('${JSON.stringify(executable)}')`);
execButton.innerHTML = `<div class="mdc-button__ripple"></div><span class="mdc-button__label">${file}</span>`;
//Create exec as admin button
var execAdminButton = document.createElement('button');
execAdminButton.className = 'mdc-button mdc-button--raised row-icon';
execAdminButton.setAttribute('data-mdc-auto-init', 'MDCRipple');
execAdminButton.setAttribute('onclick', `gamePlayAdmin('${JSON.stringify(executable)}')`);
execAdminButton.innerHTML = `<div class="mdc-button__ripple"></div><i class="material-icons mdc-button__icon" aria-hidden="true">admin_panel_settings</i>`;

//Add button to content
document.getElementById(`${name}-exec-dialog-content`).appendChild(buttonRow);
document.getElementById(`${executable}-row`).appendChild(execAdminButton);
document.getElementById(`${executable}-row`).appendChild(execButton);
window.mdc.autoInit();
}
try {
getDirectories(gameFolder).forEach((folderName) => {
const subFolder = path.join(localStorage.getItem('downloadDir'), fileName.slice(0, -4), folderName);

//Open dialog with executable list

fs.readdirSync(subFolder).forEach((file) => {
if (file.substr(file.length - 3) == 'exe') {
var executable = path.join(subFolder, file);

var buttonRow = document.createElement('div');
buttonRow.classList = 'buttonrow';
buttonRow.id = `${executable}-row`;
//Create exec button
var execButton = document.createElement('button');
execButton.className = 'mdc-button mdc-button--raised';
execButton.setAttribute('data-mdc-auto-init', 'MDCRipple');
execButton.setAttribute('onclick', `gamePlay('${JSON.stringify(executable)}')`);
execButton.innerHTML = `<div class="mdc-button__ripple"></div><span class="mdc-button__label">${file}</span>`;
//Create exec as admin button
var execAdminButton = document.createElement('button');
execAdminButton.className = 'mdc-button mdc-button--raised row-icon';
execAdminButton.setAttribute('data-mdc-auto-init', 'MDCRipple');
execAdminButton.setAttribute('onclick', `gamePlayAdmin('${JSON.stringify(executable)}')`);
execAdminButton.innerHTML = `<div class="mdc-button__ripple"></div><i class="material-icons mdc-button__icon" aria-hidden="true">admin_panel_settings</i>`;

//Add button to content
document.getElementById(`${name}-exec-dialog-content`).appendChild(buttonRow);
document.getElementById(`${executable}-row`).appendChild(execAdminButton);
document.getElementById(`${executable}-row`).appendChild(execButton);
window.mdc.autoInit();
}
});
});
});
} catch (e) {
(async () => {
var title = 'No folder found';
var name = title.replace(/ /g, '-').toLowerCase() + '-alert';
MDCAlert(title, 'Please manually select the root folder of the game');
document.querySelector(`#${name}-dialog > div > div > #${name}-dialog__actions > button`).setAttribute('onclick', `closeDialog('${name}'); selectFallbackFolder('${fileName}')`);
})();
return;
}

openDialog(`${name}-exec`);
hideProgressBar();
}
listExec();
}

function selectFallbackFolder(fileName) {
console.log(fileName);

$.getJSON(file, (data) => {
data['list'].forEach((game) => {
if (game.fileName == fileName) {
console.log(game);
}
});
});
}

function gamePlay(executable) {
console.log('exec', executable);
var exec = require('child_process').exec;
exec(`start "" "${executable}"`, (err, data) => {
console.log(err);
Expand Down Expand Up @@ -195,13 +216,10 @@ function gameDelete(gameTitle, targetFolder, fileName) {

//Get key from game name
var key = getKeyByValue(list, gameTitle);

//Remove key corresponding to the game name
delete list[key];

//Make new array without the deleted key
var newlist = {list: [...list]};

//Remove undefined values
newlist['list'] = newlist['list'].filter((n) => n);

Expand Down

0 comments on commit c2490a8

Please sign in to comment.