Skip to content

Commit

Permalink
Merge beta branch
Browse files Browse the repository at this point in the history
  • Loading branch information
StarGazer1258 committed May 26, 2019
2 parents b677e12 + e3b232c commit 1213962
Show file tree
Hide file tree
Showing 24 changed files with 579 additions and 540 deletions.
398 changes: 265 additions & 133 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "beatdrop",
"description": "A desktop app for downloading Beat Saber songs.",
"author": "Nathaniel Johns (StarGazer1258)",
"version": "2.2.0",
"version": "2.3.2",
"private": false,
"license": "CC-BY-NC-SA-4.0",
"repository": {
Expand Down
4 changes: 2 additions & 2 deletions public/electron.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,9 @@ function handleArgs(argv, sendImmediately) {

function createWindow() {
mainWindow = new BrowserWindow({
width: 1015,
width: 1080,
height: 615,
minWidth: 1015,
minWidth: 1090,
minHeight: 615,
resizable: true,
frame: false,
Expand Down
42 changes: 9 additions & 33 deletions src/actions/modActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { SET_MOD_LIST, SET_VIEW, SET_RESOURCE, SET_LOADING, LOAD_MOD_DETAILS, IN
import { MODS_VIEW, MOD_DETAILS } from '../views'

import { BEATMODS, LIBRARY } from '../constants/resources'
import { MODS as EMERGENCY_MODS } from '../constants/emergencyMods'

import modIcon from '../assets/dark/mod.png'

Expand All @@ -16,7 +15,7 @@ const execFile = remote.require('child_process').execFile

const { ipcRenderer } = window.require('electron')

export const fetchApprovedMods = () => dispatch => {
export const fetchApprovedMods = () => (dispatch, getState) => {
dispatch({
type: SET_VIEW,
payload: MODS_VIEW
Expand All @@ -29,7 +28,7 @@ export const fetchApprovedMods = () => dispatch => {
type: SET_LOADING,
payload: true
})
fetch('https://beatmods.com/api/v1/mod?status=approved')
fetch(`https://beatmods.com/api/v1/mod?status=approved&gameVersion=${getState().settings.gameVersion}`)
.then(res => res.json())
.then(beatModsResponse => {
dispatch({
Expand All @@ -43,30 +42,7 @@ export const fetchApprovedMods = () => dispatch => {
})
}

export const fetchEmergencyMods = () => dispatch => {
dispatch({
type: SET_VIEW,
payload: MODS_VIEW
})
dispatch({
type: SET_RESOURCE,
payload: BEATMODS.NEW_MODS
})
dispatch({
type: SET_LOADING,
payload: true
})
dispatch({
type: SET_MOD_LIST,
payload: EMERGENCY_MODS
})
dispatch({
type: SET_LOADING,
payload: false
})
}

export const fetchRecommendedMods = () => dispatch => {
export const fetchRecommendedMods = () => (dispatch, getState) => {
dispatch({
type: SET_VIEW,
payload: MODS_VIEW
Expand All @@ -82,7 +58,7 @@ export const fetchRecommendedMods = () => dispatch => {
let recommendedMods = ['CameraPlus', 'YUR Fit Calorie Tracker', 'SyncSaber', 'Custom Sabers', 'Custom Platforms', 'Custom Avatars', 'BeatSaberTweaks', 'PracticePlugin', 'Counters+']
let mods = []
for(let i = 0; i < recommendedMods.length; i++) {
fetch(`https://beatmods.com/api/v1/mod?name=${encodeURIComponent(recommendedMods[i])}`)
fetch(`https://beatmods.com/api/v1/mod?name=${encodeURIComponent(recommendedMods[i])}&gameVersion=${getState().settings.gameVersion}`)
.then(res => res.json())
.then(beatModsResponse => {
if(beatModsResponse.length === 0) { recommendedMods.splice(i, 1); return }
Expand Down Expand Up @@ -120,7 +96,7 @@ export const fetchModCategories = () => dispatch => {
})
}

export const fetchModCategory = category => dispatch => {
export const fetchModCategory = category => (dispatch, getState) => {
dispatch({
type: SET_VIEW,
payload: MODS_VIEW
Expand All @@ -133,7 +109,7 @@ export const fetchModCategory = category => dispatch => {
type: SET_LOADING,
payload: true
})
fetch(`https://beatmods.com/api/v1/mod?category=${ category }&status=approved`)
fetch(`https://beatmods.com/api/v1/mod?category=${ category }&status=approved&gameVersion=${getState().settings.gameVersion}`)
.then(res => res.json())
.then(beatModsResponse => {
dispatch({
Expand Down Expand Up @@ -166,7 +142,7 @@ export const fetchLocalMods = () => (dispatch, getState) => {
let installedMods = getState().mods.installedMods
let m = []
for(let i = 0; i < installedMods.length; i++) {
if(beatModsResponse.filter(mod => mod.name === installedMods[i].name)[0]) m.push(beatModsResponse.filter(mod => mod.name === installedMods[i].name)[0])
if(beatModsResponse.filter(mod => mod._id === installedMods[i].id)[0]) m.push(beatModsResponse.filter(mod => mod._id === installedMods[i].id)[0])
console.log(installedMods[i].name)
}
dispatch({
Expand Down Expand Up @@ -283,7 +259,7 @@ export const installMod = (modName, version, dependencyOf = '') => (dispatch, ge
return
}
console.log(`Fetching ${modName}@${version} from BeatMods...`)
fetch(`https://beatmods.com/api/v1/mod?status=approved&status=inactive&name=${encodeURIComponent(modName)}&version=${version}`)
fetch(`https://beatmods.com/api/v1/mod?status=approved${!!version ? `&status=inactive&version=${version}` : ''}&name=${encodeURIComponent(modName)}&gameVersion=${getState().settings.gameVersion}`)
.then(res => res.json())
.then(beatModsResponse => {
console.log(`Got the BeatMods response for ${modName}@${version}`)
Expand Down Expand Up @@ -402,7 +378,7 @@ export const installMod = (modName, version, dependencyOf = '') => (dispatch, ge
dispatch({
type: DISPLAY_WARNING,
payload: {
text: `The mod ${mod.name} does not have a version for ${installationType} installations.`
text: `The mod ${mod.name} does not have a version for ${installationType} v${getState().settings.gameVersion} installations.`
}
})
}
Expand Down
182 changes: 87 additions & 95 deletions src/actions/queueActions.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SET_QUEUE_OPEN, ADD_TO_QUEUE, CLEAR_QUEUE, UPDATE_PROGRESS, SET_VIEW, SET_DOWNLOADED_SONGS, SET_DOWNLOADING_COUNT, SET_WAIT_LIST, DISPLAY_WARNING, SET_SCANNING_FOR_SONGS } from './types'
import { SET_QUEUE_OPEN, ADD_TO_QUEUE, CLEAR_QUEUE, UPDATE_PROGRESS, SET_VIEW, SET_DOWNLOADED_SONGS, SET_DOWNLOADING_COUNT, SET_WAIT_LIST, DISPLAY_WARNING, SET_SCANNING_FOR_SONGS, SET_DISCOVERED_FILES, SET_PROCESSED_FILES } from './types'
import { SONG_LIST } from '../views'
import { isModInstalled, installEssentialMods } from './modActions';

Expand All @@ -7,7 +7,6 @@ const fs = remote.require('fs')
const path = remote.require('path')
const md5 = remote.require('md5')
const AdmZip = remote.require('adm-zip')
const Walker = remote.require('walker')
const request = remote.require('request')
const rimraf = remote.require('rimraf')

Expand Down Expand Up @@ -376,106 +375,99 @@ export const deleteSong = (identity) => (dispatch, getState) => {
}

export const checkDownloadedSongs = () => (dispatch, getState) => {
setTimeout(() => {
let discoveredFiles = 0, processedFiles = 0
dispatch({
type: SET_SCANNING_FOR_SONGS,
payload: true
type: SET_DISCOVERED_FILES,
payload: discoveredFiles
})
let state = { ...getState() }
let songs = []
let count = 0
let ended = false
let decrementCounter = () => {
count--
if(ended && count === 0) {
dispatch({
type: SET_DOWNLOADED_SONGS,
payload: songs
})
dispatch({
type: SET_SCANNING_FOR_SONGS,
payload: false
})
return
}
}
fs.access(path.join(state.settings.installationDirectory, 'CustomSongs'), (err) => {
if(err) {
fs.mkdir(path.join(state.settings.installationDirectory, 'CustomSongs'), (err) => {
if(err) {
dispatch({
type: DISPLAY_WARNING,
payload: {
text: 'Could not create CustomSongs directory. Make sure you have your Beat Saber installation directory set properly.'
}
})
}
})
installEssentialMods()(dispatch, getState)
dispatch({
type: SET_DOWNLOADED_SONGS,
payload: []
})
dispatch({
type: SET_PROCESSED_FILES,
payload: processedFiles
})
const walk = function(pathName, cb) {
let songs = []
fs.readdir(pathName, (err, files) => {
if(err) return cb(err)
let pending = files.length
dispatch({
type: SET_SCANNING_FOR_SONGS,
payload: false
type: SET_DISCOVERED_FILES,
payload: discoveredFiles += pending
})
return
}
Walker(path.join(getState().settings.installationDirectory, 'CustomSongs'))
.on('file', (file) => {
if(file === 'info.json') {
count++
fs.readFile(file, 'UTF-8', (err, data) => {
if(err) { decrementCounter(); return }
let dirs = file.split('\\')
dirs.pop()
let dir = dirs.join('\\')
let song
try {
song = JSON.parse(data)
} catch(err) {
decrementCounter()
return
}
if(song.hasOwnProperty('hash')) {
songs.push({ hash: song.hash, file })
decrementCounter()
} else {
let to_hash = ''
for(let i = 0; i < song.difficultyLevels.length; i++) {
try {
to_hash += fs.readFileSync(path.join(dir, song.difficultyLevels[i].jsonPath), 'UTF8')
} catch(err) {
decrementCounter()
return
if(!pending) return cb(null, songs)
for(let i = 0; i < files.length; i++) {
const file = path.join(pathName, files[i])
fs.stat(file, (err, stat) => { // eslint-disable-line no-loop-func
if(err) return cb(err)
if(stat && stat.isDirectory()) {
walk(file, (_, s) => {
songs = songs.concat(s)
dispatch({
type: SET_PROCESSED_FILES,
payload: ++processedFiles
})
if(!--pending) cb(null, songs)
})
} else {
if(files[i].toLowerCase() === 'info.json') {
fs.readFile(file, { encoding: 'UTF-8' }, (err, data) => {
if(err) return cb(err)
let song = JSON.parse(data)
if(song.hasOwnProperty('hash')) {
songs.push({ hash: song.hash, file })
dispatch({
type: SET_PROCESSED_FILES,
payload: ++processedFiles
})
if(!--pending) cb(null, songs)
} else {
let to_hash = ''
for(let i = 0; i < song.difficultyLevels.length; i++) {
try {
let dir = file.split(path.sep)
dir.pop()
to_hash += fs.readFileSync(path.join(dir, song.difficultyLevels[i].jsonPath), 'UTF8')
} catch(err) {}
}
let hash = md5(to_hash)
song.hash = hash
fs.writeFile(file, JSON.stringify(song), 'UTF8', (err) => { if(err) return })
songs.push({ hash, file })
dispatch({
type: SET_PROCESSED_FILES,
payload: ++processedFiles
})
if(!--pending) cb(null, songs)
}
}
let hash = md5(to_hash)
song.hash = hash
fs.writeFile(file, JSON.stringify(song), 'UTF8', (err) => { if(err) return })
songs.push({ hash, file })
decrementCounter()
})
} else {
dispatch({
type: SET_PROCESSED_FILES,
payload: ++processedFiles
})
if(!--pending) cb(null, songs)
}
})
}
})
.on('end', () => {
if(count === 0) {
dispatch({
type: SET_DOWNLOADED_SONGS,
payload: songs
})
dispatch({
type: SET_SCANNING_FOR_SONGS,
payload: false
})
return
}
ended = true
})
}
})
}
})
}

dispatch({
type: SET_SCANNING_FOR_SONGS,
payload: true
})

walk(path.join(getState().settings.installationDirectory, 'CustomSongs'), (err, songs) => {
dispatch({
type: SET_DOWNLOADED_SONGS,
payload: songs
})

dispatch({
type: SET_SCANNING_FOR_SONGS,
payload: false
})
})
}, 1000)
}

export const clearQueue = () => dispatch => {
Expand Down
16 changes: 15 additions & 1 deletion src/actions/settingsActions.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SET_SETTINGS_OPEN, SET_INSTALLATION_DIRECTORY, SET_AUTO_LOAD_MORE, SET_OFFLINE_MODE, SET_THEME, SET_FOLDER_STRUCTURE, SET_UPDATE_CHANNEL, SET_LATEST_RELEASE_NOTES, SET_INSTALLATION_TYPE } from './types'
import { SET_SETTINGS_OPEN, SET_INSTALLATION_DIRECTORY, SET_AUTO_LOAD_MORE, SET_OFFLINE_MODE, SET_THEME, SET_THEME_IMAGE, SET_FOLDER_STRUCTURE, SET_UPDATE_CHANNEL, SET_LATEST_RELEASE_NOTES, SET_INSTALLATION_TYPE, SET_GAME_VERSION } from './types'

import { checkDownloadedSongs } from './queueActions'

Expand Down Expand Up @@ -26,6 +26,13 @@ export const setInstallationType = type => dispatch => {
})
}

export const setGameVersion = version => dispatch => {
dispatch({
type: SET_GAME_VERSION,
payload: version
})
}

export const setAutoLoadMore = willAutoLoadMore => dispatch => {
dispatch({
type: SET_AUTO_LOAD_MORE,
Expand All @@ -47,6 +54,13 @@ export const setTheme = theme => dispatch => {
})
}

export const setThemeImage = imagePath => dispatch => {
dispatch({
type: SET_THEME_IMAGE,
payload: imagePath
})
}

export const setFolderStructure = structure => dispatch => {
dispatch({
type: SET_FOLDER_STRUCTURE,
Expand Down
4 changes: 4 additions & 0 deletions src/actions/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ export const SET_SCROLLTOP = 'SET_SCROLLTOP'
export const SET_DOWNLOADING_COUNT = 'SET_DOWNLOADING_COUNT'
export const SET_WAIT_LIST = 'EST_WAIT_LIST'
export const SET_SCANNING_FOR_SONGS = 'SET_SCANNING_FOR SONGS'
export const SET_DISCOVERED_FILES = 'SET_DISCOVERED_FILES'
export const SET_PROCESSED_FILES = 'SET_PROCESSED_FILES'
export const SET_LOADING = 'SET_LOADING'
export const SET_LOADING_MORE = 'SET_LOADING_MORE'

Expand Down Expand Up @@ -70,9 +72,11 @@ export const SET_SECTION = 'SET_SECTION'
export const SET_SETTINGS_OPEN = 'SET_SETTINGS_OPEN'
export const SET_INSTALLATION_DIRECTORY = 'SET_INSTALLATION_DIRECTORY'
export const SET_INSTALLATION_TYPE = 'SET_INSTALLATION_TYPE'
export const SET_GAME_VERSION = 'SET_GAME_VERSION'
export const SET_AUTO_LOAD_MORE = 'SET_AUTO_LOAD_MORE'
export const SET_OFFLINE_MODE = 'SET_OFFLINE_MODE'
export const SET_THEME = 'SET_THEME'
export const SET_THEME_IMAGE = 'SET_THEME_IMAGE'
export const SET_FOLDER_STRUCTURE = 'SET_FOLDER_STRUCTURE'
export const SET_UPDATE_CHANNEL = 'SET_UPDATE_CHANNEL'
export const SET_LATEST_RELEASE_NOTES = 'SET_LATEST_RELEASE_NOTES'
Expand Down
Loading

0 comments on commit 1213962

Please sign in to comment.