1
0

Add NickelMenu installation options

This commit is contained in:
2026-03-17 16:30:33 +01:00
parent 6d4bce8e05
commit 26c2d21fb3
8 changed files with 1058 additions and 142 deletions

View File

@@ -165,6 +165,52 @@ class KoboDevice {
};
}
/**
* Get a nested directory handle, creating directories as needed.
* pathParts is an array like ['.kobo', 'Kobo'].
*/
async getNestedDirectory(pathParts) {
let dir = this.directoryHandle;
for (const part of pathParts) {
dir = await dir.getDirectoryHandle(part, { create: true });
}
return dir;
}
/**
* Write a file at a nested path relative to the device root.
* filePath is like ['.kobo', 'KoboRoot.tgz'] or ['.adds', 'nm', 'items'].
*/
async writeFile(filePath, data) {
const dirParts = filePath.slice(0, -1);
const fileName = filePath[filePath.length - 1];
const dir = dirParts.length > 0
? await this.getNestedDirectory(dirParts)
: this.directoryHandle;
const fileHandle = await dir.getFileHandle(fileName, { create: true });
const writable = await fileHandle.createWritable();
await writable.write(data);
await writable.close();
}
/**
* Read a file at a nested path. Returns the text content, or null if not found.
*/
async readFile(filePath) {
try {
const dirParts = filePath.slice(0, -1);
const fileName = filePath[filePath.length - 1];
const dir = dirParts.length > 0
? await this.getNestedDirectory(dirParts)
: this.directoryHandle;
const fileHandle = await dir.getFileHandle(fileName);
const file = await fileHandle.getFile();
return await file.text();
} catch {
return null;
}
}
/**
* Disconnect / release the directory handle.
*/