From 70f949aee8045382a7e21423ae1b7b2805c341d0 Mon Sep 17 00:00:00 2001 From: Chris Maltby Date: Tue, 25 Jun 2019 17:54:04 +0100 Subject: [PATCH] Potential fix for issue with being unable to build if running using the Itch.io app --- src/lib/compiler/ensureBuildTools.js | 4 ++-- src/lib/compiler/makeBuild.js | 5 ++++- src/lib/helpers/getTmp.js | 12 ++++++++++++ src/middleware/buildGame.js | 7 +++---- 4 files changed, 21 insertions(+), 7 deletions(-) create mode 100644 src/lib/helpers/getTmp.js diff --git a/src/lib/compiler/ensureBuildTools.js b/src/lib/compiler/ensureBuildTools.js index 398bd67b5..455ce3a6f 100755 --- a/src/lib/compiler/ensureBuildTools.js +++ b/src/lib/compiler/ensureBuildTools.js @@ -1,14 +1,14 @@ -import { remote } from "electron"; import fs from "fs-extra"; import { buildToolsRoot } from "../../consts"; import copy from "../helpers/fsCopy"; +import getTmp from "../helpers/getTmp"; const ensureBuildTools = async () => { const buildToolsPath = `${buildToolsRoot}/${process.platform}-${ process.arch }`; - const tmpPath = remote.app.getPath("temp"); + const tmpPath = getTmp(); const tmpBuildToolsPath = `${tmpPath}/_gbs`; // Symlink build tools so that path doesn't contain any spaces diff --git a/src/lib/compiler/makeBuild.js b/src/lib/compiler/makeBuild.js index deb617e97..c6dc41bb1 100755 --- a/src/lib/compiler/makeBuild.js +++ b/src/lib/compiler/makeBuild.js @@ -4,6 +4,7 @@ import fs from "fs-extra"; import { buildToolsRoot } from "../../consts"; import copy from "../helpers/fsCopy"; import buildMakeBat from "./buildMakeBat"; +import getTmp from "../helpers/getTmp"; const HEADER_TITLE = 0x134; const HEADER_CHECKSUM = 0x14d; @@ -60,7 +61,7 @@ const makeBuild = ({ process.arch }`; - const tmpPath = remote.app.getPath("temp"); + const tmpPath = getTmp(); const tmpBuildToolsPath = `${tmpPath}/_gbs`; // Symlink build tools so that path doesn't contain any spaces @@ -77,6 +78,8 @@ const makeBuild = ({ env.PATH = [`${tmpBuildToolsPath}/gbdk/bin`, env.PATH].join(":"); env.GBDKDIR = `${tmpBuildToolsPath}/gbdk/`; env.CART_TYPE = parseInt(data.settings.cartType || "1B", 16); + env.TMP = getTmp(); + env.TEMP = getTmp(); const makeBat = await buildMakeBat(buildRoot, { CART_TYPE: env.CART_TYPE }); await fs.writeFile(`${buildRoot}/make.bat`, makeBat); diff --git a/src/lib/helpers/getTmp.js b/src/lib/helpers/getTmp.js new file mode 100644 index 000000000..5485f30a2 --- /dev/null +++ b/src/lib/helpers/getTmp.js @@ -0,0 +1,12 @@ +import { remote } from "electron"; + +export default () => { + const tmpPath = remote.app.getPath("temp"); + if (tmpPath.indexOf(" ") === -1) { + return tmpPath; + } + if (process.platform === "win32") { + return "C:\tmp"; + } + return "/tmp"; +}; diff --git a/src/middleware/buildGame.js b/src/middleware/buildGame.js index 83d8b1365..62e92c3cb 100644 --- a/src/middleware/buildGame.js +++ b/src/middleware/buildGame.js @@ -13,6 +13,7 @@ import { } from "../actions/actionTypes"; import copy from "../lib/helpers/fsCopy"; import { denormalizeProject } from "../reducers/entitiesReducer"; +import getTmp from "../lib/helpers/getTmp"; const buildUUID = uuid(); @@ -26,15 +27,13 @@ export default store => next => async action => { const state = store.getState(); const projectRoot = state.document && state.document.root; const project = denormalizeProject(state.entities.present); - const outputRoot = Path.normalize( - `${remote.app.getPath("temp")}/${buildUUID}` - ); + const outputRoot = Path.normalize(`${getTmp()}/${buildUUID}`); await buildProject(project, { projectRoot, buildType, outputRoot, - tmpPath: remote.app.getPath("temp"), + tmpPath: getTmp(), progress: message => { if ( message !== "'" &&