${gameInfo.name}
${fetchName}
@@ -55,11 +55,11 @@ function selectCard(gameInfo, fetchName, type) {
}
//Add data to the card
-async function buildCard(fetchName, type, fileName = undefined, gameFolder = undefined) {
+async function buildCard(fetchName, type, gameDir = undefined, gameFolder = undefined) {
//If no cover is found use not found logo
var gameInfo = await fetch(fetchName);
//Create the card
- gameInfo = {...gameInfo, fileName: fileName, gameFolder: gameFolder};
+ gameInfo = {...gameInfo, gameDir: gameDir, gameFolder: gameFolder};
var cardContent = selectCard(gameInfo, fetchName, type);
if (!!cardContent) {
diff --git a/app/js/components/downloader/add-game.js b/app/js/components/downloader/add-game.js
index acc4043..7884339 100644
--- a/app/js/components/downloader/add-game.js
+++ b/app/js/components/downloader/add-game.js
@@ -1,5 +1,8 @@
-function addGameToLibrary(targetPath, targetFolder, fileName, gameTitle) {
+function addGameToLibrary(targetPath, targetFolder, gameTitle) {
var file = path.join(appDataPath, '/Json/library.json');
+
+ var folderName = targetFolder.split('/').pop();
+
fs.readFile(file, 'utf-8', (err, data) => {
var array;
try {
@@ -11,8 +14,8 @@ function addGameToLibrary(targetPath, targetFolder, fileName, gameTitle) {
var updatedArray = array;
updatedArray['list'].push({
name: gameTitle,
- folder: targetFolder,
- fileName: fileName,
+ directory: targetFolder,
+ folder: folderName,
});
fs.writeFile(file, JSON.stringify(updatedArray), function (err) {
diff --git a/app/js/components/downloader/download-manager.js b/app/js/components/downloader/download-manager.js
index ab479cf..fd398cc 100644
--- a/app/js/components/downloader/download-manager.js
+++ b/app/js/components/downloader/download-manager.js
@@ -9,47 +9,47 @@ function startDownload(url, dir, gameTitle) {
if (started.includes(gameTitle)) return;
started.push(gameTitle);
- var fileName = item.getFilename();
- var fullPath = path.join(localStorage.getItem('downloadDir'), fileName);
- var name = fileName.slice(0, -4);
- var fileurl = item.getURL();
- var fileType = fileName.substr(-3);
+ var downloadDir = localStorage.getItem('downloadDir');
+ var zipFile = item.getFilename();
+ var fullPath = path.join(downloadDir, zipFile);
+ var folderName = zipFile.slice(0, -4);
+ var fileType = zipFile.substr(-3);
var snackbarData = {
['main']: [
{
- name: `${name}-download`,
+ name: `${gameTitle}-download`,
},
],
['progress']: [
{
enabled: true,
- id: `${name}-completed-progress`,
+ id: `${gameTitle}-completed-progress`,
},
],
['label']: [
{
- id: `${name}-snackbar-title`,
- innerHTML: `Downloading ${fileName} 0%`,
+ id: `${gameTitle}-snackbar-title`,
+ innerHTML: `Downloading ${zipFile} 0%`,
},
],
['actions']: [
{
type: 'button',
innerHTML: 'Pause',
- labelid: `${name}-pause-button__label`,
+ labelid: `${gameTitle}-pause-button__label`,
class: 'pause-button',
id: 'pause-button',
- onclick: `pauseDownload('${name}')`,
+ onclick: `pauseDownload('${gameTitle}')`,
},
],
['close']: [
{
enabled: true,
- onclick: `cancelDownload('${name}', true, 'Are you sure you want to cancel the download for ${fileName}', '${fullPath.replace(/\\/g, '/')}')`,
+ onclick: `cancelDownload('${gameTitle}', true, 'Are you sure you want to cancel the download for ${zipFile}', '${fullPath.replace(/\\/g, '/')}')`,
title: 'Cancel',
icon: 'close',
- id: `${name}-close`,
+ id: `${gameTitle}-close`,
},
],
};
@@ -60,22 +60,18 @@ function startDownload(url, dir, gameTitle) {
//Create snackbar
createSnack(snackbarData);
- ipcRenderer.on(`${name}-pause`, () => {
+ ipcRenderer.on(`${gameTitle}-pause`, () => {
item.pause();
});
- ipcRenderer.on(`${name}-resume`, () => {
+ ipcRenderer.on(`${gameTitle}-resume`, () => {
item.resume();
});
- ipcRenderer.on(`${name}-cancel`, () => {
+
+ ipcRenderer.on(`${gameTitle}-cancel`, () => {
item.cancel();
+ //remove item from currently downloading list
downloading.shift();
- //remove zip file
- fs.unink(fullPath, (err) => {
- if (err) {
- console.error(err);
- }
- });
//Stop
return;
});
@@ -90,8 +86,8 @@ function startDownload(url, dir, gameTitle) {
var downloadPercent = (received_bytes * 100) / total_bytes;
var scalePercent = downloadPercent / 100;
- document.getElementById(`${name}-completed-progress`).style.transform = `scaleX(${scalePercent})`;
- document.getElementById(`${name}-snackbar-title`).innerHTML = `Downloading ${fileName} ${downloadPercent.toFixed(2)}%`;
+ document.getElementById(`${gameTitle}-completed-progress`).style.transform = `scaleX(${scalePercent})`;
+ document.getElementById(`${gameTitle}-snackbar-title`).innerHTML = `Downloading ${zipFile} ${downloadPercent.toFixed(2)}%`;
} catch (e) {
/* Can error on download finish so it catches here */
}
@@ -105,19 +101,19 @@ function startDownload(url, dir, gameTitle) {
downloading.shift();
//Remove download snackbar
- closeSnackbar(`${name}-download`, false);
+ closeSnackbar(`${gameTitle}-download`, false);
//Add downloaded game to library or install update
if (gameTitle == 'vapor-store-update') {
- installUpdate(fileName);
+ installUpdate(zipFile);
} else {
- addGameToLibrary(fullPath, localStorage.getItem('downloadDir'), fileName, gameTitle);
+ addGameToLibrary(fullPath, path.join(downloadDir, folderName), gameTitle);
}
var snackbarData = {
['main']: [
{
- name: `${name}-extractyn`,
+ name: `${gameTitle}-extractyn`,
},
],
['progress']: [
@@ -127,26 +123,26 @@ function startDownload(url, dir, gameTitle) {
],
['label']: [
{
- id: `${name}-snackbar-title`,
- innerHTML: `Do you want to extract ${fileName}`,
+ id: `${gameTitle}-snackbar-title`,
+ innerHTML: `Do you want to extract ${zipFile}`,
},
],
['actions']: [
{
type: 'button',
innerHTML: 'Yes',
- labelid: `${name}-extract-button__label`,
+ labelid: `${gameTitle}-extract-button__label`,
class: 'yes-extract-button',
id: 'yes-extract-button',
- onclick: `extractDownload('${fullPath.replace(/\\/g, '/')}', '${localStorage.getItem('downloadDir').replace(/\\/g, '/')}', '${fileName}', '${gameTitle}')`,
+ onclick: `extractDownload('${fullPath.replace(/\\/g, '/')}', '${path.join(downloadDir, folderName).replace(/\\/g, '/')}', '${gameTitle}')`,
},
{
type: 'button',
innerHTML: 'No',
- labelid: `${name}-close-button__label`,
+ labelid: `${gameTitle}-close-button__label`,
class: 'no-extract-button',
id: 'no-extract-button',
- onclick: `closeSnackbar('${name}-extractyn', true, "Are you sure you don't want to extract ${fileName}")`,
+ onclick: `closeSnackbar('${gameTitle}-extractyn', true, "Are you sure you don't want to extract ${zipFile}")`,
},
],
['close']: [
@@ -157,10 +153,12 @@ function startDownload(url, dir, gameTitle) {
};
//Extract downloaded zip file
- //If auto extract is on skip this step and extract automatically
- if (localStorage.getItem('autoExtract') == 'true') {
- extractDownload(`${fullPath.replace(/\\/g, '/')}', '${localStorage.getItem('downloadDir').replace(/\\/g, '/')}', '${fileName}', '${gameTitle}`);
- } else if (fileType == 'zip') createSnack(snackbarData);
+ if (fileType == 'zip') {
+ if (localStorage.getItem('autoExtract') == 'true') {
+ //If auto extract is on skip this step and extract automatically
+ extractDownload(fullPath, path.join(downloadDir, folderName), gameTitle);
+ } else createSnack(snackbarData);
+ }
} else {
//Download didnt complete
console.log(`Download failed: ${state}`);
diff --git a/app/js/components/downloader/extractor.js b/app/js/components/downloader/extractor.js
index d28e0b9..db812a2 100644
--- a/app/js/components/downloader/extractor.js
+++ b/app/js/components/downloader/extractor.js
@@ -1,37 +1,44 @@
//Extract zip in game file
-function extractDownload(targetPath, targetFolder, filename, gameTitle) {
- var name = filename.slice(0, -4);
+function extractDownload(targetPath, targetFolder, gameTitle) {
+ var folderName = targetFolder.split('/').pop();
+ var zipFile = folderName + '.zip';
+ var extractDir = targetFolder.replace(folderName, '');
+
+ console.log('targetPath', targetPath)
+ console.log('folderName', folderName);
+ console.log('zipFile', zipFile);
+ console.log('extractDir', extractDir);
try {
- closeSnackbar(`${name}-extractyn`, false);
+ closeSnackbar(`${gameTitle}-extractyn`, false);
} catch (e) {}
var snackbarData = {
['main']: [
{
- name: `${name}-extract`,
+ name: `${gameTitle}-extract`,
},
],
['progress']: [
{
enabled: true,
- id: `${name}-progress`,
+ id: `${gameTitle}-progress`,
},
],
['label']: [
{
- id: `${name}-snackbar-title`,
- innerHTML: `Extracting ${filename} 0%`,
+ id: `${gameTitle}-snackbar-title`,
+ innerHTML: `Extracting ${zipFile} 0%`,
},
],
['actions']: [],
['close']: [
{
enabled: true,
- onclick: `hideSnackbar('${name}-extract')`,
+ onclick: `hideSnackbar('${gameTitle}-extract')`,
title: 'Hide',
icon: 'keyboard_arrow_down',
- id: `${name}-extract-hide`,
+ id: `${gameTitle}-extract-hide`,
},
],
};
@@ -39,39 +46,35 @@ function extractDownload(targetPath, targetFolder, filename, gameTitle) {
createSnack(snackbarData);
(async () => {
- try {
- var extracted = 0;
- await extract(targetPath, {
- dir: targetFolder,
- onEntry: (entry, zipfile) => {
- extracted++;
+ var extracted = 0;
+ await extract(targetPath, {
+ dir: extractDir,
+ onEntry: (entry, zipfile) => {
+ extracted++;
- var progress = (extracted * 100) / zipfile.entryCount;
- var scalePercent = progress / 100;
+ var progress = (extracted * 100) / zipfile.entryCount;
+ var scalePercent = progress / 100;
- try {
- document.getElementById(`${name}-progress`).style.transform = `scaleX(${scalePercent})`;
- document.getElementById(`${name}-snackbar-title`).innerHTML = `Extracting ${filename} ${progress.toFixed(2)}%`;
- } catch (e) {}
- },
- });
+ try {
+ document.getElementById(`${gameTitle}-progress`).style.transform = `scaleX(${scalePercent})`;
+ document.getElementById(`${gameTitle}-snackbar-title`).innerHTML = `Extracting ${zipFile} ${progress.toFixed(2)}%`;
+ } catch (e) {}
+ },
+ });
- fs.unlink(targetPath, (err) => {
- if (err) {
- console.error(err);
- }
- });
+ fs.unlink(targetPath, (err) => {
+ if (err) {
+ console.error(err);
+ }
+ });
- document.getElementById(`${name}-extract-snack-actions`).style.display = 'none';
- showSnackbar(`${name}-extract`);
- document.getElementById(`${name}-snackbar-title`).innerHTML = `Extracted ${filename}`;
+ document.getElementById(`${gameTitle}-extract-snack-actions`).style.display = 'none';
+ showSnackbar(`${gameTitle}-extract`);
+ document.getElementById(`${gameTitle}-snackbar-title`).innerHTML = `Extracted ${zipFile}`;
- //Close snackbar after 2.5 sec
- setTimeout(() => {
- closeSnackbar(`${name}-extract`, false);
- }, 5000);
- } catch (err) {
- console.log(err);
- }
+ //Close snackbar after 2.5 sec
+ setTimeout(() => {
+ closeSnackbar(`${gameTitle}-extract`, false);
+ }, 5000);
})();
}
diff --git a/app/js/components/game-management/add-custom.js b/app/js/components/game-management/add-custom.js
new file mode 100644
index 0000000..749a478
--- /dev/null
+++ b/app/js/components/game-management/add-custom.js
@@ -0,0 +1,90 @@
+function addInstalledGame() {
+ var name = 'add-game';
+ var fileName = 'test';
+ var dialogData = {
+ ['main']: {
+ name: `${name}`,
+ },
+ ['title']: {
+ id: `${name}-dialog-title`,
+ innerHTML: `Add Game`,
+ },
+ ['contents']: [
+ {
+ type: 'div',
+ innerHTML: `
+
+
+`,
+ class: 'game-name',
+ id: 'game-name',
+ },
+ {
+ type: 'div',
+ innerHTML: `
+
+`,
+ class: 'game-directory',
+ id: 'game-directory',
+ },
+ {
+ type: 'div',
+ innerHTML: `
`,
+ class: 'game-directory-text',
+ id: 'game-directory-text',
+ },
+ ],
+ ['actions']: [
+ {
+ type: 'button',
+ icon: 'close',
+ class: 'close-button',
+ id: `${name}-close-button`,
+ onclick: `closeDialog('${name}')`,
+ },
+ {
+ type: 'button',
+ icon: 'check',
+ class: 'create-button',
+ id: `${name}-create-button`,
+ onclick: `createCustomGame('${name}')`,
+ },
+ ],
+ };
+
+ createDialog(dialogData);
+}
+
+function selectGameFolder() {
+ var options = {
+ title: 'Select Folder',
+ properties: ['openDirectory'],
+ };
+ dialog.showOpenDialog(null, options).then(async (folder) => {
+ sessionStorage.setItem('selectedGameFolder', path.resolve(folder.filePaths[0]));
+ document.getElementById('game-directory-text-value').innerHTML = sessionStorage.getItem('selectedGameFolder');
+ });
+}
+
+function createCustomGame(name) {
+ var targetFolder = sessionStorage.getItem('selectedGameFolder');
+ var gameTitle = document.getElementById('game-name-value').value.replace(/ /g, '-');
+
+ if (!gameTitle || !targetFolder) return;
+
+ addGameToLibrary(undefined, targetFolder, gameTitle);
+ closeDialog(name);
+
+ sessionStorage.removeItem('selectedGameFolder');
+}
diff --git a/app/js/components/game-management/executables.js b/app/js/components/game-management/executables.js
new file mode 100644
index 0000000..eab63b4
--- /dev/null
+++ b/app/js/components/game-management/executables.js
@@ -0,0 +1,124 @@
+//Create list of executables in game folder
+function gameListExec(gameTitle, gameFolder, folderName, launchDefault) {
+ var subFolder = path.join(gameFolder, folderName);
+
+ if (launchDefault) {
+ $.getJSON(file, (data) => {
+ data['list'].forEach((game) => {
+ if (game.folder == folderName) {
+ if (!!game.default) {
+ gamePlay(path.resolve(game.default));
+ } else {
+ listExec();
+ }
+ }
+ });
+ });
+ return;
+ }
+
+ function listExec() {
+ showProgressBar();
+
+ var name = gameTitle.replace(/ /g, '-').toLowerCase();
+
+ var dialogData = {
+ ['main']: {
+ name: `${name}-exec`,
+ },
+ ['title']: {
+ id: `${name}-dialog-title`,
+ innerHTML: `Executables`,
+ },
+ ['actions']: [
+ {
+ type: 'button',
+ icon: 'close',
+ class: 'close-button',
+ id: `${name}-close-button`,
+ onclick: `closeDialog('${name}-exec')`,
+ },
+ ],
+ };
+
+ //Create dialog
+ createDialog(dialogData, false);
+
+ try {
+ getListOfExec(gameFolder).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 = `
${file}`;
+ //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 = `
admin_panel_settings`;
+
+ //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('${folderName}')`);
+ })();
+ return;
+ }
+
+ openDialog(`${name}-exec`);
+ hideProgressBar();
+ }
+ listExec();
+}
+
+function getListOfExec(gameFolder) {
+ var list;
+ var list2 = fs.readdirSync(gameFolder);
+ getSubFolders(gameFolder).forEach((subFolderName) => {
+ var fullSubFolderDir = path.join(gameFolder, subFolderName);
+ //Open dialog with executable list
+ list = fs.readdirSync(fullSubFolderDir);
+ });
+ return list.concat(list2);
+}
+
+//If subfolder return subfolder name
+function getSubFolders(dir) {
+ return fs.readdirSync(dir).filter(function (subfolder) {
+ return fs.statSync(path.join(dir, subfolder)).isDirectory();
+ });
+}
+
+function openFolder(folder, filename) {
+ shell.showItemInFolder(path.join(folder, filename.slice(0, -4)));
+}
+
+//If no folder was found
+function selectFallbackFolder(fileName) {
+ console.log(fileName);
+
+ $.getJSON(file, (data) => {
+ data['list'].forEach((game) => {
+ if (game.fileName == fileName) {
+ console.log(game);
+ }
+ });
+ });
+}
diff --git a/app/js/components/game-management/play.js b/app/js/components/game-management/play.js
new file mode 100644
index 0000000..a9d0e95
--- /dev/null
+++ b/app/js/components/game-management/play.js
@@ -0,0 +1,97 @@
+function gamePlay(executable) {
+ var exec = require('child_process').exec;
+ exec(`start "" "${executable}"`, (err, data) => {
+ console.log(err);
+ });
+}
+
+function gamePlayAdmin(executable) {
+ exec(`powershell -command "start-process \\"${executable.replace(/"/g, '')}\\" -verb runas`, (err, data) => {
+ console.log(err);
+ });
+}
+
+//Select default
+function selectDefault(gameTitle, gameFolder, folderName, launchDefault) {
+ var subFolder = path.join(gameFolder, folderName);
+ showProgressBar();
+
+ var name = gameTitle.replace(/ /g, '-').toLowerCase();
+
+ var dialogData = {
+ ['main']: {
+ name: `${name}-default`,
+ },
+ ['title']: {
+ id: `${name}-dialog-title`,
+ innerHTML: `Select default exe`,
+ },
+ ['actions']: [
+ {
+ type: 'button',
+ icon: 'close',
+ class: 'close-button',
+ id: `${name}-close-button`,
+ onclick: `closeDialog('${name}-default')`,
+ },
+ ],
+ };
+
+ //Create dialog
+ createDialog(dialogData, false);
+
+ try {
+ getListOfExec(gameFolder).forEach((file) => {
+ if (file.substr(file.length - 3) == 'exe') {
+ var shortcut = path.join(subFolder, file);
+ //Create exec button
+
+ var buttonRow = document.createElement('div');
+ buttonRow.classList = 'buttonrow';
+ buttonRow.id = `${shortcut}-row`;
+ //Create shortcut button
+ var defaultButton = document.createElement('button');
+ defaultButton.className = 'mdc-button mdc-button--raised';
+ defaultButton.setAttribute('data-mdc-auto-init', 'MDCRipple');
+ defaultButton.setAttribute('onclick', `setDefault('${gameTitle}', '${JSON.stringify(shortcut)}')`);
+ defaultButton.innerHTML = `
${file}`;
+
+ //Add button to content
+ document.getElementById(`${name}-default-dialog-content`).appendChild(buttonRow);
+ document.getElementById(`${shortcut}-row`).appendChild(defaultButton);
+ 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('${folderName}')`);
+ })();
+ return;
+ }
+
+ openDialog(`${name}-default`);
+ hideProgressBar();
+}
+
+function setDefault(gameTitle, exec) {
+ $.getJSON(file, (data) => {
+ data['list'].forEach((game) => {
+ var indexNum = data['list'].findIndex((game) => game.name == gameTitle);
+
+ if (game.name == gameTitle) {
+ data['list'][indexNum] = {
+ ...game,
+ default: exec.replace(/"/g, ''),
+ };
+ }
+ });
+
+ fs.writeFile(file, JSON.stringify(data), function (err) {
+ if (err) throw err;
+ if (isDev) console.log('Saved!');
+ });
+ });
+}
diff --git a/app/js/components/game-management/remove.js b/app/js/components/game-management/remove.js
new file mode 100644
index 0000000..d5edab2
--- /dev/null
+++ b/app/js/components/game-management/remove.js
@@ -0,0 +1,37 @@
+function gameDelete(gameTitle, gameFolder, folderName, launchDefault) {
+ //Dont do it if canceled
+ if (!confirm(`Are you sure you want to delete ${folderName}`)) return;
+
+ var file = path.join(appDataPath, '/Json/library.json');
+
+ //delete folder from game
+ rimraf(gameFolder, function () {
+ //Remove deleted game from list
+ $.getJSON(file, (data) => {
+ var list = data['list'];
+
+ //Function for getting key from game name
+ function getKeyByValue(object, value) {
+ return Object.keys(object).find((key) => {
+ return object[key].name === gameTitle;
+ });
+ }
+
+ //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);
+
+ //Save to library json file
+ fs.writeFile(file, JSON.stringify(newlist), function (err) {
+ if (err) throw err;
+ if (isDev) console.log('Saved!');
+ goto('Installed');
+ });
+ });
+ });
+}
diff --git a/app/js/components/game-management/shortcuts.js b/app/js/components/game-management/shortcuts.js
new file mode 100644
index 0000000..f51c17a
--- /dev/null
+++ b/app/js/components/game-management/shortcuts.js
@@ -0,0 +1,73 @@
+//List exe's to create shortcut
+function gameShortcut(gameTitle, gameFolder, folderName, launchDefault) {
+ var subFolder = path.join(gameFolder, folderName);
+
+ showProgressBar();
+
+ var name = gameTitle.replace(/ /g, '-').toLowerCase();
+
+ var dialogData = {
+ ['main']: {
+ name: `${name}-shortcut`,
+ },
+ ['title']: {
+ id: `${name}-dialog-title`,
+ innerHTML: `Create shortcut`,
+ },
+ ['actions']: [
+ {
+ type: 'button',
+ icon: 'close',
+ class: 'close-button',
+ id: `${name}-close-button`,
+ onclick: `closeDialog('${name}-shortcut')`,
+ },
+ ],
+ };
+
+ //Create dialog
+ createDialog(dialogData, false);
+
+ try {
+ getListOfExec(gameFolder).forEach((file) => {
+ if (file.substr(file.length - 3) == 'exe') {
+ var shortcut = path.join(subFolder, file);
+ //Create exec button
+
+ var buttonRow = document.createElement('div');
+ buttonRow.classList = 'buttonrow';
+ buttonRow.id = `${shortcut}-row`;
+ //Create shortcut button
+ var shortcutButton = document.createElement('button');
+ shortcutButton.className = 'mdc-button mdc-button--raised';
+ shortcutButton.setAttribute('data-mdc-auto-init', 'MDCRipple');
+ shortcutButton.setAttribute('onclick', `createShortcut('${JSON.stringify(shortcut)}')`);
+ shortcutButton.innerHTML = `
${file}`;
+
+ //Add button to content
+ document.getElementById(`${name}-shortcut-dialog-content`).appendChild(buttonRow);
+ document.getElementById(`${shortcut}-row`).appendChild(shortcutButton);
+ 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('${folderName}')`);
+ })();
+ return;
+ }
+
+ openDialog(`${name}-shortcut`);
+ hideProgressBar();
+}
+
+function createShortcut(executable) {
+ const shortcutsCreated = createDesktopShortcut({
+ windows: {filePath: `${executable.replace(/"/g, '')}`},
+ });
+
+ shortcutsCreated;
+}
diff --git a/app/js/components/notifications/dialog-service.js b/app/js/components/notifications/dialog-service.js
index 495a13a..4f8d2f9 100644
--- a/app/js/components/notifications/dialog-service.js
+++ b/app/js/components/notifications/dialog-service.js
@@ -1,19 +1,4 @@
-//Open dialog by id name
-/*
-function openDialog(id) {
- var dialog = document.getElementById(id);
- dialog.classList.add('');
-}
-
-//Close dialog by (this) value from button
-function closeDialog(button) {
- var dialog = button.closest('.mdc-dialog--open');
- dialog.classList.remove('mdc-dialog--open');
-}
-
-*/
-
-function createDialog(dialogData, autoshow) {
+function createDialog(dialogData, autoshow = true) {
var main = dialogData.main;
var title = dialogData.title;
diff --git a/app/js/installed.js b/app/js/installed.js
index f02a22e..e11a99c 100644
--- a/app/js/installed.js
+++ b/app/js/installed.js
@@ -48,12 +48,12 @@ function createCard(search = undefined) {
//Format name for url
- var fileName = game.fileName;
- var gameFolder = game.folder;
+ var gameDir = game.directory;
+ var folderName = game.folder;
var fetchName = game.name.replace(/ /g, '-');
//Fetch data from the game by name
- buildCard(fetchName, 'installed', fileName, gameFolder);
+ buildCard(fetchName, 'installed', gameDir, folderName);
});
});
}
@@ -67,358 +67,11 @@ function searchInstalledGames() {
}
}
-//Create list of executables in game folder
-function gameListExec(gameTitle, targetFolder, fileName, launchDefault) {
- if (launchDefault) {
- $.getJSON(file, (data) => {
- data['list'].forEach((game) => {
- if (game.fileName == fileName) {
- if (!!game.default) {
- gamePlay(path.resolve(game.default));
- } else {
- listExec();
- }
- }
- });
- });
- return;
- }
-
- function listExec() {
- const gameFolder = path.join(localStorage.getItem('downloadDir'), fileName.slice(0, -4));
-
- showProgressBar();
-
- var name = gameTitle.replace(/ /g, '-').toLowerCase();
-
- var dialogData = {
- ['main']: {
- name: `${name}-exec`,
- },
- ['title']: {
- id: `${name}-dialog-title`,
- innerHTML: `Executables`,
- },
- ['actions']: [
- {
- type: 'button',
- icon: 'close',
- class: 'close-button',
- id: `${name}-close-button`,
- onclick: `closeDialog('${name}-exec')`,
- },
- ],
- };
-
- //Create dialog
- createDialog(dialogData, false);
-
- function getDirectories(path) {
- return fs.readdirSync(path).filter(function (file) {
- return fs.statSync(path + '/' + file).isDirectory();
- });
- }
-
- 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 = `
${file}`;
- //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 = `
admin_panel_settings`;
-
- //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) {
- var exec = require('child_process').exec;
- exec(`start "" "${executable}"`, (err, data) => {
- console.log(err);
- });
-}
-
-function gamePlayAdmin(executable) {
- exec(`powershell -command "start-process \\"${executable.replace(/"/g, '')}\\" -verb runas`, (err, data) => {
- console.log(err);
- });
-}
-
-function gameDelete(gameTitle, targetFolder, fileName) {
- //Dont do it if canceled
- if (!confirm(`Are you sure you want to delete ${fileName.slice(0, -4)}`)) return;
-
- var file = path.join(appDataPath, '/Json/library.json');
- const subFolder = path.join(targetFolder, fileName.slice(0, -4));
-
- //delete folder from game
- rimraf(subFolder, function () {
- //Remove deleted game from list
- $.getJSON(file, (data) => {
- var list = data['list'];
-
- //Function for getting key from game name
- function getKeyByValue(object, value) {
- return Object.keys(object).find((key) => {
- return object[key].name === gameTitle;
- });
- }
-
- //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);
-
- //Save to library json file
- fs.writeFile(file, JSON.stringify(newlist), function (err) {
- if (err) throw err;
- if (isDev) console.log('Saved!');
- goto('Installed');
- });
- });
- });
-}
-
-//List all executables in folder (includes all subfolders)
-function getDirectories(gameFolder) {
- const subFolder = localStorage.getItem('downloadDirectory') + folder + '/' + folderName;
-
- fs.readdirSync(subFolder).forEach((file) => {
- if (file.substr(file.length - 3) == 'exe') {
- var executable = path.join(subFolder, file);
- //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 = `
${file}`;
-
- //Add button to content
- document.getElementById(`${name}-exec-dialog-content`).appendChild(execButton);
- window.mdc.autoInit();
- }
- });
-}
-
-function openFolder(folder, filename) {
- shell.showItemInFolder(path.join(folder, filename.slice(0, -4)));
-}
-
-//List exe's to create shortcut
-function gameShortcut(gameTitle, targetFolder, fileName) {
- const gameFolder = path.join(localStorage.getItem('downloadDir'), fileName.slice(0, -4));
-
+//Show game info page
+async function openInstalled(name, gameInfoName, gameDir) {
showProgressBar();
- var name = gameTitle.replace(/ /g, '-').toLowerCase();
-
- var dialogData = {
- ['main']: {
- name: `${name}-shortcut`,
- },
- ['title']: {
- id: `${name}-dialog-title`,
- innerHTML: `Create shortcut`,
- },
- ['actions']: [
- {
- type: 'button',
- icon: 'close',
- class: 'close-button',
- id: `${name}-close-button`,
- onclick: `closeDialog('${name}-shortcut')`,
- },
- ],
- };
-
- //Create dialog
- createDialog(dialogData, false);
-
- function getDirectories(path) {
- return fs.readdirSync(path).filter(function (file) {
- return fs.statSync(path + '/' + file).isDirectory();
- });
- }
-
- getDirectories(gameFolder).forEach((folderName) => {
- const subFolder = path.join(localStorage.getItem('downloadDir'), fileName.slice(0, -4), folderName);
-
- fs.readdirSync(subFolder).forEach((file) => {
- if (file.substr(file.length - 3) == 'exe') {
- var shortcut = path.join(subFolder, file);
- //Create exec button
-
- var buttonRow = document.createElement('div');
- buttonRow.classList = 'buttonrow';
- buttonRow.id = `${shortcut}-row`;
- //Create shortcut button
- var shortcutButton = document.createElement('button');
- shortcutButton.className = 'mdc-button mdc-button--raised';
- shortcutButton.setAttribute('data-mdc-auto-init', 'MDCRipple');
- shortcutButton.setAttribute('onclick', `createShortcut('${JSON.stringify(shortcut)}')`);
- shortcutButton.innerHTML = `
${file}`;
-
- //Add button to content
- document.getElementById(`${name}-shortcut-dialog-content`).appendChild(buttonRow);
- document.getElementById(`${shortcut}-row`).appendChild(shortcutButton);
- window.mdc.autoInit();
- }
- });
- });
-
- openDialog(`${name}-shortcut`);
- hideProgressBar();
-}
-
-function createShortcut(executable) {
- const shortcutsCreated = createDesktopShortcut({
- windows: {filePath: `${executable.replace(/"/g, '')}`},
- });
-
- shortcutsCreated;
-}
-
-//Select default
-function selectDefault(gameTitle, targetFolder, fileName) {
- const gameFolder = path.join(localStorage.getItem('downloadDir'), fileName.slice(0, -4));
- showProgressBar();
-
- var name = gameTitle.replace(/ /g, '-').toLowerCase();
-
- var dialogData = {
- ['main']: {
- name: `${name}-default`,
- },
- ['title']: {
- id: `${name}-dialog-title`,
- innerHTML: `Select default exe`,
- },
- ['actions']: [
- {
- type: 'button',
- icon: 'close',
- class: 'close-button',
- id: `${name}-close-button`,
- onclick: `closeDialog('${name}-default')`,
- },
- ],
- };
-
- //Create dialog
- createDialog(dialogData, false);
-
- function getDirectories(path) {
- return fs.readdirSync(path).filter(function (file) {
- return fs.statSync(path + '/' + file).isDirectory();
- });
- }
-
- getDirectories(gameFolder).forEach((folderName) => {
- const subFolder = path.join(localStorage.getItem('downloadDir'), fileName.slice(0, -4), folderName);
-
- fs.readdirSync(subFolder).forEach((file) => {
- if (file.substr(file.length - 3) == 'exe') {
- var shortcut = path.join(subFolder, file);
- //Create exec button
-
- var buttonRow = document.createElement('div');
- buttonRow.classList = 'buttonrow';
- buttonRow.id = `${shortcut}-row`;
- //Create shortcut button
- var defaultButton = document.createElement('button');
- defaultButton.className = 'mdc-button mdc-button--raised';
- defaultButton.setAttribute('data-mdc-auto-init', 'MDCRipple');
- defaultButton.setAttribute('onclick', `setDefault('${gameTitle}', '${JSON.stringify(shortcut)}')`);
- defaultButton.innerHTML = `
${file}`;
-
- //Add button to content
- document.getElementById(`${name}-default-dialog-content`).appendChild(buttonRow);
- document.getElementById(`${shortcut}-row`).appendChild(defaultButton);
- window.mdc.autoInit();
- }
- });
- });
-
- openDialog(`${name}-default`);
- hideProgressBar();
-}
-
-function setDefault(gameTitle, exec) {
- $.getJSON(file, (data) => {
- data['list'].forEach((game) => {
- var indexNum = data['list'].findIndex((game) => game.name == gameTitle);
-
- if (game.name == gameTitle) {
- data['list'][indexNum] = {
- ...game,
- default: exec.replace(/"/g, ''),
- };
- }
- });
-
- fs.writeFile(file, JSON.stringify(data), function (err) {
- if (err) throw err;
- if (isDev) console.log('Saved!');
- });
- });
-}
-
-async function openInstalled(name, gameInfoName, gameFolder, fileName) {
- showProgressBar();
+ var folderName = gameDir.split('/').pop();
//close drawer
drawer.open = false;
@@ -431,16 +84,16 @@ async function openInstalled(name, gameInfoName, gameFolder, fileName) {
document.getElementById('selected-game-cover').style.backgroundPosition = 'center';
//Set download button
- document.getElementById('selected-game-cover').setAttribute('onclick', `gameListExec('${gameInfoName}', '${gameFolder}', '${fileName}', true)`);
- document.getElementById('selected-game-play').setAttribute('onclick', `gameListExec('${gameInfoName}', '${gameFolder}', '${fileName}', true)`);
- document.getElementById('selected-game-more').setAttribute('onclick', `openMore('${gameInfoName}', '${name}', '${gameFolder}', '${fileName}')`);
+ document.getElementById('selected-game-cover').setAttribute('onclick', `gameListExec('${gameInfoName}', '${gameDir}', '${folderName}', true)`);
+ document.getElementById('selected-game-play').setAttribute('onclick', `gameListExec('${gameInfoName}', '${gameDir}', '${folderName}', true)`);
+ document.getElementById('selected-game-more').setAttribute('onclick', `openMore('${gameInfoName}', '${name}', '${gameDir}', '${folderName}')`);
document.getElementById('menu-anchorpoint').setAttribute('anchorfor', `${gameInfoName}`);
addMetadata(name, 'installed');
}
//Open more options popup
-function openMore(name, name2, folder, fileName) {
+function openMore(name, name2, gameDir, folderName) {
var anchorpoint = document.querySelector(`div[anchorfor="${name}"]`);
if (!anchorpoint.innerHTML == '') {
@@ -450,23 +103,23 @@ function openMore(name, name2, folder, fileName) {