initial commit

This commit is contained in:
ewin 2025-03-13 11:08:53 -04:00
commit 967036acf3
Signed by: erin
SSH key fingerprint: SHA256:swjoHhREbZPbWe+gyJNi24d4NAxJSyUIm3fpZj4z3wc
2 changed files with 44 additions and 0 deletions

35
index.mjs Normal file
View 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
View 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"
}
}