fix: 删除一些不必要的文件

This commit is contained in:
wangzhongjie 2025-02-12 13:56:39 +08:00
parent e2d9f87184
commit a6bea27d25

View File

@ -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<string>
// hap包名
static hapName: string = ''
// 待卸载应用名
static bundleName: string = ''
constructor() {
}
/**
* rawFile向沙箱路径复制文件
* @param namehap包名
*/
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 srchap包沙箱路径
*/
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);
}
}
}