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

Commit

Permalink
working on downloader menu
Browse files Browse the repository at this point in the history
  • Loading branch information
SushyDev committed Dec 26, 2020
1 parent 1564626 commit 5a4d780
Show file tree
Hide file tree
Showing 14 changed files with 247 additions and 23 deletions.
4 changes: 1 addition & 3 deletions app/html/downloader.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
<script src="../js/components/download-page/downloading-item.js"></script>
<script src="../js/components/download-page/extracting-item.js"></script>

<script src="../js/downloader.js"></script>

<script src="../js/components/card-grid/card-grid.js"></script>
</head>

Expand Down Expand Up @@ -45,4 +43,4 @@ <h1 class="mdc-typography--body2" id="selected-game-description"></h1>
$(document).ready(function () {
mdc.autoInit();
});
</script>
</script>
2 changes: 2 additions & 0 deletions app/html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
<!--Notifications-->
<script src="../js/components/notifications/snackbar-service.js" defer></script>
<script src="../js/components/notifications/dialog-service.js" defer></script>
<!--Add installed steam games to list-->
<script src="../js/components/game-management/steam-installed.js"></script>
<!--Window Controls-->
<script src="../js/components/window-management/window-controls.js" defer></script>
<!--App Functions-->
Expand Down
3 changes: 0 additions & 3 deletions app/html/installed.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
<button class="mdc-icon-button material-icons" data-mdc-ripple-is-unbounded="true" data-mdc-auto-init="MDCRipple" onclick="createCard()">clear</button>
</div>


<!--Div with cards-->
<div class="cards" id="cards"></div>

Expand Down Expand Up @@ -69,5 +68,3 @@ <h1 class="mdc-typography--body2" id="selected-game-description"></h1>
<button class="mdc-icon-button back-icon material-icons mdc-card__action mdc-card__action--icon--unbounded" data-mdc-ripple-is-unbounded="true" data-mdc-auto-init="MDCRipple" onclick="closeGameTab()">first_page</button>
</div>
</div>


23 changes: 23 additions & 0 deletions app/js/components/download-page/fetching-item.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,26 @@
function selectDownload(elem) {
var container = elem.closest('.downloader-list-item');

try {
document.querySelector('.active').classList.remove('active');
} catch (e) {}

container.classList.add('active');

document.getElementById('game-info-content').style.display = 'initial';
}

function removeItem(gameTitle, type) {
try {
document.getElementById(`${gameTitle}-${type}-item`).remove();
} catch (e) {}
}

fetchingDownload.forEach((game) => {
console.log(game);
createFetchingItem(game);
});

function createFetchingItem(gameTitle) {
let item = document.createElement('div');
item.className = 'fetch-item downloader-list-item';
Expand Down
2 changes: 1 addition & 1 deletion app/js/components/game-management/add-own.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ function createCustomGame(name) {

setTimeout(() => {
goto('Installed');
}, 100)
}, 100);

sessionStorage.removeItem('selectedGameFolder');
}
5 changes: 3 additions & 2 deletions app/js/components/game-management/executables.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
//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 == path.resolve(gameFolder)) {
console.log(game.folder)
if (game.folder == folderName) {
if (!!game.default) {
gamePlay(path.resolve(game.default));
} else {
Expand Down
1 change: 1 addition & 0 deletions app/js/components/game-management/play.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
function gamePlay(executable) {
console.log(executable)
var exec = require('child_process').exec;
exec(`start "" "${executable.replace(/"/g, '')}"`, (err, data) => {
console.log(err);
Expand Down
108 changes: 108 additions & 0 deletions app/js/components/game-management/steam-installed.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
function addSteamInstalled() {
//Credits: https://github.com/GigaJunky/SteamManifests
function getSteamInstalled() {
//Steam Manifests Data by BitJunky 2020-03-29
const {readFileSync, readdirSync, writeFileSync} = require('fs'),
os = require('os'),
WIN = os.platform() === 'win32';
let bp = WIN ? ['C:/Program Files (x86)/Steam'] : [os.homedir + '/.local/share/Steam'], //change path here if you did not install Steam in defaults os=Win/Lin
bifs = getBasePaths(),
sa = [];
bifs.forEach((p, i) => {
let fs = readdirSync(p + '/steamapps');
for (const f of fs) {
var mfd = readMF(p + '/steamapps/' + f, i);
if (mfd && mfd.appid !== '?') sa.push(mfd);
}
});

function getVal(mf, tag) {
const res = `"${tag}"\\s*"(.*)"`,
p = mf.match(new RegExp(res, 'g'));
if (!p) return '?';
let j = p[0].match(new RegExp(res));
return j[1];
}

function getBasePaths() {
const cfg = readFileSync(bp[0] + '/steamapps/libraryfolders.vdf').toString();
let m = cfg.match(/.*"\d{1,2}".*/g);
for (let l of m) {
let p = l.match(/"(\d)"(?:\s*)"(.*)"/);
if (p) bp.push(p[2].replace(/\\\\/g, '/'));
}
return bp;
}

function readMF(path, i) {
if (!path.endsWith('.acf')) return null;
let mf = readFileSync(path).toString();
let ps = ['appid', 'installdir', 'SizeOnDisk', 'LastUpdated'];
let r = {path: WIN ? bifs[i][0] : i};
for (const p of ps) {
r[p] = getVal(mf, p);
//if(p === 'LastUpdated') r[p] = new Date(r[p] * 1000).toISOString().replace('T',' ').substr(0,19)
}
return r;
}

return [bifs.map((s, i) => ({id: i, path: s})), sa];
}

var file = path.join(appDataPath, '/Json/library.json');
fs.readFile(file, 'utf-8', (err, data) => {
var array;
try {
array = JSON.parse(data);
} catch (e) {
array = {list: []};
}
var updatedArray = array;

(async () => {
var done = 0;
var total = 0;
getSteamInstalled()[1].forEach(async (game) => {
total++;
getSteamInstalled()[0].forEach(async (dir) => {
if (dir.path.startsWith(game.path)) {
//Check if already in list
let inList = false;
updatedArray['list'].forEach((arrayItem) => {
if (arrayItem.folder == game.installdir) inList = true;
});
if (inList) return;

$.get(`https://store.steampowered.com/api/appdetails/?appids=${game.appid}`, (gameInfo) => {
let gameName;
try {
gameName = gameInfo[game.appid].data.name;
} catch (e) {
gameName = game.installdir;
}
const installedDir = path.join(dir.path, 'steamapps/common', game.installdir);
const folderName = game.installdir;
updatedArray['list'].push({
name: gameName,
directory: installedDir,
folder: folderName,
steam: true,
});
done++;
if (done == total) {
saveList();
}
});
}
});
});
function saveList() {
fs.writeFile(file, JSON.stringify(updatedArray), function (err) {
if (err) throw err;
if (isDev) console.log('Saved!');
});
}
})();
});
}
addSteamInstalled();
2 changes: 0 additions & 2 deletions app/js/components/initialize/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ const exec = require('child_process').exec;
const createDesktopShortcut = require('../libraries/create-desktop-shortcuts');
//If development
const isDev = require('electron-is-dev');
//Get installed steam games
const humid = require('humid')

//Electron stuff
const {dialog, BrowserWindow, ipcMain, process, Notification, app} = require('electron').remote;
Expand Down
112 changes: 105 additions & 7 deletions app/js/downloader.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
function selectDownload(elem) {
var container = elem.closest('.downloader-list-item');
var container = elem.closest('.download-item');

try {
document.querySelector('.active').classList.remove('active');
Expand All @@ -9,14 +9,112 @@ function selectDownload(elem) {

document.getElementById('game-info-content').style.display = 'initial';
}
var testarray = [
{
fullPath: '/home/sushy/.config/vapor-store/Games/Emily.Wants.To.Play.zip',
gameTitle: 'emily-wants-to-play',
url: 'https://download141.uploadhaven.com/1/application/zip/2W6qYYUEHTH1MLaUn6FPlQiIGRi3T4DlalhsyNWu.zip?key=jVNb5AFo81-fYy1I8dlWZA&expire=1608998764&filename=Emily.Wants.To.Play.zip',
zipFile: 'Emily.Wants.To.Play.zip',
},
];

//document.getElementById('download-item-container').innerHTML = ''
onGoingDownloads.forEach((game) => {
createDownloadItem(game);
});

function createDownloadItem(game) {
let item = document.createElement('div');
item.className = 'download-item';
item.id = `${game.gameTitle}-download-item`
item.innerHTML = `
<div class="download-item-body mdc-ripple-surface" data-mdc-auto-init="MDCRipple" id="assetto-corsa-download" onclick="selectDownload(this); addMetadata('${game.gameTitle}', 'downloader')">
<div class="download-item-content">
<div class="title-desc">
<h1 class="mdc-typography--headline4" id="${game.gameTitle}-zipfile">${game.zipFile}</h1>
<h3 class="mdc-typography--body2" id="${game.gameTitle}-download-info"></h3>
</div>
<div role="progressbar" class="mdc-linear-progress" id="${game.gameTitle}-progress" aria-valuemin="0" aria-valuemax="1" data-mdc-auto-init="MDCLinearProgress">
<div class="mdc-linear-progress__buffer">
<div class="mdc-linear-progress__buffer-bar"></div>
<div class="mdc-linear-progress__buffer-dots"></div>
</div>
<div class="mdc-linear-progress__bar mdc-linear-progress__primary-bar">
<span class="mdc-linear-progress__bar-inner"></span>
</div>
<div class="mdc-linear-progress__bar mdc-linear-progress__secondary-bar">
<span class="mdc-linear-progress__bar-inner"></span>
</div>
</div>
</div>
</div>
<div class="download-item-actions" id="${game.gameTitle}-download-item-actions">
<button class="mdc-button" data-mdc-auto-init="MDCRipple" onclick="pauseDownload('${game.gameTitle}')">
<div class="mdc-button__ripple"></div>
<span class="mdc-button__label" id="${game.gameTitle}-downloader-pause-button__label">Pause</span>
</button>
<button class="mdc-button" data-mdc-auto-init="MDCRipple" onclick="cancelDownload('${game.gameTitle}', true, 'Are you sure you want to cancel the download for ${game.zipFile}', '${game.fullPath.replace(/\\/g, '/')}')">
<div class="mdc-button__ripple"></div>
<span class="mdc-button__label">Cancel</span>
</button>
</div>
<hr class="mdc-list-divider" />
`;

document.getElementById('download-item-container').appendChild(item);

window.mdc.autoInit();
}

ipcMain.on('item-updated-data', (e, item, data, gameTitle) => {
var received_bytes = item.received;
var total_bytes = item.total;

var downloadPercent = (received_bytes * 100) / total_bytes;
var scalePercent = downloadPercent / 100;

//received / 1000000 / time;

var seconds = (Date.now() - item.startTime) / 1000;
var MB = received_bytes / (1024 * 1024);
var GB = MB / 1024;
var MBps = MB / seconds;
var totalGB = total_bytes / (1024 * 1024 * 1024);

console.log(MBps.toFixed(2));

function removeItem(gameTitle, type) {
try {
document.getElementById(`${gameTitle}-${type}-item`).remove();
} catch (e) {}
var downloadInfo = document.getElementById(`${gameTitle}-download-info`);
downloadInfo.innerHTML = `${downloadPercent.toFixed(2)}% | ${MBps.toFixed(2)}MB/s | ${GB.toFixed(2)}GB/${totalGB.toFixed(2)}GB`;
var progress = document.getElementById(`${gameTitle}-progress`);
var mlp = new mdc.linearProgress.MDCLinearProgress(progress);
mlp.progress = scalePercent;
} catch (e) {
console.log(e);
}
});

function pauseDownload(name) {
if (document.getElementById(`${name}-downloader-pause-button__label`).innerHTML == 'Pause') {
ipcRenderer.sendTo(mainWindow.id, `${name}-pause`);
document.getElementById(`${name}-downloader-pause-button__label`).innerHTML = 'Resume';
} else {
ipcRenderer.sendTo(mainWindow.id, `${name}-resume`);
document.getElementById(`${name}-downloader-pause-button__label`).innerHTML = 'Pause';
}
}

//Cancel download
async function cancelDownload(name, alert, message, targetPath) {
//if pressed cancel dont continue
if (!closeSnackbar(`${name}-download`, alert, message)) return;
//set canceled in localstorage
ipcRenderer.sendTo(mainWindow.id, `${name}-cancel`);

goto('Downloader');
}

fetchingDownload.forEach((game) => {
console.log(game);
createFetchingItem(game);
ipcMain.on('item-download-completed', (event, gameTitle) => {
document.getElementById(`${gameTitle}-download-item`).remove
});
2 changes: 0 additions & 2 deletions app/js/home.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,3 @@ $.get('https://raw.githubusercontent.com/SushyDev/vapor-store/data/home.html', f
document.getElementById('version').innerHTML = `Ver: ${app.getVersion()}`;
window.mdc.autoInit();
});

console.log(humid.find('/path/to/steam/library'));
2 changes: 1 addition & 1 deletion app/js/installed.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,4 @@ function openMore(name, name2, gameDir, folderName) {
`;
}
}
}
2 changes: 1 addition & 1 deletion app/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ window.addEventListener('resize', () => {
});

//Jquery function for dynamically loading in content to the main-content div
function goto(page = 'Downloader') {
function goto(page = 'Home') {
document.getElementById('top-app-bar-title').innerHTML = page;

$('#main-content').load('../html/' + page.toLowerCase().replace(/ /g, '_') + '.html');
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vapor-store",
"version": "2.0.0-beta-34",
"version": "2.0.0-beta-35",
"description": "Vapor Store",
"author": "SushyDev",
"main": "app.js",
Expand Down

0 comments on commit 5a4d780

Please sign in to comment.