Skip to content

Commit 9b78973

Browse files
authored
Detect previous pristine platform configs and update to documentation (#120)
1 parent a8101e4 commit 9b78973

File tree

6 files changed

+185
-109
lines changed

6 files changed

+185
-109
lines changed

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
VERSION="3.15.1"
1+
VERSION="3.15.2"

docs/PLATFORMS.md

Lines changed: 63 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,13 @@ Take this example from the `peas.json` file:
4444

4545
!!! tip
4646

47-
Since Skyscraper 3.13.0 you may also maintain local changes to the `peas.json`
47+
Since Skyscraper 3.13.0 you should maintain local changes to the `peas.json`
4848
in a separate file called `peas_local.json` alongside to the `peas.json`. The
49-
format is identical to the `peas.json`. Precedence: Any platform entry from
49+
format is identical to the `peas.json`. Since Skyscraper 3.15 you can also
50+
maintain local changes to the `platforms_idmap.csv` in a separate file with a
51+
`_local` postfix. Note the order of precedence: Any platform entry from
5052
`peas_local.json` with the same platform name as in `peas.json` overwrites
51-
the one from `peas.json`.
53+
the one from `peas.json`. The same applies for the platforms ID-mapping.
5254

5355
!!! tip
5456

@@ -93,7 +95,10 @@ Outline:
9395
block created before, or copy an existing block and adapt to your needs. For
9496
RetroPie your chosen `<platform_name>` must match the folder in
9597
`~/RetroPie/roms/<platform_name>`.
96-
3. Use `<platform_name>` also in `platforms_idmap.csv` (see below for details).
98+
3. Use `<platform_name>` also in `platforms_idmap_local.csv`. If you need to
99+
create an `platforms_idmap_local.csv` put in the column names
100+
`folder,screenscraper_id,mobygames_id,tgdb_id` (i.e. the first line of
101+
`platforms_idmap.csv`) . See also below for details of this CSV-file.
97102
4. If you use RetroPie do add the platform/system also to your `es_systems.cfg`
98103
as documented
99104
[here](https://retropie.org.uk/docs/Add-a-New-System-in-EmulationStation/).
@@ -106,31 +111,34 @@ can continue with the [hands-on example](PLATFORMS.md#sample-usecase-adding-plat
106111
These two files are ment to be locally edited and extended for additional
107112
platforms. Whenever you add a new platform block to the `peas_local.json` do also
108113
lookup the corresponding platform ids and add them to `platforms_idmap_local.csv` for
109-
the scraping sites with an API.
114+
the scraping sites via a web-API.
110115

111-
From Skyscraper 3.15.0 onwards creating/editing the `peas_local.json` and
116+
**From Skyscraper 3.15 onwards** creating/editing the `peas_local.json` and
112117
`platforms_idmap_local.csv` is the preferred way. In any case both files (e.g.
113118
`peas.json` and `peas_local.json`) will be evalutated but the `_local`
114119
configuration has precedence over the distributed `peas.json`. The same rule
115120
applies to `platforms_idmap.csv` and `platforms_idmap_local.csv`.
116121
If you have made local changes before Skyscraper 3.15 to either `peas.json` or
117-
`platforms_idmap.csv` read the section [Transferring Local Platform
122+
`platforms_idmap.csv` Skyscraper will inform you with an warning. Read the
123+
section [Transferring Local Platform
118124
Changes](PLATFORMS.md#transferring-local-platform-changes) on how to transfer
119125
your changes to the corresponding `*_local.*` files.
120126

121127
To find the platform ids for Screenscraper, Mobygames and The Games DB, please
122128
consult the files `screenscraper_platforms.json`, `mobygames_platforms.json` and
123129
`tgdb_platforms.json` which are located sibling to your `config.ini` of the
124-
Skyscraper installation. If you can not identify an id in these files use `-1`
130+
Skyscraper installation. If you can not identify an ID in these files use `-1`
125131
as value in the CSV. If you add `-1` to CSV, the `aliases` from peas are tried
126132
to find a match upon scraping. Edits in `screenscraper_platforms.json`,
127-
`mobygames_platforms.json` and `tgdb_platforms.json` are not needed and moreover
128-
they will be overwritten with each Skyscraper update, as these files are only a
129-
reference for finding the id values for the `platforms_idmap.csv`.
133+
`mobygames_platforms.json` and `tgdb_platforms.json` are not needed. Moreover,
134+
they will be overwritten with each Skyscraper update as these files are only a
135+
reference for finding the id values for the `platforms_idmap[_local].csv`.
130136

131-
For those scraping sites without an API or without exact id match do use the
132-
platform name which is used on the scraping site and put it into the in the `aliases`
133-
list in the `peas.json` for the respective platform/system at `<platform_name>`.
137+
For those scraping sites without a web-API or without exact ID match do use the
138+
platform name which is used on the respective scraping source site and put it
139+
into the in the `aliases` list in the `peas_local.json` for the respective
140+
platform/system at `<platform_name>`. The `<platform_name>` is identical to the
141+
folder on your filesystem where you keep your games.
134142

135143
!!! example Use of Aliases
136144

@@ -190,14 +198,7 @@ Use `-1` as ID when no exact match is provided for the scraping site. Whenever
190198
an `-1` is encountered Skyscraper tries the `"aliases":` from `peas.json` (and
191199
from `peas_local.json` if present) to find scraping data.
192200

193-
Add this information at the end of the CSV file. Why at the end? On rare
194-
occasions the `platforms_idmap.csv` may be updated on a new release. On RetroPie
195-
the installed file is then named `platforms_idmap.csv.rp-dist`, having changes
196-
at the end may be a less cumbersome manual merge with your local
197-
`platforms_idmap.csv`.
198-
199-
Add this information:
200-
201+
Add this information to your `platforms_idmap_local.csv`:
201202
```csv
202203
satellaview,107,-1,-1
203204
```
@@ -239,13 +240,14 @@ additional information on this.
239240

240241
!!! note
241242

242-
If you run a different frontend than EmulationStation, consult the documentation for your frontend on how to add additional systems.
243+
If you run a different frontend than EmulationStation, consult the
244+
documentation for your frontend on how to add additional systems.
243245

244246
#### Step 4: Happy Scraping
245247

246248
1. Scrape and generate the `satellaview/gamelist.xml` as in the [introductive
247-
use case](USECASE.md) using `Skyscraper -p
248-
satellaview -s screenscraper` and `Skyscraper -p satellaview`
249+
use case](USECASE.md) using `Skyscraper -p satellaview -s screenscraper` and
250+
then `Skyscraper -p satellaview`
249251
2. Restart EmulationStation, respective trigger reload of the gamelist in your
250252
frontend.
251253
3. Smile :)
@@ -258,20 +260,19 @@ satellaview -s screenscraper` and `Skyscraper -p satellaview`
258260

259261
This section describes how to transfer your changes from `peas.json` and
260262
`platforms_idmap.csv` to `*_local.*` files with the same format. If you never
261-
changed these files, you can safely ignore this section.
262-
Whenever there is an update and maybe changes to `peas.json` and
263-
`platforms_idmap.csv` Skyscraper will place the distribution files as
263+
changed the first two files, you can safely ignore this section.
264+
Introduction: Whenever there is an update and maybe upstream changes to `peas.json` and
265+
`platforms_idmap.csv` Skyscraper will place the upstream/distribution files as
264266
`peas.json.rp-dist` and `platforms_idmap.csv.rp-dist`.
265-
Before Skyscraper 3.15.0 you had to manually transfer updates from
266-
`peas.json.rp-dist` and `platforms_idmap.csv.rp-dist`. With Skyscraper 3.15.0
267-
onwards there is a semi-automated approach.
267+
Before Skyscraper 3.15 you had to manually transfer updates from
268+
`peas.json.rp-dist` and `platforms_idmap.csv.rp-dist` to the actual files. With
269+
Skyscraper 3.15 onwards there is a semi-automated approach.
268270

269271
!!! note Non-RetroPie Users
270272

271-
If you are using Skyscraper without RetroPie
272-
context these files will have the suffix `.dist`.
273-
The manual will use `.rp-dist` as synonym for both.
274-
273+
If you are using Skyscraper in a non-RetroPie
274+
setup these files will have the suffix `.dist`. The manual will use
275+
`.rp-dist` as synonym for both.
275276

276277
#### Step 1: Transfer Platform Information (`peas`) to Local File
277278

@@ -282,14 +283,15 @@ Install Python Deepdiff: `sudo apt install python3-deepdiff`. Then navigate to
282283
!!! tip Non-RetroPie Users
283284

284285
If you are using Skyscraper without RetroPie
285-
context the you can find the Python script in source in the
286-
`supplementary/scraperdata` folder.
286+
context the you can find the Python script in the source-tree below
287+
the `supplementary/scraperdata` folder.
287288

288289
The script expects at least two parameters:
289290

290291
1. `<source_peas.json>`: The pristiine/baseline file with all platform
291-
information
292-
2. `<dest_peas.json>`: The file with your local changes
292+
information (most likely `peas.json.rp-dist`)
293+
2. `<dest_peas.json>`: The file with your current local changes (most likely
294+
`peas.json`)
293295
3. Optionally `<outfile_peas.json>`: Once you have reviewed the changes provide
294296
this file to store the platform "diff" between the pristine file and your
295297
changes
@@ -306,17 +308,26 @@ Review the diff, then run:
306308
python3 deepdiff_peas_jsonfiles.py peas.json.rp-dist peas.json peas_local.json
307309
```
308310

309-
Backup your `peas.json` if needed and when satisfied move
310-
`peas.json.rp-dist` to `peas.json`.
311+
Backup your `peas.json` if needed and when satisfied with the content of
312+
`peas_local.json` move `peas.json.rp-dist` to `peas.json`.
311313

312314
#### Step 2: Transfer Platform Scraper IDs (`platforms_idmap`) to Local File
313315

314316
The logic is the same as before and provides an output of the lines you have
315317
changed in `platforms_idmap.csv` in relation to the baseline
316-
`platforms_idmap.csv.rp-dist`.
318+
`platforms_idmap.csv.rp-dist`.
319+
320+
!!! warning
321+
322+
If you already have an existing `platforms_idmap_local.csv` make a
323+
backup as the following command will create a new one.
324+
You may also alter the file redirect to a different file to avoid the
325+
file to be overwritten.
326+
317327
Navigate to the folder with the `platforms_idmap.csv`. Then run:
318328

319329
```bash
330+
[[ -e platforms_idmap_local.csv ]] && mv platforms_idmap_local.csv platforms_idmap_local.csv.backup
320331
diff \
321332
--new-line-format="%L" \
322333
--old-line-format="" \
@@ -333,20 +344,18 @@ cat - platforms_idmap_local.csv > tmp_piggy.csv && \
333344
mv tmp_piggy.csv platforms_idmap_local.csv
334345
```
335346

336-
Backup your `platforms_idmap.csv` if needed and when satisfied move
337-
`platforms_idmap.csv.rp-dist` to `platforms_idmap.csv`.
347+
Backup your `platforms_idmap.csv` if needed and when satisfied with the content
348+
of your `platforms_idmap_local.csv` move `platforms_idmap.csv.rp-dist` to
349+
`platforms_idmap.csv`.
338350

339-
#### Step 3: Automatically Apply Distribution Updates for Platform Configuration
351+
#### Finish
340352

341-
Navigate to the folder with the `_local.*` files mentioned before. Create an
342-
empty file names `.platformcfg_overwrite_ok` (note the heading dot). If this
343-
file is present Skyscraper will overwrite the existing `peas.json` and
344-
`platforms_idmap.csv` with the files from the distribution when updating to a
345-
newer version.
346-
If you remove the file `.platformcfg_overwrite_ok`, Skyscraper will install the
347-
`*.rp-dist` files again on the next install.
353+
From now on upstream changes will be placed in `peas.json` and
354+
`platforms_idmap.csv` and your local additions or changes are kept in the
355+
`*_local.*` counterparts. However, remember when platforms are defined in both
356+
files the `*_local.*` platform configuration wins.
348357

349-
### One More Thing...
358+
#### One More Thing...
350359

351360
If you have changes which would be beneficial for the community, feel free to
352361
file an issue with the proposed additions/changes or table it in the [RetroPie
@@ -392,7 +401,7 @@ Filenames shown _italic_ are user editable.
392401
| _`platforms_idmap.csv`_ | 3.9.0 | maps the platform names (handles) from _`peas.json`_ / _`peas_local.json`_ to exact platform IDs used in scrapers MobyGames, Screenscraper or TGDB; do edit to add new platforms |
393402
| _`peas.json`_ | 3.9.0 | maps platform names (read: ROM folder names) to extensions and aliases for that platform |
394403
| _`peas_local.json`_ | 3.13.0 | same as usage as `peas.json`, the `_local.json` file will not be altered by Skyscraper updates. Entries in this file have higher precedence than the distribution file `peas.json` |
395-
| _`platforms_idmap_local.csv`_ | 3.15.0 | same as usage as `platforms_idmap.csv`, the `_local.csv` file will not be altered by Skyscraper updates. Entries in this file have higher precedence than the distribution file `platforms_idmap.csv` |
404+
| _`platforms_idmap_local.csv`_ | 3.15.2 | same as usage as `platforms_idmap.csv`, the `_local.csv` file will not be altered by Skyscraper updates. Entries in this file have higher precedence than the distribution file `platforms_idmap.csv` |
396405
| ~~`screenscraper.json`~~ | 3.7.7-2 (@detain) | IDs formerly used in here are part of `platforms_idmap.csv` (3.9.0); superseded by `screenscraper_platforms.json` (3.9.0) which is not to be edited |
397406
| `tgdb_developers.json` | 2.5.3 (@muldjord) | API mapping of 'Developers'; Uses leaner format as before (3.9.0); not to be edited |
398407
| `tgdb_genres.json` | 3.9.0 | API mapping of 'Genres' (3.9.0); not to be edited |

src/config.cpp

Lines changed: 48 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -98,37 +98,37 @@ void Config::initSkyFolders() {
9898

9999
QString Config::getSkyFolder(SkyFolderType type) { return skyFolders[type]; }
100100

101-
void Config::copyFile(const QString &src, const QString &dest, FileOp fileOp) {
102-
if (QFileInfo::exists(src)) {
103-
if (QFileInfo::exists(dest)) {
104-
if (fileOp == FileOp::OVERWRITE) {
105-
if (QFileInfo(QFileInfo(dest).dir().path() %
106-
"/.platformcfg_overwrite_ok")
107-
.exists() &&
108-
(src.endsWith("peas.json") ||
109-
src.endsWith("platforms_idmap.csv"))) {
110-
QFile::remove(dest % ".dist");
111-
}
112-
QFile::remove(dest);
113-
QFile::copy(src, dest);
114-
qDebug() << "Overwritten file" << dest;
115-
} else if (fileOp == FileOp::CREATE_DIST) {
116-
QString d = QString(dest + ".dist");
117-
QFile::remove(d);
118-
QFile::copy(src, d);
119-
qDebug() << "Copied original distribution file" << src << "as"
120-
<< d;
121-
}
122-
} else {
123-
QFile::copy(src, dest);
124-
qDebug() << "Created file" << dest;
125-
}
126-
} else {
101+
void Config::copyFile(const QString &src, const QString &dest, bool isPristine,
102+
FileOp fileOp) {
103+
if (!QFileInfo::exists(src)) {
127104
printf("\033[1;31mSource config file not found '%s'. Please check "
128105
"setup, bailing out...\033[0m\n",
129106
src.toStdString().c_str());
130107
exit(1);
131108
}
109+
110+
if (QFileInfo::exists(dest)) {
111+
if (fileOp == FileOp::OVERWRITE) {
112+
if (isPristine && (src.endsWith("peas.json") ||
113+
src.endsWith("platforms_idmap.csv"))) {
114+
QFile::remove(dest % ".dist");
115+
qDebug() << (dest % ".dist") << "removed as prisitine" << dest
116+
<< "detected";
117+
}
118+
QFile::remove(dest);
119+
QFile::copy(src, dest);
120+
qDebug() << "Overwritten file" << dest
121+
<< "with newer or same version";
122+
} else if (fileOp == FileOp::CREATE_DIST) {
123+
QString d = QString(dest + ".dist");
124+
QFile::remove(d);
125+
QFile::copy(src, d);
126+
qDebug() << "Copied original distribution file" << src << "as" << d;
127+
}
128+
} else {
129+
QFile::copy(src, dest);
130+
qDebug() << "Created file" << dest;
131+
}
132132
}
133133

134134
void Config::setupUserConfig() {
@@ -164,7 +164,8 @@ void Config::setupUserConfig() {
164164
QString rpInst = "/opt/retropie/supplementary/skyscraper/Skyscraper";
165165
bool isRpInstall = QFileInfo(rpInst).isFile();
166166
QString manualInst = PREFIX "/bin/Skyscraper";
167-
bool exeIsNotSymlink = QFileInfo(manualInst).isFile() && !QFileInfo(manualInst).isSymLink();
167+
bool exeIsNotSymlink =
168+
QFileInfo(manualInst).isFile() && !QFileInfo(manualInst).isSymLink();
168169

169170
if (exeIsNotSymlink && isRpInstall) {
170171
printf("\033[1;31mDuplicate installation of Skyscraper found:\n%s "
@@ -217,11 +218,13 @@ void Config::setupUserConfig() {
217218
{"artwork.xml", QPair<QString, FileOp>("", FileOp::CREATE_DIST)},
218219
{"peas.json", QPair<QString, FileOp>("", FileOp::CREATE_DIST)},
219220
{"platforms_idmap.csv", QPair<QString, FileOp>("", FileOp::CREATE_DIST)}
220-
// clang-format off
221+
// clang-format on
221222
};
222223

224+
bool isPristine;
223225
for (auto src : configFiles.keys()) {
224226
QString dest = configFiles.value(src).first;
227+
isPristine = false;
225228
if (dest.isEmpty()) {
226229
dest = src;
227230
}
@@ -235,12 +238,24 @@ void Config::setupUserConfig() {
235238
} else if (src.startsWith("resources/")) {
236239
tgtDir = getSkyFolder(SkyFolderType::RESOURCE);
237240
dest = dest.replace("resources/", "");
238-
} else if (QFileInfo(tgtDir % "/.platformcfg_overwrite_ok").exists() &&
239-
(src == "peas.json" || src == "platforms_idmap.csv")) {
240-
configFiles[src] = QPair<QString, FileOp>("", FileOp::OVERWRITE);
241+
} else if ((src == "peas.json" || src == "platforms_idmap.csv")) {
242+
isPristine =
243+
Platform::get().isPlatformCfgfilePristine(tgtDir % "/" % dest);
244+
if (isPristine) {
245+
configFiles[src] =
246+
QPair<QString, FileOp>("", FileOp::OVERWRITE);
247+
} else {
248+
printf(
249+
"\033[1;33mLooks like '%s' has local changes. Please "
250+
"transfer local changes to another file to mute this "
251+
"warning. See topic 'Transferring Local Platform Changes' "
252+
"in the PLATFORM.md documentation for guidance.\033[0m\n",
253+
(tgtDir % "/" % dest).toUtf8().constData());
254+
}
241255
}
242256
QString tgt = tgtDir % "/" % dest;
243-
copyFile(localEtcPath % src, tgt, configFiles.value(src).second);
257+
copyFile(localEtcPath % src, tgt, isPristine,
258+
configFiles.value(src).second);
244259
}
245260
}
246261

@@ -284,4 +299,4 @@ QString Config::getRetropieVersion() {
284299
rpVer.close();
285300
}
286301
return ver;
287-
}
302+
}

src/config.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ namespace Config {
3232
void initSkyFolders();
3333
QString getSkyFolder(SkyFolderType type = SkyFolderType::CONFIG);
3434

35-
void copyFile(const QString &src, const QString &dest,
35+
void copyFile(const QString &src, const QString &dest, bool isPristine,
3636
FileOp fileOp = FileOp::OVERWRITE);
3737
void setupUserConfig();
3838
void checkLegacyFiles();

0 commit comments

Comments
 (0)