Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for local grid images #2

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ In the `emulators` folder, you will find configuration files for emulators. In e

Once you changed all of your console and emulator config files, run the script again with `steam-roms-importer` and you should see the games being added to the Steam shortcut file. Restart Steam to see them in your library.

### Note on Grid Images

Grid images are retrieved locally or from remote sources if not found locally. In order to use a locally stored grid image, simply create it as a .png with the same exact name as your rom and in the same directory.

## Running in dev

First of all, install the dependencies:
Expand Down
39 changes: 31 additions & 8 deletions dist/service/grid-provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,18 @@ var cleanName = function cleanName(name) {
return gameName;
};

var localGridImage = async function localGridImage(gameName, consoleName, romFilePath) {
var gridImagePath = romFilePath.replace(/\.[^/.]+$/, '.png');
var images = [];
if (_fs2.default.existsSync(gridImagePath)) {
images.push({
image: gridImagePath,
thumbnail: gridImagePath
});
}
return images;
};

var searchSteamGridDB = async function searchSteamGridDB(gameName) {
var game = cleanName(gameName);
var url = 'http://www.steamgriddb.com/search.php?name=' + encodeURIComponent(game);
Expand Down Expand Up @@ -123,16 +135,17 @@ var searchConsoleGridDB = async function searchConsoleGridDB(gameName, consoleNa
return images;
};

var gridProviders = [searchSteamGridDB, searchConsoleGridDB];
var gridProviders = [localGridImage, searchSteamGridDB, searchConsoleGridDB];

var findGridImage = async function findGridImage(gameName) {
var consoleName = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
var romFilePath = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '';

var images = [];

await (0, _util.each)(gridProviders, async function (searchFunction) {
try {
var foundImages = await searchFunction(gameName, consoleName);
var foundImages = await searchFunction(gameName, consoleName, romFilePath);
images = images.concat(foundImages);
} catch (e) {}
});
Expand All @@ -148,7 +161,8 @@ var findGridImages = async function findGridImages(games, steamConfigPath) {
await (0, _util.each)(games, async function (game) {
var gameName = game.gameName,
consoleName = game.consoleName,
appid = game.appid;
appid = game.appid,
romFilePath = game.romFilePath;


var gridPath = _path2.default.join(steamConfigPath, 'grid');
Expand All @@ -157,15 +171,24 @@ var findGridImages = async function findGridImages(games, steamConfigPath) {
if (!_fs2.default.existsSync(gridPath)) _fs2.default.mkdirSync(gridPath);

if (!_fs2.default.existsSync(filePath)) {
var images = await findGridImage(gameName, consoleName);
var images = await findGridImage(gameName, consoleName, romFilePath);
var foundImages = false;

if (images && images.length) {
try {
var response = await _request2.default.get(images[0].image);
response.pipe(_fs2.default.createWriteStream(filePath));

foundImages = true;
if (images[0].image.indexOf('http') === 0) {
// remote read
var response = await _request2.default.get(images[0].image);
response.pipe(_fs2.default.createWriteStream(filePath));

foundImages = true;
} else {
// local read
var localFileContents = _fs2.default.readFileSync(images[0].image);
_fs2.default.writeFileSync(filePath, localFileContents);

foundImages = true;
}
} catch (err) {
foundImages = false;
}
Expand Down
1 change: 1 addition & 0 deletions dist/service/shortcuts-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ async function generateShortcuts(consoles, shortcutsFile) {
console.log(' ' + '+'.green + ' Added game ' + game.cleanName.bgBlack.white + ' with APP ID ' + appid.grey);

games.push({
romFilePath: game.filePath,
gameName: game.cleanName,
consoleName: gameConsole.name,
appid: appid
Expand Down
Loading