Prechádzať zdrojové kódy

Merge pull request #36 from StarGazer1258/song-sync-update

Changed directory getter
Nathaniel Johns 5 rokov pred
rodič
commit
a68fe3e4b3
2 zmenil súbory, kde vykonal 16 pridanie a 11 odobranie
  1. 1 1
      src/actions/modActions.js
  2. 15 10
      src/actions/queueActions.js

+ 1 - 1
src/actions/modActions.js

@@ -295,7 +295,7 @@ export const installMod = (modName, version, dependencyOf = '') => (dispatch, ge
       console.log(`Installing ${ modName }...`)
       if(mod.downloads.some(version => version.type === 'universal')) {
         req = request.get({ url: `https://beatmods.com${mod.downloads.filter(version => version.type === 'universal')[0].url}`, encoding: null }, (err, r, data) => {
-          if(r) if(err || r.statusCode !== 200) {
+          if(r) if(err || (r.hasOwnProperty('statusCode') && r.statusCode !== 200)) {
             dispatch({
               type: DISPLAY_WARNING,
               payload: { text: `An error occured while downloading ${modName}. There may have been a connection error.

+ 15 - 10
src/actions/queueActions.js

@@ -421,17 +421,22 @@ export const checkDownloadedSongs = () => (dispatch, getState) => {
                   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) {}
+                  try {
+                    for (let i = 0; i < song.difficultyLevels.length; i++) {
+                      to_hash += fs.readFileSync(path.join(path.dirname(file), song.difficultyLevels[i].jsonPath), 'UTF8')
+                    }
+                    let hash = md5(to_hash)
+                    song.hash = hash
+                    fs.writeFile(file, JSON.stringify(song), 'UTF8', (err) => { if(err) return })
+                    songs.push({ hash, file })
+                  } catch(err) {
+                    dispatch({
+                      type: DISPLAY_WARNING,
+                      payload: {
+                        text: `Failed to generate hash: a file could not be accessed.`
+                      }
+                    })
                   }
-                  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