Skip to content
This repository was archived by the owner on Jun 6, 2022. It is now read-only.

Check for games notfound #116

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 68 additions & 5 deletions src/js/Import.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,34 +119,59 @@ class Import extends React.Component {
if (platform.games.length) {
// Get grids for each platform
const ids = platform.games.map((x) => encodeURIComponent(x.id));

const gameName = platform.games.map((x) => x.name);
const getGrids = this.SGDB.getGrids({
type: platform.id,
id: ids.join(','),
dimensions: ['460x215', '920x430'],
})
.then((res) => {
platform.grids = this._formatResponse(ids, res);
return res;
})
.catch((e) => {
log.error('Erorr getting grids from SGDB');
console.error(e);
// show an error toast
if (e.message == "Game not found") {
const checkPromises = this.checkFailedGames([{ id: ids, name: gameName }]);
Promise.all(checkPromises).then((res) => this.logFailedGames(res));
}
else {
log.error('Erorr getting grids from SGDB');
console.error(e);
}

// @todo We need a way to log which game caused the error
// @todo Fallback to text search
// @todo show an error toast
});

gridsPromises.push(platform.games.map(x => ({ name: x.name, id: x.id })));
gridsPromises.push(getGrids);
}
});

// Update state after we got the grids
Promise.all(gridsPromises)
.then(() => {
.then((res) => {
this.setState({
isLoaded: true,
installedPlatforms,
});
var failedGames = [];
for (var i = 0; i < res.length; i += 2) {
var games = res[i];
var result = res[i + 1];

// we will only find errors here for a multiple id search, in single search on error will be caught above
if (games.length > 1) {
games.map((game, i) => {
if ((!result[i].success) && result[i].errors[0] == "Game not found") {
failedGames.push(games[i]);
}
});
}
}
const checkPromises = this.checkFailedGames(failedGames);
Promise.all(checkPromises).then((res) => this.logFailedGames(res));
});
})
.catch((err) => {
Expand All @@ -156,6 +181,42 @@ class Import extends React.Component {
}
}

logFailedGames(res) {
for (var i = 0; i < res.length; i += 2) {
var pre = res[i];
var msgs = res[i + 1];

log.info(pre);
msgs.map((msg) => {
log.info(msg);
});
}
}

checkFailedGames(failedGames) {
var promises = [];

failedGames.map((failedGame) => {
promises.push(`Game '${failedGame.name}', id '${failedGame.id}' not found, looking for alternatives...`);
const sg = new Promise((resolve, reject) => {
this.SGDB.searchGame(failedGame.name).then((res) => {
var results = [];
res.forEach((altGame, i) => {
const altGameTypes = JSON.stringify(altGame.types);
results.push(`${i}: name: '${altGame.name}', id: '${altGame.id}', type: '${altGameTypes}'`);
});

resolve(results);
}).catch((err) => {
reject(`searchGame: ${err}`);
});
});
promises.push(sg);
});

return promises;
}

/*
* @todo We might want to put this at the App level, and publish changes via PubSub or props,
* so different pages can display their own message if Steam is running.
Expand Down Expand Up @@ -231,6 +292,8 @@ class Import extends React.Component {
icon: game.icon,
}));

log.info(`Trying to import ${games.length} games from ${platform.name}`);

Steam.addShortcuts(shortcuts).then(() => {
Steam.addCategory(games, platform.name).then(() => {
PubSub.publish('toast', {
Expand Down