-
Notifications
You must be signed in to change notification settings - Fork 305
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
VVPPをデフォルトエンジンに指定可能にし、未インストール時にインストールするか聞くようにする #2270
base: main
Are you sure you want to change the base?
The head ref may contain hidden characters: "\u6307\u5B9A\u3055\u308C\u3066\u3044\u308BVVPP\u304C\u306A\u304B\u3063\u305F\u3089\u78BA\u8A8D\u5F8C\u306B\u30A4\u30F3\u30B9\u30C8\u30FC\u30EB\u3057\u3001\u4F7F\u3048\u308B\u3088\u3046\u306B\u3059\u308B\u3088\u3046\u306B\u3059\u308B"
Changes from all commits
f1bc063
3310c6f
06ac776
8237c8f
674d116
f5f705d
e2e3b88
3b642aa
f6a51da
87e666f
2c6a974
187cc8a
8884110
6e637ad
1627f00
6d56d0b
a198568
51e6461
c9d4edf
e179306
692f001
ad41881
016e142
965cee5
d9cc465
c6f1d71
cb5d716
6e155bf
b74cce6
166ea3d
13e9a14
7c8c4f8
f7b17d6
32a2f2e
bacf688
c0219f2
d8013ae
e903075
b2434d6
02e758a
687212c
40e180a
973a5a5
cee971a
c054061
b5756d2
091df5f
fa29982
32f334c
9fa130e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
import path from "path"; | ||
import fs from "fs"; | ||
import log from "electron-log/main"; | ||
import { BrowserWindow, dialog } from "electron"; | ||
|
||
|
@@ -12,6 +14,13 @@ import { | |
engineSettingSchema, | ||
EngineSettingType, | ||
} from "@/type/preload"; | ||
import { | ||
PackageInfo, | ||
fetchLatestDefaultEngineInfo, | ||
getSuitablePackageInfo, | ||
} from "@/domain/defaultEngine/latetDefaultEngine"; | ||
import { loadEnvEngineInfos } from "@/domain/defaultEngine/envEngineInfo"; | ||
import { UnreachableError } from "@/type/utility"; | ||
|
||
/** | ||
* エンジンとVVPP周りの処理の流れを制御するクラス。 | ||
|
@@ -131,6 +140,95 @@ export class EngineAndVvppController { | |
} | ||
} | ||
|
||
/** | ||
* インストール可能なデフォルトエンジンの情報とパッケージの情報を取得する。 | ||
*/ | ||
async fetchInsallablePackageInfos(): Promise< | ||
{ engineName: string; packageInfo: PackageInfo }[] | ||
> { | ||
// ダウンロード可能なVVPPのうち、未インストールのものを返す | ||
const targetInfos = []; | ||
for (const envEngineInfo of loadEnvEngineInfos()) { | ||
if (envEngineInfo.type != "downloadVvpp") { | ||
continue; | ||
} | ||
|
||
// 最新情報を取得 | ||
const latestUrl = envEngineInfo.latestUrl; | ||
if (latestUrl == undefined) throw new Error("latestUrl is undefined"); | ||
|
||
const latestInfo = await fetchLatestDefaultEngineInfo(latestUrl); | ||
if (latestInfo.formatVersion != 1) { | ||
log.error(`Unsupported format version: ${latestInfo.formatVersion}`); | ||
continue; | ||
} | ||
|
||
// 実行環境に合うパッケージを取得 | ||
const packageInfo = getSuitablePackageInfo(latestInfo); | ||
log.info(`Latest default engine version: ${packageInfo.version}`); | ||
|
||
// インストール済みだった場合はスキップ | ||
// FIXME: より新しいバージョンがあれば更新できるようにする | ||
if (this.engineInfoManager.hasEngineInfo(envEngineInfo.uuid)) { | ||
log.info(`Default engine ${envEngineInfo.uuid} is already installed.`); | ||
continue; | ||
} | ||
|
||
targetInfos.push({ engineName: envEngineInfo.name, packageInfo }); | ||
} | ||
|
||
return targetInfos; | ||
} | ||
|
||
/** VVPPパッケージをダウンロードし、インストールする */ | ||
async downloadAndInstallVvppEngine( | ||
downloadDir: string, | ||
packageInfo: PackageInfo, | ||
) { | ||
if (packageInfo.packages.length === 0) { | ||
throw new UnreachableError("No packages to download"); | ||
} | ||
|
||
let failed = false; | ||
const downloadedPaths: string[] = []; | ||
try { | ||
// ダウンロード | ||
await Promise.all( | ||
packageInfo.packages.map(async (p) => { | ||
const { url, name, size } = p; | ||
|
||
log.info(`Download ${name} from ${url}, size: ${size}`); | ||
const res = await fetch(url); | ||
const buffer = await res.arrayBuffer(); | ||
if (failed) return; // 他のダウンロードが失敗していたら中断 | ||
|
||
const downloadPath = path.join(downloadDir, name); | ||
await fs.promises.writeFile(downloadPath, Buffer.from(buffer)); | ||
Comment on lines
+202
to
+206
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 1GBを超えるファイルをメモリに載せるのは流石に良くない気がします。 |
||
log.info(`Downloaded ${name} to ${downloadPath}`); | ||
|
||
downloadedPaths.push(downloadPath); | ||
|
||
// TODO: ハッシュチェック | ||
}), | ||
); | ||
|
||
// インストール | ||
await this.installVvppEngine(downloadedPaths[0]); | ||
} catch (e) { | ||
failed = true; | ||
log.error(`Failed to download and install VVPP engine:`, e); | ||
throw e; | ||
} finally { | ||
// ダウンロードしたファイルを削除 | ||
await Promise.all( | ||
downloadedPaths.map(async (path) => { | ||
log.info(`Delete downloaded file: ${path}`); | ||
await fs.promises.unlink(path); | ||
}), | ||
); | ||
} | ||
} | ||
|
||
/** エンジンの設定を更新し、保存する */ | ||
updateEngineSetting(engineId: EngineId, engineSetting: EngineSettingType) { | ||
const engineSettings = this.configManager.get("engineSettings"); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
globalのfetchを使っていますがelectronのfetch(net.fetch)を使うべきだと思います。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
みた感じそこまで変わらなさそう?( https://www.electronjs.org/ja/docs/latest/tutorial/progress-bar が適用されるというわけでもなさそうだし)