fix bugs
This commit is contained in:
+17
-6
@@ -55,8 +55,7 @@ async function deleteFiles(directoryHandle: FileSystemDirectoryHandle, path: Pat
|
||||
return directoryHandle.removeEntry(basename, options)
|
||||
}
|
||||
|
||||
async function getHash(data: Uint8Array<ArrayBuffer> | string, format: HashFormat) {
|
||||
if (typeof data === 'string') data = new TextEncoder().encode(data)
|
||||
async function getHash(data: Uint8Array<ArrayBuffer>, format: HashFormat) {
|
||||
if (format.startsWith('sha')) { // copied from https://developer.mozilla.org/en-US/docs/Web/API/Web_Crypto_API/Non-cryptographic_uses_of_subtle_crypto#hashing_a_file
|
||||
const hashAsArrayBuffer = await crypto.subtle.digest("SHA-" + format.substring(3), data);
|
||||
const uint8ViewOfHash = new Uint8Array(hashAsArrayBuffer);
|
||||
@@ -219,8 +218,8 @@ export class PackwizPack {
|
||||
/** Loads a modpack from storage, ignoring and rebuilding the index so that changes made outside of packwiz(-extras) are included. */
|
||||
static async refreshPack(packDirectoryHandle: FileSystemDirectoryHandle, packFileName = "pack.toml"): Promise<PackwizPack> {
|
||||
console.log("refreshing pack")
|
||||
const { packMetaData, packFileHandle } = await getFileHandle(packDirectoryHandle, packFileName).then(async packDirectoryHandle => {
|
||||
const packFile = await packDirectoryHandle.getFile()
|
||||
const { packMetaData, packFileHandle } = await getFileHandle(packDirectoryHandle, packFileName).then(async packFileHandle => {
|
||||
const packFile = await packFileHandle.getFile()
|
||||
const packFileText = await packFile.text()
|
||||
const packMetaData = parseTOML(packFileText) as PackMetaData
|
||||
return { packMetaData, packFileHandle }
|
||||
@@ -229,6 +228,7 @@ export class PackwizPack {
|
||||
const packIndexFile = await indexFileHandle.getFile()
|
||||
const packIndexBytes = await packIndexFile.bytes()
|
||||
const packIndexPathSegments = packMetaData.index.file.split(pathSeperatorRegex)
|
||||
packIndexPathSegments.pop()
|
||||
const packIndexDirname = packIndexPathSegments.join("/")
|
||||
const packIndex = parseTOML(decode(packIndexBytes)) as PackIndex
|
||||
packIndex.files = [] as any
|
||||
@@ -249,7 +249,7 @@ export class PackwizPack {
|
||||
directoryHandles.push(handle)
|
||||
return
|
||||
}
|
||||
if (handle.isSameEntry(indexFileHandle) || handle.isSameEntry(packFileHandle)) return
|
||||
if (await handle.isSameEntry(indexFileHandle) || await handle.isSameEntry(packFileHandle)) return
|
||||
const pathSegments = await indexDirectoryHandle.resolve(handle)
|
||||
const filePath = pathSegments.join("/")
|
||||
const isMetafile = handle.name.endsWith(".pw.toml")
|
||||
@@ -263,6 +263,7 @@ export class PackwizPack {
|
||||
else pack.packFiles.set(filePath, fileBytes)
|
||||
})
|
||||
} while (directoryHandles.length !== 0)
|
||||
pack.packFiles.clearChanged()
|
||||
console.log("pack refreshed")
|
||||
return pack
|
||||
}
|
||||
@@ -287,7 +288,15 @@ export class PackwizPack {
|
||||
index -= deletedFileCount
|
||||
const entry = this.packIndex.files[index]
|
||||
let data = changeMap.get(entry.file)
|
||||
if (data === undefined) return
|
||||
if (data === undefined) {
|
||||
if (hashes && !entry.hash) {
|
||||
data = this.packFiles.get(entry.file)
|
||||
if (!(data instanceof Uint8Array)) data = encode(stringifyTOML(data))
|
||||
entry.hash = await getHash(data, entry["hash-format"] || this.packIndex["hash-format"])
|
||||
.then(hash => hash.toString())
|
||||
} else if (!hashes && entry.hash) delete entry.hash
|
||||
return
|
||||
}
|
||||
const filePath = packIndexDirname + "/" + entry.file
|
||||
if (data === null) {
|
||||
this.packIndex.files.splice(index, 1)
|
||||
@@ -382,6 +391,7 @@ export class PackwizPack {
|
||||
if (!filePath) return
|
||||
const mod = mods.get(match.file.modId)
|
||||
const filePathSegments = filePath.split(pathSeperatorRegex)
|
||||
filePathSegments.pop()
|
||||
const fileDirname = filePathSegments.join("/")
|
||||
const newFilePath = fileDirname + "/" + mod.slug + ".pw.toml"
|
||||
this.packFiles.delete(filePath)
|
||||
@@ -451,6 +461,7 @@ export class PackwizPack {
|
||||
if (!filePath) return
|
||||
const mod = projects.get(match.project_id)
|
||||
const filePathSegments = filePath.split(pathSeperatorRegex)
|
||||
filePathSegments.pop()
|
||||
const fileDirname = filePathSegments.join("/")
|
||||
const newFilePath = fileDirname + "/" + mod.slug + ".pw.toml"
|
||||
this.packFiles.delete(filePath)
|
||||
|
||||
Reference in New Issue
Block a user