尾缀识别
This commit is contained in:
1 parent
d9f7bd2f89
commit
94e9304d9e
34 files changed
+971
-13
No files matched your search
@@ -55,4 +55,35 @@ async function resolveDataPath(app) {
|
||||
return path.join(process.env.XDG_CONFIG_HOME || path.join(home, '.config'), 'Eagle');
|
||||
}
|
||||
|
||||
module.exports = { createStore, resolveDataPath };
|
||||
// 尾缀表是全局偏好(不是每个素材一份):同一台机器上所有素材、所有库共用。
|
||||
// 查看器在加载资源前读取它,用户的增删都会立即落盘。
|
||||
function createSuffixStore(userDataPath) {
|
||||
const directory = path.join(userDataPath, 'SpineViewer');
|
||||
const file = path.join(directory, 'suffix-settings.json');
|
||||
return {
|
||||
file,
|
||||
read() {
|
||||
try {
|
||||
const data = JSON.parse(fs.readFileSync(file, 'utf8'));
|
||||
return Array.isArray(data.suffixes) ? data.suffixes : [];
|
||||
} catch (e) {
|
||||
if (e.code === 'ENOENT') return [];
|
||||
throw e;
|
||||
}
|
||||
},
|
||||
// 仅在用户通过下拉列表增删尾缀时调用。
|
||||
write(suffixes) {
|
||||
if (!Array.isArray(suffixes)) throw new TypeError('尾缀设置必须为数组');
|
||||
fs.mkdirSync(directory, { recursive: true });
|
||||
const temp = file + '.' + crypto.randomBytes(8).toString('hex') + '.tmp';
|
||||
try {
|
||||
fs.writeFileSync(temp, JSON.stringify({ suffixes }, null, 2) + '\n', { flag: 'wx' });
|
||||
fs.renameSync(temp, file);
|
||||
} finally {
|
||||
try { fs.unlinkSync(temp); } catch (e) { if (e.code !== 'ENOENT') throw e; }
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = { createStore, createSuffixStore, resolveDataPath };
|
||||
Reference in new issue
Block a user