fix (i hope) all bugs
This commit is contained in:
parent
e8cd664965
commit
201f9d7a7e
11 changed files with 195 additions and 37 deletions
18
src/paths.js
18
src/paths.js
|
|
@ -64,6 +64,22 @@ function ensureDirs() {
|
|||
}
|
||||
}
|
||||
|
||||
// Portable paths: anything stored under FILES/ goes into the registry as a
|
||||
// path RELATIVE to FILES (e.g. apps/<id>/game.exe), so moving the whole
|
||||
// launcher folder keeps the library working. Absolute paths outside FILES
|
||||
// (games left in place) are stored as-is. Resolve on read, normalize on write.
|
||||
function toPortablePath(p) {
|
||||
if (typeof p !== 'string' || !p || !path.isAbsolute(p)) return p
|
||||
const rel = path.relative(FILES, p)
|
||||
if (!rel || rel.startsWith('..') || path.isAbsolute(rel)) return p
|
||||
return rel
|
||||
}
|
||||
|
||||
function resolvePortablePath(p) {
|
||||
if (typeof p !== 'string' || !p || path.isAbsolute(p)) return p
|
||||
return path.join(FILES, p)
|
||||
}
|
||||
|
||||
function readJson(file, fallback) {
|
||||
try {
|
||||
return JSON.parse(fs.readFileSync(file, 'utf8'))
|
||||
|
|
@ -79,4 +95,4 @@ function writeJson(file, data) {
|
|||
fs.renameSync(tmp, file)
|
||||
}
|
||||
|
||||
module.exports = { RESOURCES, APP_ROOT, BUILD, FILES, DATA, DIRS, ensureDirs, readJson, writeJson }
|
||||
module.exports = { RESOURCES, APP_ROOT, BUILD, FILES, DATA, DIRS, ensureDirs, readJson, writeJson, toPortablePath, resolvePortablePath }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue