Skip to content
This repository has been archived by the owner on Dec 19, 2024. It is now read-only.

Commit

Permalink
fix: 修复解压时的一些异常情况
Browse files Browse the repository at this point in the history
  • Loading branch information
ChingCdesu committed May 22, 2023
1 parent b896073 commit 0269344
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 14 deletions.
13 changes: 12 additions & 1 deletion packages/main/componentManager/installers/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,18 @@ export default class CoreInstaller extends InstallerBase {
Full: () => new RegExp(`MAA-v(.+)${suffix}${ext.replaceAll('.', '\\.')}`, 'g'),
},
this.componentType,
this.componentDir
this.componentDir,
(oldUrl: string) => {
const urlMatches =
/^https:\/\/(.+)\/MaaAssistantArknights\/MaaAssistantArknights\/releases\/download\/(.+)\/(.+)$/.exec(
oldUrl
)
if (!urlMatches) {
throw new Error(`Invalid update url: ${oldUrl}`)
}
const [, host, version, filename] = urlMatches
return `https://s3.maa-org.net:25240/maa-release/MaaAssistantArknights/MaaAssistantArknights/releases/download/${filename}`
}
)
}

Expand Down
18 changes: 6 additions & 12 deletions packages/main/componentManager/utils/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ export function createCheckUpdate(
Full: () => RegExp
},
component: ComponentType,
componentDir: string
componentDir: string,
urlReplacer?: (oldUrl: string) => string
) {
return async (): Promise<UpdateStatus> => {
const release = (await getRelease()) ?? null
Expand Down Expand Up @@ -87,7 +88,7 @@ export function createCheckUpdate(
} else {
logger.warn(
`[Component Installer | ${component}] ` +
'Unable to acquire OTA update asset, attempting to obtain full update asset'
'Unable to acquire OTA update asset, attempting to obtain full update asset'
)
}
}
Expand All @@ -106,19 +107,12 @@ export function createCheckUpdate(

fs.writeFileSync(infoPath.latestFile, item.name, 'utf-8')

const url = item.browser_download_url
const urlMatches =
/^https:\/\/(.+)\/MaaAssistantArknights\/MaaAssistantArknights\/releases\/download\/(.+)\/(.+)$/.exec(
url
)
if (!urlMatches) {
throw new Error(`Invalid update url: ${url}`)
}
const [, host, version, filename] = urlMatches
return {
msg: 'haveUpdate',
update: {
url: `https://s3.maa-org.net:25240/maa-release/MaaAssistantArknights/MaaAssistantArknights/releases/download/${filename}`,
url:
urlReplacer?.call(createCheckUpdate, item.browser_download_url) ??
item.browser_download_url,
version: latestVersion,
releaseDate: published_at,
postUpgrade: () => {
Expand Down
9 changes: 8 additions & 1 deletion packages/main/utils/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ export async function unzipFile(src: string, dest: string) {
for (const file of dir.files.filter(file => file.type === 'Directory')) {
const dirpath = path.join(dest, file.path)
if (!fs.existsSync(dirpath)) {
fs.mkdirSync(dirpath)
logger.debug(`[Extract Helper] create directory: ${dirpath}`)
fs.mkdirSync(dirpath, { recursive: true })
}
}
// 写入文件
Expand All @@ -35,6 +36,12 @@ export async function unzipFile(src: string, dest: string) {
.map(
file =>
new Promise((resolve, reject) => {
const dirpath = path.join(dest, path.dirname(file.path))
if (!fs.existsSync(dirpath)) {
logger.debug(`[Extract Helper] create directory: ${dirpath}`)
fs.mkdirSync(dirpath, { recursive: true })
}
logger.debug(`[Extract Helper] create file: ${file.path}`)
const writeStream = fs.createWriteStream(path.join(dest, file.path), {
mode: (file.externalFileAttributes >>> 16) & 0o777,
})
Expand Down

0 comments on commit 0269344

Please sign in to comment.