From b9cc5108a7d809d6d1727b45a15ab447b76c6968 Mon Sep 17 00:00:00 2001 From: Florian Rival Date: Sat, 12 Dec 2020 16:47:20 +0100 Subject: [PATCH] Fix games not working on iOS when exported from Windows --- .../Export/LocalExporters/LocalFileSystem.js | 42 ++++++++++++------- 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/newIDE/app/src/Export/LocalExporters/LocalFileSystem.js b/newIDE/app/src/Export/LocalExporters/LocalFileSystem.js index 41050c0d1b..685c5982fa 100644 --- a/newIDE/app/src/Export/LocalExporters/LocalFileSystem.js +++ b/newIDE/app/src/Export/LocalExporters/LocalFileSystem.js @@ -4,6 +4,12 @@ var path = optionalRequire('path'); var os = optionalRequire('os'); const gd /* TODO: add flow in this file */ = global.gd; +/** + * Gives access to the local filesystem, but returns paths + * that are using "/" as a path separator, even on Windows + * (so that in exported games, paths are slashs, which is + * supported everywhere). + */ export default { mkDir: function(path) { try { @@ -45,17 +51,17 @@ export default { getTempDir: function() { return os.tmpdir(); }, - fileNameFrom: function(fullpath) { - if (this._isExternalUrl(fullpath)) return fullpath; + fileNameFrom: function(fullPath) { + if (this._isExternalUrl(fullPath)) return fullPath; - fullpath = this._translateUrl(fullpath); - return path.basename(fullpath); + fullPath = this._translateUrl(fullPath); + return path.basename(fullPath); }, - dirNameFrom: function(fullpath) { - if (this._isExternalUrl(fullpath)) return ''; + dirNameFrom: function(fullPath) { + if (this._isExternalUrl(fullPath)) return ''; - fullpath = this._translateUrl(fullpath); - return path.dirname(fullpath); + fullPath = this._translateUrl(fullPath); + return path.dirname(fullPath).replace(/\\/g, '/'); }, makeAbsolute: function(filename, baseDirectory) { if (this._isExternalUrl(filename)) return filename; @@ -64,22 +70,26 @@ export default { if (!this.isAbsolute(baseDirectory)) baseDirectory = path.resolve(baseDirectory); - return path.resolve(baseDirectory, path.normalize(filename)); + return path + .resolve(baseDirectory, path.normalize(filename)) + .replace(/\\/g, '/'); }, makeRelative: function(filename, baseDirectory) { if (this._isExternalUrl(filename)) return filename; filename = this._translateUrl(filename); - return path.relative(baseDirectory, path.normalize(filename)); + return path + .relative(baseDirectory, path.normalize(filename)) + .replace(/\\/g, '/'); }, - isAbsolute: function(fullpath) { - if (this._isExternalUrl(fullpath)) return true; + isAbsolute: function(fullPath) { + if (this._isExternalUrl(fullPath)) return true; - if (fullpath.length === 0) return true; - fullpath = this._translateUrl(fullpath); + if (fullPath.length === 0) return true; + fullPath = this._translateUrl(fullPath); return ( - (fullpath.length > 0 && fullpath.charAt(0) === '/') || - (fullpath.length > 1 && fullpath.charAt(1) === ':') + (fullPath.length > 0 && fullPath.charAt(0) === '/') || + (fullPath.length > 1 && fullPath.charAt(1) === ':') ); }, copyFile: function(source, dest) {