Skip to content

Commit

Permalink
Fixed bug where info.dat would === Info.dat (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
doughtnerd authored Nov 26, 2020
1 parent 1ae3e16 commit bfa02f8
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 51 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"email": "doughtnerd@gmail.com",
"url": "https://github.com/Doughtnerd"
},
"version": "1.6.1",
"version": "1.6.3",
"main": "./src/electron.js",
"license": "(MIT OR Apache-2.0)",
"repository": {
Expand Down Expand Up @@ -47,7 +47,7 @@
"windows:electron-dev": "run-p autobuild windows:pure-electron-dev",
"pure-electron-dev": "NODE_ENV=development electron --inspect=3000 .",
"windows:pure-electron-dev": "set NODE_ENV=development&&set ROLLUP_WATCH=true&&electron --inspect=3000 .",
"publish": "electron-builder --win -p always"
"publish": "electron-builder --win -p always ."
},
"build": {
"publish": [
Expand Down
16 changes: 7 additions & 9 deletions src/electron.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,16 @@ function createWindow() {
sandbox: true,
enableRemoteModule: false,
allowRunningInsecureContent: false,
preload: path.join(__dirname, "preload.js")
}
preload: path.join(__dirname, "preload.js"),
},
});

mainWindow.setMenu(null);

let watcher;
if (mode == "development") {
watcher = require("chokidar").watch(
[path.join(__dirname, "..", "public", "bundle.js"), path.join(__dirname)],
{ ignoreInitial: true }
);
mainWindow.openDevTools();
watcher = require("chokidar").watch([path.join(__dirname, "..", "public", "bundle.js"), path.join(__dirname)], { ignoreInitial: true });
watcher.on("change", () => {
mainWindow.reload();
});
Expand All @@ -46,7 +44,7 @@ function createWindow() {
url.format({
pathname: path.join(__dirname, "..", "public", "index.html"),
protocol: "file:",
slashes: true
slashes: true,
})
);
mainWindow.on("closed", () => {
Expand All @@ -64,10 +62,10 @@ app.on("ready", () => {
callback({
responseHeaders: Object.assign(
{
"Content-Security-Policy": ["default-src 'self'"]
"Content-Security-Policy": ["default-src 'self'"],
},
details.responseHeaders
)
),
});
});

Expand Down
26 changes: 17 additions & 9 deletions src/main/previewing/previewManager.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
const { ipcMain } = require("electron");
const {
PREVIEW_BEATMAP,
PREVIEW_LOADED,
PREVIEW_ERROR
} = require("../../constants/channelNames");
const { PREVIEW_BEATMAP, PREVIEW_LOADED, PREVIEW_ERROR } = require("../../constants/channelNames");
const AdmZip = require("adm-zip");
const { download } = require("../utils");

Expand All @@ -16,26 +12,38 @@ function register(mainWindow) {
download(
`https://beatsaver.com${beatmap.directDownload}`,
() => {},
async buffer => {
async (buffer) => {
try {
const zip = new AdmZip(buffer);
const infoEntry = zip.getEntry("info.dat");

let infoEntry = zip.getEntry("info.dat");

if (!infoEntry) {
infoEntry = zip.getEntry("Info.dat");
}

if (!infoEntry) {
sendStatusToWindow(PREVIEW_ERROR, { beatmap, error: new Error("Could not find info.dat file.") });
}

const infoJSON = JSON.parse(zip.readAsText(infoEntry));

const songFilename = infoJSON._songFilename;

const audioFileEntry = zip.getEntry(songFilename);

const audioBuffer = await new Promise((resolve, reject) => {
audioFileEntry.getDataAsync(data => {
audioFileEntry.getDataAsync((data) => {
resolve(data);
});
});
sendStatusToWindow(PREVIEW_LOADED, { buffer: audioBuffer, beatmap });
} catch (error) {
console.log(error.message);
sendStatusToWindow(PREVIEW_ERROR, { beatmap, error });
}
},
error => {
(error) => {
sendStatusToWindow(PREVIEW_ERROR, { beatmap, error });
}
);
Expand Down
49 changes: 18 additions & 31 deletions src/render/stores/beatmap-preview.store.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
import { writable, derived, readable } from "svelte/store";
import { errorsStore } from "./errors.store";
import {
PREVIEW_BEATMAP,
PREVIEW_LOADED,
PREVIEW_ERROR
} from "../../constants/channelNames";
import { PREVIEW_BEATMAP, PREVIEW_LOADED, PREVIEW_ERROR } from "../../constants/channelNames";

function createBeatmapPreviewStore() {
const store = writable({
beatmapToPreview: null,
activePreview: null,
previewUrl: "",
loading: false
loading: false,
});

window.api.receive(PREVIEW_LOADED, ({ buffer, beatmap }) => {
Expand All @@ -22,30 +18,29 @@ function createBeatmapPreviewStore() {
beatmapToPreview: null,
activePreview: beatmap,
previewUrl,
loading: false
loading: false,
});
});

window.api.receive(PREVIEW_ERROR, ({ beatmap, error }) => {
errorsStore.showMessage(
"Encountered error while trying to preview " + beatmap.name
);
console.log(error);
errorsStore.showMessage("Encountered error while trying to preview " + beatmap.name);
store.set({
beatmapToPreview: null,
activePreview: null,
previewUrl: "",
loading: false
loading: false,
});
});

return {
subscribe: store.subscribe,
preview: async beatmap => {
preview: async (beatmap) => {
store.set({
beatmapToPreview: beatmap,
activebeatmapToPreviewPreview: null,
previewUrl: "",
loading: true
loading: true,
});

window.api.invoke(PREVIEW_BEATMAP, { beatmap });
Expand All @@ -55,27 +50,19 @@ function createBeatmapPreviewStore() {
beatmapToPreview: null,
activePreview: null,
previewUrl: "",
loading: false
loading: false,
});
}
},
};
}

export const beatmapPreviewStore = createBeatmapPreviewStore();
export const activeBeatmapPreviewKey = derived(
beatmapPreviewStore,
$beatmapPreviewStore => {
const { activePreview } = $beatmapPreviewStore;
return activePreview && activePreview.key ? activePreview.key : null;
}
);
export const activeBeatmapPreviewKey = derived(beatmapPreviewStore, ($beatmapPreviewStore) => {
const { activePreview } = $beatmapPreviewStore;
return activePreview && activePreview.key ? activePreview.key : null;
});

export const beatmapToPreviewKey = derived(
beatmapPreviewStore,
$beatmapPreviewStore => {
const { beatmapToPreview } = $beatmapPreviewStore;
return beatmapToPreview && beatmapToPreview.key
? beatmapToPreview.key
: null;
}
);
export const beatmapToPreviewKey = derived(beatmapPreviewStore, ($beatmapPreviewStore) => {
const { beatmapToPreview } = $beatmapPreviewStore;
return beatmapToPreview && beatmapToPreview.key ? beatmapToPreview.key : null;
});

0 comments on commit bfa02f8

Please sign in to comment.