fix(core): Windows Server 缺少媒体基础组件时给出明确提示
QQNT.dll 静态依赖 mf.dll / mfplat.dll / mfreadwrite.dll,Windows Server 默认不安装 「媒体基础」,加载 wrapper.node 时系统只报 The specified module could not be found(#2069)。 现在 Windows 下加载失败且找不到 mfplat.dll 时,直接提示安装媒体基础的方法。
This commit is contained in:
2 files changed
+70
-7
No files matched your search
@@ -59,12 +59,30 @@ export enum NapCatCoreWorkingEnv {
|
||||
Framework = 2,
|
||||
}
|
||||
|
||||
function dlopenWrapper (wrapperPath: string): WrapperNodeApi {
|
||||
const nativemodule: { exports: WrapperNodeApi; } = { exports: {} as WrapperNodeApi };
|
||||
try {
|
||||
process.dlopen(nativemodule, wrapperPath);
|
||||
} catch (error) {
|
||||
// QQNT.dll 依赖媒体基础(mfplat.dll 等),Windows Server 默认不装这个组件。
|
||||
// 缺了它系统只会报 The specified module could not be found,看不出缺的是什么
|
||||
const mfplatPath = path.join(process.env['SystemRoot'] || 'C:\\Windows', 'System32', 'mfplat.dll');
|
||||
if (os.platform() === 'win32' && !fs.existsSync(mfplatPath)) {
|
||||
throw new Error(
|
||||
'加载 wrapper.node 失败:系统缺少「媒体基础」组件(找不到 mfplat.dll),Windows Server 默认不安装它。' +
|
||||
'请在服务器管理器的「添加角色和功能」里勾选「媒体基础」,' +
|
||||
'或在管理员 PowerShell 中执行 Install-WindowsFeature Server-Media-Foundation,重启后再启动。' +
|
||||
`原始错误:${(error as Error).message}`
|
||||
);
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
return nativemodule.exports;
|
||||
}
|
||||
|
||||
export function loadQQWrapper (execPath: string | undefined, QQVersion: string): WrapperNodeApi {
|
||||
if (process.env['NAPCAT_WRAPPER_PATH']) {
|
||||
const wrapperPath = process.env['NAPCAT_WRAPPER_PATH'];
|
||||
const nativemodule: { exports: WrapperNodeApi; } = { exports: {} as WrapperNodeApi };
|
||||
process.dlopen(nativemodule, wrapperPath);
|
||||
return nativemodule.exports;
|
||||
return dlopenWrapper(process.env['NAPCAT_WRAPPER_PATH']);
|
||||
}
|
||||
if (!execPath) {
|
||||
throw new Error('无法加载Wrapper,execPath未定义');
|
||||
@@ -85,10 +103,9 @@ export function loadQQWrapper (execPath: string | undefined, QQVersion: string):
|
||||
if (!fs.existsSync(wrapperNodePath)) {
|
||||
wrapperNodePath = path.join(path.dirname(execPath), `./resources/app/versions/${QQVersion}/wrapper.node`);
|
||||
}
|
||||
const nativemodule: { exports: WrapperNodeApi; } = { exports: {} as WrapperNodeApi };
|
||||
process.dlopen(nativemodule, wrapperNodePath);
|
||||
const exports = dlopenWrapper(wrapperNodePath);
|
||||
process.env['NAPCAT_WRAPPER_PATH'] = wrapperNodePath;
|
||||
return nativemodule.exports;
|
||||
return exports;
|
||||
}
|
||||
export function getMajorPath (execPath: string, QQVersion: string): string {
|
||||
// major.node
|
||||
|
||||
Reference in new issue
Block a user