From c8d924d86315106ab3e2db2666f4be82b23a7165 Mon Sep 17 00:00:00 2001 From: nonameShijian <2954700422@qq.com> Date: Mon, 5 Feb 2024 23:17:29 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=9C=AC=E4=BD=93=E4=B8=AD?= =?UTF-8?q?=E7=9A=84window.resolveLocalFileSystemURL=E8=B0=83=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- noname/game/index.js | 12 ++++++------ noname/ui/index.js | 14 +++++++------- noname/util/index.js | 2 ++ 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/noname/game/index.js b/noname/game/index.js index 7fefb3262..a48005ab8 100644 --- a/noname/game/index.js +++ b/noname/game/index.js @@ -16,7 +16,7 @@ import { Library as lib } from '../library/index.js'; import { status as _status } from '../status/index.js'; import { UI as ui } from '../ui/index.js'; import { GNC as gnc } from '../gnc/index.js'; -import { userAgent, Uninstantable, GeneratorFunction, AsyncFunction, delay } from "../util/index.js"; +import { userAgent, Uninstantable, GeneratorFunction, AsyncFunction, delay, nonameInitialized } from "../util/index.js"; import { DynamicStyle } from "./dynamic-style/index.js"; import { GamePromises } from "./promises.js"; @@ -1901,7 +1901,7 @@ export class Game extends Uninstantable { */ static createDir(directory, successCallback, errorCallback) { const paths = directory.split('/').reverse(); - if (window.resolveLocalFileSystemURL) return new Promise((resolve, reject) => window.resolveLocalFileSystemURL(lib.assetURL, resolve, reject)).then(directoryEntry => { + if (window.resolveLocalFileSystemURL) return new Promise((resolve, reject) => window.resolveLocalFileSystemURL(nonameInitialized, resolve, reject)).then(directoryEntry => { const redo = entry => new Promise((resolve, reject) => entry.getDirectory(paths.pop(), { create: true }, resolve, reject)).then(resolvedDirectoryEntry => { @@ -2028,7 +2028,7 @@ export class Game extends Uninstantable { } game.ensureDirectory(`extension/${extensionName}`).then(writeFile).catch(UHP); } - else new Promise((resolve, reject) => window.resolveLocalFileSystemURL(lib.assetURL, resolve, reject)).then(directoryEntry => new Promise((resolve, reject) => directoryEntry.getDirectory(`extension/${extensionName}`, { + else new Promise((resolve, reject) => window.resolveLocalFileSystemURL(nonameInitialized, resolve, reject)).then(directoryEntry => new Promise((resolve, reject) => directoryEntry.getDirectory(`extension/${extensionName}`, { create: true }, resolve, reject))).then(directoryEntry => { //扩展文件夹 @@ -4677,9 +4677,9 @@ export class Game extends Uninstantable { deleteFolderRecursive(`${__dirname}/extension/${extensionName}`); } catch (error) { - console.log(error); + console.error(error); } - else new Promise((resolve, reject) => window.resolveLocalFileSystemURL(`${lib.assetURL}extension/${extensionName}`, resolve, reject)).then(directoryEntry => directoryEntry.removeRecursively()); + else new Promise((resolve, reject) => window.resolveLocalFileSystemURL(`${nonameInitialized}extension/${extensionName}`, resolve, reject)).then(directoryEntry => directoryEntry.removeRecursively()); } static addRecentCharacter() { let list = get.config('recentCharacter') || []; @@ -8122,7 +8122,7 @@ export class Game extends Uninstantable { /** * @param { string } key * @param { * } [value] - * @param { string } [local] + * @param { string | boolean } [local] * @param { Function } [callback] */ static saveConfig(key, value, local, callback) { diff --git a/noname/ui/index.js b/noname/ui/index.js index 2960b84ac..a3638acfa 100644 --- a/noname/ui/index.js +++ b/noname/ui/index.js @@ -1,4 +1,4 @@ -import { Uninstantable } from "../util/index.js"; +import { Uninstantable, nonameInitialized } from "../util/index.js"; import { Library as lib } from '../library/index.js'; import { Game as game } from "../game/index.js"; import { Get as get } from "../get/index.js"; @@ -2111,7 +2111,7 @@ class Create extends Uninstantable { if (directoryList.length) { var dir = directoryList.shift(); var filelist = directories[dir]; - window.resolveLocalFileSystemURL(lib.assetURL + dir, function (entry) { + window.resolveLocalFileSystemURL(nonameInitialized + dir, function (entry) { var writeFile = function () { if (filelist.length) { var filename = filelist.shift(); @@ -2202,7 +2202,7 @@ class Create extends Uninstantable { unlink(); } else { - window.resolveLocalFileSystemURL(lib.assetURL + page.currentpath, function (entry) { + window.resolveLocalFileSystemURL(nonameInitialized + page.currentpath, function (entry) { var unlink = function () { if (selected.length) { entry.getFile(selected.shift().filename, { create: false }, function (fileEntry) { @@ -2257,7 +2257,7 @@ class Create extends Uninstantable { } } else { - window.resolveLocalFileSystemURL(lib.assetURL + this.path, function (entry) { + window.resolveLocalFileSystemURL(nonameInitialized + this.path, function (entry) { entry.removeRecursively(function () { enterDirectory(page, page.currentpath); }); @@ -2369,7 +2369,7 @@ class Create extends Uninstantable { lib.node.fs.mkdir(__dirname + '/' + path + '/' + str, refresh); } else { - window.resolveLocalFileSystemURL(lib.assetURL + path, function (entry) { + window.resolveLocalFileSystemURL(nonameInitialized + path, function (entry) { entry.getDirectory(str, { create: true }, refresh); }); } @@ -4327,7 +4327,7 @@ class Create extends Uninstantable { var url = lib.assetURL + 'extension/' + name + '/' + file; createButton(i, url); if (lib.device == 'ios' || lib.device == 'android') { - window.resolveLocalFileSystemURL(lib.assetURL + 'extension/' + name, function (entry) { + window.resolveLocalFileSystemURL(nonameInitialized + 'extension/' + name, function (entry) { entry.getFile(file, {}, function (fileEntry) { fileEntry.file(function (fileToLoad) { var fileReader = new FileReader(); @@ -4863,7 +4863,7 @@ class Create extends Uninstantable { var url = lib.assetURL + 'extension/' + name + '/' + file; createButton(i, url, fullskin); if (lib.device == 'ios' || lib.device == 'android') { - window.resolveLocalFileSystemURL(lib.assetURL + 'extension/' + name, function (entry) { + window.resolveLocalFileSystemURL(nonameInitialized + 'extension/' + name, function (entry) { entry.getFile(file, {}, function (fileEntry) { fileEntry.file(function (fileToLoad) { var fileReader = new FileReader(); diff --git a/noname/util/index.js b/noname/util/index.js index a1ac7857f..11face5a7 100644 --- a/noname/util/index.js +++ b/noname/util/index.js @@ -1,3 +1,5 @@ +/** @type { string } */ +// @ts-ignore export const nonameInitialized = localStorage.getItem('noname_inited'); export const assetURL = location.protocol.startsWith('http') || typeof nonameInitialized != 'string' || nonameInitialized == 'nodejs' ? '' : nonameInitialized; export const GeneratorFunction = (function* () {}).constructor;