diff --git a/entry/src/main/ets/common/utils/AppInstaller.ts b/entry/src/main/ets/common/utils/AppInstaller.ts deleted file mode 100644 index ae2c7a53..00000000 --- a/entry/src/main/ets/common/utils/AppInstaller.ts +++ /dev/null @@ -1,100 +0,0 @@ -/** - * 静默安装 - * 事前准备:打包、放在rawFile文件夹下 - */ -import installer from '@ohos.bundle.installer'; -// @ts-ignore -// import { BusinessError } from '@ohos.base'; -import fs from '@ohos.file.fs'; -import buffer from '@ohos.buffer'; - -let TAG = 'APPInstall-' -// let context = getContext(this) as common.UIAbilityContext; -let filesDir = globalThis.context.filesDir; - - -let installParam: installer.InstallParam = { - userId: 100, - isKeepData: false, - installFlag: 1, -}; - -export default class AppInstaller { - // hap包沙箱路径 - static hapFilePaths: Array - // hap包名 - static hapName: string = '' - // 待卸载应用名 - static bundleName: string = '' - - constructor() { - - } - - /** - * 从rawFile向沙箱路径复制文件 - * @param name:待安装的hap包名 - */ - async FromRawToBox(name: string) { - - let file = filesDir + '/' + name; - AppInstaller.hapFilePaths = [file] - try { - fs.access(file).then((res: boolean) => { - if (res) { - console.info(TAG + "file exists"); - } else { - let sss = fs.createStreamSync(file, "w+"); //没有会创建一个空的 - sss.closeSync(); - - //获取rawfile下hap包 - let uint8Array: Uint8Array = globalThis.context.resourceManager.getRawFileContentSync(name); - let bf - try { - bf = buffer.from(uint8Array).buffer; - } catch (error) { - console.log('buffererror', error) - } - - // 打开文件 - const fsOpen = - fs.openSync(file, fs.OpenMode.READ_WRITE | fs.OpenMode.READ_ONLY | fs.OpenMode.CREATE | fs.OpenMode.TRUNC) - - // 写入文件 - let destFile = fs.writeSync(fsOpen.fd, bf); - console.info(TAG + 'write successfully!') - // 关闭文件 - fs.close(destFile) - } - }).catch((err) => { - console.error("access failed with error message: " + err.message + ", error code: " + err.code); - }); - } catch (err) { - console.log(err) - } - - } - - /** - * 安装hap包 - * @param src:hap包沙箱路径 - */ - async SlientInstaller(src: string) { - let hapFilePaths = [src] - try { - const data = await installer.getBundleInstaller().then((data: installer.BundleInstaller) => { - data.install(hapFilePaths, installParam) - .then((data: void) => { - console.info(TAG + 'install successfully: ' + JSON.stringify(data)); - }).catch((error) => { - console.error(TAG + 'install failed:' + error.message); - }); - }).catch((error) => { - console.error(TAG + 'getBundleInstaller failed. Cause: ' + error.message); - }); - } catch (error) { - // let message = (error as BusinessError).message; - console.error('getBundleInstaller failed. Cause: ' + error); - } - } -} \ No newline at end of file