Commit 0ffda196 authored by Laura Heimann's avatar Laura Heimann

added library database

parent 5f79e795
{ {
"name": "spinshare-client", "name": "spinshare-client",
"version": "2.5.0", "version": "2.5.1",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {
...@@ -2468,34 +2468,11 @@ ...@@ -2468,34 +2468,11 @@
"dev": true "dev": true
}, },
"axios": { "axios": {
"version": "0.19.2", "version": "0.21.1",
"resolved": "https://registry.npmjs.org/axios/-/axios-0.19.2.tgz", "resolved": "https://registry.npmjs.org/axios/-/axios-0.21.1.tgz",
"integrity": "sha512-fjgm5MvRHLhx+osE2xoekY70AhARk3a6hkN+3Io1jc00jtquGvxYlKlsFUhmUET0V5te6CcZI7lcv2Ym61mjHA==", "integrity": "sha512-dKQiRHxGD9PPRIUNIWvZhPTPpl1rf/OxTYKsqKUDjBwYylTvV7SjSHJb9ratfyzM6wCdLCOYLzs73qpg5c4iGA==",
"requires": { "requires": {
"follow-redirects": "1.5.10" "follow-redirects": "^1.10.0"
},
"dependencies": {
"debug": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz",
"integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==",
"requires": {
"ms": "2.0.0"
}
},
"follow-redirects": {
"version": "1.5.10",
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.5.10.tgz",
"integrity": "sha512-0V5l4Cizzvqt5D44aTXbFZz+FtyXV1vrDN6qrelxtfYQKW0KO0W2T/hkE8xvGa/540LkZlkaUjO4ailYTFtHVQ==",
"requires": {
"debug": "=3.1.0"
}
},
"ms": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
"integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g="
}
} }
}, },
"babel-loader": { "babel-loader": {
...@@ -3491,6 +3468,11 @@ ...@@ -3491,6 +3468,11 @@
"integrity": "sha1-tUc7M9yXxCTl2Y3IfVXU2KKci/I=", "integrity": "sha1-tUc7M9yXxCTl2Y3IfVXU2KKci/I=",
"dev": true "dev": true
}, },
"charenc": {
"version": "0.0.2",
"resolved": "https://registry.npmjs.org/charenc/-/charenc-0.0.2.tgz",
"integrity": "sha1-wKHS86cJLgN3S/qD8UwPxXkKhmc="
},
"check-types": { "check-types": {
"version": "8.0.3", "version": "8.0.3",
"resolved": "https://registry.npmjs.org/check-types/-/check-types-8.0.3.tgz", "resolved": "https://registry.npmjs.org/check-types/-/check-types-8.0.3.tgz",
...@@ -4314,6 +4296,11 @@ ...@@ -4314,6 +4296,11 @@
"which": "^1.2.9" "which": "^1.2.9"
} }
}, },
"crypt": {
"version": "0.0.2",
"resolved": "https://registry.npmjs.org/crypt/-/crypt-0.0.2.tgz",
"integrity": "sha1-iNf/fsDfuG9xPch7u0LQRNPmxBs="
},
"crypto-browserify": { "crypto-browserify": {
"version": "3.12.0", "version": "3.12.0",
"resolved": "https://registry.npmjs.org/crypto-browserify/-/crypto-browserify-3.12.0.tgz", "resolved": "https://registry.npmjs.org/crypto-browserify/-/crypto-browserify-3.12.0.tgz",
...@@ -6129,7 +6116,6 @@ ...@@ -6129,7 +6116,6 @@
"version": "1.11.0", "version": "1.11.0",
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.11.0.tgz", "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.11.0.tgz",
"integrity": "sha512-KZm0V+ll8PfBrKwMzdo5D13b1bur9Iq9Zd/RMmAoQQcl2PxxFml8cxXPaaPYVbV0RjNjq1CU7zIzAOqtUPudmA==", "integrity": "sha512-KZm0V+ll8PfBrKwMzdo5D13b1bur9Iq9Zd/RMmAoQQcl2PxxFml8cxXPaaPYVbV0RjNjq1CU7zIzAOqtUPudmA==",
"dev": true,
"requires": { "requires": {
"debug": "^3.0.0" "debug": "^3.0.0"
}, },
...@@ -6138,7 +6124,6 @@ ...@@ -6138,7 +6124,6 @@
"version": "3.2.6", "version": "3.2.6",
"resolved": "https://registry.npmjs.org/debug/-/debug-3.2.6.tgz", "resolved": "https://registry.npmjs.org/debug/-/debug-3.2.6.tgz",
"integrity": "sha512-mel+jf7nrtEl5Pn1Qx46zARXKDpBbvzezse7p7LqINmdoIk8PYP5SySaxEmYv6TZ0JyEKA1hsCId6DIhgITtWQ==", "integrity": "sha512-mel+jf7nrtEl5Pn1Qx46zARXKDpBbvzezse7p7LqINmdoIk8PYP5SySaxEmYv6TZ0JyEKA1hsCId6DIhgITtWQ==",
"dev": true,
"requires": { "requires": {
"ms": "^2.1.1" "ms": "^2.1.1"
} }
...@@ -7759,8 +7744,7 @@ ...@@ -7759,8 +7744,7 @@
"is-buffer": { "is-buffer": {
"version": "1.1.6", "version": "1.1.6",
"resolved": "https://registry.npmjs.org/is-buffer/-/is-buffer-1.1.6.tgz", "resolved": "https://registry.npmjs.org/is-buffer/-/is-buffer-1.1.6.tgz",
"integrity": "sha512-NcdALwpXkTm5Zvvbk7owOUSvVvBKDgKP5/ewfXEznmQFfs4ZRmanOeKBTjRVjka3QFoN6XJ+9F3USqfHqTaU5w==", "integrity": "sha512-NcdALwpXkTm5Zvvbk7owOUSvVvBKDgKP5/ewfXEznmQFfs4ZRmanOeKBTjRVjka3QFoN6XJ+9F3USqfHqTaU5w=="
"dev": true
}, },
"is-callable": { "is-callable": {
"version": "1.1.5", "version": "1.1.5",
...@@ -8589,6 +8573,16 @@ ...@@ -8589,6 +8573,16 @@
"object-visit": "^1.0.0" "object-visit": "^1.0.0"
} }
}, },
"md5": {
"version": "2.3.0",
"resolved": "https://registry.npmjs.org/md5/-/md5-2.3.0.tgz",
"integrity": "sha512-T1GITYmFaKuO91vxyoQMFETst+O71VUPEU3ze5GNzDm0OWdP8v1ziTaAEPUr/3kLsY3Sftgz242A1SetQiDL7g==",
"requires": {
"charenc": "0.0.2",
"crypt": "0.0.2",
"is-buffer": "~1.1.6"
}
},
"md5-file": { "md5-file": {
"version": "5.0.0", "version": "5.0.0",
"resolved": "https://registry.npmjs.org/md5-file/-/md5-file-5.0.0.tgz", "resolved": "https://registry.npmjs.org/md5-file/-/md5-file-5.0.0.tgz",
...@@ -8919,8 +8913,7 @@ ...@@ -8919,8 +8913,7 @@
"ms": { "ms": {
"version": "2.1.2", "version": "2.1.2",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",
"integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==", "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w=="
"dev": true
}, },
"multicast-dns": { "multicast-dns": {
"version": "6.2.3", "version": "6.2.3",
......
...@@ -21,10 +21,11 @@ ...@@ -21,10 +21,11 @@
"dependencies": { "dependencies": {
"@mdi/font": "^5.8.55", "@mdi/font": "^5.8.55",
"adm-zip": "^0.4.16", "adm-zip": "^0.4.16",
"axios": "^0.19.2", "axios": "^0.21.1",
"core-js": "^3.6.4", "core-js": "^3.6.4",
"get-folder-size": "^2.0.1", "get-folder-size": "^2.0.1",
"glob": "^7.1.6", "glob": "^7.1.6",
"md5": "^2.3.0",
"md5-file": "^5.0.0", "md5-file": "^5.0.0",
"moment": "^2.27.0", "moment": "^2.27.0",
"ncp": "^2.0.0", "ncp": "^2.0.0",
......
<template> <template>
<div :class="'song-item-local ' + (isSpinShare ? '' : 'song-item-onlylocal')" v-on:contextmenu="showContextMenu($event)" v-on:click="openInClient()"> <div :class="'song-item-local ' + (isSpinShare ? '' : 'song-item-onlylocal')" v-on:contextmenu="showContextMenu($event)" v-on:click="openInClient()">
<div class="song-cover" v-bind:style="'background-image: '+ backgroundImage +' , url(' + require('@/assets/img/defaultAlbumArt.jpg') + ');'" v-observe-visibility="visibilityChanged"> <div class="song-cover" v-bind:style="'background-image: ' + backgroundImage + ' , url(' + require('@/assets/img/defaultAlbumArt.jpg') + ');'" v-observe-visibility="visibilityChanged">
<div class="song-charter-info"> <div class="song-charter-info">
<div class="song-charter"><i class="mdi mdi-account-circle"></i><span>{{ detail.charter ? detail.charter : "Unknown" }}</span></div> <div class="song-charter"><i class="mdi mdi-account-circle"></i><span>{{ charter ? charter : "Unknown" }}</span></div>
</div> </div>
</div> </div>
<div class="song-metadata"> <div class="song-metadata">
<div class="song-title">{{ detail.title ? detail.title : "Untitled" }}</div> <div class="song-title">{{ title ? title : "Untitled" }}</div>
<div class="song-artist">{{ detail.artist ? detail.artist : "Unknown" }}</div> <div class="song-artist">{{ artist ? artist : "Unknown" }}</div>
<div class="song-difficulties">
<div v-if="hasEasyDifficulty" class="difficulty"><span>E</span> {{ easyDifficulty ? easyDifficulty : 0 }}</div>
<div v-if="hasNormalDifficulty" class="difficulty"><span>N</span> {{ normalDifficulty ? normalDifficulty : 0 }}</div>
<div v-if="hasHardDifficulty" class="difficulty"><span>H</span> {{ hardDifficulty ? hardDifficulty : 0 }}</div>
<div v-if="hasExpertDifficulty" class="difficulty"><span>EX</span> {{ expertDifficulty ? expertDifficulty : 0 }}</div>
<div v-if="hasXDDifficulty" class="difficulty"><span>XD</span> {{ XDDifficulty ? XDDifficulty : 0 }}</div>
</div>
</div> </div>
</div> </div>
</template> </template>
<script> <script>
import { remote } from 'electron'; import { remote } from 'electron';
import fs from 'fs';
import path from 'path'; import path from 'path';
const { shell } = remote; const { shell } = remote;
import SSAPI from '@/modules/module.api.js';
export default { export default {
name: 'SongLocalItem', name: 'SongLocalItem',
props: [ props: [
'id', 'title',
'file', 'subtitle',
'detail', 'artist',
'cover', 'charter',
'isSpinShare' 'hasEasyDifficulty',
'hasNormalDifficulty',
'hasHardDifficulty',
'hasExpertDifficulty',
'hasXDDifficulty',
'easyDifficulty',
'normalDifficulty',
'hardDifficulty',
'expertDifficulty',
'XDDifficulty',
'paths'
], ],
data: function() { data: function() {
return { return {
isContextMenuActive: false, isContextMenuActive: false,
backgroundImage: "none;" backgroundImage: "none;",
baseFileName: "",
isSpinShare: false,
spinShareID: null,
} }
}, },
computed: { computed: {
imageUrl() { imageUrl() {
return this.$data.backgroundImage return this.$data.backgroundImage;
} }
}, },
mounted: function() { mounted: function() {
let ssapi = new SSAPI();
this.$data.baseFileName = path.basename(this.$props.paths.srtb).replace(".srtb", "");
ssapi.getSongDetail(this.$data.baseFileName).then(data => {
if(data.status == 200) {
this.$data.isSpinShare = true;
this.$data.spinShareID = data.data.id;
}
});
}, },
methods: { methods: {
showContextMenu: function(e) { showContextMenu: function(e) {
...@@ -49,7 +80,7 @@ ...@@ -49,7 +80,7 @@
} }
items.push({ icon: "folder-outline", title: this.$t('contextmenu.openInExplorer'), method: () => { this.openInExplorer(); } }); items.push({ icon: "folder-outline", title: this.$t('contextmenu.openInExplorer'), method: () => { this.openInExplorer(); } });
items.push({ icon: "delete", title: this.$t('contextmenu.delete'), method: () => { this.$parent.$parent.$emit('delete', this.$props.file); } }); items.push({ icon: "delete", title: this.$t('contextmenu.delete'), method: () => { this.$parent.$parent.$emit('delete', this.$props.paths.srtb); } });
this.$root.$emit('showContextMenu', { this.$root.$emit('showContextMenu', {
x: e.pageX, x: e.pageX,
...@@ -59,15 +90,15 @@ ...@@ -59,15 +90,15 @@
}, },
openInClient: function() { openInClient: function() {
if(this.isSpinShare) { if(this.isSpinShare) {
if(this.isSpinShare.includes("spinshare_")) { if(this.isSpinShare) {
this.$router.push({ name: 'SongDetailReviews', params: { id: this.isSpinShare } }); this.$router.push({ name: 'SongDetailReviews', params: { id: this.spinShareID } });
} }
} }
}, },
openOnSpinShare: function() { openOnSpinShare: function() {
if(this.isSpinShare) { if(this.isSpinShare) {
if(this.isSpinShare.includes("spinshare_")) { if(this.isSpinShare) {
shell.openExternal("https://spinsha.re/song/" + this.isSpinShare); shell.openExternal("https://spinsha.re/song/" + this.spinShareID);
} }
} }
}, },
...@@ -76,10 +107,8 @@ ...@@ -76,10 +107,8 @@
}, },
visibilityChanged (isVisible, entry) { visibilityChanged (isVisible, entry) {
if (isVisible) { if (isVisible) {
this.$data.backgroundImage = "url(" + this.$props.cover + ")"; this.$data.backgroundImage = "url(" + this.$props.paths.coverBase64 + ")";
} } else {
//url(" + require('@/assets/img/defaultAlbumArt.jpg') + ");
else {
this.$data.backgroundImage = "none;"; this.$data.backgroundImage = "none;";
} }
} }
...@@ -138,6 +167,8 @@ ...@@ -138,6 +167,8 @@
& .song-metadata { & .song-metadata {
padding: 15px; padding: 15px;
color: #fff;
text-decoration: none;
& .song-title { & .song-title {
font-weight: bold; font-weight: bold;
...@@ -150,6 +181,25 @@ ...@@ -150,6 +181,25 @@
overflow: hidden; overflow: hidden;
white-space: nowrap; white-space: nowrap;
} }
& .song-difficulties {
margin-top: 10px;
height: 20px;
display: flex;
& .difficulty {
background: #fff;
color: #000;
border-radius: 4px;
padding: 3px 5px;
margin-right: 4px;
font-size: 10px;
& span {
// padding-right: 3px;
font-weight: bold;
}
}
}
} }
&:not(.song-item-onlylocal):hover { &:not(.song-item-onlylocal):hover {
......
...@@ -8,6 +8,10 @@ import VueTilt from 'vue-tilt.js' ...@@ -8,6 +8,10 @@ import VueTilt from 'vue-tilt.js'
import { ipcRenderer } from 'electron'; import { ipcRenderer } from 'electron';
import VueObserveVisibility from 'vue-observe-visibility' import VueObserveVisibility from 'vue-observe-visibility'
import { VTooltip, VPopover, VClosePopover } from 'v-tooltip' import { VTooltip, VPopover, VClosePopover } from 'v-tooltip'
import ChartLibrary from '@/modules/module.library.js';
let chartLibrary = new ChartLibrary();
chartLibrary.updateLibrary();
Vue.use(VueTilt); Vue.use(VueTilt);
Vue.use(VueObserveVisibility); Vue.use(VueObserveVisibility);
......
const { electron, remote } = require('electron');
const app = remote.app;
const md5 = require('md5');
const fs = require('fs');
const { glob } = require('glob');
const path = require('path');
const UserSettings = require('@/modules/module.usersettings.js');
const { createHmac } = require('crypto');
class ChartLibrary {
constructor() {
const userDataPath = app.getPath('userData');
this.path = path.join(userDataPath, 'ChartLibrary.json');
}
async getLibrary() {
let userSettings = new UserSettings();
let data = this.parseDataFile(this.path, false);
console.log("[ChartLibrary] Get Library");
if(data == false) {
return this.updateLibrary();
} else {
if(data.folderMD5 != md5(userSettings.get('gameDirectory'))) {
return this.updateLibrary();
} else {
return data;
}
}
}
async updateLibrary() {
let userSettings = new UserSettings();
let data = {
folderMD5: "",
charts: []
};
console.log("[ChartLibrary] Library Refresh");
data.folderMD5 = md5(userSettings.get('gameDirectory'));
// Find all SRTB files
let srtbFiles = glob.sync(path.join(userSettings.get('gameDirectory'), "*.srtb"));
srtbFiles.forEach((file) => {
// Parse SRTB file
try {
data.charts.push(this.parseSRTBFile(file));
} catch(error) {
console.error(error);
}
});
console.log("[ChartLibrary] Library Refresh Done.");
// Save changes
fs.writeFileSync(this.path, JSON.stringify(data));
console.log("[ChartLibrary] Wrote Library to: " + this.path);
return data;
}
parseSRTBFile(srtbFilePath) {
let userSettings = new UserSettings();
let data = {
title: "",
subtitle: "",
artist: "",
charter: "",
hasEasyDifficulty: false,
hasNormalDifficulty: false,
hasHardDifficulty: false,
hasExpertDifficulty: false,
hasXDDifficulty: false,
easyDifficulty: 0,
normalDifficulty: 0,
hardDifficulty: 0,
expertDifficulty: 0,
XDDifficulty: 0,
srtbHash: "",
paths: {
srtb: "",
ogg: "",
cover: "",
coverBase64: "",
}
}
let srtbRawData = fs.readFileSync(srtbFilePath, "utf-8");
let srtbData = JSON.parse( srtbRawData );
data.paths.srtb = srtbFilePath;
data.srtbHash = md5( srtbData );
srtbData.largeStringValuesContainer.values.forEach(lSV => {
let lSVData = JSON.parse( lSV.val );
// Parse TrackInfo
if(lSV.key.includes("TrackInfo")) {
// Extract values
data.title = lSVData.title;
data.subtitle = lSVData.subtitle;
data.artist = lSVData.artistName;
data.charter = lSVData.charter;
data.paths.cover = glob.sync(path.join(userSettings.get('gameDirectory'), "AlbumArt", lSVData.albumArtReference.assetName + '.*'))[0];
if(data.paths.cover != undefined) {
try {
data.paths.coverBase64 = "data:image/jpg;base64," + fs.readFileSync(data.paths.cover, { encoding: 'base64' })
} catch(error) {
console.error(error);
}
}
lSVData.difficulties.forEach(difficulty => {
if(difficulty._active) {
switch(difficulty._difficulty) {
case 2:
// Easy
data.hasEasyDifficulty = true;
break;
case 3:
// Normal
data.hasNormalDifficulty = true;
break;
case 4:
// Hard
data.hasHardDifficulty = true;
break;
case 5:
// Expert
data.hasExpertDifficulty = true;
break;
case 6:
// XD
data.hasXDDifficulty = true;
break;
}
}
});
}
// Parse TrackData
if(lSV.key.includes("TrackData")) {
if(lSVData != null) {
switch(lSVData.difficultyType) {
case 2:
// Easy
data.easyDifficulty = lSVData.difficultyRating;
break;
case 3:
// Normal
data.normalDifficulty = lSVData.difficultyRating;
break;
case 4:
// Hard
data.hardDifficulty = lSVData.difficultyRating;
break;
case 5:
// Expert
data.expertDifficulty = lSVData.difficultyRating;
break;
case 6:
// XD
data.XDDifficulty = lSVData.difficultyRating;
break;
}
}
}
// Parse ClipInfo
if(lSV.key.includes("ClipInfo")) {
data.paths.ogg = glob.sync(path.join(userSettings.get('gameDirectory'), "AudioClips", lSVData.clipAssetReference.assetName + '.*'))[0];
}
});
// console.log("[ChartLibrary] Parsed SRTB: " + data.paths.srtb);
return data;
}
parseDataFile(filePath, defaults) {
try {
return JSON.parse(fs.readFileSync(filePath));
} catch(error) {
return defaults;
}
}
}
module.exports = ChartLibrary;
\ No newline at end of file
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
<div class="title">{{ $t('library.header') }}</div> <div class="title">{{ $t('library.header') }}</div>
<div class="actions"> <div class="actions">
<div class="button" v-on:click="install()">{{ $t('library.actions.install') }}</div> <div class="button" v-on:click="install()">{{ $t('library.actions.install') }}</div>
<div class="button" v-on:click="refreshLibrary()">{{ $t('library.actions.refresh') }}</div> <div class="button" v-on:click="refreshLibrary(true)">{{ $t('library.actions.refresh') }}</div>
<div class="button" v-on:click="openLibrary()">{{ $t('library.actions.open') }}</div> <div class="button" v-on:click="openLibrary()">{{ $t('library.actions.open') }}</div>
<span></span> <span></span>
</div> </div>
...@@ -25,12 +25,12 @@ ...@@ -25,12 +25,12 @@
<template v-slot:song-list> <template v-slot:song-list>
<SongLocalItem <SongLocalItem
v-for="song in librarySongs" v-for="song in librarySongs"
v-bind:key="song.detail.id" v-bind:key="song.paths.srtb"
v-bind="song" /> v-bind="song" />
</template> </template>
</SongRow> </SongRow>
<div class="loading" v-if="!apiFinished"> <div class="loading" v-if="isLoading">
<Loading /> <Loading />
</div> </div>
...@@ -47,6 +47,7 @@ ...@@ -47,6 +47,7 @@
import path from 'path'; import path from 'path';
import UserSettings from '@/modules/module.usersettings.js'; import UserSettings from '@/modules/module.usersettings.js';
import ChartLibrary from '@/modules/module.library.js';
import SSAPI from '@/modules/module.api.js'; import SSAPI from '@/modules/module.api.js';
import SRXD from '@/modules/module.srxd.js'; import SRXD from '@/modules/module.srxd.js';
...@@ -63,8 +64,7 @@ ...@@ -63,8 +64,7 @@
showDeleteOverlay: false, showDeleteOverlay: false,
deleteFiles: [], deleteFiles: [],
hasUnusedFiles: false, hasUnusedFiles: false,
apiFinished: false, isLoading: false
useAPIForLibrary: false
} }
}, },
components: { components: {
...@@ -74,11 +74,8 @@ ...@@ -74,11 +74,8 @@
DeleteOverlay DeleteOverlay
}, },
mounted: function() { mounted: function() {
// Put initial refresh on a timeout so the loading animation is rendered first this.refreshLibrary(false);
setTimeout(() => {
this.refreshLibrary();
}, 50);
this.$on('delete', (file) => { this.$on('delete', (file) => {
this.$data.showDeleteOverlay = true; this.$data.showDeleteOverlay = true;
this.$data.deleteFiles = this.getConnectedFiles(file); this.$data.deleteFiles = this.getConnectedFiles(file);
...@@ -91,7 +88,7 @@ ...@@ -91,7 +88,7 @@
this.$data.deleteFiles.forEach((file) => { this.$data.deleteFiles.forEach((file) => {
fs.unlinkSync(file); fs.unlinkSync(file);
}); });
this.refreshLibrary(); this.refreshLibrary(false);
this.$data.showDeleteOverlay = false; this.$data.showDeleteOverlay = false;
this.$data.deleteFiles = ""; this.$data.deleteFiles = "";
}); });
...@@ -101,62 +98,30 @@ ...@@ -101,62 +98,30 @@
// Refresh if the Download Queue finished an item // Refresh if the Download Queue finished an item
ipcRenderer.on("download-complete", (event, downloadItem) => { ipcRenderer.on("download-complete", (event, downloadItem) => {
this.refreshLibrary(); this.refreshLibrary(false);
}); });
}, },
methods: { methods: {
refreshLibrary: async function() { refreshLibrary: async function(hardRefresh = false) {
let ssapi = new SSAPI(); let ssapi = new SSAPI();
let userSettings = new UserSettings(); let userSettings = new UserSettings();
let chartLibrary = new ChartLibrary();
this.$data.hasUnusedFiles = false; this.$data.hasUnusedFiles = false;
this.$data.librarySongs = []; this.$data.librarySongs = [];
this.$data.apiFinished = false; this.$data.isLoading = true;
await ssapi.ping().then((data) => {
this.$data.useAPIForLibrary = true;
}).catch((error) => {
console.log(error);
this.$data.useAPIForLibrary = false;
console.log("ERROR WHILE PINGING API");
});
// Load local .srtb
glob(path.join(userSettings.get('gameDirectory'), "*.srtb"), (error, files) => {
files.forEach((file) => {
// Get Detail Data
this.getSongDetail(file).then((songDetail) => {
let librarySong = {};
let fileReference = false;
if(path.basename(file).includes("spinshare_")) {
fileReference = path.basename(file).replace(".srtb", "");
}
let songCover = glob.sync(path.join(userSettings.get('gameDirectory'), "AlbumArt", songDetail.coverReference + ".*"))[0];
if(songCover) {
songCover = "data:image/jpg;base64," + fs.readFileSync(songCover, { encoding: 'base64' });
}
librarySong = {
file: file,
detail: songDetail,
cover: songCover,
modifiedDate: fs.statSync(file).mtime,
isSpinShare: fileReference
};
this.$data.librarySongs.push(librarySong);
this.$data.apiFinished = true;
});
});
// Order library by modifiedDate if(hardRefresh) {
this.$data.librarySongs.sort(function(a, b) { chartLibrary.updateLibrary().then(data => {
return new Date(b.modifiedDate) - new Date(a.modifiedDate); this.$data.isLoading = false;
this.$data.librarySongs = data.charts;
}); });
}); } else {
chartLibrary.getLibrary().then(data => {
this.$data.isLoading = false;
this.$data.librarySongs = data.charts;
});
}
this.getUnusedFiles().then((data) => { this.getUnusedFiles().then((data) => {
if(data.differingAssets.length > 0) { if(data.differingAssets.length > 0) {
...@@ -295,7 +260,7 @@ ...@@ -295,7 +260,7 @@
srxdControl.installBackup(extractResult, userSettings.get('gameDirectory')).then((result) => { srxdControl.installBackup(extractResult, userSettings.get('gameDirectory')).then((result) => {
console.log("[COPY] Backup installed!"); console.log("[COPY] Backup installed!");
setTimeout(() => { setTimeout(() => {
this.refreshLibrary(); this.refreshLibrary(false);
}, 250); }, 250);
}).catch(error => { }).catch(error => {
console.error(error); console.error(error);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment