initial commit
This commit is contained in:
commit
967036acf3
35
index.mjs
Normal file
35
index.mjs
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
import {glob, readFile, stat, watch} from 'node:fs/promises';
|
||||||
|
import path from 'node:path';
|
||||||
|
|
||||||
|
const steamUserID = process.env.STEAM_USER_ID;
|
||||||
|
const homeDir = process.env.HOME;
|
||||||
|
|
||||||
|
const solutionsDir = `${homeDir}/.local/share/Opus Magnum/${steamUserID}`;
|
||||||
|
|
||||||
|
async function readSolutionName (solutionPath) {
|
||||||
|
const buf = await readFile(solutionPath);
|
||||||
|
return buf.subarray(0x0A, 0x0A + buf[0x09]).toString('utf-8');
|
||||||
|
}
|
||||||
|
|
||||||
|
const solutionNames = Object.create(null);
|
||||||
|
|
||||||
|
for await (const solutionPath of glob(path.join(solutionsDir, '*.solution'))) {
|
||||||
|
const solutionName = await readSolutionName(solutionPath);
|
||||||
|
solutionNames[solutionPath] = solutionName;
|
||||||
|
}
|
||||||
|
|
||||||
|
for await (const {filename} of watch(solutionsDir)) {
|
||||||
|
if (path.extname(filename) !== '.solution') continue; // ignore options etc
|
||||||
|
|
||||||
|
const solutionPath = path.join(solutionsDir, filename);
|
||||||
|
if (!(await stat(solutionPath)).isFile) continue; // ignore deleted
|
||||||
|
|
||||||
|
const solutionName = await readSolutionName(solutionPath);
|
||||||
|
if (solutionName !== solutionNames[solutionPath]) {
|
||||||
|
console.log(
|
||||||
|
'changed:', filename,
|
||||||
|
solutionNames[solutionPath], '->', solutionName
|
||||||
|
);
|
||||||
|
solutionNames[solutionPath] = solutionName;
|
||||||
|
}
|
||||||
|
}
|
9
package.json
Normal file
9
package.json
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
{
|
||||||
|
"name": "opus-magnum-solution-watcher",
|
||||||
|
"private": true,
|
||||||
|
"type": "module",
|
||||||
|
"main": "index.mjs",
|
||||||
|
"scripts": {
|
||||||
|
"test": "echo \"Error: no test specified\" && exit 1"
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue