1
0
mirror of https://gitcode.com/gh_mirrors/re/react-native-pushy.git synced 2025-11-22 23:46:10 +08:00
Code Issues Packages Projects Releases Wiki Activity GitHub Gitee

Compare commits

...

4 Commits

6 changed files with 40 additions and 94 deletions

View File

@@ -7,7 +7,7 @@
"@react-native-oh/react-native-harmony": "^0.72.59",
"react": "18.2.0",
"react-native": "0.72.5",
"react-native-update": "^10.35.1",
"react-native-update": "^10.35.2",
},
"devDependencies": {
"@babel/core": "^7.20.0",
@@ -1399,7 +1399,7 @@
"react-native": ["react-native@0.72.5", "", { "dependencies": { "@jest/create-cache-key-function": "^29.2.1", "@react-native-community/cli": "11.3.7", "@react-native-community/cli-platform-android": "11.3.7", "@react-native-community/cli-platform-ios": "11.3.7", "@react-native/assets-registry": "^0.72.0", "@react-native/codegen": "^0.72.7", "@react-native/gradle-plugin": "^0.72.11", "@react-native/js-polyfills": "^0.72.1", "@react-native/normalize-colors": "^0.72.0", "@react-native/virtualized-lists": "^0.72.8", "abort-controller": "^3.0.0", "anser": "^1.4.9", "base64-js": "^1.1.2", "deprecated-react-native-prop-types": "4.1.0", "event-target-shim": "^5.0.1", "flow-enums-runtime": "^0.0.5", "invariant": "^2.2.4", "jest-environment-node": "^29.2.1", "jsc-android": "^250231.0.0", "memoize-one": "^5.0.0", "metro-runtime": "0.76.8", "metro-source-map": "0.76.8", "mkdirp": "^0.5.1", "nullthrows": "^1.1.1", "pretty-format": "^26.5.2", "promise": "^8.3.0", "react-devtools-core": "^4.27.2", "react-refresh": "^0.4.0", "react-shallow-renderer": "^16.15.0", "regenerator-runtime": "^0.13.2", "scheduler": "0.24.0-canary-efb381bbf-20230505", "stacktrace-parser": "^0.1.10", "use-sync-external-store": "^1.0.0", "whatwg-fetch": "^3.0.0", "ws": "^6.2.2", "yargs": "^17.6.2" }, "peerDependencies": { "react": "18.2.0" }, "bin": { "react-native": "cli.js" } }, "sha512-oIewslu5DBwOmo7x5rdzZlZXCqDIna0R4dUwVpfmVteORYLr4yaZo5wQnMeR+H7x54GaMhmgeqp0ZpULtulJFg=="],
"react-native-update": ["react-native-update@10.35.1", "", { "dependencies": { "nanoid": "^3.3.3", "react-native-url-polyfill": "^2.0.0" }, "peerDependencies": { "react": ">=16.8.0", "react-native": ">=0.59.0" } }, "sha512-xbFd7Z5dLXYd0MZw3NrZADU3uLTgwW77PdRzEBuc2uS8yH4jU5XrDjn8ArhaqA9sl7pZvJFAkPciffdQJGv3ug=="],
"react-native-update": ["react-native-update@10.35.2", "", { "dependencies": { "nanoid": "^3.3.3", "react-native-url-polyfill": "^2.0.0" }, "peerDependencies": { "react": ">=16.8.0", "react-native": ">=0.59.0" } }, "sha512-rM/GGFY/yr5ANsBpEOOirIEVWzZ/aDIszzr5iGIbmiBFHNDlPNZL0pTGubHtglnhlkQbNoouVcYh9wbVQeivcA=="],
"react-native-url-polyfill": ["react-native-url-polyfill@2.0.0", "", { "dependencies": { "whatwg-url-without-unicode": "8.0.0-3" }, "peerDependencies": { "react-native": "*" } }, "sha512-My330Do7/DvKnEvwQc0WdcBnFPploYKp9CYlefDXzIdEaA+PAhDYllkvGeEroEzvc4Kzzj2O4yVdz8v6fjRvhA=="],

View File

@@ -18,7 +18,7 @@
"@react-native-oh/react-native-harmony": "^0.72.59",
"react": "18.2.0",
"react-native": "0.72.5",
"react-native-update": "^10.35.1"
"react-native-update": "^10.35.2"
},
"devDependencies": {
"@babel/core": "^7.20.0",

View File

@@ -273,6 +273,7 @@ public class UpdateContext {
if (lastVersion == null) {
editor.remove("currentVersion");
} else {
editor.remove("lastVersion");
editor.putString("currentVersion", lastVersion);
}
editor.putBoolean("firstTimeOk", true);

View File

@@ -1,8 +1,7 @@
import http from '@ohos.net.http';
import fileIo from '@ohos.file.fs';
import common from '@ohos.app.ability.common';
import { buffer } from '@kit.ArkTS';
import { zlib, BusinessError } from '@kit.BasicServicesKit';
import { zlib } from '@kit.BasicServicesKit';
import { EventHub } from './EventHub';
import { DownloadTaskParams } from './DownloadTaskParams';
import Pushy from 'librnupdate.so';
@@ -128,53 +127,6 @@ export class DownloadTask {
});
}
private async copyFile(from: string, to: string): Promise<void> {
let reader;
let writer;
try {
reader = fileIo.openSync(from, fileIo.OpenMode.READ_ONLY);
writer = fileIo.openSync(
to,
fileIo.OpenMode.CREATE | fileIo.OpenMode.WRITE_ONLY,
);
const arrayBuffer = new ArrayBuffer(4096);
let bytesRead: number;
do {
bytesRead = await fileIo
.read(reader.fd, arrayBuffer)
.catch((err: BusinessError) => {
throw Error(
`Error reading file: ${err.message}, code: ${err.code}`,
);
});
if (bytesRead > 0) {
const buf = buffer.from(arrayBuffer, 0, bytesRead);
await fileIo
.write(writer.fd, buf.buffer, {
offset: 0,
length: bytesRead,
})
.catch((err: BusinessError) => {
throw Error(
`Error writing file: ${err.message}, code: ${err.code}`,
);
});
}
} while (bytesRead > 0);
console.info('File copied successfully');
} catch (error) {
console.error('Copy file failed:', error);
throw error;
} finally {
if (reader !== undefined) {
fileIo.closeSync(reader);
}
if (writer !== undefined) {
fileIo.closeSync(writer);
}
}
}
private async doFullPatch(params: DownloadTaskParams): Promise<void> {
await this.downloadFile(params);
await this.removeDirectory(params.unzipDirectory);
@@ -243,7 +195,7 @@ export class DownloadTask {
const copies = obj.copies;
for (const to in copies) {
let from = copies[to];
let from = copies[to].replace('resources/rawfile/', '');
if (from === '') {
from = to;
}
@@ -310,7 +262,6 @@ export class DownloadTask {
let foundDiff = false;
let foundBundlePatch = false;
const copyList: Map<string, Array<any>> = new Map();
await zlib.decompressFile(params.targetFile, params.unzipDirectory);
const zipFile = await this.processUnzippedFiles(params.unzipDirectory);
for (const entry of zipFile.entries) {
@@ -318,6 +269,13 @@ export class DownloadTask {
if (fn === '__diff.json') {
foundDiff = true;
await fileIo
.copyDir(params.originDirectory + '/', params.unzipDirectory + '/')
.catch(error => {
console.error('copy error:', error);
});
let jsonContent = '';
const bufferArray = new Uint8Array(entry.content);
for (let i = 0; i < bufferArray.length; i++) {
@@ -325,22 +283,23 @@ export class DownloadTask {
}
const obj = JSON.parse(jsonContent);
const copies = obj.copies;
for (const to in copies) {
let from = copies[to];
if (from === '') {
from = to;
}
if (!copyList.has(from)) {
copyList.set(from, []);
}
const target = copyList.get(from);
if (target) {
const toFile = `${params.unzipDirectory}/${to}`;
target.push(toFile);
}
const { copies, deletes } = obj;
for (const [to, from] of Object.entries(copies)) {
await fileIo
.copyFile(
`${params.originDirectory}/${from}`,
`${params.unzipDirectory}/${to}`,
)
.catch(error => {
console.error('copy error:', error);
});
}
for (const fileToDelete of Object.keys(deletes)) {
await fileIo
.unlink(`${params.unzipDirectory}/${fileToDelete}`)
.catch(error => {
console.error('delete error:', error);
});
}
continue;
}
@@ -397,29 +356,14 @@ export class DownloadTask {
copyList: Map<string, Array<string>>,
): Promise<void> {
try {
const bundlePath = this.context.bundleCodeDir;
const resourceManager = this.context.resourceManager;
const files = await fileIo.listFile(bundlePath);
for (const file of files) {
if (file === '.' || file === '..') {
continue;
}
const targets = copyList.get(file);
if (targets) {
let lastTarget: string | undefined;
for (const target of targets) {
console.info(`Copying from resource ${file} to ${target}`);
if (lastTarget) {
await this.copyFile(lastTarget, target);
} else {
const sourcePath = `${bundlePath}/${file}`;
await this.copyFile(sourcePath, target);
lastTarget = target;
}
}
for (const [from, targets] of copyList.entries()) {
const fromContent = await resourceManager.getRawFileContent(from);
for (const target of targets) {
const fileStream = fileIo.createStreamSync(target, 'w+');
fileStream.writeSync(fromContent.buffer);
fileStream.close();
}
}
} catch (error) {

View File

@@ -245,6 +245,7 @@ export class UpdateContext {
if (!lastVersion) {
this.preferences.deleteSync('currentVersion');
} else {
this.preferences.deleteSync('lastVersion');
this.preferences.putSync('currentVersion', lastVersion);
}
this.preferences.putSync('firstTimeOk', true);

View File

@@ -1,6 +1,6 @@
{
"name": "react-native-update",
"version": "10.35.2",
"version": "10.35.4",
"description": "react-native hot update",
"main": "src/index",
"scripts": {