Skip to content

Commit

Permalink
使用集中的TEMP文件夹
Browse files Browse the repository at this point in the history
  • Loading branch information
Cnotech committed May 22, 2022
1 parent 3b84c40 commit 6cea9a6
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 32 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ ZIP-TEMP
.bak
.log
/yarn-error.log
TEMP
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "flash-collector",
"version": "1.6.0",
"version": "1.5.0",
"main": "dist/main/index.cjs",
"author": "Cno <[email protected]>",
"license": "MPL-2.0",
Expand Down
36 changes: 18 additions & 18 deletions packages/main/bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,14 @@ const registry: { [name: string]: (...args: any) => any } = {
if (r.canceled) return new Err("Error:User didn't select a package")

//尝试解压
let res = await release(r.filePaths[0], "UNZIP-TEMP", true)
let res = await release(r.filePaths[0], "TEMP/UNZIP-TEMP", true)
if (!res) return new Err("Error:Can't unzip package")

//基础校验
const types = ['flash', 'h5', 'unity']
let valid = false
for (let type of types) {
if (fs.existsSync(path.join("UNZIP-TEMP", type))) {
if (fs.existsSync(path.join("TEMP/UNZIP-TEMP", type))) {
valid = true
break
}
Expand All @@ -128,13 +128,13 @@ const registry: { [name: string]: (...args: any) => any } = {
//info可用性校验
let p: string, result
for (let type of types) {
p = path.join("UNZIP-TEMP", type)
p = path.join("TEMP/UNZIP-TEMP", type)
if (!fs.existsSync(p)) {
continue
}
let dir = fs.readdirSync(p)
for (let folder of dir) {
p = path.join("UNZIP-TEMP", type, folder, "info.json")
p = path.join("TEMP/UNZIP-TEMP", type, folder, "info.json")
if (fs.existsSync(p)) {
//json schema 校验
result = infoValidator(JSON.parse(fs.readFileSync(p).toString()))
Expand All @@ -150,7 +150,7 @@ const registry: { [name: string]: (...args: any) => any } = {
}

//读取目录
let list = manager.readList("UNZIP-TEMP")
let list = manager.readList("TEMP/UNZIP-TEMP")

//生成列表并校验重复
let gameList: { info: GameInfo, overwriteAlert: boolean }[] = []
Expand All @@ -170,7 +170,7 @@ const registry: { [name: string]: (...args: any) => any } = {
let source, target
for (let game of games) {
if (game.local == null) return new Err(`Error:Fatal error : ${game.title} don't include local key`)
source = path.join("UNZIP-TEMP", game.type, game.local.folder)
source = path.join("TEMP/UNZIP-TEMP", game.type, game.local.folder)
target = path.join("games", game.type, game.local.folder)
//检测重复并删除
if (fs.existsSync(target)) {
Expand All @@ -188,16 +188,16 @@ const registry: { [name: string]: (...args: any) => any } = {
} else {
//处理导出
//清理临时目录
if(fs.existsSync("ZIP-TEMP")){
shelljs.rm("-rf","ZIP-TEMP")
if (fs.existsSync("TEMP/ZIP-TEMP")) {
shelljs.rm("-rf", "TEMP/ZIP-TEMP")
}
shelljs.mkdir("ZIP-TEMP")
shelljs.mkdir("-p", "TEMP/ZIP-TEMP")
//弹出选择对话框
const d=new Date()
let dRes=await dialog.showSaveDialog({
title:"导出 Flash Collector Games 压缩包",
defaultPath:d.getFullYear().toString()+(d.getMonth()+1)+d.getDate()+"-"+d.getHours()+d.getMinutes()+d.getSeconds(),
filters:[
const d = new Date()
let dRes = await dialog.showSaveDialog({
title: "导出 Flash Collector Games 压缩包",
defaultPath: d.getFullYear().toString() + (d.getMonth() + 1) + d.getDate() + "-" + d.getHours() + d.getMinutes() + d.getSeconds(),
filters: [
{
name: "Flash Collector Games 压缩包",
extensions: ['fcg.7z']
Expand All @@ -209,16 +209,16 @@ const registry: { [name: string]: (...args: any) => any } = {
}
//复制文件
let source, target
for(let game of games){
for(let game of games) {
if (game.local == null) return new Err(`Error:Fatal error : ${game.title} don't include local key`)
source = path.join("games", game.type, game.local.folder)
target = path.join("ZIP-TEMP", game.type, game.local.folder)
shelljs.mkdir("-p",path.join("ZIP-TEMP", game.type))
target = path.join("TEMP/ZIP-TEMP", game.type, game.local.folder)
shelljs.mkdir("-p", path.join("TEMP/ZIP-TEMP", game.type))
shelljs.cp('-R', source, target)
}
//压缩
if(!fs.existsSync("exports")) shelljs.mkdir("exports")
let zipRes = await compress("ZIP-TEMP", dRes.filePath, 5)
let zipRes = await compress("ZIP-TEMP", dRes.filePath, 5, "TEMP")
if (!zipRes) {
return new Err("Error:Can't compress into package")
}
Expand Down
8 changes: 6 additions & 2 deletions packages/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,12 @@ function version() {
}

function enableUpdate(v: string) {
updateOnExit = true
latestVersion = v
if (app.isPackaged) {
updateOnExit = true
latestVersion = v
} else {
console.log('Reject update due to develop mode')
}
}

function update() {
Expand Down
2 changes: 1 addition & 1 deletion packages/main/manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ function spawnServer() {
})
app.use('/retinue', express.static('retinue'))
app.use('/games', express.static('games'))
app.use('/temp', express.static('UNZIP-TEMP'))
app.use('/temp', express.static('TEMP/UNZIP-TEMP'))
app.get('/play/:type/:folder', (req, res) => {
const {type, folder} = req.params, config = getConfig()
//查询信息
Expand Down
10 changes: 5 additions & 5 deletions packages/main/p7zip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import path from 'path';

const shell = require('shelljs');

const p7zip = path.join("retinue", "7zip", "7z.exe")
const p7zip = path.join(process.cwd(), "retinue", "7zip", "7z.exe")

async function release(file: string, intoDir: string, overwrite?: boolean, cwd?: string): Promise<boolean> {
return new Promise((resolve => {
Expand Down Expand Up @@ -33,13 +33,13 @@ async function compress(choosePlainDir: string, file: string, compressLevel: num
}
shell.rm('-f', path.join(cwd ?? '', file));
try {
cp.exec(`${path.join("..",p7zip)} a -mx${compressLevel} "${file}" *`, {cwd: path.join(cwd ?? '', choosePlainDir)},(err)=>{
if(err){
cp.exec(`${p7zip} a -mx${compressLevel} "${file}" *`, {cwd: path.join(cwd ?? '', choosePlainDir)}, (err) => {
if (err) {
console.log('Error:Compress command failed\n' + err);
resolve(false);
return;
}else{
resolve(fs.existsSync(path.join(cwd ?? '', file)));
} else {
resolve(fs.existsSync(file));
}
});
} catch (e) {
Expand Down
8 changes: 4 additions & 4 deletions packages/main/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ const shelljs = require('shelljs')

async function update(pkg: string, latestVersion: string): Promise<Result<null, string>> {
//清空更新文件夹
if (fs.existsSync("UPDATE-TEMP")) shelljs.rm("-rf", "UPDATE-TEMP")
shelljs.mkdir("UPDATE-TEMP")
if (fs.existsSync("TEMP/UPDATE-TEMP")) shelljs.rm("-rf", "TEMP/UPDATE-TEMP")
shelljs.mkdir("-p", "TEMP/UPDATE-TEMP")

//下载更新压缩包
const sp = pkg.split("/")
let downloadedFileName = sp[sp.length - 1]
const d = new Downloader({
url: pkg,
directory: "UPDATE-TEMP",
directory: "TEMP/UPDATE-TEMP",
onBeforeSave(finalName: string) {
downloadedFileName = finalName
}
Expand All @@ -30,7 +30,7 @@ async function update(pkg: string, latestVersion: string): Promise<Result<null,
}

//解压
let r = await release("UPDATE-TEMP/" + downloadedFileName, "UPDATE-TEMP/release")
let r = await release("TEMP/UPDATE-TEMP/" + downloadedFileName, "TEMP/UPDATE-TEMP/release")
if (!r) {
return new Err("Error:Can't release patch")
}
Expand Down
2 changes: 1 addition & 1 deletion retinue/update/main.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ echo Waiting for main program evacuation...
@ping 127.0.0.1 -n 2 >nul
TASKKILL /F /IM flash-collector.exe /T >nul

xcopy /s /r /y .\UPDATE-TEMP\release\* .\
xcopy /s /r /y .\TEMP\UPDATE-TEMP\release\* .\
if exist "app.asar" move /y app.asar .\resources\
echo Applying version patch...
.\retinue\update\rcedit-x64.exe flash-collector.exe --set-file-version "%1%"
Expand Down

0 comments on commit 6cea9a6

Please sign in to comment.