Skip to content

Commit

Permalink
获取编辑器版本
Browse files Browse the repository at this point in the history
  • Loading branch information
sumneko committed Dec 9, 2024
1 parent 267876f commit 40757eb
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,9 @@ class Env {
}

public editorVersion: EditorVersion = 'unknown';
// Editor.exe 的路径
public editorUri?: vscode.Uri;
// Game_x64h.exe 的路径
public editorExeUri?: vscode.Uri;
public mapUri?: vscode.Uri;
public scriptUri?: vscode.Uri;
Expand Down
21 changes: 21 additions & 0 deletions src/mainMenu/pages/environments.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { env } from "../../env";
import { TreeNode, ViewInExplorerNode, ViewInNewVSCode, ViewInVSCode } from "../treeNode";
import * as vscode from 'vscode';
import * as y3 from 'y3-helper';

export class 环境 extends TreeNode {
constructor() {
Expand Down Expand Up @@ -30,6 +31,26 @@ export class 环境 extends TreeNode {
iconPath: new vscode.ThemeIcon('play'),
}),
new ViewInExplorerNode(env.editorUri),
new TreeNode('本地版本', {
iconPath: new vscode.ThemeIcon('versions'),
description: '获取中...',
tooltip: '获取中...',
update: async (node) => {
let version = await y3.version.getClient();
node.description = version ? String(version.display) : '获取失败...';
node.tooltip = version ? version.display : undefined;
},
}),
new TreeNode('最新版本', {
iconPath: new vscode.ThemeIcon('cloud-download'),
description: '获取中...',
tooltip: '获取中...',
update: async (node) => {
let version = await y3.version.getServer();
node.description = version ? String(version.display) : '获取失败...';
node.tooltip = version ? version.display : undefined;
},
})
] : undefined;
},
}),
Expand Down
5 changes: 3 additions & 2 deletions src/tools/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export { download } from './download';
export { log } from './log';
export * from './download';
export * from './log';
export * as fs from './fs';
export * as json from './json';
export * as lua from './lua';
export * as tracy from './tracy';
export * as version from './version';
53 changes: 53 additions & 0 deletions src/tools/version.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import * as y3 from 'y3-helper';

interface Version {
version: number;
display: string;
}

export async function getClient(): Promise<Version | undefined> {
if (!y3.env.editorUri) {
return undefined;
}
for (const filePath of [
"LocalData/Patch/editor_patchmd5_windows64_normal.txt",
"Package/editor_patchmd5_windows64_normal.txt"
]) {
const fullUri = y3.uri(y3.env.editorUri, '..', filePath);
if (!await y3.fs.isExists(fullUri)) {
continue;
}
try {
let file = await y3.fs.readFile(fullUri);
let json = y3.json.parse(file!.string);
let version = Number(json[y3.env.editorVersion]['@version@']);
let display = json[y3.env.editorVersion]['@displayversion@'];
y3.assert(Number.isInteger(version));
return {version, display};
} catch (error) {
y3.log.error(String(error));
return undefined;
}
}
return undefined;
}


export async function getServer(): Promise<Version | undefined> {
// 从指定网址上下载json并解析出版本号
const url = 'https://up5.update.netease.com/pl/patchmd5_windows64_produp5_release.txt';
try {
let response = await fetch(url);
if (!response.ok) {
return undefined;
}
let json = await response.json() as any;
let version = Number(json[y3.env.editorVersion]['@version@']);
let display = json[y3.env.editorVersion]['@metadata@']['@displayversion@'];
y3.assert(Number.isInteger(version));
return {version, display};
} catch (error) {
y3.log.error(String(error));
return undefined;
}
}

0 comments on commit 40757eb

Please sign in to comment.