Skip to content

Commit d641c54

Browse files
committed
don't allow games for a different platform to be installed
So can't install a Unity3D for Windows game on OSX for example. Added this because drag and drop might make it too easy to try to install the wrong file
1 parent 39044f3 commit d641c54

File tree

6 files changed

+83
-36
lines changed

6 files changed

+83
-36
lines changed

docs/changelist.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
Changelist
22
==========
33

4+
* 0.0.40
5+
6+
* don't allow games for a different platform to be installed.
7+
48
* 0.0.39
59

610
* Games have context menu with "GetInfo", "Uninstall" and/or "Remove"

lib/gameinfo.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ GameInfo.prototype.checkRequiredFiles = (function() {
287287
].concat(controllerChecks),
288288
};
289289

290-
return function(runtimeInfo) {
290+
return function(runtimeInfo, fileNames) {
291291
var info = runtimeInfo.info;
292292
var found = [];
293293
var foundCount = 0;
@@ -298,7 +298,7 @@ GameInfo.prototype.checkRequiredFiles = (function() {
298298
checks = checks.concat(gameChecks);
299299
}
300300

301-
var fileNames = readdirtree.sync(runtimeInfo.htmlPath);
301+
var fileNames = fileNames || readdirtree.sync(runtimeInfo.htmlPath);
302302
for (var ii = 0; ii < fileNames.length && foundCount < checks.length; ++ii) {
303303
var fileName = fileNames[ii].replace(/\\/g, '/');
304304
checks.forEach(function(check, ndx) { // eslint-disable-line

lib/games.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ var InstalledGamesList = function() {
127127
if (!info) {
128128
throw "";
129129
}
130-
gameInfo.checkRequiredFiles(info, info.rootPath);
130+
gameInfo.checkRequiredFiles(info);
131131

132132
getInstalledGames();
133133
var index = indexByPath(gamePath);

management/install.js

Lines changed: 74 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ var install = function(releasePath, opt_destPath, opt_options) {
7878
});
7979
var runtimeInfo;
8080
var zipRootPath;
81+
var zipPackagePath;
8182

8283
var packageLocations = gameInfo.getPackageLocations();
8384
var checkPackageLocations = function(entry) {
@@ -106,18 +107,50 @@ var install = function(releasePath, opt_destPath, opt_options) {
106107
if (!packageEntry) {
107108
return reject("no package.json found in " + releasePath);
108109
}
109-
zipRootPath = packageEntry.name.replace(/\\/g, "/");
110-
zipRootPath = zipRootPath.substring(0, zipRootPath.indexOf("/"));
110+
zipPackagePath = packageEntry.name.replace(/\\/g, "/");
111+
zipRootPath = zipPackagePath.substring(0, zipPackagePath.indexOf("/"));
111112
runtimeInfo = gameInfo.parseGameInfo(packageEntry.asText(), packageEntry.name, zipRootPath);
112113
} catch (e) {
113114
return reject("could not parse package.json. Maybe this is not a HappyFunTimes game?");
114115
}
115116

117+
// Check it's got the required files
118+
try {
119+
var zipPackageDir = path.dirname(zipPackagePath);
120+
var fileNames = entries.map(function(entry) {
121+
return path.relative(zipPackageDir, entry.name.replace(/[\\/]/g, path.sep)).replace(/\\/g, "/");
122+
});
123+
gameInfo.checkRequiredFiles(runtimeInfo, fileNames);
124+
} catch (e) {
125+
return reject(e);
126+
}
127+
116128
var info = runtimeInfo.info;
117129
var hftInfo = info.happyFunTimes;
118130
var gameId = runtimeInfo.originalGameId;
131+
var safeGameId = releaseUtils.safeishName(gameId);
119132
var destBasePath;
120133

134+
var fileExists = {};
135+
entries.forEach(function(entry) {
136+
var filename = entry.name.replace(/\\/g, "/").replace(/.*?\//, "");
137+
fileExists[filename] = true;
138+
});
139+
140+
// Check for more files that should exist.
141+
// Games that are "added" don't need this but games
142+
// that are "installed" do.
143+
log("checking gametype: " + hftInfo.gameType);
144+
if (hftInfo.gameType.toLowerCase() === "unity3d") {
145+
var exePath = platformInfo.exePath;
146+
if (exePath) {
147+
exePath = strings.replaceParams(exePath, { gameId: safeGameId });
148+
if (!fileExists[exePath]) {
149+
return reject("path not found: " + exePath + "\nIs this the correct zip file for " + platformInfo.id + "?");
150+
}
151+
}
152+
}
153+
121154
// is it already installed?
122155
var installedGame = gameDB.getGameById(gameId);
123156
if (installedGame) {
@@ -130,55 +163,66 @@ var install = function(releasePath, opt_destPath, opt_options) {
130163
}
131164
}
132165

133-
var safeGameId = releaseUtils.safeishName(gameId);
134-
135166
if (!destBasePath) {
136167
// make the dir after we're sure we're ready to install
137168
destBasePath = path.join(config.getConfig().gamesDir, safeGameId);
138169
}
139170

140171
destBasePath = opt_destPath ? opt_destPath : destBasePath;
141172

173+
// Check for bad paths
174+
var bad = false;
175+
var errors = [];
176+
entries.forEach(function(entry) {
177+
if (bad) {
178+
return;
179+
}
180+
var filePath = entry.name.substring(zipRootPath.length + 1);
181+
var destPath = path.resolve(path.join(destBasePath, filePath));
182+
if (destPath.substring(0, destBasePath.length) !== destBasePath) {
183+
errors.push("ERROR: bad zip file. Path would write outside game folder");
184+
bad = true;
185+
}
186+
});
187+
188+
if (bad) {
189+
// Should delete all work here?
190+
return reject(errors.join("\n"));
191+
}
192+
142193
console.log("installing to: " + destBasePath);
143194
if (!options.dryRun) {
144195
mkdirp.sync(destBasePath);
145196
}
146197

147198
var files = [];
148-
var errors = [];
149-
var bad = false;
150199
entries.forEach(function(entry) {
151200
if (bad) {
152201
return;
153202
}
154203
var filePath = entry.name.substring(zipRootPath.length + 1);
155204
files.push(filePath);
156205
var destPath = path.resolve(path.join(destBasePath, filePath));
157-
if (destPath.substring(0, destBasePath.length) !== destBasePath) {
158-
errors.push("ERROR: bad zip file. Path would write outside game folder");
159-
bad = true;
160-
} else {
161-
var isDir = entry.dir;
162-
if (destPath.substr(-1) === "/" || destPath.substr(-1) === "\\") {
163-
destPath = destPath.substr(0, destPath.length - 1);
164-
isDir = true;
206+
var isDir = entry.dir;
207+
if (destPath.substr(-1) === "/" || destPath.substr(-1) === "\\") {
208+
destPath = destPath.substr(0, destPath.length - 1);
209+
isDir = true;
210+
}
211+
//??
212+
if (isDir) {
213+
log("mkdir : " + destPath);
214+
if (!options.dryRun) {
215+
mkdirp.sync(destPath);
165216
}
166-
//??
167-
if (isDir) {
168-
log("mkdir : " + destPath);
169-
if (!options.dryRun) {
170-
mkdirp.sync(destPath);
171-
}
172-
} else {
173-
log("install: " + entry.name + " -> " + destPath);
174-
if (!options.dryRun) {
175-
var dirPath = path.dirname(destPath);
176-
if (!fs.existsSync(dirPath)) {
177-
log("mkdir : " + dirPath);
178-
mkdirp.sync(dirPath);
179-
}
180-
fs.writeFileSync(destPath, entry.asNodeBuffer());
217+
} else {
218+
log("install: " + entry.name + " -> " + destPath);
219+
if (!options.dryRun) {
220+
var dirPath = path.dirname(destPath);
221+
if (!fs.existsSync(dirPath)) {
222+
log("mkdir : " + dirPath);
223+
mkdirp.sync(dirPath);
181224
}
225+
fs.writeFileSync(destPath, entry.asNodeBuffer());
182226
}
183227
}
184228
});
@@ -188,8 +232,7 @@ var install = function(releasePath, opt_destPath, opt_options) {
188232
return reject(errors.join("\n"));
189233
}
190234

191-
// Should this be in the zip?
192-
log("checking gametype: " + hftInfo.gameType);
235+
// Set the executable bit
193236
if (hftInfo.gameType.toLowerCase() === "unity3d") {
194237
var exePath = platformInfo.exePath;
195238
if (exePath) {

management/make-controller-bundle.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ var make = function(gamePath, destFolder, options) {
208208
}
209209

210210
try {
211-
gameInfo.checkRequiredFiles(runtimeInfo, gamePath);
211+
gameInfo.checkRequiredFiles(runtimeInfo);
212212
if (!fs.existsSync(destFolder)) {
213213
fs.mkdirSync(destFolder);
214214
}

management/make.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ var make = function(gamePath, destFolder, options) {
320320
}
321321

322322
try {
323-
gameInfo.checkRequiredFiles(runtimeInfo, gamePath);
323+
gameInfo.checkRequiredFiles(runtimeInfo);
324324
if (!fs.existsSync(destFolder)) {
325325
fs.mkdirSync(destFolder);
326326
}

0 commit comments

Comments
 (0)