├── .DS_Store
├── .gitignore
├── README.md
├── bsdiff
├── capacitor-code-update
├── .eslintignore
├── .gitignore
├── .prettierignore
├── CONTRIBUTING.md
├── CapacitorCodeUpdate.podspec
├── README.md
├── android
│ ├── .gitignore
│ ├── build.gradle
│ ├── gradle.properties
│ ├── gradle
│ │ └── wrapper
│ │ │ ├── gradle-wrapper.jar
│ │ │ └── gradle-wrapper.properties
│ ├── gradlew
│ ├── gradlew.bat
│ ├── proguard-rules.pro
│ ├── settings.gradle
│ └── src
│ │ ├── androidTest
│ │ └── java
│ │ │ └── com
│ │ │ └── getcapacitor
│ │ │ └── android
│ │ │ └── ExampleInstrumentedTest.java
│ │ ├── main
│ │ ├── AndroidManifest.xml
│ │ ├── java
│ │ │ └── site
│ │ │ │ └── chenwei
│ │ │ │ └── codeupdate
│ │ │ │ ├── BSPatch.java
│ │ │ │ ├── CapacitorCodeUpdate.java
│ │ │ │ ├── CapacitorCodeUpdatePlugin.java
│ │ │ │ ├── CodeUpdateNetWorker.java
│ │ │ │ ├── IdUtil.java
│ │ │ │ └── SystemUtil.java
│ │ └── res
│ │ │ └── .gitkeep
│ │ └── test
│ │ └── java
│ │ └── com
│ │ └── getcapacitor
│ │ └── ExampleUnitTest.java
├── ios
│ ├── Plugin.xcodeproj
│ │ ├── project.pbxproj
│ │ ├── project.xcworkspace
│ │ │ ├── contents.xcworkspacedata
│ │ │ └── xcshareddata
│ │ │ │ └── IDEWorkspaceChecks.plist
│ │ └── xcshareddata
│ │ │ └── xcschemes
│ │ │ ├── Plugin.xcscheme
│ │ │ └── PluginTests.xcscheme
│ ├── Plugin.xcworkspace
│ │ ├── contents.xcworkspacedata
│ │ └── xcshareddata
│ │ │ └── IDEWorkspaceChecks.plist
│ ├── Plugin
│ │ ├── BsPatch.h
│ │ ├── BsPatch.m
│ │ ├── CapacitorCodeUpdate.swift
│ │ ├── CapacitorCodeUpdatePlugin.h
│ │ ├── CapacitorCodeUpdatePlugin.m
│ │ ├── CapacitorCodeUpdatePlugin.swift
│ │ ├── Info.plist
│ │ ├── Plugin-Bridging-Header.h
│ │ ├── Test_Bsdiff.h
│ │ ├── bsdiff-4.3
│ │ │ ├── bsdiff.c
│ │ │ └── bspatch.c
│ │ └── bzip2-1.0.6
│ │ │ ├── blocksort.c
│ │ │ ├── bzip2.c
│ │ │ ├── bzip2recover.c
│ │ │ ├── bzlib.c
│ │ │ ├── bzlib.h
│ │ │ ├── bzlib_private.h
│ │ │ ├── compress.c
│ │ │ ├── crctable.c
│ │ │ ├── decompress.c
│ │ │ ├── dlltest.c
│ │ │ ├── huffman.c
│ │ │ ├── mk251.c
│ │ │ ├── randtable.c
│ │ │ ├── spewG.c
│ │ │ └── unzcrash.c
│ ├── PluginTests
│ │ ├── CapacitorCodeUpdateTests.swift
│ │ └── Info.plist
│ └── Podfile
├── package-lock.json
├── package.json
├── rollup.config.js
├── src
│ ├── definitions.ts
│ ├── index.ts
│ └── web.ts
└── tsconfig.json
└── code-update-server
├── pom.xml
├── src
├── main
│ ├── java
│ │ └── site
│ │ │ └── chenwei
│ │ │ ├── .DS_Store
│ │ │ └── update
│ │ │ ├── .DS_Store
│ │ │ ├── CodeUpdateServerApplication.java
│ │ │ ├── common
│ │ │ ├── .DS_Store
│ │ │ ├── bsdiff
│ │ │ │ ├── BSDiff.java
│ │ │ │ └── BSPatch.java
│ │ │ ├── config
│ │ │ │ └── CodeUpdateConfig.java
│ │ │ ├── constant
│ │ │ │ ├── CommonConstants.java
│ │ │ │ ├── SerialNoConstant.java
│ │ │ │ └── SystemConfigConstant.java
│ │ │ ├── exception
│ │ │ │ ├── BusinessException.java
│ │ │ │ ├── SerialException.java
│ │ │ │ └── resolver
│ │ │ │ │ └── ExceptionResolver.java
│ │ │ ├── model
│ │ │ │ ├── Result.java
│ │ │ │ └── SerialNo.java
│ │ │ ├── serialNo
│ │ │ │ └── SerialNoGenerator.java
│ │ │ └── util
│ │ │ │ ├── FileUtils.java
│ │ │ │ ├── MD5Util.java
│ │ │ │ └── QiNiuFileUtil.java
│ │ │ ├── controller
│ │ │ ├── ApplicationVersionController.java
│ │ │ └── SystemConfigController.java
│ │ │ ├── mapper
│ │ │ ├── ApplicationMapper.java
│ │ │ ├── ApplicationVersionMapper.java
│ │ │ ├── SerialNoMapper.java
│ │ │ ├── SystemConfigMapper.java
│ │ │ └── UpdateRecorderMapper.java
│ │ │ ├── model
│ │ │ ├── Application.java
│ │ │ ├── ApplicationVersion.java
│ │ │ ├── SystemConfig.java
│ │ │ ├── UpdateRecorder.java
│ │ │ └── vo
│ │ │ │ └── ApplicationVersionVo.java
│ │ │ └── service
│ │ │ ├── .DS_Store
│ │ │ ├── ApplicationVersionService.java
│ │ │ ├── SerialNoService.java
│ │ │ ├── SystemConfigService.java
│ │ │ ├── UpdateRecorderService.java
│ │ │ └── impl
│ │ │ ├── ApplicationVersionServiceImpl.java
│ │ │ ├── SerialNoServiceImpl.java
│ │ │ ├── SystemConfigServiceImpl.java
│ │ │ └── UpdateRecorderServiceImpl.java
│ └── resources
│ │ ├── .DS_Store
│ │ ├── application.yaml
│ │ ├── bsdiff
│ │ ├── bsdiff
│ │ └── bspatch
│ │ └── mapper
│ │ ├── ApplicationMapper.xml
│ │ ├── ApplicationVersionMapper.xml
│ │ ├── SerialNoMapper.xml
│ │ ├── SystemConfigMapper.xml
│ │ └── UpdateRecorderMapper.xml
└── test
│ └── java
│ └── site
│ └── chenwei
│ └── update
│ └── CodeUpdateServerApplicationTests.java
└── target
└── classes
├── META-INF
└── spring-configuration-metadata.json
├── application.yaml
├── bsdiff
├── bsdiff
└── bspatch
└── mapper
├── ApplicationMapper.xml
├── ApplicationVersionMapper.xml
├── SerialNoMapper.xml
├── SystemConfigMapper.xml
└── UpdateRecorderMapper.xml
/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/site-chenwei/code-update/d8d40ff1643f47509696f39433b4bce4214f78e7/.DS_Store
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Built application files
2 | *.apk
3 | *.aar
4 | *.ap_
5 | *.aab
6 |
7 | # Files for the ART/Dalvik VM
8 | *.dex
9 |
10 | # Java class files
11 | *.class
12 |
13 | # Generated files
14 | bin/
15 | gen/
16 | out/
17 | # Uncomment the following line in case you need and you don't have the release build type files in your app
18 | # release/
19 |
20 | # Gradle files
21 | .gradle/
22 | build/
23 |
24 | # Local configuration file (sdk path, etc)
25 | local.properties
26 |
27 | # Proguard folder generated by Eclipse
28 | proguard/
29 |
30 | # Log Files
31 | *.log
32 |
33 | # Android Studio Navigation editor temp files
34 | .navigation/
35 |
36 | # Android Studio captures folder
37 | captures/
38 |
39 | # IntelliJ
40 | *.iml
41 | .idea/workspace.xml
42 | .idea/tasks.xml
43 | .idea/gradle.xml
44 | .idea/assetWizardSettings.xml
45 | .idea/dictionaries
46 | .idea/libraries
47 | # Android Studio 3 in .gitignore file.
48 | .idea/caches
49 | .idea/modules.xml
50 | # Comment next line if keeping position of elements in Navigation Editor is relevant for you
51 | .idea/navEditor.xml
52 |
53 | # Keystore files
54 | # Uncomment the following lines if you do not want to check your keystore files in.
55 | #*.jks
56 | #*.keystore
57 |
58 | # External native build folder generated in Android Studio 2.2 and later
59 | .externalNativeBuild
60 | .cxx/
61 |
62 | # Google Services (e.g. APIs or Firebase)
63 | # google-services.json
64 |
65 | # Freeline
66 | freeline.py
67 | freeline/
68 | freeline_project_description.json
69 |
70 | # fastlane
71 | fastlane/report.xml
72 | fastlane/Preview.html
73 | fastlane/screenshots
74 | fastlane/test_output
75 | fastlane/readme.md
76 |
77 | # Version control
78 | vcs.xml
79 |
80 | # lint
81 | lint/intermediates/
82 | lint/generated/
83 | lint/outputs/
84 | lint/tmp/
85 | # lint/reports/
86 | version
87 | .idea
88 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # code-update
2 | hybrid热更新服务实现
3 |
4 | ## code-update-server
5 | 热更新服务端,服务接受上传新版本应用包并生成与各版本对应的差分增量包,同时接受客户端的请求以检查并完成更新
6 | 目前已实现基础的版本上传、差分生成、更新检查等功能,其他功能实现中
7 |
8 |
9 | ## capacitor-code-update
10 | 基于capacitor的热更新客户端插件。 已实现iOS、Android的热更新,且支持热更新。其他功能正在实现中
11 |
12 | ## cordova-code-update
13 | 基于cordova的热更新客户端插件,正在实现中。
14 |
--------------------------------------------------------------------------------
/bsdiff:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/site-chenwei/code-update/d8d40ff1643f47509696f39433b4bce4214f78e7/bsdiff
--------------------------------------------------------------------------------
/capacitor-code-update/.eslintignore:
--------------------------------------------------------------------------------
1 | build
2 | dist
3 |
--------------------------------------------------------------------------------
/capacitor-code-update/.gitignore:
--------------------------------------------------------------------------------
1 | # node files
2 | dist
3 | node_modules
4 |
5 | # iOS files
6 | Pods
7 | Podfile.lock
8 | Build
9 | xcuserdata
10 |
11 | # macOS files
12 | .DS_Store
13 |
14 |
15 |
16 | # Based on Android gitignore template: https://github.com/github/gitignore/blob/HEAD/Android.gitignore
17 |
18 | # Built application files
19 | *.apk
20 | *.ap_
21 |
22 | # Files for the ART/Dalvik VM
23 | *.dex
24 |
25 | # Java class files
26 | *.class
27 |
28 | # Generated files
29 | bin
30 | gen
31 | out
32 |
33 | # Gradle files
34 | .gradle
35 | build
36 |
37 | # Local configuration file (sdk path, etc)
38 | local.properties
39 |
40 | # Proguard folder generated by Eclipse
41 | proguard
42 |
43 | # Log Files
44 | *.log
45 |
46 | # Android Studio Navigation editor temp files
47 | .navigation
48 |
49 | # Android Studio captures folder
50 | captures
51 |
52 | # IntelliJ
53 | *.iml
54 | .idea
55 |
56 | # Keystore files
57 | # Uncomment the following line if you do not want to check your keystore files in.
58 | #*.jks
59 |
60 | # External native build folder generated in Android Studio 2.2 and later
61 | .externalNativeBuild
62 | example
--------------------------------------------------------------------------------
/capacitor-code-update/.prettierignore:
--------------------------------------------------------------------------------
1 | build
2 | dist
3 |
--------------------------------------------------------------------------------
/capacitor-code-update/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # Contributing
2 |
3 | This guide provides instructions for contributing to this Capacitor plugin.
4 |
5 | ## Developing
6 |
7 | ### Local Setup
8 |
9 | 1. Fork and clone the repo.
10 | 1. Install the dependencies.
11 |
12 | ```shell
13 | npm install
14 | ```
15 |
16 | 1. Install SwiftLint if you're on macOS.
17 |
18 | ```shell
19 | brew install swiftlint
20 | ```
21 |
22 | ### Scripts
23 |
24 | #### `npm run build`
25 |
26 | Build the plugin web assets and generate plugin API documentation using [`@capacitor/docgen`](https://github.com/ionic-team/capacitor-docgen).
27 |
28 | It will compile the TypeScript code from `src/` into ESM JavaScript in `dist/esm/`. These files are used in apps with bundlers when your plugin is imported.
29 |
30 | Then, Rollup will bundle the code into a single file at `dist/plugin.js`. This file is used in apps without bundlers by including it as a script in `index.html`.
31 |
32 | #### `npm run verify`
33 |
34 | Build and validate the web and native projects.
35 |
36 | This is useful to run in CI to verify that the plugin builds for all platforms.
37 |
38 | #### `npm run lint` / `npm run fmt`
39 |
40 | Check formatting and code quality, autoformat/autofix if possible.
41 |
42 | This template is integrated with ESLint, Prettier, and SwiftLint. Using these tools is completely optional, but the [Capacitor Community](https://github.com/capacitor-community/) strives to have consistent code style and structure for easier cooperation.
43 |
44 | ## Publishing
45 |
46 | There is a `prepublishOnly` hook in `package.json` which prepares the plugin before publishing, so all you need to do is run:
47 |
48 | ```shell
49 | npm publish
50 | ```
51 |
52 | > **Note**: The [`files`](https://docs.npmjs.com/cli/v7/configuring-npm/package-json#files) array in `package.json` specifies which files get published. If you rename files/directories or add files elsewhere, you may need to update it.
53 |
--------------------------------------------------------------------------------
/capacitor-code-update/CapacitorCodeUpdate.podspec:
--------------------------------------------------------------------------------
1 | require 'json'
2 |
3 | package = JSON.parse(File.read(File.join(__dir__, 'package.json')))
4 |
5 | Pod::Spec.new do |s|
6 | s.name = 'CapacitorCodeUpdate'
7 | s.version = package['version']
8 | s.summary = package['description']
9 | s.license = package['license']
10 | s.homepage = package['repository']['url']
11 | s.author = package['author']
12 | s.source = { :git => package['repository']['url'], :tag => s.version.to_s }
13 | s.source_files = 'ios/Plugin/**/*.{swift,h,m,c,cc,mm,cpp}'
14 | s.ios.deployment_target = '12.0'
15 | s.dependency 'Capacitor'
16 | s.dependency 'SSZipArchive'
17 | s.swift_version = '5.1'
18 | end
19 |
--------------------------------------------------------------------------------
/capacitor-code-update/README.md:
--------------------------------------------------------------------------------
1 | # capacitor-code-update
2 |
3 | Capacitor-Code-Update
4 |
5 | ## Install
6 |
7 | ```bash
8 | npm install capacitor-code-update
9 | npx cap sync
10 | ```
11 |
12 | ## API
13 |
14 |
15 |
16 | * [`checkUpdate()`](#checkupdate)
17 | * [`download(...)`](#download)
18 | * [`install(...)`](#install)
19 | * [`addListener('downloadProgress', ...)`](#addlistenerdownloadprogress)
20 | * [Interfaces](#interfaces)
21 | * [Enums](#enums)
22 |
23 |
24 |
25 |
26 |
27 |
28 | ### checkUpdate()
29 |
30 | ```typescript
31 | checkUpdate() => Promise
32 | ```
33 |
34 | **Returns:** Promise<Update | null>
35 |
36 | --------------------
37 |
38 |
39 | ### download(...)
40 |
41 | ```typescript
42 | download(option: Update) => Promise
43 | ```
44 |
45 | | Param | Type |
46 | | ------------ | ----------------------------------------- |
47 | | **`option`** | Update
|
48 |
49 | **Returns:** Promise<LocalPackage | null>
50 |
51 | --------------------
52 |
53 |
54 | ### install(...)
55 |
56 | ```typescript
57 | install(option: { installMode: InstallMode; }) => Promise
58 | ```
59 |
60 | | Param | Type |
61 | | ------------ | --------------------------------------------------------------------- |
62 | | **`option`** | { installMode: InstallMode; }
|
63 |
64 | **Returns:** Promise<InstallResult>
65 |
66 | --------------------
67 |
68 |
69 | ### addListener('downloadProgress', ...)
70 |
71 | ```typescript
72 | addListener(eventName: 'downloadProgress', listenerFunc: (percent: string) => void) => Promise
73 | ```
74 |
75 | | Param | Type |
76 | | ------------------ | ----------------------------------------- |
77 | | **`eventName`** | 'downloadProgress'
|
78 | | **`listenerFunc`** | (percent: string) => void
|
79 |
80 | **Returns:** Promise<PluginListenerHandle>
81 |
82 | --------------------
83 |
84 |
85 | ### Interfaces
86 |
87 |
88 | #### Update
89 |
90 | | Prop | Type |
91 | | ----------------- | -------------------------------------------------- |
92 | | **`id`** | string
|
93 | | **`name`** | string
|
94 | | **`signature`** | string
|
95 | | **`downloadUrl`** | string
|
96 | | **`updateType`** | 'FULL_UPDATE' \| 'INCREMENTAL_UPDATE'
|
97 |
98 |
99 | #### LocalPackage
100 |
101 | | Prop | Type |
102 | | ------------------- | ------------------- |
103 | | **`version`** | string
|
104 | | **`applicationId`** | string
|
105 | | **`versionName`** | string
|
106 | | **`signature`** | string
|
107 | | **`updateType`** | string
|
108 |
109 |
110 | #### InstallResult
111 |
112 | | Prop | Type |
113 | | ------------- | -------------------- |
114 | | **`success`** | boolean
|
115 |
116 |
117 | #### PluginListenerHandle
118 |
119 | | Prop | Type |
120 | | ------------ | ----------------------------------------- |
121 | | **`remove`** | () => Promise<void>
|
122 |
123 |
124 | ### Enums
125 |
126 |
127 | #### InstallMode
128 |
129 | | Members |
130 | | ------------------ |
131 | | **`IMMEDIATE`** |
132 | | **`NEXT_RESUME`** |
133 | | **`NEXT_RESTART`** |
134 |
135 |
136 |
--------------------------------------------------------------------------------
/capacitor-code-update/android/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/capacitor-code-update/android/build.gradle:
--------------------------------------------------------------------------------
1 | ext {
2 | junitVersion = project.hasProperty('junitVersion') ? rootProject.ext.junitVersion : '4.13.1'
3 | androidxAppCompatVersion = project.hasProperty('androidxAppCompatVersion') ? rootProject.ext.androidxAppCompatVersion : '1.2.0'
4 | androidxJunitVersion = project.hasProperty('androidxJunitVersion') ? rootProject.ext.androidxJunitVersion : '1.1.2'
5 | androidxEspressoCoreVersion = project.hasProperty('androidxEspressoCoreVersion') ? rootProject.ext.androidxEspressoCoreVersion : '3.3.0'
6 | }
7 |
8 | buildscript {
9 | repositories {
10 | google()
11 | jcenter()
12 | }
13 | dependencies {
14 | classpath 'com.android.tools.build:gradle:4.2.1'
15 | }
16 | }
17 |
18 | apply plugin: 'com.android.library'
19 |
20 | android {
21 | compileSdkVersion project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 30
22 | defaultConfig {
23 | minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 21
24 | targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 30
25 | versionCode 1
26 | versionName "1.0"
27 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
28 | }
29 | buildTypes {
30 | release {
31 | minifyEnabled false
32 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
33 | }
34 | }
35 | lintOptions {
36 | abortOnError false
37 | }
38 | compileOptions {
39 | sourceCompatibility JavaVersion.VERSION_1_8
40 | targetCompatibility JavaVersion.VERSION_1_8
41 | }
42 | }
43 |
44 | repositories {
45 | google()
46 | mavenCentral()
47 | jcenter()
48 | }
49 |
50 |
51 | dependencies {
52 | implementation fileTree(dir: 'libs', include: ['*.jar'])
53 | implementation project(':capacitor-android')
54 | implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion"
55 | implementation 'org.apache.commons:commons-compress:1.20'
56 | implementation 'org.apache.commons:commons-lang3:3.12.0'
57 | implementation 'commons-codec:commons-codec:1.15'
58 | testImplementation "junit:junit:$junitVersion"
59 | androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion"
60 | androidTestImplementation "androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion"
61 | }
62 |
--------------------------------------------------------------------------------
/capacitor-code-update/android/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | org.gradle.jvmargs=-Xmx1536m
13 |
14 | # When configured, Gradle will run in incubating parallel mode.
15 | # This option should only be used with decoupled projects. More details, visit
16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
17 | # org.gradle.parallel=true
18 |
19 | # AndroidX package structure to make it clearer which packages are bundled with the
20 | # Android operating system, and which are packaged with your app's APK
21 | # https://developer.android.com/topic/libraries/support-library/androidx-rn
22 | android.useAndroidX=true
23 | # Automatically convert third-party libraries to use AndroidX
24 | android.enableJetifier=true
25 |
--------------------------------------------------------------------------------
/capacitor-code-update/android/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/site-chenwei/code-update/d8d40ff1643f47509696f39433b4bce4214f78e7/capacitor-code-update/android/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/capacitor-code-update/android/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionBase=GRADLE_USER_HOME
2 | distributionPath=wrapper/dists
3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.0-all.zip
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 |
--------------------------------------------------------------------------------
/capacitor-code-update/android/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | #
4 | # Copyright 2015 the original author or authors.
5 | #
6 | # Licensed under the Apache License, Version 2.0 (the "License");
7 | # you may not use this file except in compliance with the License.
8 | # You may obtain a copy of the License at
9 | #
10 | # https://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing, software
13 | # distributed under the License is distributed on an "AS IS" BASIS,
14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | # See the License for the specific language governing permissions and
16 | # limitations under the License.
17 | #
18 |
19 | ##############################################################################
20 | ##
21 | ## Gradle start up script for UN*X
22 | ##
23 | ##############################################################################
24 |
25 | # Attempt to set APP_HOME
26 | # Resolve links: $0 may be a link
27 | PRG="$0"
28 | # Need this for relative symlinks.
29 | while [ -h "$PRG" ] ; do
30 | ls=`ls -ld "$PRG"`
31 | link=`expr "$ls" : '.*-> \(.*\)$'`
32 | if expr "$link" : '/.*' > /dev/null; then
33 | PRG="$link"
34 | else
35 | PRG=`dirname "$PRG"`"/$link"
36 | fi
37 | done
38 | SAVED="`pwd`"
39 | cd "`dirname \"$PRG\"`/" >/dev/null
40 | APP_HOME="`pwd -P`"
41 | cd "$SAVED" >/dev/null
42 |
43 | APP_NAME="Gradle"
44 | APP_BASE_NAME=`basename "$0"`
45 |
46 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
47 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
48 |
49 | # Use the maximum available, or set MAX_FD != -1 to use that value.
50 | MAX_FD="maximum"
51 |
52 | warn () {
53 | echo "$*"
54 | }
55 |
56 | die () {
57 | echo
58 | echo "$*"
59 | echo
60 | exit 1
61 | }
62 |
63 | # OS specific support (must be 'true' or 'false').
64 | cygwin=false
65 | msys=false
66 | darwin=false
67 | nonstop=false
68 | case "`uname`" in
69 | CYGWIN* )
70 | cygwin=true
71 | ;;
72 | Darwin* )
73 | darwin=true
74 | ;;
75 | MINGW* )
76 | msys=true
77 | ;;
78 | NONSTOP* )
79 | nonstop=true
80 | ;;
81 | esac
82 |
83 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
84 |
85 |
86 | # Determine the Java command to use to start the JVM.
87 | if [ -n "$JAVA_HOME" ] ; then
88 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
89 | # IBM's JDK on AIX uses strange locations for the executables
90 | JAVACMD="$JAVA_HOME/jre/sh/java"
91 | else
92 | JAVACMD="$JAVA_HOME/bin/java"
93 | fi
94 | if [ ! -x "$JAVACMD" ] ; then
95 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
96 |
97 | Please set the JAVA_HOME variable in your environment to match the
98 | location of your Java installation."
99 | fi
100 | else
101 | JAVACMD="java"
102 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
103 |
104 | Please set the JAVA_HOME variable in your environment to match the
105 | location of your Java installation."
106 | fi
107 |
108 | # Increase the maximum file descriptors if we can.
109 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
110 | MAX_FD_LIMIT=`ulimit -H -n`
111 | if [ $? -eq 0 ] ; then
112 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
113 | MAX_FD="$MAX_FD_LIMIT"
114 | fi
115 | ulimit -n $MAX_FD
116 | if [ $? -ne 0 ] ; then
117 | warn "Could not set maximum file descriptor limit: $MAX_FD"
118 | fi
119 | else
120 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
121 | fi
122 | fi
123 |
124 | # For Darwin, add options to specify how the application appears in the dock
125 | if $darwin; then
126 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
127 | fi
128 |
129 | # For Cygwin or MSYS, switch paths to Windows format before running java
130 | if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
131 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
132 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
133 |
134 | JAVACMD=`cygpath --unix "$JAVACMD"`
135 |
136 | # We build the pattern for arguments to be converted via cygpath
137 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
138 | SEP=""
139 | for dir in $ROOTDIRSRAW ; do
140 | ROOTDIRS="$ROOTDIRS$SEP$dir"
141 | SEP="|"
142 | done
143 | OURCYGPATTERN="(^($ROOTDIRS))"
144 | # Add a user-defined pattern to the cygpath arguments
145 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
146 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
147 | fi
148 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
149 | i=0
150 | for arg in "$@" ; do
151 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
152 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
153 |
154 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
155 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
156 | else
157 | eval `echo args$i`="\"$arg\""
158 | fi
159 | i=`expr $i + 1`
160 | done
161 | case $i in
162 | 0) set -- ;;
163 | 1) set -- "$args0" ;;
164 | 2) set -- "$args0" "$args1" ;;
165 | 3) set -- "$args0" "$args1" "$args2" ;;
166 | 4) set -- "$args0" "$args1" "$args2" "$args3" ;;
167 | 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
168 | 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
169 | 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
170 | 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
171 | 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
172 | esac
173 | fi
174 |
175 | # Escape application args
176 | save () {
177 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
178 | echo " "
179 | }
180 | APP_ARGS=`save "$@"`
181 |
182 | # Collect all arguments for the java command, following the shell quoting and substitution rules
183 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
184 |
185 | exec "$JAVACMD" "$@"
186 |
--------------------------------------------------------------------------------
/capacitor-code-update/android/gradlew.bat:
--------------------------------------------------------------------------------
1 | @rem
2 | @rem Copyright 2015 the original author or authors.
3 | @rem
4 | @rem Licensed under the Apache License, Version 2.0 (the "License");
5 | @rem you may not use this file except in compliance with the License.
6 | @rem You may obtain a copy of the License at
7 | @rem
8 | @rem https://www.apache.org/licenses/LICENSE-2.0
9 | @rem
10 | @rem Unless required by applicable law or agreed to in writing, software
11 | @rem distributed under the License is distributed on an "AS IS" BASIS,
12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | @rem See the License for the specific language governing permissions and
14 | @rem limitations under the License.
15 | @rem
16 |
17 | @if "%DEBUG%" == "" @echo off
18 | @rem ##########################################################################
19 | @rem
20 | @rem Gradle startup script for Windows
21 | @rem
22 | @rem ##########################################################################
23 |
24 | @rem Set local scope for the variables with windows NT shell
25 | if "%OS%"=="Windows_NT" setlocal
26 |
27 | set DIRNAME=%~dp0
28 | if "%DIRNAME%" == "" set DIRNAME=.
29 | set APP_BASE_NAME=%~n0
30 | set APP_HOME=%DIRNAME%
31 |
32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter.
33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
34 |
35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
37 |
38 | @rem Find java.exe
39 | if defined JAVA_HOME goto findJavaFromJavaHome
40 |
41 | set JAVA_EXE=java.exe
42 | %JAVA_EXE% -version >NUL 2>&1
43 | if "%ERRORLEVEL%" == "0" goto execute
44 |
45 | echo.
46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
47 | echo.
48 | echo Please set the JAVA_HOME variable in your environment to match the
49 | echo location of your Java installation.
50 |
51 | goto fail
52 |
53 | :findJavaFromJavaHome
54 | set JAVA_HOME=%JAVA_HOME:"=%
55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
56 |
57 | if exist "%JAVA_EXE%" goto execute
58 |
59 | echo.
60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
61 | echo.
62 | echo Please set the JAVA_HOME variable in your environment to match the
63 | echo location of your Java installation.
64 |
65 | goto fail
66 |
67 | :execute
68 | @rem Setup the command line
69 |
70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
71 |
72 |
73 | @rem Execute Gradle
74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
75 |
76 | :end
77 | @rem End local scope for the variables with windows NT shell
78 | if "%ERRORLEVEL%"=="0" goto mainEnd
79 |
80 | :fail
81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
82 | rem the _cmd.exe /c_ return code!
83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
84 | exit /b 1
85 |
86 | :mainEnd
87 | if "%OS%"=="Windows_NT" endlocal
88 |
89 | :omega
90 |
--------------------------------------------------------------------------------
/capacitor-code-update/android/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/capacitor-code-update/android/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':capacitor-android'
2 | project(':capacitor-android').projectDir = new File('../node_modules/@capacitor/android/capacitor')
--------------------------------------------------------------------------------
/capacitor-code-update/android/src/androidTest/java/com/getcapacitor/android/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.getcapacitor.android;
2 |
3 | import static org.junit.Assert.*;
4 |
5 | import android.content.Context;
6 | import androidx.test.ext.junit.runners.AndroidJUnit4;
7 | import androidx.test.platform.app.InstrumentationRegistry;
8 | import org.junit.Test;
9 | import org.junit.runner.RunWith;
10 |
11 | /**
12 | * Instrumented test, which will execute on an Android device.
13 | *
14 | * @see Testing documentation
15 | */
16 | @RunWith(AndroidJUnit4.class)
17 | public class ExampleInstrumentedTest {
18 |
19 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
23 |
24 | assertEquals("com.getcapacitor.android", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/capacitor-code-update/android/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/capacitor-code-update/android/src/main/java/site/chenwei/codeupdate/BSPatch.java:
--------------------------------------------------------------------------------
1 | package site.chenwei.codeupdate;
2 |
3 | import org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream;
4 |
5 | import java.io.*;
6 |
7 | public class BSPatch {
8 | private RandomAccessFile mOld;
9 | private OutputStream mNew;
10 | private InputStream mPatch;
11 |
12 | private InputStream bzCtrl;
13 | private InputStream bzData;
14 | private InputStream bzExtra;
15 |
16 | private BSPatch(RandomAccessFile old, OutputStream New, InputStream patch) {
17 | mOld = old;
18 | mNew = New;
19 | mPatch = patch;
20 | }
21 |
22 | private static long readLong(InputStream is) throws IOException {
23 | byte[] bytes = new byte[8];
24 | is.read(bytes);
25 | long ret = ((long) (bytes[7] & 0x7F) << 56) | ((long) (bytes[6] & 0xFF) << 48) | ((long) (bytes[5] & 0xFF) << 40) | ((long) (bytes[4] & 0xFF) << 32) | ((long) (bytes[3] & 0xFF) << 24) | ((long) (bytes[2] & 0xFF) << 16) | ((long) (bytes[1] & 0xFF) << 8) | ((long) (bytes[0] & 0xFF));
26 | return ((bytes[7] & 0x80) != 0) ? -ret : ret;
27 | }
28 |
29 | private static void checkHeader(InputStream is) throws IOException {
30 | /* Check header for appropriate magic 'BSDIFF40' */
31 | byte[] bytes = new byte[8];
32 | is.read(bytes);
33 | String str = new String(bytes);
34 | if (!str.equals("BSDIFF40")) {
35 | throw new IOException("patch file doesn't start from 'BSDIFF40'" + " but with '" + str + "'");
36 | }
37 | }
38 |
39 | private long readPatchFile() throws IOException {
40 | /* Check for appropriate magic */
41 | checkHeader(mPatch);
42 |
43 | /* Read lengths from header */
44 | long bzCtrlLen = readLong(mPatch);
45 | long bzDataLen = readLong(mPatch);
46 | long newSize = readLong(mPatch);
47 | if (bzCtrlLen < 0 || bzDataLen < 0 || newSize < 0 || bzCtrlLen > Integer.MAX_VALUE || bzDataLen > Integer.MAX_VALUE) {
48 | throw new IOException("bzCtrlLen=" + bzCtrlLen + ", bzDataLen=" + bzDataLen + ", newSize=" + newSize);
49 | }
50 |
51 | byte[] bytes = new byte[(int) bzCtrlLen];
52 | mPatch.read(bytes);
53 | bzCtrl = new BZip2CompressorInputStream(new ByteArrayInputStream(bytes));
54 | bytes = new byte[(int) bzDataLen];
55 | mPatch.read(bytes);
56 | bzData = new BZip2CompressorInputStream(new ByteArrayInputStream(bytes));
57 | bzExtra = new BZip2CompressorInputStream(new BufferedInputStream(mPatch));
58 |
59 | return newSize;
60 | }
61 |
62 | private void writeDiffData(long diffLen) throws IOException {
63 | byte[] bytes = new byte[1024];
64 | byte[] bytes2 = new byte[1024];
65 | /* Read diff string and add old data to diff string */
66 | for (long i = 0; i < diffLen; ) {
67 | int len = (i + bytes.length > diffLen) ? (int) (diffLen - i) : bytes.length;
68 | len = bzData.read(bytes, 0, len);
69 | mOld.readFully(bytes2, 0, len);
70 | for (int j = 0; j < len; j++) {
71 | bytes[j] += bytes2[j];
72 | }
73 | mNew.write(bytes, 0, len);
74 | i += len;
75 | }
76 | mNew.flush();
77 | }
78 |
79 | private void writeExtraData(long extraLen) throws IOException {
80 | byte[] bytes = new byte[1024];
81 | /* Read extra string */
82 | for (long i = 0; i < extraLen; ) {
83 | int len = (i + bytes.length > extraLen) ? (int) (extraLen - i) : bytes.length;
84 | len = bzExtra.read(bytes, 0, len);
85 | mNew.write(bytes, 0, len);
86 | i += len;
87 | }
88 | mNew.flush();
89 | }
90 |
91 | private void patch() throws IOException {
92 | long newSize = readPatchFile();
93 |
94 | long newPos = 0;
95 | while (newPos < newSize) {
96 | /* Read control data */
97 | long diffLen = readLong(bzCtrl);
98 | long extraLen = readLong(bzCtrl);
99 | long adjustLen = readLong(bzCtrl);
100 |
101 | /* Sanity-check */
102 | if (newPos + diffLen > newSize) {
103 | throw new IOException("newPos(" + newPos + ") + diffLen(" + diffLen + ") > newSize(" + newSize + ")");
104 | }
105 | writeDiffData(diffLen);
106 | newPos += diffLen;
107 |
108 | /* Sanity-check */
109 | if (newPos + extraLen > newSize) {
110 | throw new IOException("newPos(" + newPos + ") + extraLen(" + extraLen + ") > newSize(" + newSize + ")");
111 | }
112 | writeExtraData(extraLen);
113 | newPos += extraLen;
114 | mOld.seek(mOld.getFilePointer() + adjustLen);
115 | }
116 |
117 | bzCtrl.close();
118 | bzData.close();
119 | bzExtra.close();
120 | }
121 |
122 | private void close() throws IOException {
123 | mOld.close();
124 | mNew.close();
125 | mPatch.close();
126 | }
127 |
128 | public static void patch(String oldPath, String newPath, String patchPath) throws IOException {
129 | BSPatch This = new BSPatch(new RandomAccessFile(oldPath, "r"), new FileOutputStream(newPath), new FileInputStream(patchPath));
130 | This.patch();
131 | This.close();
132 | }
133 | }
134 |
--------------------------------------------------------------------------------
/capacitor-code-update/android/src/main/java/site/chenwei/codeupdate/CapacitorCodeUpdatePlugin.java:
--------------------------------------------------------------------------------
1 | package site.chenwei.codeupdate;
2 |
3 | import com.getcapacitor.JSObject;
4 | import com.getcapacitor.Plugin;
5 | import com.getcapacitor.PluginCall;
6 | import com.getcapacitor.PluginMethod;
7 | import com.getcapacitor.annotation.CapacitorPlugin;
8 |
9 | @CapacitorPlugin(name = "CapacitorCodeUpdate")
10 | public class CapacitorCodeUpdatePlugin extends Plugin {
11 |
12 | private CapacitorCodeUpdate implementation;
13 | private static final String DOWNLOAD_PROGRESS_LISTENER = "downloadProgress";
14 |
15 | @Override
16 | public void load() {
17 | super.load();
18 | this.implementation = new CapacitorCodeUpdate(getContext(), this);
19 | }
20 |
21 | @PluginMethod
22 | public void checkUpdate(PluginCall call) {
23 | call.resolve(implementation.checkUpdate());
24 | }
25 |
26 | @PluginMethod
27 | public void download(PluginCall call) {
28 | JSObject data = call.getData();
29 | call.resolve(implementation.download(data));
30 | }
31 |
32 | @PluginMethod
33 | public void install(PluginCall call) {
34 | JSObject data = call.getData();
35 | call.resolve(implementation.install(data));
36 | }
37 |
38 | @Override
39 | protected void handleOnResume() {
40 | super.handleOnResume();
41 | this.implementation.onResume();
42 | }
43 |
44 | @Override
45 | protected void handleOnRestart() {
46 | super.handleOnRestart();
47 | this.implementation.onRestart();
48 | }
49 |
50 | public void notifyDownload(String percent) {
51 | JSObject jsObject = new JSObject();
52 | jsObject.put("percent", percent);
53 | notifyListeners(DOWNLOAD_PROGRESS_LISTENER, jsObject);
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/capacitor-code-update/android/src/main/java/site/chenwei/codeupdate/CodeUpdateNetWorker.java:
--------------------------------------------------------------------------------
1 | package site.chenwei.codeupdate;
2 |
3 | import org.json.JSONObject;
4 |
5 | import java.io.ByteArrayOutputStream;
6 | import java.io.InputStream;
7 | import java.net.HttpURLConnection;
8 | import java.net.MalformedURLException;
9 | import java.net.URL;
10 | import java.net.URLConnection;
11 | import java.net.URLEncoder;
12 | import java.nio.charset.StandardCharsets;
13 | import java.util.Map;
14 | import java.util.Set;
15 |
16 | import javax.net.ssl.HttpsURLConnection;
17 |
18 | public class CodeUpdateNetWorker {
19 | public static final String CHECK_UPDATE = "/application/version/check";
20 | public static final String SYNC_STATUS = "/application/version/status/sync";
21 | private static final int CONNECTION_TIME_OUT_SECONDS = 5;
22 | private static final int READ_TIME_OUT_SECONDS = 10;
23 | private static String baseUrl = "";
24 | private static final String SUCCESS = "S000000";
25 |
26 | public static JSONObject get(String urlStr) throws Exception {
27 | if (urlStr == null || "".equals(urlStr)) {
28 | return null;
29 | }
30 | URL url = new URL(urlStr);
31 | HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
32 | urlConnection.setRequestMethod("GET");
33 | urlConnection.setConnectTimeout(CONNECTION_TIME_OUT_SECONDS * 1000);
34 | urlConnection.setReadTimeout(READ_TIME_OUT_SECONDS * 1000);
35 | urlConnection.connect();
36 | if (urlConnection.getResponseCode() == 200) {
37 | InputStream inputStream = urlConnection.getInputStream();
38 | String read = read(inputStream);
39 | JSONObject jsonObject = new JSONObject(read);
40 | String code = (String) jsonObject.get("code");
41 | if (SUCCESS.equals(code)) {
42 | return (JSONObject) jsonObject.get("data");
43 | }
44 | }
45 | return null;
46 | }
47 |
48 | public static String buildUrl(String serverUrl, String uri, Map params) {
49 | addPublicParams(params);
50 | if (serverUrl == null || "".equals(serverUrl)) {
51 | if ("".equals(baseUrl)) {
52 | return "";
53 | }
54 | serverUrl = baseUrl;
55 | } else {
56 | baseUrl = serverUrl;
57 | }
58 | if (serverUrl.lastIndexOf("/") != serverUrl.length() - 1) {
59 | serverUrl = serverUrl + "/";
60 | }
61 | if (uri.indexOf("/") == 0) {
62 | uri = uri.substring(1);
63 | }
64 | serverUrl = serverUrl + uri;
65 | StringBuilder sb = new StringBuilder();
66 | Set keys = params.keySet();
67 | for (String key : keys) {
68 | if (params.get(key) == null) {
69 | continue;
70 | }
71 | sb = sb.append(key).append("=").append(URLEncoder.encode(params.get(key))).append("&");
72 | }
73 | String paramsStr = sb.substring(0, sb.length() - 1);
74 | return serverUrl + "?" + paramsStr;
75 | }
76 |
77 |
78 | //从流中读取数据
79 | private static String read(InputStream inStream) throws Exception {
80 | ByteArrayOutputStream outStream = new ByteArrayOutputStream();
81 | byte[] buffer = new byte[1024];
82 | int len;
83 | while ((len = inStream.read(buffer)) != -1) {
84 | outStream.write(buffer, 0, len);
85 | }
86 | inStream.close();
87 | return new String(outStream.toByteArray(), StandardCharsets.UTF_8);
88 | }
89 |
90 | private static void addPublicParams(Map params) {
91 | params.put("phoneOsType", "ANDROID");
92 | params.put("phoneVersion", android.os.Build.VERSION.RELEASE);
93 | params.put("phoneType", android.os.Build.BRAND);
94 | params.put("serialId", CapacitorCodeUpdate.GUID);
95 | params.put("versionName", CapacitorCodeUpdate.APP_VERSION);
96 | }
97 | }
98 |
--------------------------------------------------------------------------------
/capacitor-code-update/android/src/main/java/site/chenwei/codeupdate/IdUtil.java:
--------------------------------------------------------------------------------
1 | package site.chenwei.codeupdate;
2 |
3 | public class IdUtil {
4 | }
5 |
--------------------------------------------------------------------------------
/capacitor-code-update/android/src/main/java/site/chenwei/codeupdate/SystemUtil.java:
--------------------------------------------------------------------------------
1 | package site.chenwei.codeupdate;
2 |
3 | public class SystemUtil {
4 |
5 | /**
6 | * 获取当前手机系统版本号
7 | *
8 | * @return 系统版本号
9 | */
10 | public static String getSystemVersion() {
11 | return android.os.Build.VERSION.RELEASE;
12 | }
13 |
14 | /**
15 | * 获取手机型号
16 | *
17 | * @return 手机型号
18 | */
19 | public static String getSystemModel() {
20 | return android.os.Build.MODEL;
21 | }
22 |
23 | /**
24 | * 获取手机厂商
25 | *
26 | * @return 手机厂商
27 | */
28 | public static String getDeviceBrand() {
29 | return android.os.Build.BRAND;
30 | }
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/capacitor-code-update/android/src/main/res/.gitkeep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/site-chenwei/code-update/d8d40ff1643f47509696f39433b4bce4214f78e7/capacitor-code-update/android/src/main/res/.gitkeep
--------------------------------------------------------------------------------
/capacitor-code-update/android/src/test/java/com/getcapacitor/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.getcapacitor;
2 |
3 | import static org.junit.Assert.*;
4 |
5 | import org.junit.Test;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 |
14 | @Test
15 | public void addition_isCorrect() throws Exception {
16 | assertEquals(4, 2 + 2);
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/capacitor-code-update/ios/Plugin.xcodeproj/project.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/capacitor-code-update/ios/Plugin.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDEDidComputeMac32BitWarning
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/capacitor-code-update/ios/Plugin.xcodeproj/xcshareddata/xcschemes/Plugin.xcscheme:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
15 |
21 |
22 |
23 |
24 |
25 |
30 |
31 |
33 |
39 |
40 |
41 |
42 |
43 |
53 |
54 |
60 |
61 |
67 |
68 |
69 |
70 |
72 |
73 |
76 |
77 |
78 |
--------------------------------------------------------------------------------
/capacitor-code-update/ios/Plugin.xcodeproj/xcshareddata/xcschemes/PluginTests.xcscheme:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
15 |
21 |
22 |
23 |
24 |
25 |
30 |
31 |
33 |
39 |
40 |
41 |
42 |
43 |
53 |
54 |
60 |
61 |
63 |
64 |
67 |
68 |
69 |
--------------------------------------------------------------------------------
/capacitor-code-update/ios/Plugin.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/capacitor-code-update/ios/Plugin.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDEDidComputeMac32BitWarning
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/capacitor-code-update/ios/Plugin/BsPatch.h:
--------------------------------------------------------------------------------
1 | //
2 | // BsPatch.h
3 | // Plugin
4 | //
5 | // Created by 陈炜 on 2022/3/31.
6 | // Copyright © 2022 Max Lynch. All rights reserved.
7 | //
8 |
9 | #ifndef BsPatch_h
10 | #define BsPatch_h
11 |
12 | #import
13 | #import "Test_Bsdiff.h"
14 | @interface BsPatch : NSObject
15 | +(void)patch:(NSString*)oldPath newPath:(NSString*)newPath patchPath:(NSString*)patchPath;
16 | @end
17 |
18 | #endif /* BsPatch_h */
19 |
20 |
--------------------------------------------------------------------------------
/capacitor-code-update/ios/Plugin/BsPatch.m:
--------------------------------------------------------------------------------
1 | //
2 | // BsPatch.m
3 | // Plugin
4 | //
5 | // Created by 陈炜 on 2022/3/31.
6 | // Copyright © 2022 Max Lynch. All rights reserved.
7 | //
8 |
9 | #import "BsPatch.h"
10 | @implementation BsPatch
11 |
12 | +(void)patch:(NSString*)oldPath newPath:(NSString*)newPath patchPath:(NSString*)patchPath{
13 | const char *argv[4];
14 | argv[0] = "bspatch";
15 | // oldPath
16 | argv[1] = [oldPath UTF8String];
17 | // newPath
18 | argv[2] = [newPath UTF8String];
19 | // patchPath
20 | argv[3] = [patchPath UTF8String];
21 | BsdiffUntils_bspatch(4,argv);
22 | }
23 |
24 | @end
25 |
--------------------------------------------------------------------------------
/capacitor-code-update/ios/Plugin/CapacitorCodeUpdate.swift:
--------------------------------------------------------------------------------
1 | import Foundation
2 |
3 | @objc public class CapacitorCodeUpdate: NSObject {
4 | @objc public func echo(_ value: String) -> String {
5 | print(value)
6 | return value
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/capacitor-code-update/ios/Plugin/CapacitorCodeUpdatePlugin.h:
--------------------------------------------------------------------------------
1 | #import
2 |
3 | //! Project version number for Plugin.
4 | FOUNDATION_EXPORT double PluginVersionNumber;
5 |
6 | //! Project version string for Plugin.
7 | FOUNDATION_EXPORT const unsigned char PluginVersionString[];
8 |
9 | // In this header, you should import all the public headers of your framework using statements like #import
10 |
11 |
--------------------------------------------------------------------------------
/capacitor-code-update/ios/Plugin/CapacitorCodeUpdatePlugin.m:
--------------------------------------------------------------------------------
1 | #import
2 | #import
3 |
4 | // Define the plugin using the CAP_PLUGIN Macro, and
5 | // each method the plugin supports using the CAP_PLUGIN_METHOD macro.
6 | CAP_PLUGIN(CapacitorCodeUpdatePlugin, "CapacitorCodeUpdate",
7 | CAP_PLUGIN_METHOD(checkUpdate, CAPPluginReturnPromise);
8 | CAP_PLUGIN_METHOD(download, CAPPluginReturnPromise);
9 | CAP_PLUGIN_METHOD(install, CAPPluginReturnPromise);
10 | )
11 |
--------------------------------------------------------------------------------
/capacitor-code-update/ios/Plugin/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | $(DEVELOPMENT_LANGUAGE)
7 | CFBundleExecutable
8 | $(EXECUTABLE_NAME)
9 | CFBundleIdentifier
10 | $(PRODUCT_BUNDLE_IDENTIFIER)
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundleName
14 | $(PRODUCT_NAME)
15 | CFBundlePackageType
16 | FMWK
17 | CFBundleShortVersionString
18 | 1.0
19 | CFBundleVersion
20 | $(CURRENT_PROJECT_VERSION)
21 | NSPrincipalClass
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/capacitor-code-update/ios/Plugin/Plugin-Bridging-Header.h:
--------------------------------------------------------------------------------
1 | //
2 | // Plugin-Bridging-Header.h
3 | // Plugin
4 | //
5 | // Created by 陈炜 on 2022/3/30.
6 | // Copyright © 2022 Max Lynch. All rights reserved.
7 | //
8 | #import "BsPatch.h"
9 |
--------------------------------------------------------------------------------
/capacitor-code-update/ios/Plugin/Test_Bsdiff.h:
--------------------------------------------------------------------------------
1 | //
2 | // Test_Bsdiff.h
3 | // Bsdiff_Demo
4 | //
5 | // Created by Laomeng on 2017/12/10.
6 | // Copyright © 2017年 Laomeng. All rights reserved.
7 | //
8 |
9 | #ifndef Test_Bsdiff_h
10 | #define Test_Bsdiff_h
11 |
12 | int BsdiffUntils_bsdiff(int argc, char *argv[]);
13 |
14 | int BsdiffUntils_bspatch(int argc,char * argv[]);
15 |
16 | void testPrintf();
17 |
18 | #endif /* Test_Bsdiff_h */
19 |
--------------------------------------------------------------------------------
/capacitor-code-update/ios/Plugin/bsdiff-4.3/bspatch.c:
--------------------------------------------------------------------------------
1 | /*-
2 | * Copyright 2003-2005 Colin Percival
3 | * All rights reserved
4 | *
5 | * Redistribution and use in source and binary forms, with or without
6 | * modification, are permitted providing that the following conditions
7 | * are met:
8 | * 1. Redistributions of source code must retain the above copyright
9 | * notice, this list of conditions and the following disclaimer.
10 | * 2. Redistributions in binary form must reproduce the above copyright
11 | * notice, this list of conditions and the following disclaimer in the
12 | * documentation and/or other materials provided with the distribution.
13 | *
14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
15 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
18 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
22 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
23 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
24 | * POSSIBILITY OF SUCH DAMAGE.
25 | */
26 |
27 | #if 0
28 | __FBSDID("$FreeBSD: src/usr.bin/bsdiff/bspatch/bspatch.c,v 1.1 2005/08/06 01:59:06 cperciva Exp $");
29 | #endif
30 |
31 | #include
32 | #include
33 | #include
34 | #include
35 | #include
36 | #include
37 | #include
38 |
39 | static off_t offtin(u_char *buf)
40 | {
41 | off_t y;
42 |
43 | y=buf[7]&0x7F;
44 | y=y*256;y+=buf[6];
45 | y=y*256;y+=buf[5];
46 | y=y*256;y+=buf[4];
47 | y=y*256;y+=buf[3];
48 | y=y*256;y+=buf[2];
49 | y=y*256;y+=buf[1];
50 | y=y*256;y+=buf[0];
51 |
52 | if(buf[7]&0x80) y=-y;
53 |
54 | return y;
55 | }
56 |
57 | int BsdiffUntils_bspatch(int argc,char * argv[])
58 | {
59 | FILE * f, * cpf, * dpf, * epf;
60 | BZFILE * cpfbz2, * dpfbz2, * epfbz2;
61 | int cbz2err, dbz2err, ebz2err;
62 | int fd;
63 | ssize_t oldsize,newsize;
64 | ssize_t bzctrllen,bzdatalen;
65 | u_char header[32],buf[8];
66 | u_char *old, *new;
67 | off_t oldpos,newpos;
68 | off_t ctrl[3];
69 | off_t lenread;
70 | off_t i;
71 |
72 | if(argc!=4) errx(1,"usage: %s oldfile newfile patchfile\n",argv[0]);
73 |
74 | /* Open patch file */
75 | if ((f = fopen(argv[3], "r")) == NULL)
76 | err(1, "fopen(%s)", argv[3]);
77 |
78 | /*
79 | File format:
80 | 0 8 "BSDIFF40"
81 | 8 8 X
82 | 16 8 Y
83 | 24 8 sizeof(newfile)
84 | 32 X bzip2(control block)
85 | 32+X Y bzip2(diff block)
86 | 32+X+Y ??? bzip2(extra block)
87 | with control block a set of triples (x,y,z) meaning "add x bytes
88 | from oldfile to x bytes from the diff block; copy y bytes from the
89 | extra block; seek forwards in oldfile by z bytes".
90 | */
91 |
92 | /* Read header */
93 | if (fread(header, 1, 32, f) < 32) {
94 | if (feof(f))
95 | errx(1, "Corrupt patch\n");
96 | err(1, "fread(%s)", argv[3]);
97 | }
98 |
99 | /* Check for appropriate magic */
100 | if (memcmp(header, "BSDIFF40", 8) != 0)
101 | errx(1, "Corrupt patch\n");
102 |
103 | /* Read lengths from header */
104 | bzctrllen=offtin(header+8);
105 | bzdatalen=offtin(header+16);
106 | newsize=offtin(header+24);
107 | if((bzctrllen<0) || (bzdatalen<0) || (newsize<0))
108 | errx(1,"Corrupt patch\n");
109 |
110 | /* Close patch file and re-open it via libbzip2 at the right places */
111 | if (fclose(f))
112 | err(1, "fclose(%s)", argv[3]);
113 | if ((cpf = fopen(argv[3], "r")) == NULL)
114 | err(1, "fopen(%s)", argv[3]);
115 | if (fseeko(cpf, 32, SEEK_SET))
116 | err(1, "fseeko(%s, %lld)", argv[3],
117 | (long long)32);
118 | if ((cpfbz2 = BZ2_bzReadOpen(&cbz2err, cpf, 0, 0, NULL, 0)) == NULL)
119 | errx(1, "BZ2_bzReadOpen, bz2err = %d", cbz2err);
120 | if ((dpf = fopen(argv[3], "r")) == NULL)
121 | err(1, "fopen(%s)", argv[3]);
122 | if (fseeko(dpf, 32 + bzctrllen, SEEK_SET))
123 | err(1, "fseeko(%s, %lld)", argv[3],
124 | (long long)(32 + bzctrllen));
125 | if ((dpfbz2 = BZ2_bzReadOpen(&dbz2err, dpf, 0, 0, NULL, 0)) == NULL)
126 | errx(1, "BZ2_bzReadOpen, bz2err = %d", dbz2err);
127 | if ((epf = fopen(argv[3], "r")) == NULL)
128 | err(1, "fopen(%s)", argv[3]);
129 | if (fseeko(epf, 32 + bzctrllen + bzdatalen, SEEK_SET))
130 | err(1, "fseeko(%s, %lld)", argv[3],
131 | (long long)(32 + bzctrllen + bzdatalen));
132 | if ((epfbz2 = BZ2_bzReadOpen(&ebz2err, epf, 0, 0, NULL, 0)) == NULL)
133 | errx(1, "BZ2_bzReadOpen, bz2err = %d", ebz2err);
134 |
135 | if(((fd=open(argv[1],O_RDONLY,0))<0) ||
136 | ((oldsize=lseek(fd,0,SEEK_END))==-1) ||
137 | ((old=malloc(oldsize+1))==NULL) ||
138 | (lseek(fd,0,SEEK_SET)!=0) ||
139 | (read(fd,old,oldsize)!=oldsize) ||
140 | (close(fd)==-1)) err(1,"%s",argv[1]);
141 | if((new=malloc(newsize+1))==NULL) err(1,NULL);
142 |
143 | oldpos=0;newpos=0;
144 | while(newposnewsize)
156 | errx(1,"Corrupt patch\n");
157 |
158 | /* Read diff string */
159 | lenread = BZ2_bzRead(&dbz2err, dpfbz2, new + newpos, ctrl[0]);
160 | if ((lenread < ctrl[0]) ||
161 | ((dbz2err != BZ_OK) && (dbz2err != BZ_STREAM_END)))
162 | errx(1, "Corrupt patch\n");
163 |
164 | /* Add old data to diff string */
165 | for(i=0;i=0) && (oldpos+inewsize)
175 | errx(1,"Corrupt patch\n");
176 |
177 | /* Read extra string */
178 | lenread = BZ2_bzRead(&ebz2err, epfbz2, new + newpos, ctrl[1]);
179 | if ((lenread < ctrl[1]) ||
180 | ((ebz2err != BZ_OK) && (ebz2err != BZ_STREAM_END)))
181 | errx(1, "Corrupt patch\n");
182 |
183 | /* Adjust pointers */
184 | newpos+=ctrl[1];
185 | oldpos+=ctrl[2];
186 | };
187 |
188 | /* Clean up the bzip2 reads */
189 | BZ2_bzReadClose(&cbz2err, cpfbz2);
190 | BZ2_bzReadClose(&dbz2err, dpfbz2);
191 | BZ2_bzReadClose(&ebz2err, epfbz2);
192 | if (fclose(cpf) || fclose(dpf) || fclose(epf))
193 | err(1, "fclose(%s)", argv[3]);
194 |
195 | /* Write the new file */
196 | if(((fd=open(argv[2],O_CREAT|O_TRUNC|O_WRONLY,0666))<0) ||
197 | (write(fd,new,newsize)!=newsize) || (close(fd)==-1))
198 | err(1,"%s",argv[2]);
199 |
200 | free(new);
201 | free(old);
202 |
203 | return 0;
204 | }
205 |
--------------------------------------------------------------------------------
/capacitor-code-update/ios/Plugin/bzip2-1.0.6/bzlib.h:
--------------------------------------------------------------------------------
1 |
2 | /*-------------------------------------------------------------*/
3 | /*--- Public header file for the library. ---*/
4 | /*--- bzlib.h ---*/
5 | /*-------------------------------------------------------------*/
6 |
7 | /* ------------------------------------------------------------------
8 | This file is part of bzip2/libbzip2, a program and library for
9 | lossless, block-sorting data compression.
10 |
11 | bzip2/libbzip2 version 1.0.6 of 6 September 2010
12 | Copyright (C) 1996-2010 Julian Seward
13 |
14 | Please read the WARNING, DISCLAIMER and PATENTS sections in the
15 | README file.
16 |
17 | This program is released under the terms of the license contained
18 | in the file LICENSE.
19 | ------------------------------------------------------------------ */
20 |
21 |
22 | #ifndef _BZLIB_H
23 | #define _BZLIB_H
24 |
25 | #ifdef __cplusplus
26 | extern "C" {
27 | #endif
28 |
29 | #define BZ_RUN 0
30 | #define BZ_FLUSH 1
31 | #define BZ_FINISH 2
32 |
33 | #define BZ_OK 0
34 | #define BZ_RUN_OK 1
35 | #define BZ_FLUSH_OK 2
36 | #define BZ_FINISH_OK 3
37 | #define BZ_STREAM_END 4
38 | #define BZ_SEQUENCE_ERROR (-1)
39 | #define BZ_PARAM_ERROR (-2)
40 | #define BZ_MEM_ERROR (-3)
41 | #define BZ_DATA_ERROR (-4)
42 | #define BZ_DATA_ERROR_MAGIC (-5)
43 | #define BZ_IO_ERROR (-6)
44 | #define BZ_UNEXPECTED_EOF (-7)
45 | #define BZ_OUTBUFF_FULL (-8)
46 | #define BZ_CONFIG_ERROR (-9)
47 |
48 | typedef
49 | struct {
50 | char *next_in;
51 | unsigned int avail_in;
52 | unsigned int total_in_lo32;
53 | unsigned int total_in_hi32;
54 |
55 | char *next_out;
56 | unsigned int avail_out;
57 | unsigned int total_out_lo32;
58 | unsigned int total_out_hi32;
59 |
60 | void *state;
61 |
62 | void *(*bzalloc)(void *,int,int);
63 | void (*bzfree)(void *,void *);
64 | void *opaque;
65 | }
66 | bz_stream;
67 |
68 |
69 | #ifndef BZ_IMPORT
70 | #define BZ_EXPORT
71 | #endif
72 |
73 | #ifndef BZ_NO_STDIO
74 | /* Need a definitition for FILE */
75 | #include
76 | #endif
77 |
78 | #ifdef _WIN32
79 | # include
80 | # ifdef small
81 | /* windows.h define small to char */
82 | # undef small
83 | # endif
84 | # ifdef BZ_EXPORT
85 | # define BZ_API(func) WINAPI func
86 | # define BZ_EXTERN extern
87 | # else
88 | /* import windows dll dynamically */
89 | # define BZ_API(func) (WINAPI * func)
90 | # define BZ_EXTERN
91 | # endif
92 | #else
93 | # define BZ_API(func) func
94 | # define BZ_EXTERN extern
95 | #endif
96 |
97 |
98 | /*-- Core (low-level) library functions --*/
99 |
100 | BZ_EXTERN int BZ_API(BZ2_bzCompressInit) (
101 | bz_stream* strm,
102 | int blockSize100k,
103 | int verbosity,
104 | int workFactor
105 | );
106 |
107 | BZ_EXTERN int BZ_API(BZ2_bzCompress) (
108 | bz_stream* strm,
109 | int action
110 | );
111 |
112 | BZ_EXTERN int BZ_API(BZ2_bzCompressEnd) (
113 | bz_stream* strm
114 | );
115 |
116 | BZ_EXTERN int BZ_API(BZ2_bzDecompressInit) (
117 | bz_stream *strm,
118 | int verbosity,
119 | int small
120 | );
121 |
122 | BZ_EXTERN int BZ_API(BZ2_bzDecompress) (
123 | bz_stream* strm
124 | );
125 |
126 | BZ_EXTERN int BZ_API(BZ2_bzDecompressEnd) (
127 | bz_stream *strm
128 | );
129 |
130 |
131 |
132 | /*-- High(er) level library functions --*/
133 |
134 | #ifndef BZ_NO_STDIO
135 | #define BZ_MAX_UNUSED 5000
136 |
137 | typedef void BZFILE;
138 |
139 | BZ_EXTERN BZFILE* BZ_API(BZ2_bzReadOpen) (
140 | int* bzerror,
141 | FILE* f,
142 | int verbosity,
143 | int small,
144 | void* unused,
145 | int nUnused
146 | );
147 |
148 | BZ_EXTERN void BZ_API(BZ2_bzReadClose) (
149 | int* bzerror,
150 | BZFILE* b
151 | );
152 |
153 | BZ_EXTERN void BZ_API(BZ2_bzReadGetUnused) (
154 | int* bzerror,
155 | BZFILE* b,
156 | void** unused,
157 | int* nUnused
158 | );
159 |
160 | BZ_EXTERN int BZ_API(BZ2_bzRead) (
161 | int* bzerror,
162 | BZFILE* b,
163 | void* buf,
164 | int len
165 | );
166 |
167 | BZ_EXTERN BZFILE* BZ_API(BZ2_bzWriteOpen) (
168 | int* bzerror,
169 | FILE* f,
170 | int blockSize100k,
171 | int verbosity,
172 | int workFactor
173 | );
174 |
175 | BZ_EXTERN void BZ_API(BZ2_bzWrite) (
176 | int* bzerror,
177 | BZFILE* b,
178 | void* buf,
179 | int len
180 | );
181 |
182 | BZ_EXTERN void BZ_API(BZ2_bzWriteClose) (
183 | int* bzerror,
184 | BZFILE* b,
185 | int abandon,
186 | unsigned int* nbytes_in,
187 | unsigned int* nbytes_out
188 | );
189 |
190 | BZ_EXTERN void BZ_API(BZ2_bzWriteClose64) (
191 | int* bzerror,
192 | BZFILE* b,
193 | int abandon,
194 | unsigned int* nbytes_in_lo32,
195 | unsigned int* nbytes_in_hi32,
196 | unsigned int* nbytes_out_lo32,
197 | unsigned int* nbytes_out_hi32
198 | );
199 | #endif
200 |
201 |
202 | /*-- Utility functions --*/
203 |
204 | BZ_EXTERN int BZ_API(BZ2_bzBuffToBuffCompress) (
205 | char* dest,
206 | unsigned int* destLen,
207 | char* source,
208 | unsigned int sourceLen,
209 | int blockSize100k,
210 | int verbosity,
211 | int workFactor
212 | );
213 |
214 | BZ_EXTERN int BZ_API(BZ2_bzBuffToBuffDecompress) (
215 | char* dest,
216 | unsigned int* destLen,
217 | char* source,
218 | unsigned int sourceLen,
219 | int small,
220 | int verbosity
221 | );
222 |
223 |
224 | /*--
225 | Code contributed by Yoshioka Tsuneo (tsuneo@rr.iij4u.or.jp)
226 | to support better zlib compatibility.
227 | This code is not _officially_ part of libbzip2 (yet);
228 | I haven't tested it, documented it, or considered the
229 | threading-safeness of it.
230 | If this code breaks, please contact both Yoshioka and me.
231 | --*/
232 |
233 | BZ_EXTERN const char * BZ_API(BZ2_bzlibVersion) (
234 | void
235 | );
236 |
237 | #ifndef BZ_NO_STDIO
238 | BZ_EXTERN BZFILE * BZ_API(BZ2_bzopen) (
239 | const char *path,
240 | const char *mode
241 | );
242 |
243 | BZ_EXTERN BZFILE * BZ_API(BZ2_bzdopen) (
244 | int fd,
245 | const char *mode
246 | );
247 |
248 | BZ_EXTERN int BZ_API(BZ2_bzread) (
249 | BZFILE* b,
250 | void* buf,
251 | int len
252 | );
253 |
254 | BZ_EXTERN int BZ_API(BZ2_bzwrite) (
255 | BZFILE* b,
256 | void* buf,
257 | int len
258 | );
259 |
260 | BZ_EXTERN int BZ_API(BZ2_bzflush) (
261 | BZFILE* b
262 | );
263 |
264 | BZ_EXTERN void BZ_API(BZ2_bzclose) (
265 | BZFILE* b
266 | );
267 |
268 | BZ_EXTERN const char * BZ_API(BZ2_bzerror) (
269 | BZFILE *b,
270 | int *errnum
271 | );
272 | #endif
273 |
274 | #ifdef __cplusplus
275 | }
276 | #endif
277 |
278 | #endif
279 |
280 | /*-------------------------------------------------------------*/
281 | /*--- end bzlib.h ---*/
282 | /*-------------------------------------------------------------*/
283 |
--------------------------------------------------------------------------------
/capacitor-code-update/ios/Plugin/bzip2-1.0.6/crctable.c:
--------------------------------------------------------------------------------
1 |
2 | /*-------------------------------------------------------------*/
3 | /*--- Table for doing CRCs ---*/
4 | /*--- crctable.c ---*/
5 | /*-------------------------------------------------------------*/
6 |
7 | /* ------------------------------------------------------------------
8 | This file is part of bzip2/libbzip2, a program and library for
9 | lossless, block-sorting data compression.
10 |
11 | bzip2/libbzip2 version 1.0.6 of 6 September 2010
12 | Copyright (C) 1996-2010 Julian Seward
13 |
14 | Please read the WARNING, DISCLAIMER and PATENTS sections in the
15 | README file.
16 |
17 | This program is released under the terms of the license contained
18 | in the file LICENSE.
19 | ------------------------------------------------------------------ */
20 |
21 |
22 | #include "bzlib_private.h"
23 |
24 | /*--
25 | I think this is an implementation of the AUTODIN-II,
26 | Ethernet & FDDI 32-bit CRC standard. Vaguely derived
27 | from code by Rob Warnock, in Section 51 of the
28 | comp.compression FAQ.
29 | --*/
30 |
31 | UInt32 BZ2_crc32Table[256] = {
32 |
33 | /*-- Ugly, innit? --*/
34 |
35 | 0x00000000L, 0x04c11db7L, 0x09823b6eL, 0x0d4326d9L,
36 | 0x130476dcL, 0x17c56b6bL, 0x1a864db2L, 0x1e475005L,
37 | 0x2608edb8L, 0x22c9f00fL, 0x2f8ad6d6L, 0x2b4bcb61L,
38 | 0x350c9b64L, 0x31cd86d3L, 0x3c8ea00aL, 0x384fbdbdL,
39 | 0x4c11db70L, 0x48d0c6c7L, 0x4593e01eL, 0x4152fda9L,
40 | 0x5f15adacL, 0x5bd4b01bL, 0x569796c2L, 0x52568b75L,
41 | 0x6a1936c8L, 0x6ed82b7fL, 0x639b0da6L, 0x675a1011L,
42 | 0x791d4014L, 0x7ddc5da3L, 0x709f7b7aL, 0x745e66cdL,
43 | 0x9823b6e0L, 0x9ce2ab57L, 0x91a18d8eL, 0x95609039L,
44 | 0x8b27c03cL, 0x8fe6dd8bL, 0x82a5fb52L, 0x8664e6e5L,
45 | 0xbe2b5b58L, 0xbaea46efL, 0xb7a96036L, 0xb3687d81L,
46 | 0xad2f2d84L, 0xa9ee3033L, 0xa4ad16eaL, 0xa06c0b5dL,
47 | 0xd4326d90L, 0xd0f37027L, 0xddb056feL, 0xd9714b49L,
48 | 0xc7361b4cL, 0xc3f706fbL, 0xceb42022L, 0xca753d95L,
49 | 0xf23a8028L, 0xf6fb9d9fL, 0xfbb8bb46L, 0xff79a6f1L,
50 | 0xe13ef6f4L, 0xe5ffeb43L, 0xe8bccd9aL, 0xec7dd02dL,
51 | 0x34867077L, 0x30476dc0L, 0x3d044b19L, 0x39c556aeL,
52 | 0x278206abL, 0x23431b1cL, 0x2e003dc5L, 0x2ac12072L,
53 | 0x128e9dcfL, 0x164f8078L, 0x1b0ca6a1L, 0x1fcdbb16L,
54 | 0x018aeb13L, 0x054bf6a4L, 0x0808d07dL, 0x0cc9cdcaL,
55 | 0x7897ab07L, 0x7c56b6b0L, 0x71159069L, 0x75d48ddeL,
56 | 0x6b93dddbL, 0x6f52c06cL, 0x6211e6b5L, 0x66d0fb02L,
57 | 0x5e9f46bfL, 0x5a5e5b08L, 0x571d7dd1L, 0x53dc6066L,
58 | 0x4d9b3063L, 0x495a2dd4L, 0x44190b0dL, 0x40d816baL,
59 | 0xaca5c697L, 0xa864db20L, 0xa527fdf9L, 0xa1e6e04eL,
60 | 0xbfa1b04bL, 0xbb60adfcL, 0xb6238b25L, 0xb2e29692L,
61 | 0x8aad2b2fL, 0x8e6c3698L, 0x832f1041L, 0x87ee0df6L,
62 | 0x99a95df3L, 0x9d684044L, 0x902b669dL, 0x94ea7b2aL,
63 | 0xe0b41de7L, 0xe4750050L, 0xe9362689L, 0xedf73b3eL,
64 | 0xf3b06b3bL, 0xf771768cL, 0xfa325055L, 0xfef34de2L,
65 | 0xc6bcf05fL, 0xc27dede8L, 0xcf3ecb31L, 0xcbffd686L,
66 | 0xd5b88683L, 0xd1799b34L, 0xdc3abdedL, 0xd8fba05aL,
67 | 0x690ce0eeL, 0x6dcdfd59L, 0x608edb80L, 0x644fc637L,
68 | 0x7a089632L, 0x7ec98b85L, 0x738aad5cL, 0x774bb0ebL,
69 | 0x4f040d56L, 0x4bc510e1L, 0x46863638L, 0x42472b8fL,
70 | 0x5c007b8aL, 0x58c1663dL, 0x558240e4L, 0x51435d53L,
71 | 0x251d3b9eL, 0x21dc2629L, 0x2c9f00f0L, 0x285e1d47L,
72 | 0x36194d42L, 0x32d850f5L, 0x3f9b762cL, 0x3b5a6b9bL,
73 | 0x0315d626L, 0x07d4cb91L, 0x0a97ed48L, 0x0e56f0ffL,
74 | 0x1011a0faL, 0x14d0bd4dL, 0x19939b94L, 0x1d528623L,
75 | 0xf12f560eL, 0xf5ee4bb9L, 0xf8ad6d60L, 0xfc6c70d7L,
76 | 0xe22b20d2L, 0xe6ea3d65L, 0xeba91bbcL, 0xef68060bL,
77 | 0xd727bbb6L, 0xd3e6a601L, 0xdea580d8L, 0xda649d6fL,
78 | 0xc423cd6aL, 0xc0e2d0ddL, 0xcda1f604L, 0xc960ebb3L,
79 | 0xbd3e8d7eL, 0xb9ff90c9L, 0xb4bcb610L, 0xb07daba7L,
80 | 0xae3afba2L, 0xaafbe615L, 0xa7b8c0ccL, 0xa379dd7bL,
81 | 0x9b3660c6L, 0x9ff77d71L, 0x92b45ba8L, 0x9675461fL,
82 | 0x8832161aL, 0x8cf30badL, 0x81b02d74L, 0x857130c3L,
83 | 0x5d8a9099L, 0x594b8d2eL, 0x5408abf7L, 0x50c9b640L,
84 | 0x4e8ee645L, 0x4a4ffbf2L, 0x470cdd2bL, 0x43cdc09cL,
85 | 0x7b827d21L, 0x7f436096L, 0x7200464fL, 0x76c15bf8L,
86 | 0x68860bfdL, 0x6c47164aL, 0x61043093L, 0x65c52d24L,
87 | 0x119b4be9L, 0x155a565eL, 0x18197087L, 0x1cd86d30L,
88 | 0x029f3d35L, 0x065e2082L, 0x0b1d065bL, 0x0fdc1becL,
89 | 0x3793a651L, 0x3352bbe6L, 0x3e119d3fL, 0x3ad08088L,
90 | 0x2497d08dL, 0x2056cd3aL, 0x2d15ebe3L, 0x29d4f654L,
91 | 0xc5a92679L, 0xc1683bceL, 0xcc2b1d17L, 0xc8ea00a0L,
92 | 0xd6ad50a5L, 0xd26c4d12L, 0xdf2f6bcbL, 0xdbee767cL,
93 | 0xe3a1cbc1L, 0xe760d676L, 0xea23f0afL, 0xeee2ed18L,
94 | 0xf0a5bd1dL, 0xf464a0aaL, 0xf9278673L, 0xfde69bc4L,
95 | 0x89b8fd09L, 0x8d79e0beL, 0x803ac667L, 0x84fbdbd0L,
96 | 0x9abc8bd5L, 0x9e7d9662L, 0x933eb0bbL, 0x97ffad0cL,
97 | 0xafb010b1L, 0xab710d06L, 0xa6322bdfL, 0xa2f33668L,
98 | 0xbcb4666dL, 0xb8757bdaL, 0xb5365d03L, 0xb1f740b4L
99 | };
100 |
101 |
102 | /*-------------------------------------------------------------*/
103 | /*--- end crctable.c ---*/
104 | /*-------------------------------------------------------------*/
105 |
--------------------------------------------------------------------------------
/capacitor-code-update/ios/Plugin/bzip2-1.0.6/dlltest.c:
--------------------------------------------------------------------------------
1 | /*
2 | minibz2
3 | libbz2.dll test program.
4 | by Yoshioka Tsuneo (tsuneo@rr.iij4u.or.jp)
5 | This file is Public Domain. Welcome any email to me.
6 |
7 | usage: minibz2 [-d] [-{1,2,..9}] [[srcfilename] destfilename]
8 | */
9 |
10 | #define BZ_IMPORT
11 | #include
12 | #include
13 | #include "bzlib.h"
14 | #ifdef _WIN32
15 | #include
16 | #endif
17 |
18 |
19 | #ifdef _WIN32
20 |
21 | #define BZ2_LIBNAME "libbz2-1.0.2.DLL"
22 |
23 | #include
24 | static int BZ2DLLLoaded = 0;
25 | static HINSTANCE BZ2DLLhLib;
26 | int BZ2DLLLoadLibrary(void)
27 | {
28 | HINSTANCE hLib;
29 |
30 | if(BZ2DLLLoaded==1){return 0;}
31 | hLib=LoadLibrary(BZ2_LIBNAME);
32 | if(hLib == NULL){
33 | fprintf(stderr,"Can't load %s\n",BZ2_LIBNAME);
34 | return -1;
35 | }
36 | BZ2_bzlibVersion=GetProcAddress(hLib,"BZ2_bzlibVersion");
37 | BZ2_bzopen=GetProcAddress(hLib,"BZ2_bzopen");
38 | BZ2_bzdopen=GetProcAddress(hLib,"BZ2_bzdopen");
39 | BZ2_bzread=GetProcAddress(hLib,"BZ2_bzread");
40 | BZ2_bzwrite=GetProcAddress(hLib,"BZ2_bzwrite");
41 | BZ2_bzflush=GetProcAddress(hLib,"BZ2_bzflush");
42 | BZ2_bzclose=GetProcAddress(hLib,"BZ2_bzclose");
43 | BZ2_bzerror=GetProcAddress(hLib,"BZ2_bzerror");
44 |
45 | if (!BZ2_bzlibVersion || !BZ2_bzopen || !BZ2_bzdopen
46 | || !BZ2_bzread || !BZ2_bzwrite || !BZ2_bzflush
47 | || !BZ2_bzclose || !BZ2_bzerror) {
48 | fprintf(stderr,"GetProcAddress failed.\n");
49 | return -1;
50 | }
51 | BZ2DLLLoaded=1;
52 | BZ2DLLhLib=hLib;
53 | return 0;
54 |
55 | }
56 | int BZ2DLLFreeLibrary(void)
57 | {
58 | if(BZ2DLLLoaded==0){return 0;}
59 | FreeLibrary(BZ2DLLhLib);
60 | BZ2DLLLoaded=0;
61 | }
62 | #endif /* WIN32 */
63 |
64 | void usage(void)
65 | {
66 | puts("usage: minibz2 [-d] [-{1,2,..9}] [[srcfilename] destfilename]");
67 | }
68 |
69 | int dlltest_main(int argc,char *argv[])
70 | {
71 | int decompress = 0;
72 | int level = 9;
73 | char *fn_r = NULL;
74 | char *fn_w = NULL;
75 |
76 | #ifdef _WIN32
77 | if(BZ2DLLLoadLibrary()<0){
78 | fprintf(stderr,"Loading of %s failed. Giving up.\n", BZ2_LIBNAME);
79 | exit(1);
80 | }
81 | printf("Loading of %s succeeded. Library version is %s.\n",
82 | BZ2_LIBNAME, BZ2_bzlibVersion() );
83 | #endif
84 | while(++argv,--argc){
85 | if(**argv =='-' || **argv=='/'){
86 | char *p;
87 |
88 | for(p=*argv+1;*p;p++){
89 | if(*p=='d'){
90 | decompress = 1;
91 | }else if('1'<=*p && *p<='9'){
92 | level = *p - '0';
93 | }else{
94 | usage();
95 | exit(1);
96 | }
97 | }
98 | }else{
99 | break;
100 | }
101 | }
102 | if(argc>=1){
103 | fn_r = *argv;
104 | argc--;argv++;
105 | }else{
106 | fn_r = NULL;
107 | }
108 | if(argc>=1){
109 | fn_w = *argv;
110 | argc--;argv++;
111 | }else{
112 | fn_w = NULL;
113 | }
114 | {
115 | int len;
116 | char buff[0x1000];
117 | char mode[10];
118 |
119 | if(decompress){
120 | BZFILE *BZ2fp_r = NULL;
121 | FILE *fp_w = NULL;
122 |
123 | if(fn_w){
124 | if((fp_w = fopen(fn_w,"wb"))==NULL){
125 | printf("can't open [%s]\n",fn_w);
126 | perror("reason:");
127 | exit(1);
128 | }
129 | }else{
130 | fp_w = stdout;
131 | }
132 | if((fn_r == NULL && (BZ2fp_r = BZ2_bzdopen(fileno(stdin),"rb"))==NULL)
133 | || (fn_r != NULL && (BZ2fp_r = BZ2_bzopen(fn_r,"rb"))==NULL)){
134 | printf("can't bz2openstream\n");
135 | exit(1);
136 | }
137 | while((len=BZ2_bzread(BZ2fp_r,buff,0x1000))>0){
138 | fwrite(buff,1,len,fp_w);
139 | }
140 | BZ2_bzclose(BZ2fp_r);
141 | if(fp_w != stdout) fclose(fp_w);
142 | }else{
143 | BZFILE *BZ2fp_w = NULL;
144 | FILE *fp_r = NULL;
145 |
146 | if(fn_r){
147 | if((fp_r = fopen(fn_r,"rb"))==NULL){
148 | printf("can't open [%s]\n",fn_r);
149 | perror("reason:");
150 | exit(1);
151 | }
152 | }else{
153 | fp_r = stdin;
154 | }
155 | mode[0]='w';
156 | mode[1] = '0' + level;
157 | mode[2] = '\0';
158 |
159 | if((fn_w == NULL && (BZ2fp_w = BZ2_bzdopen(fileno(stdout),mode))==NULL)
160 | || (fn_w !=NULL && (BZ2fp_w = BZ2_bzopen(fn_w,mode))==NULL)){
161 | printf("can't bz2openstream\n");
162 | exit(1);
163 | }
164 | while((len=fread(buff,1,0x1000,fp_r))>0){
165 | BZ2_bzwrite(BZ2fp_w,buff,len);
166 | }
167 | BZ2_bzclose(BZ2fp_w);
168 | if(fp_r!=stdin)fclose(fp_r);
169 | }
170 | }
171 | #ifdef _WIN32
172 | BZ2DLLFreeLibrary();
173 | #endif
174 | return 0;
175 | }
176 |
--------------------------------------------------------------------------------
/capacitor-code-update/ios/Plugin/bzip2-1.0.6/huffman.c:
--------------------------------------------------------------------------------
1 |
2 | /*-------------------------------------------------------------*/
3 | /*--- Huffman coding low-level stuff ---*/
4 | /*--- huffman.c ---*/
5 | /*-------------------------------------------------------------*/
6 |
7 | /* ------------------------------------------------------------------
8 | This file is part of bzip2/libbzip2, a program and library for
9 | lossless, block-sorting data compression.
10 |
11 | bzip2/libbzip2 version 1.0.6 of 6 September 2010
12 | Copyright (C) 1996-2010 Julian Seward
13 |
14 | Please read the WARNING, DISCLAIMER and PATENTS sections in the
15 | README file.
16 |
17 | This program is released under the terms of the license contained
18 | in the file LICENSE.
19 | ------------------------------------------------------------------ */
20 |
21 |
22 | #include "bzlib_private.h"
23 |
24 | /*---------------------------------------------------*/
25 | #define WEIGHTOF(zz0) ((zz0) & 0xffffff00)
26 | #define DEPTHOF(zz1) ((zz1) & 0x000000ff)
27 | #define MYMAX(zz2,zz3) ((zz2) > (zz3) ? (zz2) : (zz3))
28 |
29 | #define ADDWEIGHTS(zw1,zw2) \
30 | (WEIGHTOF(zw1)+WEIGHTOF(zw2)) | \
31 | (1 + MYMAX(DEPTHOF(zw1),DEPTHOF(zw2)))
32 |
33 | #define UPHEAP(z) \
34 | { \
35 | Int32 zz, tmp; \
36 | zz = z; tmp = heap[zz]; \
37 | while (weight[tmp] < weight[heap[zz >> 1]]) { \
38 | heap[zz] = heap[zz >> 1]; \
39 | zz >>= 1; \
40 | } \
41 | heap[zz] = tmp; \
42 | }
43 |
44 | #define DOWNHEAP(z) \
45 | { \
46 | Int32 zz, yy, tmp; \
47 | zz = z; tmp = heap[zz]; \
48 | while (True) { \
49 | yy = zz << 1; \
50 | if (yy > nHeap) break; \
51 | if (yy < nHeap && \
52 | weight[heap[yy+1]] < weight[heap[yy]]) \
53 | yy++; \
54 | if (weight[tmp] < weight[heap[yy]]) break; \
55 | heap[zz] = heap[yy]; \
56 | zz = yy; \
57 | } \
58 | heap[zz] = tmp; \
59 | }
60 |
61 |
62 | /*---------------------------------------------------*/
63 | void BZ2_hbMakeCodeLengths ( UChar *len,
64 | Int32 *freq,
65 | Int32 alphaSize,
66 | Int32 maxLen )
67 | {
68 | /*--
69 | Nodes and heap entries run from 1. Entry 0
70 | for both the heap and nodes is a sentinel.
71 | --*/
72 | Int32 nNodes, nHeap, n1, n2, i, j, k;
73 | Bool tooLong;
74 |
75 | Int32 heap [ BZ_MAX_ALPHA_SIZE + 2 ];
76 | Int32 weight [ BZ_MAX_ALPHA_SIZE * 2 ];
77 | Int32 parent [ BZ_MAX_ALPHA_SIZE * 2 ];
78 |
79 | for (i = 0; i < alphaSize; i++)
80 | weight[i+1] = (freq[i] == 0 ? 1 : freq[i]) << 8;
81 |
82 | while (True) {
83 |
84 | nNodes = alphaSize;
85 | nHeap = 0;
86 |
87 | heap[0] = 0;
88 | weight[0] = 0;
89 | parent[0] = -2;
90 |
91 | for (i = 1; i <= alphaSize; i++) {
92 | parent[i] = -1;
93 | nHeap++;
94 | heap[nHeap] = i;
95 | UPHEAP(nHeap);
96 | }
97 |
98 | AssertH( nHeap < (BZ_MAX_ALPHA_SIZE+2), 2001 );
99 |
100 | while (nHeap > 1) {
101 | n1 = heap[1]; heap[1] = heap[nHeap]; nHeap--; DOWNHEAP(1);
102 | n2 = heap[1]; heap[1] = heap[nHeap]; nHeap--; DOWNHEAP(1);
103 | nNodes++;
104 | parent[n1] = parent[n2] = nNodes;
105 | weight[nNodes] = ADDWEIGHTS(weight[n1], weight[n2]);
106 | parent[nNodes] = -1;
107 | nHeap++;
108 | heap[nHeap] = nNodes;
109 | UPHEAP(nHeap);
110 | }
111 |
112 | AssertH( nNodes < (BZ_MAX_ALPHA_SIZE * 2), 2002 );
113 |
114 | tooLong = False;
115 | for (i = 1; i <= alphaSize; i++) {
116 | j = 0;
117 | k = i;
118 | while (parent[k] >= 0) { k = parent[k]; j++; }
119 | len[i-1] = j;
120 | if (j > maxLen) tooLong = True;
121 | }
122 |
123 | if (! tooLong) break;
124 |
125 | /* 17 Oct 04: keep-going condition for the following loop used
126 | to be 'i < alphaSize', which missed the last element,
127 | theoretically leading to the possibility of the compressor
128 | looping. However, this count-scaling step is only needed if
129 | one of the generated Huffman code words is longer than
130 | maxLen, which up to and including version 1.0.2 was 20 bits,
131 | which is extremely unlikely. In version 1.0.3 maxLen was
132 | changed to 17 bits, which has minimal effect on compression
133 | ratio, but does mean this scaling step is used from time to
134 | time, enough to verify that it works.
135 |
136 | This means that bzip2-1.0.3 and later will only produce
137 | Huffman codes with a maximum length of 17 bits. However, in
138 | order to preserve backwards compatibility with bitstreams
139 | produced by versions pre-1.0.3, the decompressor must still
140 | handle lengths of up to 20. */
141 |
142 | for (i = 1; i <= alphaSize; i++) {
143 | j = weight[i] >> 8;
144 | j = 1 + (j / 2);
145 | weight[i] = j << 8;
146 | }
147 | }
148 | }
149 |
150 |
151 | /*---------------------------------------------------*/
152 | void BZ2_hbAssignCodes ( Int32 *code,
153 | UChar *length,
154 | Int32 minLen,
155 | Int32 maxLen,
156 | Int32 alphaSize )
157 | {
158 | Int32 n, vec, i;
159 |
160 | vec = 0;
161 | for (n = minLen; n <= maxLen; n++) {
162 | for (i = 0; i < alphaSize; i++)
163 | if (length[i] == n) { code[i] = vec; vec++; };
164 | vec <<= 1;
165 | }
166 | }
167 |
168 |
169 | /*---------------------------------------------------*/
170 | void BZ2_hbCreateDecodeTables ( Int32 *limit,
171 | Int32 *base,
172 | Int32 *perm,
173 | UChar *length,
174 | Int32 minLen,
175 | Int32 maxLen,
176 | Int32 alphaSize )
177 | {
178 | Int32 pp, i, j, vec;
179 |
180 | pp = 0;
181 | for (i = minLen; i <= maxLen; i++)
182 | for (j = 0; j < alphaSize; j++)
183 | if (length[j] == i) { perm[pp] = j; pp++; };
184 |
185 | for (i = 0; i < BZ_MAX_CODE_LEN; i++) base[i] = 0;
186 | for (i = 0; i < alphaSize; i++) base[length[i]+1]++;
187 |
188 | for (i = 1; i < BZ_MAX_CODE_LEN; i++) base[i] += base[i-1];
189 |
190 | for (i = 0; i < BZ_MAX_CODE_LEN; i++) limit[i] = 0;
191 | vec = 0;
192 |
193 | for (i = minLen; i <= maxLen; i++) {
194 | vec += (base[i+1] - base[i]);
195 | limit[i] = vec-1;
196 | vec <<= 1;
197 | }
198 | for (i = minLen + 1; i <= maxLen; i++)
199 | base[i] = ((limit[i-1] + 1) << 1) - base[i];
200 | }
201 |
202 |
203 | /*-------------------------------------------------------------*/
204 | /*--- end huffman.c ---*/
205 | /*-------------------------------------------------------------*/
206 |
--------------------------------------------------------------------------------
/capacitor-code-update/ios/Plugin/bzip2-1.0.6/mk251.c:
--------------------------------------------------------------------------------
1 |
2 | /* Spew out a long sequence of the byte 251. When fed to bzip2
3 | versions 1.0.0 or 1.0.1, causes it to die with internal error
4 | 1007 in blocksort.c. This assertion misses an extremely rare
5 | case, which is fixed in this version (1.0.2) and above.
6 | */
7 |
8 | /* ------------------------------------------------------------------
9 | This file is part of bzip2/libbzip2, a program and library for
10 | lossless, block-sorting data compression.
11 |
12 | bzip2/libbzip2 version 1.0.6 of 6 September 2010
13 | Copyright (C) 1996-2010 Julian Seward
14 |
15 | Please read the WARNING, DISCLAIMER and PATENTS sections in the
16 | README file.
17 |
18 | This program is released under the terms of the license contained
19 | in the file LICENSE.
20 | ------------------------------------------------------------------ */
21 |
22 |
23 | #include
24 |
25 | int mk251_main ()
26 | {
27 | int i;
28 | for (i = 0; i < 48500000 ; i++)
29 | putchar(251);
30 | return 0;
31 | }
32 |
--------------------------------------------------------------------------------
/capacitor-code-update/ios/Plugin/bzip2-1.0.6/randtable.c:
--------------------------------------------------------------------------------
1 |
2 | /*-------------------------------------------------------------*/
3 | /*--- Table for randomising repetitive blocks ---*/
4 | /*--- randtable.c ---*/
5 | /*-------------------------------------------------------------*/
6 |
7 | /* ------------------------------------------------------------------
8 | This file is part of bzip2/libbzip2, a program and library for
9 | lossless, block-sorting data compression.
10 |
11 | bzip2/libbzip2 version 1.0.6 of 6 September 2010
12 | Copyright (C) 1996-2010 Julian Seward
13 |
14 | Please read the WARNING, DISCLAIMER and PATENTS sections in the
15 | README file.
16 |
17 | This program is released under the terms of the license contained
18 | in the file LICENSE.
19 | ------------------------------------------------------------------ */
20 |
21 |
22 | #include "bzlib_private.h"
23 |
24 |
25 | /*---------------------------------------------*/
26 | Int32 BZ2_rNums[512] = {
27 | 619, 720, 127, 481, 931, 816, 813, 233, 566, 247,
28 | 985, 724, 205, 454, 863, 491, 741, 242, 949, 214,
29 | 733, 859, 335, 708, 621, 574, 73, 654, 730, 472,
30 | 419, 436, 278, 496, 867, 210, 399, 680, 480, 51,
31 | 878, 465, 811, 169, 869, 675, 611, 697, 867, 561,
32 | 862, 687, 507, 283, 482, 129, 807, 591, 733, 623,
33 | 150, 238, 59, 379, 684, 877, 625, 169, 643, 105,
34 | 170, 607, 520, 932, 727, 476, 693, 425, 174, 647,
35 | 73, 122, 335, 530, 442, 853, 695, 249, 445, 515,
36 | 909, 545, 703, 919, 874, 474, 882, 500, 594, 612,
37 | 641, 801, 220, 162, 819, 984, 589, 513, 495, 799,
38 | 161, 604, 958, 533, 221, 400, 386, 867, 600, 782,
39 | 382, 596, 414, 171, 516, 375, 682, 485, 911, 276,
40 | 98, 553, 163, 354, 666, 933, 424, 341, 533, 870,
41 | 227, 730, 475, 186, 263, 647, 537, 686, 600, 224,
42 | 469, 68, 770, 919, 190, 373, 294, 822, 808, 206,
43 | 184, 943, 795, 384, 383, 461, 404, 758, 839, 887,
44 | 715, 67, 618, 276, 204, 918, 873, 777, 604, 560,
45 | 951, 160, 578, 722, 79, 804, 96, 409, 713, 940,
46 | 652, 934, 970, 447, 318, 353, 859, 672, 112, 785,
47 | 645, 863, 803, 350, 139, 93, 354, 99, 820, 908,
48 | 609, 772, 154, 274, 580, 184, 79, 626, 630, 742,
49 | 653, 282, 762, 623, 680, 81, 927, 626, 789, 125,
50 | 411, 521, 938, 300, 821, 78, 343, 175, 128, 250,
51 | 170, 774, 972, 275, 999, 639, 495, 78, 352, 126,
52 | 857, 956, 358, 619, 580, 124, 737, 594, 701, 612,
53 | 669, 112, 134, 694, 363, 992, 809, 743, 168, 974,
54 | 944, 375, 748, 52, 600, 747, 642, 182, 862, 81,
55 | 344, 805, 988, 739, 511, 655, 814, 334, 249, 515,
56 | 897, 955, 664, 981, 649, 113, 974, 459, 893, 228,
57 | 433, 837, 553, 268, 926, 240, 102, 654, 459, 51,
58 | 686, 754, 806, 760, 493, 403, 415, 394, 687, 700,
59 | 946, 670, 656, 610, 738, 392, 760, 799, 887, 653,
60 | 978, 321, 576, 617, 626, 502, 894, 679, 243, 440,
61 | 680, 879, 194, 572, 640, 724, 926, 56, 204, 700,
62 | 707, 151, 457, 449, 797, 195, 791, 558, 945, 679,
63 | 297, 59, 87, 824, 713, 663, 412, 693, 342, 606,
64 | 134, 108, 571, 364, 631, 212, 174, 643, 304, 329,
65 | 343, 97, 430, 751, 497, 314, 983, 374, 822, 928,
66 | 140, 206, 73, 263, 980, 736, 876, 478, 430, 305,
67 | 170, 514, 364, 692, 829, 82, 855, 953, 676, 246,
68 | 369, 970, 294, 750, 807, 827, 150, 790, 288, 923,
69 | 804, 378, 215, 828, 592, 281, 565, 555, 710, 82,
70 | 896, 831, 547, 261, 524, 462, 293, 465, 502, 56,
71 | 661, 821, 976, 991, 658, 869, 905, 758, 745, 193,
72 | 768, 550, 608, 933, 378, 286, 215, 979, 792, 961,
73 | 61, 688, 793, 644, 986, 403, 106, 366, 905, 644,
74 | 372, 567, 466, 434, 645, 210, 389, 550, 919, 135,
75 | 780, 773, 635, 389, 707, 100, 626, 958, 165, 504,
76 | 920, 176, 193, 713, 857, 265, 203, 50, 668, 108,
77 | 645, 990, 626, 197, 510, 357, 358, 850, 858, 364,
78 | 936, 638
79 | };
80 |
81 |
82 | /*-------------------------------------------------------------*/
83 | /*--- end randtable.c ---*/
84 | /*-------------------------------------------------------------*/
85 |
--------------------------------------------------------------------------------
/capacitor-code-update/ios/Plugin/bzip2-1.0.6/spewG.c:
--------------------------------------------------------------------------------
1 |
2 | /* spew out a thoroughly gigantic file designed so that bzip2
3 | can compress it reasonably rapidly. This is to help test
4 | support for large files (> 2GB) in a reasonable amount of time.
5 | I suggest you use the undocumented --exponential option to
6 | bzip2 when compressing the resulting file; this saves a bit of
7 | time. Note: *don't* bother with --exponential when compressing
8 | Real Files; it'll just waste a lot of CPU time :-)
9 | (but is otherwise harmless).
10 | */
11 |
12 | /* ------------------------------------------------------------------
13 | This file is part of bzip2/libbzip2, a program and library for
14 | lossless, block-sorting data compression.
15 |
16 | bzip2/libbzip2 version 1.0.6 of 6 September 2010
17 | Copyright (C) 1996-2010 Julian Seward
18 |
19 | Please read the WARNING, DISCLAIMER and PATENTS sections in the
20 | README file.
21 |
22 | This program is released under the terms of the license contained
23 | in the file LICENSE.
24 | ------------------------------------------------------------------ */
25 |
26 |
27 | #define _FILE_OFFSET_BITS 64
28 |
29 | #include
30 | #include
31 |
32 | /* The number of megabytes of junk to spew out (roughly) */
33 | #define MEGABYTES 5000
34 |
35 | #define N_BUF 1000000
36 | char buf[N_BUF];
37 |
38 | int spewG_main ( int argc, char** argv )
39 | {
40 | int ii, kk, p;
41 | srandom(1);
42 | setbuffer ( stdout, buf, N_BUF );
43 | for (kk = 0; kk < MEGABYTES * 515; kk+=3) {
44 | p = 25+random()%50;
45 | for (ii = 0; ii < p; ii++)
46 | printf ( "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" );
47 | for (ii = 0; ii < p-1; ii++)
48 | printf ( "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" );
49 | for (ii = 0; ii < p+1; ii++)
50 | printf ( "ccccccccccccccccccccccccccccccccccccc" );
51 | }
52 | fflush(stdout);
53 | return 0;
54 | }
55 |
--------------------------------------------------------------------------------
/capacitor-code-update/ios/Plugin/bzip2-1.0.6/unzcrash.c:
--------------------------------------------------------------------------------
1 |
2 | /* A test program written to test robustness to decompression of
3 | corrupted data. Usage is
4 | unzcrash filename
5 | and the program will read the specified file, compress it (in memory),
6 | and then repeatedly decompress it, each time with a different bit of
7 | the compressed data inverted, so as to test all possible one-bit errors.
8 | This should not cause any invalid memory accesses. If it does,
9 | I want to know about it!
10 |
11 | PS. As you can see from the above description, the process is
12 | incredibly slow. A file of size eg 5KB will cause it to run for
13 | many hours.
14 | */
15 |
16 | /* ------------------------------------------------------------------
17 | This file is part of bzip2/libbzip2, a program and library for
18 | lossless, block-sorting data compression.
19 |
20 | bzip2/libbzip2 version 1.0.6 of 6 September 2010
21 | Copyright (C) 1996-2010 Julian Seward
22 |
23 | Please read the WARNING, DISCLAIMER and PATENTS sections in the
24 | README file.
25 |
26 | This program is released under the terms of the license contained
27 | in the file LICENSE.
28 | ------------------------------------------------------------------ */
29 |
30 |
31 | #include
32 | #include
33 | #include "bzlib.h"
34 |
35 | #define M_BLOCK 1000000
36 |
37 | typedef unsigned char uchar;
38 |
39 | #define M_BLOCK_OUT (M_BLOCK + 1000000)
40 | uchar inbuf[M_BLOCK];
41 | uchar outbuf[M_BLOCK_OUT];
42 | uchar zbuf[M_BLOCK + 600 + (M_BLOCK / 100)];
43 |
44 | int nIn, nOut, nZ;
45 |
46 | static char *bzerrorstrings[] = {
47 | "OK"
48 | ,"SEQUENCE_ERROR"
49 | ,"PARAM_ERROR"
50 | ,"MEM_ERROR"
51 | ,"DATA_ERROR"
52 | ,"DATA_ERROR_MAGIC"
53 | ,"IO_ERROR"
54 | ,"UNEXPECTED_EOF"
55 | ,"OUTBUFF_FULL"
56 | ,"???" /* for future */
57 | ,"???" /* for future */
58 | ,"???" /* for future */
59 | ,"???" /* for future */
60 | ,"???" /* for future */
61 | ,"???" /* for future */
62 | };
63 |
64 | void flip_bit ( int bit )
65 | {
66 | int byteno = bit / 8;
67 | int bitno = bit % 8;
68 | uchar mask = 1 << bitno;
69 | //fprintf ( stderr, "(byte %d bit %d mask %d)",
70 | // byteno, bitno, (int)mask );
71 | zbuf[byteno] ^= mask;
72 | }
73 |
74 | int unzcrash_main ( int argc, char** argv )
75 | {
76 | FILE* f;
77 | int r;
78 | int bit;
79 | int i;
80 |
81 | if (argc != 2) {
82 | fprintf ( stderr, "usage: unzcrash filename\n" );
83 | return 1;
84 | }
85 |
86 | f = fopen ( argv[1], "r" );
87 | if (!f) {
88 | fprintf ( stderr, "unzcrash: can't open %s\n", argv[1] );
89 | return 1;
90 | }
91 |
92 | nIn = fread ( inbuf, 1, M_BLOCK, f );
93 | fprintf ( stderr, "%d bytes read\n", nIn );
94 |
95 | nZ = M_BLOCK;
96 | r = BZ2_bzBuffToBuffCompress (
97 | zbuf, &nZ, inbuf, nIn, 9, 0, 30 );
98 |
99 | assert (r == BZ_OK);
100 | fprintf ( stderr, "%d after compression\n", nZ );
101 |
102 | for (bit = 0; bit < nZ*8; bit++) {
103 | fprintf ( stderr, "bit %d ", bit );
104 | flip_bit ( bit );
105 | nOut = M_BLOCK_OUT;
106 | r = BZ2_bzBuffToBuffDecompress (
107 | outbuf, &nOut, zbuf, nZ, 0, 0 );
108 | fprintf ( stderr, " %d %s ", r, bzerrorstrings[-r] );
109 |
110 | if (r != BZ_OK) {
111 | fprintf ( stderr, "\n" );
112 | } else {
113 | if (nOut != nIn) {
114 | fprintf(stderr, "nIn/nOut mismatch %d %d\n", nIn, nOut );
115 | return 1;
116 | } else {
117 | for (i = 0; i < nOut; i++)
118 | if (inbuf[i] != outbuf[i]) {
119 | fprintf(stderr, "mismatch at %d\n", i );
120 | return 1;
121 | }
122 | if (i == nOut) fprintf(stderr, "really ok!\n" );
123 | }
124 | }
125 |
126 | flip_bit ( bit );
127 | }
128 |
129 | #if 0
130 | assert (nOut == nIn);
131 | for (i = 0; i < nOut; i++) {
132 | if (inbuf[i] != outbuf[i]) {
133 | fprintf ( stderr, "difference at %d !\n", i );
134 | return 1;
135 | }
136 | }
137 | #endif
138 |
139 | fprintf ( stderr, "all ok\n" );
140 | return 0;
141 | }
142 |
--------------------------------------------------------------------------------
/capacitor-code-update/ios/PluginTests/CapacitorCodeUpdateTests.swift:
--------------------------------------------------------------------------------
1 | import XCTest
2 | @testable import Plugin
3 |
4 | class CapacitorCodeUpdateTests: XCTestCase {
5 | override func setUp() {
6 | super.setUp()
7 | // Put setup code here. This method is called before the invocation of each test method in the class.
8 | }
9 |
10 | override func tearDown() {
11 | // Put teardown code here. This method is called after the invocation of each test method in the class.
12 | super.tearDown()
13 | }
14 |
15 | func testEcho() {
16 | // This is an example of a functional test case for a plugin.
17 | // Use XCTAssert and related functions to verify your tests produce the correct results.
18 |
19 | let implementation = CapacitorCodeUpdate()
20 | let value = "Hello, World!"
21 | let result = implementation.echo(value)
22 |
23 | XCTAssertEqual(value, result)
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/capacitor-code-update/ios/PluginTests/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | $(DEVELOPMENT_LANGUAGE)
7 | CFBundleExecutable
8 | $(EXECUTABLE_NAME)
9 | CFBundleIdentifier
10 | $(PRODUCT_BUNDLE_IDENTIFIER)
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundleName
14 | $(PRODUCT_NAME)
15 | CFBundlePackageType
16 | BNDL
17 | CFBundleShortVersionString
18 | 1.0
19 | CFBundleVersion
20 | 1
21 |
22 |
23 |
--------------------------------------------------------------------------------
/capacitor-code-update/ios/Podfile:
--------------------------------------------------------------------------------
1 | platform :ios, '12.0'
2 |
3 | def capacitor_pods
4 | # Comment the next line if you're not using Swift and don't want to use dynamic frameworks
5 | use_frameworks!
6 | pod 'Capacitor', :path => '../node_modules/@capacitor/ios'
7 | pod 'CapacitorCordova', :path => '../node_modules/@capacitor/ios'
8 | end
9 |
10 | target 'Plugin' do
11 | capacitor_pods
12 | end
13 |
14 | target 'PluginTests' do
15 | capacitor_pods
16 | end
17 |
--------------------------------------------------------------------------------
/capacitor-code-update/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "capacitor-code-update",
3 | "version": "0.0.1",
4 | "description": "Capacitor-Code-Update",
5 | "main": "dist/plugin.cjs.js",
6 | "module": "dist/esm/index.js",
7 | "types": "dist/esm/index.d.ts",
8 | "unpkg": "dist/plugin.js",
9 | "files": [
10 | "android/src/main/",
11 | "android/build.gradle",
12 | "dist/",
13 | "ios/Plugin/",
14 | "CapacitorCodeUpdate.podspec"
15 | ],
16 | "author": "ChenWei",
17 | "license": "Apache-2.0",
18 | "repository": {
19 | "type": "git",
20 | "url": "git+https://github.com/site-chenwei/code-update.git.git"
21 | },
22 | "bugs": {
23 | "url": "https://github.com/site-chenwei/code-update.git/issues"
24 | },
25 | "keywords": [
26 | "capacitor",
27 | "plugin",
28 | "native"
29 | ],
30 | "scripts": {
31 | "verify": "npm run verify:ios && npm run verify:android && npm run verify:web",
32 | "verify:ios": "cd ios && pod install && xcodebuild -workspace Plugin.xcworkspace -scheme Plugin && cd ..",
33 | "verify:android": "cd android && ./gradlew clean build test && cd ..",
34 | "verify:web": "npm run build",
35 | "lint": "npm run eslint && npm run prettier -- --check && npm run swiftlint -- lint",
36 | "fmt": "npm run eslint -- --fix && npm run prettier -- --write && npm run swiftlint -- --fix --format",
37 | "eslint": "eslint . --ext ts",
38 | "prettier": "prettier \"**/*.{css,html,ts,js,java}\"",
39 | "swiftlint": "node-swiftlint",
40 | "docgen": "docgen --api CapacitorCodeUpdatePlugin --output-readme README.md --output-json dist/docs.json",
41 | "build": "npm run clean && npm run docgen && tsc && rollup -c rollup.config.js",
42 | "clean": "rimraf ./dist",
43 | "watch": "tsc --watch",
44 | "prepublishOnly": "npm run build"
45 | },
46 | "devDependencies": {
47 | "@capacitor/android": "^3.0.0",
48 | "@capacitor/core": "^3.0.0",
49 | "@capacitor/cli": "^3.0.0",
50 | "@capacitor/docgen": "^0.0.18",
51 | "@capacitor/ios": "^3.0.0",
52 | "@ionic/eslint-config": "^0.3.0",
53 | "@ionic/prettier-config": "^1.0.1",
54 | "@ionic/swiftlint-config": "^1.1.2",
55 | "eslint": "^7.11.0",
56 | "prettier": "~2.2.0",
57 | "prettier-plugin-java": "~1.0.0",
58 | "rimraf": "^3.0.2",
59 | "rollup": "^2.32.0",
60 | "swiftlint": "^1.0.1",
61 | "typescript": "~4.0.3"
62 | },
63 | "peerDependencies": {
64 | "@capacitor/core": "^3.0.0"
65 | },
66 | "prettier": "@ionic/prettier-config",
67 | "swiftlint": "@ionic/swiftlint-config",
68 | "eslintConfig": {
69 | "extends": "@ionic/eslint-config/recommended"
70 | },
71 | "capacitor": {
72 | "ios": {
73 | "src": "ios"
74 | },
75 | "android": {
76 | "src": "android"
77 | }
78 | }
79 | }
80 |
--------------------------------------------------------------------------------
/capacitor-code-update/rollup.config.js:
--------------------------------------------------------------------------------
1 | export default {
2 | input: 'dist/esm/index.js',
3 | output: [
4 | {
5 | file: 'dist/plugin.js',
6 | format: 'iife',
7 | name: 'capacitorCapacitorCodeUpdate',
8 | globals: {
9 | '@capacitor/core': 'capacitorExports',
10 | },
11 | sourcemap: true,
12 | inlineDynamicImports: true,
13 | },
14 | {
15 | file: 'dist/plugin.cjs.js',
16 | format: 'cjs',
17 | sourcemap: true,
18 | inlineDynamicImports: true,
19 | },
20 | ],
21 | external: ['@capacitor/core'],
22 | };
23 |
--------------------------------------------------------------------------------
/capacitor-code-update/src/definitions.ts:
--------------------------------------------------------------------------------
1 | ///
2 | import type { Plugin } from '@capacitor/core';
3 | import type { PluginListenerHandle } from '@capacitor/core/types/definitions';
4 |
5 | declare module '@capacitor/cli' {
6 | export interface PluginConfig {
7 | CapacitorCodeUpdate: {
8 | serverUrl: string,
9 | applicationId: string
10 | };
11 | }
12 | }
13 |
14 | export interface CapacitorCodeUpdatePlugin extends Plugin {
15 | checkUpdate(): Promise;
16 |
17 | download(option: Update): Promise;
18 |
19 | install(option: { installMode: InstallMode }): Promise;
20 |
21 | addListener(eventName: 'downloadProgress', listenerFunc: (percent: string) => void): Promise;
22 | }
23 |
24 | export enum InstallMode {
25 | IMMEDIATE,
26 | NEXT_RESUME,
27 | NEXT_RESTART
28 | }
29 |
30 | export interface CodeUpdateBaseOption {
31 | applicationId: string,
32 | serverUrl: string
33 | }
34 |
35 | export interface LocalPackage {
36 | version: string;
37 | applicationId: string;
38 | versionName: string;
39 | signature: string;
40 | updateType: string;
41 | }
42 |
43 | export interface InstallResult {
44 | success: boolean;
45 | }
46 |
47 | export interface Update extends CodeUpdateBaseOption {
48 | id: string,
49 | name: string,
50 | signature: string,
51 | downloadUrl: string,
52 | updateType: 'FULL_UPDATE' | 'INCREMENTAL_UPDATE',
53 | }
54 |
--------------------------------------------------------------------------------
/capacitor-code-update/src/index.ts:
--------------------------------------------------------------------------------
1 | import {registerPlugin} from '@capacitor/core';
2 |
3 | import type {CapacitorCodeUpdatePlugin} from './definitions';
4 |
5 | const CapacitorCodeUpdate = registerPlugin(
6 | 'CapacitorCodeUpdate',
7 | {
8 | web: () => import('./web').then(m => new m.CapacitorCodeUpdateWeb()),
9 | },
10 | );
11 |
12 |
13 | export * from './definitions';
14 | export {CapacitorCodeUpdate};
15 |
--------------------------------------------------------------------------------
/capacitor-code-update/src/web.ts:
--------------------------------------------------------------------------------
1 | import { WebPlugin } from '@capacitor/core';
2 |
3 | import type { CapacitorCodeUpdatePlugin, InstallResult, LocalPackage, Update, InstallMode } from './definitions';
4 |
5 | export class CapacitorCodeUpdateWeb extends WebPlugin implements CapacitorCodeUpdatePlugin {
6 | checkUpdate(): Promise {
7 | return Promise.resolve(null);
8 | }
9 |
10 | download(option: Update): Promise {
11 | console.log('Code_Update_WEB_Download:' + option);
12 | return Promise.resolve(null);
13 | }
14 |
15 | install(option: { installMode: InstallMode }): Promise {
16 | console.log('Code_Update_WEB_Install:' + option);
17 | return Promise.resolve({ success: false });
18 | }
19 |
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/capacitor-code-update/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | "allowUnreachableCode": false,
4 | "declaration": true,
5 | "esModuleInterop": true,
6 | "inlineSources": true,
7 | "lib": ["dom", "es2017"],
8 | "module": "esnext",
9 | "moduleResolution": "node",
10 | "noFallthroughCasesInSwitch": true,
11 | "noUnusedLocals": true,
12 | "noUnusedParameters": true,
13 | "outDir": "dist/esm",
14 | "pretty": true,
15 | "sourceMap": true,
16 | "strict": true,
17 | "target": "es2017"
18 | },
19 | "files": ["src/index.ts"]
20 | }
21 |
--------------------------------------------------------------------------------
/code-update-server/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | org.springframework.boot
7 | spring-boot-starter-parent
8 | 2.6.4
9 |
10 |
11 | site.chenwei
12 | update
13 | 0.0.1-SNAPSHOT
14 | code-update-server
15 | code-update-server
16 |
17 | 1.8
18 |
19 |
20 |
21 | org.springframework.boot
22 | spring-boot-starter-web
23 |
24 |
25 | org.mybatis.spring.boot
26 | mybatis-spring-boot-starter
27 | 2.2.2
28 |
29 |
30 |
31 | org.springframework.boot
32 | spring-boot-devtools
33 | runtime
34 | true
35 |
36 |
37 | mysql
38 | mysql-connector-java
39 | runtime
40 |
41 |
42 | org.springframework.boot
43 | spring-boot-starter-aop
44 |
45 |
46 | org.aspectj
47 | aspectjweaver
48 |
49 |
50 | org.springframework.boot
51 | spring-boot-configuration-processor
52 | true
53 |
54 |
55 | org.projectlombok
56 | lombok
57 | true
58 |
59 |
60 | org.springframework.boot
61 | spring-boot-starter-test
62 | test
63 |
64 |
65 | com.qiniu
66 | qiniu-java-sdk
67 | 7.9.3
68 |
69 |
70 | org.apache.commons
71 | commons-compress
72 | 1.20
73 |
74 |
75 | cn.hutool
76 | hutool-all
77 | 5.7.22
78 |
79 |
80 | org.apache.commons
81 | commons-lang3
82 |
83 |
84 |
85 |
86 |
87 |
88 | org.springframework.boot
89 | spring-boot-maven-plugin
90 |
91 |
92 |
93 | org.projectlombok
94 | lombok
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
--------------------------------------------------------------------------------
/code-update-server/src/main/java/site/chenwei/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/site-chenwei/code-update/d8d40ff1643f47509696f39433b4bce4214f78e7/code-update-server/src/main/java/site/chenwei/.DS_Store
--------------------------------------------------------------------------------
/code-update-server/src/main/java/site/chenwei/update/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/site-chenwei/code-update/d8d40ff1643f47509696f39433b4bce4214f78e7/code-update-server/src/main/java/site/chenwei/update/.DS_Store
--------------------------------------------------------------------------------
/code-update-server/src/main/java/site/chenwei/update/CodeUpdateServerApplication.java:
--------------------------------------------------------------------------------
1 | package site.chenwei.update;
2 |
3 | import org.mybatis.spring.annotation.MapperScan;
4 | import org.springframework.boot.SpringApplication;
5 | import org.springframework.boot.autoconfigure.SpringBootApplication;
6 | import org.springframework.boot.context.properties.ConfigurationPropertiesScan;
7 | import org.springframework.transaction.annotation.EnableTransactionManagement;
8 |
9 | @ConfigurationPropertiesScan
10 | @SpringBootApplication
11 | @EnableTransactionManagement
12 | @MapperScan(basePackages = "site.chenwei.update.mapper")
13 | public class CodeUpdateServerApplication {
14 |
15 | public static void main(String[] args) {
16 | SpringApplication.run(CodeUpdateServerApplication.class, args);
17 | }
18 |
19 | }
20 |
--------------------------------------------------------------------------------
/code-update-server/src/main/java/site/chenwei/update/common/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/site-chenwei/code-update/d8d40ff1643f47509696f39433b4bce4214f78e7/code-update-server/src/main/java/site/chenwei/update/common/.DS_Store
--------------------------------------------------------------------------------
/code-update-server/src/main/java/site/chenwei/update/common/bsdiff/BSDiff.java:
--------------------------------------------------------------------------------
1 | package site.chenwei.update.common.bsdiff;
2 |
3 | import cn.hutool.core.io.FileUtil;
4 |
5 | import java.io.File;
6 | import java.net.URL;
7 |
8 | /**
9 | * @author cw
10 | * @date 2022年03月17日 13:47
11 | */
12 | public class BSDiff {
13 | private static String BS_DIFF_PATH;
14 | private static String BS_DIFF_NAME = "bsdiff";
15 |
16 | static {
17 | try {
18 | URL resource = BSDiff.class.getResource("/bsdiff/bsdiff");
19 | String currentPath = System.getProperty("user.dir");
20 | File file = new File(currentPath + File.separator + BS_DIFF_NAME);
21 | if (resource != null) {
22 | BS_DIFF_PATH = resource.getPath();
23 | if (file.exists()) {
24 | file.delete();
25 | }
26 | FileUtil.copyFile(new File(BS_DIFF_PATH), file);
27 | BS_DIFF_PATH = currentPath + File.separator + BS_DIFF_NAME;
28 | }
29 | } catch (Exception e) {
30 | e.printStackTrace();
31 | }
32 | }
33 |
34 | public static boolean diff(String oldPath, String newPath, String patchPath) {
35 | try {
36 | Runtime runtime = Runtime.getRuntime();
37 | Process exec = runtime.exec(BS_DIFF_PATH + " " + oldPath + " " + newPath + " " + patchPath);
38 | exec.waitFor();
39 | return true;
40 | } catch (Exception e) {
41 | e.printStackTrace();
42 | }
43 | return false;
44 | }
45 |
46 | public static void main(String[] args) {
47 | BSDiff.diff("/Users/cw/Documents/code/cw/code-update/version/2022031700000001/2022031700000002/dist.zip", "/Users/cw/Documents/code/cw/code-update/version/2022031700000001/2022031700000003/dist2.zip", "/Users/cw/Documents/code/cw/code-update/version/2022031700000001/2022031700000002/patch/patch.zip");
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/code-update-server/src/main/java/site/chenwei/update/common/bsdiff/BSPatch.java:
--------------------------------------------------------------------------------
1 | package site.chenwei.update.common.bsdiff;
2 |
3 | import org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream;
4 |
5 | import java.io.*;
6 |
7 | public class BSPatch {
8 | private RandomAccessFile mOld;
9 | private OutputStream mNew;
10 | private InputStream mPatch;
11 |
12 | private InputStream bzCtrl;
13 | private InputStream bzData;
14 | private InputStream bzExtra;
15 |
16 | private BSPatch(RandomAccessFile old, OutputStream New, InputStream patch) {
17 | mOld = old;
18 | mNew = New;
19 | mPatch = patch;
20 | }
21 |
22 | private static long readLong(InputStream is) throws IOException {
23 | byte[] bytes = new byte[8];
24 | is.read(bytes);
25 | long ret = ((long) (bytes[7] & 0x7F) << 56) | ((long) (bytes[6] & 0xFF) << 48) | ((long) (bytes[5] & 0xFF) << 40) | ((long) (bytes[4] & 0xFF) << 32) | ((long) (bytes[3] & 0xFF) << 24) | ((long) (bytes[2] & 0xFF) << 16) | ((long) (bytes[1] & 0xFF) << 8) | ((long) (bytes[0] & 0xFF));
26 | return ((bytes[7] & 0x80) != 0) ? -ret : ret;
27 | }
28 |
29 | private static void checkHeader(InputStream is) throws IOException {
30 | /* Check header for appropriate magic 'BSDIFF40' */
31 | byte[] bytes = new byte[8];
32 | is.read(bytes);
33 | String str = new String(bytes);
34 | if (!str.equals("BSDIFF40")) {
35 | throw new IOException("patch file doesn't start from 'BSDIFF40'" + " but with '" + str + "'");
36 | }
37 | }
38 |
39 | private long readPatchFile() throws IOException {
40 | /* Check for appropriate magic */
41 | checkHeader(mPatch);
42 |
43 | /* Read lengths from header */
44 | long bzCtrlLen = readLong(mPatch);
45 | long bzDataLen = readLong(mPatch);
46 | long newSize = readLong(mPatch);
47 | if (bzCtrlLen < 0 || bzDataLen < 0 || newSize < 0 || bzCtrlLen > Integer.MAX_VALUE || bzDataLen > Integer.MAX_VALUE) {
48 | throw new IOException("bzCtrlLen=" + bzCtrlLen + ", bzDataLen=" + bzDataLen + ", newSize=" + newSize);
49 | }
50 |
51 | byte[] bytes = new byte[(int) bzCtrlLen];
52 | mPatch.read(bytes);
53 | bzCtrl = new BZip2CompressorInputStream(new ByteArrayInputStream(bytes));
54 | bytes = new byte[(int) bzDataLen];
55 | mPatch.read(bytes);
56 | bzData = new BZip2CompressorInputStream(new ByteArrayInputStream(bytes));
57 | bzExtra = new BZip2CompressorInputStream(new BufferedInputStream(mPatch));
58 |
59 | return newSize;
60 | }
61 |
62 | private void writeDiffData(long diffLen) throws IOException {
63 | byte[] bytes = new byte[1024];
64 | byte[] bytes2 = new byte[1024];
65 | /* Read diff string and add old data to diff string */
66 | for (long i = 0; i < diffLen; ) {
67 | int len = (i + bytes.length > diffLen) ? (int) (diffLen - i) : bytes.length;
68 | len = bzData.read(bytes, 0, len);
69 | mOld.readFully(bytes2, 0, len);
70 | for (int j = 0; j < len; j++) {
71 | bytes[j] += bytes2[j];
72 | }
73 | mNew.write(bytes, 0, len);
74 | i += len;
75 | }
76 | mNew.flush();
77 | }
78 |
79 | private void writeExtraData(long extraLen) throws IOException {
80 | byte[] bytes = new byte[1024];
81 | /* Read extra string */
82 | for (long i = 0; i < extraLen; ) {
83 | int len = (i + bytes.length > extraLen) ? (int) (extraLen - i) : bytes.length;
84 | len = bzExtra.read(bytes, 0, len);
85 | mNew.write(bytes, 0, len);
86 | i += len;
87 | }
88 | mNew.flush();
89 | }
90 |
91 | private void patch() throws IOException {
92 | long newSize = readPatchFile();
93 |
94 | long newPos = 0;
95 | while (newPos < newSize) {
96 | /* Read control data */
97 | long diffLen = readLong(bzCtrl);
98 | long extraLen = readLong(bzCtrl);
99 | long adjustLen = readLong(bzCtrl);
100 |
101 | /* Sanity-check */
102 | if (newPos + diffLen > newSize) {
103 | throw new IOException("newPos(" + newPos + ") + diffLen(" + diffLen + ") > newSize(" + newSize + ")");
104 | }
105 | writeDiffData(diffLen);
106 | newPos += diffLen;
107 |
108 | /* Sanity-check */
109 | if (newPos + extraLen > newSize) {
110 | throw new IOException("newPos(" + newPos + ") + extraLen(" + extraLen + ") > newSize(" + newSize + ")");
111 | }
112 | writeExtraData(extraLen);
113 | newPos += extraLen;
114 | mOld.seek(mOld.getFilePointer() + adjustLen);
115 | }
116 |
117 | bzCtrl.close();
118 | bzData.close();
119 | bzExtra.close();
120 | }
121 |
122 | private void close() throws IOException {
123 | mOld.close();
124 | mNew.close();
125 | mPatch.close();
126 | }
127 |
128 | public static void patch(String oldPath, String newPath, String patchPath) throws IOException {
129 | BSPatch This = new BSPatch(new RandomAccessFile(oldPath, "r"), new FileOutputStream(newPath), new FileInputStream(patchPath));
130 | This.patch();
131 | This.close();
132 | }
133 | }
134 |
--------------------------------------------------------------------------------
/code-update-server/src/main/java/site/chenwei/update/common/config/CodeUpdateConfig.java:
--------------------------------------------------------------------------------
1 | package site.chenwei.update.common.config;
2 |
3 | import lombok.Data;
4 | import org.springframework.boot.context.properties.ConfigurationProperties;
5 | import org.springframework.boot.context.properties.EnableConfigurationProperties;
6 | import org.springframework.stereotype.Component;
7 |
8 | /**
9 | * @author cw
10 | * @date 2022年03月17日 09:50
11 | */
12 | @Data
13 | @Component
14 | @EnableConfigurationProperties
15 | @ConfigurationProperties(prefix = "code.update")
16 | public class CodeUpdateConfig {
17 |
18 | private String qiNiuSecretKey;
19 |
20 | private String qiNiuAccessKey;
21 |
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/code-update-server/src/main/java/site/chenwei/update/common/constant/CommonConstants.java:
--------------------------------------------------------------------------------
1 | package site.chenwei.update.common.constant;
2 |
3 | /**
4 | * @author cw
5 | * @date 2022年02月24日 17:38
6 | */
7 | public class CommonConstants {
8 | public interface Request {
9 | String SUCCESS = "S000000";
10 | String SUCCESS_MESSAGE = "操作成功";
11 | String ERROR = "E000000";
12 | String ERROR_MESSAGE = "操作失败";
13 | String INTERNAL_ERROR = "E000001";
14 | String INTERNAL_ERROR_MESSAGE = "服务器异常,请稍后再试";
15 | String PARAM_ERROR = "E000002";
16 | String PARAM_ERROR_MESSAGE = "参数有误,请重试";
17 | String NO_DOWNLOAD_URL_PREFIX = "E000003";
18 | String NO_FILE_BASE_URL = "E000004";
19 |
20 | }
21 |
22 | public interface MediaType {
23 | String APPLICATION_JSON_UTF8 = "application/json;charset=UTF-8";
24 | String APPLICATION_JSON = "application/json";
25 | String TEXT_PLAIN = "text/plain";
26 | String TEXT_PLAIN_UTF8 = "text/plain; charset=utf-8";
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/code-update-server/src/main/java/site/chenwei/update/common/constant/SerialNoConstant.java:
--------------------------------------------------------------------------------
1 | package site.chenwei.update.common.constant;
2 |
3 | /**
4 | * @author cw
5 | * @date 2022年03月16日 20:44
6 | */
7 | public interface SerialNoConstant {
8 | String SYSTEM_CONFIG = "system_config";
9 | String APPLICATION_SERIAL = "application_id_serial";
10 | String APPLICATION_VERSION_SERIAL = "application_version_serial";
11 | String UPDATE_RECORDER_SERIAL = "update_recorder_serial";
12 | }
13 |
--------------------------------------------------------------------------------
/code-update-server/src/main/java/site/chenwei/update/common/constant/SystemConfigConstant.java:
--------------------------------------------------------------------------------
1 | package site.chenwei.update.common.constant;
2 |
3 | /**
4 | * @author cw
5 | * @date 2022年03月17日 16:34
6 | */
7 | public interface SystemConfigConstant {
8 | String FILE_BASE_PATH = "file.base.path";
9 | String DOWNLOAD_URL_PREFIX = "download.url.prefix";
10 | }
11 |
--------------------------------------------------------------------------------
/code-update-server/src/main/java/site/chenwei/update/common/exception/BusinessException.java:
--------------------------------------------------------------------------------
1 | package site.chenwei.update.common.exception;
2 |
3 | import lombok.AllArgsConstructor;
4 | import lombok.Data;
5 | import lombok.EqualsAndHashCode;
6 |
7 | /**
8 | * @author cw
9 | * @date 2022年03月15日 13:24
10 | */
11 | @Data
12 | @AllArgsConstructor
13 | @EqualsAndHashCode(callSuper = true)
14 | public class BusinessException extends RuntimeException {
15 | private String code;
16 | private String msg;
17 | }
18 |
--------------------------------------------------------------------------------
/code-update-server/src/main/java/site/chenwei/update/common/exception/SerialException.java:
--------------------------------------------------------------------------------
1 | package site.chenwei.update.common.exception;
2 |
3 | import lombok.Data;
4 | import lombok.EqualsAndHashCode;
5 |
6 | /**
7 | * @author cw
8 | * @date 2022年03月17日 09:41
9 | */
10 | @Data
11 | @EqualsAndHashCode(callSuper = true)
12 | public class SerialException extends Exception {
13 | private String msg;
14 |
15 | public SerialException(String msg) {
16 | this.msg = msg;
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/code-update-server/src/main/java/site/chenwei/update/common/exception/resolver/ExceptionResolver.java:
--------------------------------------------------------------------------------
1 | package site.chenwei.update.common.exception.resolver;
2 |
3 | import org.springframework.web.bind.annotation.ExceptionHandler;
4 | import org.springframework.web.bind.annotation.RestControllerAdvice;
5 | import site.chenwei.update.common.constant.CommonConstants;
6 | import site.chenwei.update.common.exception.BusinessException;
7 | import site.chenwei.update.common.model.Result;
8 |
9 | /**
10 | * @author cw
11 | * @date 2022年03月17日 09:16
12 | */
13 | @RestControllerAdvice
14 | public class ExceptionResolver {
15 | @ExceptionHandler(value = Exception.class)
16 | public Result resolve(Exception e) {
17 | if (e instanceof BusinessException) {
18 | BusinessException businessException = (BusinessException) e;
19 | return Result.error(businessException.getCode(), businessException.getMessage());
20 | }
21 | return Result.error(CommonConstants.Request.INTERNAL_ERROR, CommonConstants.Request.INTERNAL_ERROR_MESSAGE);
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/code-update-server/src/main/java/site/chenwei/update/common/model/Result.java:
--------------------------------------------------------------------------------
1 | package site.chenwei.update.common.model;
2 |
3 | import lombok.AllArgsConstructor;
4 | import lombok.Builder;
5 | import lombok.Data;
6 | import lombok.NoArgsConstructor;
7 | import site.chenwei.update.common.constant.CommonConstants;
8 |
9 | /**
10 | * @author cw
11 | * @date 2022年02月24日 17:21
12 | */
13 | @Data
14 | @AllArgsConstructor
15 | @NoArgsConstructor
16 | @Builder
17 | public class Result {
18 | private String message;
19 | private R data;
20 | private String code;
21 |
22 | public static Result success(T data) {
23 | ResultBuilder builder = Result.builder();
24 | return builder.data(data).message(CommonConstants.Request.SUCCESS_MESSAGE).code(CommonConstants.Request.SUCCESS).build();
25 | }
26 |
27 | public static Result success(T data, String code) {
28 | ResultBuilder builder = Result.builder();
29 | return builder.data(data).message(CommonConstants.Request.SUCCESS_MESSAGE).code(code).build();
30 | }
31 |
32 | public static Result success(T data, String code, String message) {
33 | ResultBuilder builder = Result.builder();
34 | return builder.data(data).message(message).code(code).build();
35 | }
36 |
37 | public static Result error(String code, String message) {
38 | ResultBuilder builder = Result.builder();
39 | return builder.data(null).message(message).code(code).build();
40 | }
41 |
42 | public static Result error() {
43 | ResultBuilder builder = Result.builder();
44 | return builder.data(null).message(CommonConstants.Request.INTERNAL_ERROR_MESSAGE).code(CommonConstants.Request.INTERNAL_ERROR).build();
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/code-update-server/src/main/java/site/chenwei/update/common/model/SerialNo.java:
--------------------------------------------------------------------------------
1 | package site.chenwei.update.common.model;
2 |
3 | import lombok.AllArgsConstructor;
4 | import lombok.Builder;
5 | import lombok.Data;
6 | import lombok.NoArgsConstructor;
7 |
8 | import java.util.Date;
9 |
10 |
11 | /**
12 | * @author cw
13 | * @date 2022年03月16日 20:50
14 | */
15 | @Data
16 | @Builder
17 | @AllArgsConstructor
18 | @NoArgsConstructor
19 | public class SerialNo {
20 | private String id;
21 |
22 | private String name;
23 |
24 | private Long value;
25 |
26 | private Date createTime;
27 |
28 | private Date updateTime;
29 |
30 | /**
31 | * 序列格式:yyyyMMdd########
32 | */
33 | private String format;
34 | }
35 |
--------------------------------------------------------------------------------
/code-update-server/src/main/java/site/chenwei/update/common/serialNo/SerialNoGenerator.java:
--------------------------------------------------------------------------------
1 | package site.chenwei.update.common.serialNo;
2 |
3 | import site.chenwei.update.common.exception.SerialException;
4 | import site.chenwei.update.common.model.SerialNo;
5 | import site.chenwei.update.mapper.SerialNoMapper;
6 |
7 | import java.text.SimpleDateFormat;
8 | import java.util.Date;
9 |
10 | /**
11 | * @author cw
12 | * @date 2022年03月16日 20:53
13 | */
14 | public class SerialNoGenerator {
15 | private final SerialNoMapper serialNoMapper;
16 | private SerialNo serialNo;
17 |
18 | public SerialNoGenerator(SerialNoMapper serialNoMapper, SerialNo serialNo) {
19 | this.serialNoMapper = serialNoMapper;
20 | this.serialNo = serialNo;
21 | }
22 |
23 | public synchronized String generate() throws SerialException {
24 | SerialNo serialNo = serialNoMapper.selectByPrimaryKey(this.serialNo.getId());
25 | serialNo.setValue(serialNo.getValue() + 1);
26 | String serialStr = format(serialNo.getValue(), serialNo.getFormat());
27 | serialNoMapper.updateByPrimaryKey(serialNo);
28 | this.serialNo = serialNo;
29 | return serialStr;
30 | }
31 |
32 | private String format(Long value, String format) throws SerialException {
33 | try {
34 | String dateFormat = format.replaceAll("#", "");
35 | SimpleDateFormat simpleDateFormat = new SimpleDateFormat(dateFormat);
36 | String formattedDateStr = simpleDateFormat.format(new Date());
37 | StringBuilder stringBuilder = new StringBuilder(format.replace(dateFormat, formattedDateStr));
38 | String valueStr = String.valueOf(value);
39 | int zeroIndex = formattedDateStr.length();
40 | while (zeroIndex < format.length() - valueStr.length()) {
41 | stringBuilder.replace(zeroIndex, zeroIndex + 1, "0");
42 | zeroIndex++;
43 | }
44 | int valueIndex = zeroIndex;
45 | while (zeroIndex < format.length()) {
46 | stringBuilder.replace(zeroIndex, zeroIndex + 1, String.valueOf(valueStr.charAt(zeroIndex - valueIndex)));
47 | zeroIndex++;
48 | }
49 | return stringBuilder.toString();
50 | } catch (Exception e) {
51 | throw new SerialException("生成序列号失败");
52 | }
53 | }
54 |
55 |
56 | public static void main(String[] args) throws SerialException {
57 | SerialNoGenerator serialNoGenerator = new SerialNoGenerator(null, null);
58 | String format = serialNoGenerator.format(0L, "yyyyMMdd########");
59 | System.out.println();
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/code-update-server/src/main/java/site/chenwei/update/common/util/FileUtils.java:
--------------------------------------------------------------------------------
1 | package site.chenwei.update.common.util;
2 |
3 | /**
4 | * @author cw
5 | * @date 2022年03月17日 15:07
6 | */
7 | public class FileUtils {
8 | }
9 |
--------------------------------------------------------------------------------
/code-update-server/src/main/java/site/chenwei/update/common/util/MD5Util.java:
--------------------------------------------------------------------------------
1 | package site.chenwei.update.common.util;
2 |
3 | import org.springframework.util.DigestUtils;
4 |
5 | import java.io.IOException;
6 | import java.io.InputStream;
7 |
8 | /**
9 | * @author cw
10 | * @date 2022年03月17日 14:55
11 | */
12 | public class MD5Util {
13 | public static String md5(InputStream inputStream) {
14 | try {
15 | return DigestUtils.md5DigestAsHex(inputStream);
16 | } catch (IOException e) {
17 | e.printStackTrace();
18 | }
19 | return "";
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/code-update-server/src/main/java/site/chenwei/update/common/util/QiNiuFileUtil.java:
--------------------------------------------------------------------------------
1 | package site.chenwei.update.common.util;
2 |
3 | import org.springframework.stereotype.Component;
4 | import site.chenwei.update.common.config.CodeUpdateConfig;
5 |
6 | import javax.annotation.Resource;
7 |
8 | /**
9 | * @author cw
10 | * @date 2022年03月17日 09:47
11 | */
12 | @Component
13 | public class QiNiuFileUtil {
14 | @Resource
15 | CodeUpdateConfig codeUpdateConfig;
16 | }
17 |
--------------------------------------------------------------------------------
/code-update-server/src/main/java/site/chenwei/update/controller/ApplicationVersionController.java:
--------------------------------------------------------------------------------
1 | package site.chenwei.update.controller;
2 |
3 | import org.springframework.web.bind.annotation.RequestMapping;
4 | import org.springframework.web.bind.annotation.RequestPart;
5 | import org.springframework.web.bind.annotation.RestController;
6 | import org.springframework.web.multipart.MultipartFile;
7 | import site.chenwei.update.common.model.Result;
8 | import site.chenwei.update.model.ApplicationVersion;
9 | import site.chenwei.update.model.UpdateRecorder;
10 | import site.chenwei.update.service.ApplicationVersionService;
11 | import site.chenwei.update.service.UpdateRecorderService;
12 |
13 | import javax.annotation.Resource;
14 |
15 | /**
16 | * @author cw
17 | * @date 2022年03月17日 15:03
18 | */
19 | @RestController()
20 | @RequestMapping("application/version")
21 | public class ApplicationVersionController {
22 | @Resource
23 | ApplicationVersionService applicationVersionService;
24 | @Resource
25 | UpdateRecorderService updateRecorderService;
26 |
27 | @RequestMapping("new")
28 | public Result newVersion(@RequestPart(name = "file") MultipartFile file, ApplicationVersion applicationVersion) {
29 | return Result.success(applicationVersionService.newVersion(file, applicationVersion));
30 | }
31 |
32 | @RequestMapping("check")
33 | public Result checkUpdate(ApplicationVersion applicationVersion, UpdateRecorder updateRecorder) {
34 | return Result.success(applicationVersionService.checkUpdate(applicationVersion, updateRecorder));
35 | }
36 |
37 | @RequestMapping("status/sync")
38 | public Result syncStatus(UpdateRecorder updateRecorder) {
39 | return Result.success(updateRecorderService.syncStatus(updateRecorder));
40 | }
41 |
42 |
43 | }
44 |
--------------------------------------------------------------------------------
/code-update-server/src/main/java/site/chenwei/update/controller/SystemConfigController.java:
--------------------------------------------------------------------------------
1 | package site.chenwei.update.controller;
2 |
3 | import org.springframework.web.bind.annotation.RequestMapping;
4 | import org.springframework.web.bind.annotation.RestController;
5 | import site.chenwei.update.common.model.Result;
6 | import site.chenwei.update.model.SystemConfig;
7 | import site.chenwei.update.service.SystemConfigService;
8 |
9 | import javax.annotation.Resource;
10 |
11 | /**
12 | * @author cw
13 | * @date 2022年03月17日 16:20
14 | */
15 | @RestController
16 | @RequestMapping("system/config")
17 | public class SystemConfigController {
18 | @Resource
19 | SystemConfigService systemConfigService;
20 |
21 | @RequestMapping("new")
22 | public Result newConfig(SystemConfig systemConfig) {
23 | return Result.success(systemConfigService.newConfig(systemConfig));
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/code-update-server/src/main/java/site/chenwei/update/mapper/ApplicationMapper.java:
--------------------------------------------------------------------------------
1 | package site.chenwei.update.mapper;
2 |
3 | import java.util.List;
4 | import org.apache.ibatis.annotations.Param;
5 | import site.chenwei.update.model.Application;
6 |
7 |
8 | /**
9 | * @author cw
10 | * @date 2022年03月17日 15:02
11 | */
12 | public interface ApplicationMapper {
13 | int deleteByPrimaryKey(String id);
14 |
15 | int insert(Application record);
16 |
17 | int insertOrUpdate(Application record);
18 |
19 | int insertOrUpdateSelective(Application record);
20 |
21 | int insertSelective(Application record);
22 |
23 | Application selectByPrimaryKey(String id);
24 |
25 | int updateByPrimaryKeySelective(Application record);
26 |
27 | int updateByPrimaryKey(Application record);
28 |
29 | int updateBatch(List list);
30 |
31 | int batchInsert(@Param("list") List list);
32 | }
--------------------------------------------------------------------------------
/code-update-server/src/main/java/site/chenwei/update/mapper/ApplicationVersionMapper.java:
--------------------------------------------------------------------------------
1 | package site.chenwei.update.mapper;
2 |
3 | import org.apache.ibatis.annotations.Param;
4 | import site.chenwei.update.model.ApplicationVersion;
5 |
6 | import java.util.List;
7 |
8 |
9 | /**
10 | * @author cw
11 | * @date 2022年03月17日 18:09
12 | */
13 | public interface ApplicationVersionMapper {
14 | int deleteByPrimaryKey(String id);
15 |
16 | int insert(ApplicationVersion record);
17 |
18 | int insertOrUpdate(ApplicationVersion record);
19 |
20 | int insertOrUpdateSelective(ApplicationVersion record);
21 |
22 | int insertSelective(ApplicationVersion record);
23 |
24 | ApplicationVersion selectByPrimaryKey(String id);
25 |
26 | int updateByPrimaryKeySelective(ApplicationVersion record);
27 |
28 | int updateByPrimaryKey(ApplicationVersion record);
29 |
30 | int updateBatch(List list);
31 |
32 | int batchInsert(@Param("list") List list);
33 |
34 | ApplicationVersion selectByApplicationIdAndSignature(String applicationId, String signature);
35 |
36 | List selectListByApplicationId(String applicationId);
37 |
38 | ApplicationVersion selectCurrentVersionByApplicationID(String applicationId);
39 | }
40 |
--------------------------------------------------------------------------------
/code-update-server/src/main/java/site/chenwei/update/mapper/SerialNoMapper.java:
--------------------------------------------------------------------------------
1 | package site.chenwei.update.mapper;
2 |
3 | import org.apache.ibatis.annotations.Param;
4 | import site.chenwei.update.common.model.SerialNo;
5 |
6 | import java.util.List;
7 |
8 |
9 | /**
10 | * @author cw
11 | * @date 2022年03月16日 20:50
12 | */
13 | public interface SerialNoMapper {
14 | int deleteByPrimaryKey(String id);
15 |
16 | int insert(SerialNo record);
17 |
18 | int insertOrUpdate(SerialNo record);
19 |
20 | int insertOrUpdateSelective(SerialNo record);
21 |
22 | int insertSelective(SerialNo record);
23 |
24 | SerialNo selectByPrimaryKey(String id);
25 |
26 | int updateByPrimaryKeySelective(SerialNo record);
27 |
28 | int updateByPrimaryKey(SerialNo record);
29 |
30 | int updateBatch(List list);
31 |
32 | int batchInsert(@Param("list") List list);
33 |
34 | List selectAllSerialNos();
35 | }
36 |
--------------------------------------------------------------------------------
/code-update-server/src/main/java/site/chenwei/update/mapper/SystemConfigMapper.java:
--------------------------------------------------------------------------------
1 | package site.chenwei.update.mapper;
2 |
3 | import org.apache.ibatis.annotations.Param;
4 | import site.chenwei.update.model.SystemConfig;
5 |
6 | import java.util.List;
7 |
8 |
9 | /**
10 | * @author cw
11 | * @date 2022年03月17日 15:02
12 | */
13 | public interface SystemConfigMapper {
14 | int deleteByPrimaryKey(String id);
15 |
16 | int insert(SystemConfig record);
17 |
18 | int insertOrUpdate(SystemConfig record);
19 |
20 | int insertOrUpdateSelective(SystemConfig record);
21 |
22 | int insertSelective(SystemConfig record);
23 |
24 | SystemConfig selectByPrimaryKey(String id);
25 | SystemConfig selectByName(String name);
26 |
27 | int updateByPrimaryKeySelective(SystemConfig record);
28 |
29 | int updateByPrimaryKey(SystemConfig record);
30 |
31 | int updateBatch(List list);
32 |
33 | int batchInsert(@Param("list") List list);
34 | }
35 |
--------------------------------------------------------------------------------
/code-update-server/src/main/java/site/chenwei/update/mapper/UpdateRecorderMapper.java:
--------------------------------------------------------------------------------
1 | package site.chenwei.update.mapper;
2 |
3 | import java.util.List;
4 | import org.apache.ibatis.annotations.Param;
5 | import site.chenwei.update.model.UpdateRecorder;
6 |
7 |
8 | /**
9 | * @author cw
10 | * @date 2022年03月18日 20:39
11 | */
12 | public interface UpdateRecorderMapper {
13 | int deleteByPrimaryKey(String id);
14 |
15 | int insert(UpdateRecorder record);
16 |
17 | int insertOrUpdate(UpdateRecorder record);
18 |
19 | int insertOrUpdateSelective(UpdateRecorder record);
20 |
21 | int insertSelective(UpdateRecorder record);
22 |
23 | UpdateRecorder selectByPrimaryKey(String id);
24 |
25 | int updateByPrimaryKeySelective(UpdateRecorder record);
26 |
27 | int updateByPrimaryKey(UpdateRecorder record);
28 |
29 | int updateBatch(List list);
30 |
31 | int batchInsert(@Param("list") List list);
32 | }
--------------------------------------------------------------------------------
/code-update-server/src/main/java/site/chenwei/update/model/Application.java:
--------------------------------------------------------------------------------
1 | package site.chenwei.update.model;
2 |
3 | import java.util.Date;
4 | import lombok.AllArgsConstructor;
5 | import lombok.Builder;
6 | import lombok.Data;
7 | import lombok.NoArgsConstructor;
8 |
9 |
10 | /**
11 | * @author cw
12 | * @date 2022年03月17日 15:02
13 | */
14 | @Data
15 | @Builder
16 | @AllArgsConstructor
17 | @NoArgsConstructor
18 | public class Application {
19 | private String id;
20 |
21 | private String name;
22 |
23 | private Date createTime;
24 |
25 | private Date updateTime;
26 |
27 | private String enableStatus;
28 | }
--------------------------------------------------------------------------------
/code-update-server/src/main/java/site/chenwei/update/model/ApplicationVersion.java:
--------------------------------------------------------------------------------
1 | package site.chenwei.update.model;
2 |
3 | import com.fasterxml.jackson.annotation.JsonIgnore;
4 | import lombok.AllArgsConstructor;
5 | import lombok.Builder;
6 | import lombok.Data;
7 | import lombok.NoArgsConstructor;
8 |
9 | import java.util.Date;
10 |
11 |
12 | /**
13 | * @author cw
14 | * @date 2022年03月17日 18:09
15 | */
16 | @Data
17 | @Builder
18 | @AllArgsConstructor
19 | @NoArgsConstructor
20 | public class ApplicationVersion {
21 | private String id;
22 |
23 | private String applicationId;
24 |
25 | private String name;
26 |
27 | @JsonIgnore
28 | private Date createTime;
29 |
30 | @JsonIgnore
31 | private Date updateTime;
32 |
33 | @JsonIgnore
34 | private String enableStatus;
35 |
36 | private String signature;
37 |
38 | @JsonIgnore
39 | private String versionFile;
40 |
41 | @JsonIgnore
42 | private String patchFile;
43 |
44 | @JsonIgnore
45 | private Boolean currentVersion;
46 | }
47 |
--------------------------------------------------------------------------------
/code-update-server/src/main/java/site/chenwei/update/model/SystemConfig.java:
--------------------------------------------------------------------------------
1 | package site.chenwei.update.model;
2 |
3 | import java.util.Date;
4 | import lombok.AllArgsConstructor;
5 | import lombok.Builder;
6 | import lombok.Data;
7 | import lombok.NoArgsConstructor;
8 |
9 |
10 | /**
11 | * @author cw
12 | * @date 2022年03月17日 15:02
13 | */
14 | @Data
15 | @Builder
16 | @AllArgsConstructor
17 | @NoArgsConstructor
18 | public class SystemConfig {
19 | private String id;
20 |
21 | private String name;
22 |
23 | private String value;
24 |
25 | private Date createTime;
26 |
27 | private Date updateTime;
28 |
29 | private String enableStatus;
30 | }
--------------------------------------------------------------------------------
/code-update-server/src/main/java/site/chenwei/update/model/UpdateRecorder.java:
--------------------------------------------------------------------------------
1 | package site.chenwei.update.model;
2 |
3 | import lombok.AllArgsConstructor;
4 | import lombok.Builder;
5 | import lombok.Data;
6 | import lombok.NoArgsConstructor;
7 |
8 | import java.util.Date;
9 |
10 |
11 | /**
12 | * 更新记录
13 | *
14 | * @author cw
15 | * @date 2022年03月18日 20:39
16 | */
17 | @Data
18 | @Builder
19 | @AllArgsConstructor
20 | @NoArgsConstructor
21 | public class UpdateRecorder {
22 | private String id;
23 |
24 | private String serialId;
25 |
26 | private String phoneOsType;
27 |
28 | private String phoneVersion;
29 |
30 | private String phoneType;
31 |
32 | private String versionName;
33 |
34 | private String applicationId;
35 |
36 | private String applicationVersionId;
37 |
38 | private Date createTime;
39 |
40 | /**
41 | * 0:检测更新
42 | * 1:已下载
43 | * 2:已完成更新
44 | */
45 | private String updateStatus;
46 |
47 | private Date checkTime;
48 |
49 | private Date downloadTime;
50 |
51 | private Date installTime;
52 | }
53 |
--------------------------------------------------------------------------------
/code-update-server/src/main/java/site/chenwei/update/model/vo/ApplicationVersionVo.java:
--------------------------------------------------------------------------------
1 | package site.chenwei.update.model.vo;
2 |
3 | import lombok.AllArgsConstructor;
4 | import lombok.Data;
5 | import lombok.EqualsAndHashCode;
6 | import lombok.NoArgsConstructor;
7 | import site.chenwei.update.model.ApplicationVersion;
8 |
9 | /**
10 | * @author cw
11 | * @date 2022年03月17日 18:01
12 | */
13 | @Data
14 | @AllArgsConstructor
15 | @NoArgsConstructor
16 | @EqualsAndHashCode(callSuper = true)
17 | public class ApplicationVersionVo extends ApplicationVersion {
18 | public enum UpdateType {
19 | FULL_UPDATE,
20 | INCREMENTAL_UPDATE;
21 | }
22 |
23 | public ApplicationVersionVo(ApplicationVersion applicationVersion) {
24 | super(applicationVersion.getId(),
25 | applicationVersion.getApplicationId(),
26 | applicationVersion.getName(),
27 | applicationVersion.getCreateTime(),
28 | applicationVersion.getUpdateTime(),
29 | applicationVersion.getEnableStatus(),
30 | applicationVersion.getSignature(),
31 | applicationVersion.getVersionFile(),
32 | applicationVersion.getPatchFile(),
33 | applicationVersion.getCurrentVersion());
34 | }
35 |
36 | private String downloadUrl;
37 | /**
38 | * 更新类型 1 增量更新 0全量更新 默认为1
39 | */
40 | private UpdateType updateType = UpdateType.INCREMENTAL_UPDATE;
41 |
42 | }
43 |
--------------------------------------------------------------------------------
/code-update-server/src/main/java/site/chenwei/update/service/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/site-chenwei/code-update/d8d40ff1643f47509696f39433b4bce4214f78e7/code-update-server/src/main/java/site/chenwei/update/service/.DS_Store
--------------------------------------------------------------------------------
/code-update-server/src/main/java/site/chenwei/update/service/ApplicationVersionService.java:
--------------------------------------------------------------------------------
1 | package site.chenwei.update.service;
2 |
3 | import org.springframework.web.multipart.MultipartFile;
4 | import site.chenwei.update.model.ApplicationVersion;
5 | import site.chenwei.update.model.UpdateRecorder;
6 | import site.chenwei.update.model.vo.ApplicationVersionVo;
7 |
8 | /**
9 | * @author cw
10 | * @date 2022年03月17日 15:06
11 | */
12 | public interface ApplicationVersionService {
13 | ApplicationVersion newVersion(MultipartFile file, ApplicationVersion applicationVersion);
14 |
15 | ApplicationVersionVo checkUpdate(ApplicationVersion applicationVersion, UpdateRecorder updateRecorder);
16 | }
17 |
--------------------------------------------------------------------------------
/code-update-server/src/main/java/site/chenwei/update/service/SerialNoService.java:
--------------------------------------------------------------------------------
1 | package site.chenwei.update.service;
2 |
3 | /**
4 | * @author cw
5 | * @date 2022年03月16日 20:51
6 | */
7 | public interface SerialNoService {
8 | String generateSerialNo(String serialName);
9 | }
10 |
--------------------------------------------------------------------------------
/code-update-server/src/main/java/site/chenwei/update/service/SystemConfigService.java:
--------------------------------------------------------------------------------
1 | package site.chenwei.update.service;
2 |
3 | import site.chenwei.update.model.SystemConfig;
4 |
5 | /**
6 | * @author cw
7 | * @date 2022年03月17日 16:22
8 | */
9 | public interface SystemConfigService {
10 | SystemConfig newConfig(SystemConfig systemConfig);
11 |
12 | SystemConfig getConfig(SystemConfig systemConfig);
13 | }
14 |
--------------------------------------------------------------------------------
/code-update-server/src/main/java/site/chenwei/update/service/UpdateRecorderService.java:
--------------------------------------------------------------------------------
1 | package site.chenwei.update.service;
2 |
3 | import site.chenwei.update.model.UpdateRecorder;
4 |
5 | /**
6 | * @author cw
7 | * @date 2022年03月18日 20:40
8 | */
9 | public interface UpdateRecorderService {
10 |
11 | UpdateRecorder addRecorder(UpdateRecorder updateRecorder);
12 |
13 | UpdateRecorder syncStatus(UpdateRecorder updateRecorder);
14 | }
15 |
--------------------------------------------------------------------------------
/code-update-server/src/main/java/site/chenwei/update/service/impl/ApplicationVersionServiceImpl.java:
--------------------------------------------------------------------------------
1 | package site.chenwei.update.service.impl;
2 |
3 | import org.apache.commons.lang3.StringUtils;
4 | import org.springframework.beans.factory.annotation.Autowired;
5 | import org.springframework.stereotype.Service;
6 | import org.springframework.transaction.annotation.Transactional;
7 | import org.springframework.web.multipart.MultipartFile;
8 | import site.chenwei.update.common.bsdiff.BSDiff;
9 | import site.chenwei.update.common.bsdiff.BSPatch;
10 | import site.chenwei.update.common.constant.CommonConstants;
11 | import site.chenwei.update.common.constant.SerialNoConstant;
12 | import site.chenwei.update.common.constant.SystemConfigConstant;
13 | import site.chenwei.update.common.exception.BusinessException;
14 | import site.chenwei.update.common.util.MD5Util;
15 | import site.chenwei.update.mapper.ApplicationVersionMapper;
16 | import site.chenwei.update.model.ApplicationVersion;
17 | import site.chenwei.update.model.SystemConfig;
18 | import site.chenwei.update.model.UpdateRecorder;
19 | import site.chenwei.update.model.vo.ApplicationVersionVo;
20 | import site.chenwei.update.service.ApplicationVersionService;
21 | import site.chenwei.update.service.SerialNoService;
22 | import site.chenwei.update.service.SystemConfigService;
23 |
24 | import javax.annotation.Resource;
25 | import java.io.File;
26 | import java.io.FileInputStream;
27 | import java.util.List;
28 |
29 | /**
30 | * @author cw
31 | * @date 2022年03月17日 15:06
32 | */
33 | @Service
34 | public class ApplicationVersionServiceImpl implements ApplicationVersionService {
35 | private static String FILE_BASE_URL = "";
36 | private static String DOWNLOAD_URL_PREFIX = "";
37 | private static final String VERSION_FILE_FOLDER = "version";
38 | private static final String VERSION_PATCH_FILE_NAME = "patch.zip";
39 | private static final String VERSION_PATCHED_FILE_NAME = "patched.zip";
40 | private static final String DOWNLOAD_URL_SEPARATOR = "/";
41 | @Resource
42 | SystemConfigService systemConfigService;
43 | @Resource
44 | SerialNoService serialNoService;
45 | @Resource
46 | ApplicationVersionMapper applicationVersionMapper;
47 |
48 | @Autowired
49 | public void init() {
50 | SystemConfig config = systemConfigService.getConfig(SystemConfig.builder().name(SystemConfigConstant.FILE_BASE_PATH).build());
51 | if (config != null) {
52 | FILE_BASE_URL = config.getValue();
53 | }
54 | config = systemConfigService.getConfig(SystemConfig.builder().name(SystemConfigConstant.DOWNLOAD_URL_PREFIX).build());
55 | if (config != null) {
56 | String value = config.getValue();
57 | if (StringUtils.endsWith(value, "/")) {
58 | DOWNLOAD_URL_PREFIX = value.substring(0, StringUtils.lastIndexOf(value, "/") - 1);
59 | } else {
60 | DOWNLOAD_URL_PREFIX = value;
61 | }
62 | }
63 | }
64 |
65 | @Override
66 | @Transactional
67 | public ApplicationVersion newVersion(MultipartFile file, ApplicationVersion applicationVersion) {
68 | if (file == null) {
69 | throw new BusinessException(CommonConstants.Request.PARAM_ERROR, "请上传更新ZIP包");
70 | }
71 | if (applicationVersion == null) {
72 | throw new BusinessException(CommonConstants.Request.PARAM_ERROR, "请指定更新版本信息");
73 | }
74 | if (StringUtils.isBlank(applicationVersion.getApplicationId())) {
75 | throw new BusinessException(CommonConstants.Request.PARAM_ERROR, "请指定更新应用信息");
76 | }
77 | if (StringUtils.isBlank(applicationVersion.getName())) {
78 | throw new BusinessException(CommonConstants.Request.PARAM_ERROR, "请指定更新版本号");
79 | }
80 | if (StringUtils.isBlank(FILE_BASE_URL)) {
81 | SystemConfig config = systemConfigService.getConfig(SystemConfig.builder().name(SystemConfigConstant.FILE_BASE_PATH).build());
82 | if (config == null || StringUtils.isBlank(config.getValue())) {
83 | throw new BusinessException(CommonConstants.Request.NO_FILE_BASE_URL, "未配置更新文件目录!");
84 | }
85 | FILE_BASE_URL = config.getValue();
86 | }
87 | String applicationVersionId = serialNoService.generateSerialNo(SerialNoConstant.APPLICATION_VERSION_SERIAL);
88 | applicationVersion.setId(applicationVersionId);
89 | String destPath = FILE_BASE_URL + File.separator + VERSION_FILE_FOLDER + File.separator + applicationVersion.getApplicationId() + File.separator + applicationVersionId + File.separator + file.getOriginalFilename();
90 | try {
91 | File destFile = new File(destPath);
92 | if (destFile.exists()) {
93 | destFile.delete();
94 | }
95 | destFile.mkdirs();
96 | file.transferTo(destFile);
97 | applicationVersion.setVersionFile(destPath);
98 | String sign = MD5Util.md5(new FileInputStream(destPath));
99 | applicationVersion.setSignature(sign);
100 | List applicationVersions = applicationVersionMapper.selectListByApplicationId(applicationVersion.getApplicationId());
101 | for (ApplicationVersion applicationVersionOld : applicationVersions) {
102 | String oldFilePath = applicationVersionOld.getVersionFile();
103 | File oldFile = new File(oldFilePath);
104 | applicationVersionOld.setCurrentVersion(false);
105 | if (!oldFile.exists()) {
106 | continue;
107 | }
108 | String patchFilePath = oldFile.getParent() + File.separator + VERSION_PATCH_FILE_NAME;
109 | File patchFile = new File(patchFilePath);
110 | if (patchFile.exists()) {
111 | patchFile.delete();
112 | }
113 | if (!BSDiff.diff(oldFilePath, destPath, patchFilePath)) {
114 | continue;
115 | }
116 | String patchedFilePath = oldFile.getParent() + File.separator + VERSION_PATCHED_FILE_NAME;
117 | File patchedFile = new File(patchedFilePath);
118 | if (patchedFile.exists()) {
119 | patchedFile.delete();
120 | }
121 | BSPatch.patch(oldFilePath, patchedFilePath, patchFilePath);
122 | if (!StringUtils.equals(MD5Util.md5(new FileInputStream(patchedFilePath)), MD5Util.md5(new FileInputStream(destPath)))) {
123 | continue;
124 | }
125 | applicationVersionOld.setPatchFile(patchFilePath);
126 | }
127 | if (!applicationVersions.isEmpty()) {
128 | applicationVersionMapper.updateBatch(applicationVersions);
129 | }
130 | applicationVersion.setCurrentVersion(true);
131 | applicationVersionMapper.insertSelective(applicationVersion);
132 | } catch (Exception e) {
133 | e.printStackTrace();
134 | throw new BusinessException(CommonConstants.Request.INTERNAL_ERROR, "上传新版本失败");
135 | }
136 | return applicationVersion;
137 | }
138 |
139 | @Override
140 | public ApplicationVersionVo checkUpdate(ApplicationVersion applicationVersion, UpdateRecorder updateRecorder) {
141 | if (applicationVersion == null || StringUtils.isBlank(applicationVersion.getApplicationId())) {
142 | throw new BusinessException(CommonConstants.Request.PARAM_ERROR, "请传入当前应用信息");
143 | }
144 | ApplicationVersion latestVersion = applicationVersionMapper.selectCurrentVersionByApplicationID(applicationVersion.getApplicationId());
145 | if (StringUtils.equals(latestVersion.getSignature(), applicationVersion.getSignature())) {
146 | return null;
147 | }
148 | ApplicationVersion currentVersion = applicationVersionMapper.selectByApplicationIdAndSignature(applicationVersion.getApplicationId(), applicationVersion.getSignature());
149 | ApplicationVersionVo applicationVersionVo = new ApplicationVersionVo(latestVersion);
150 | if (currentVersion != null) {
151 | applicationVersionVo.setDownloadUrl(currentVersion.getPatchFile());
152 | applicationVersionVo.setUpdateType(ApplicationVersionVo.UpdateType.INCREMENTAL_UPDATE);
153 | } else {
154 | applicationVersionVo.setDownloadUrl(latestVersion.getVersionFile());
155 | applicationVersionVo.setUpdateType(ApplicationVersionVo.UpdateType.FULL_UPDATE);
156 | }
157 | if (StringUtils.isBlank(DOWNLOAD_URL_PREFIX)) {
158 | SystemConfig config = systemConfigService.getConfig(SystemConfig.builder().name(SystemConfigConstant.DOWNLOAD_URL_PREFIX).build());
159 | if (config == null || StringUtils.isBlank(config.getValue())) {
160 | throw new BusinessException(CommonConstants.Request.NO_DOWNLOAD_URL_PREFIX, "未匹配下载URL,无法更新");
161 | }
162 | DOWNLOAD_URL_PREFIX = config.getValue();
163 | if (StringUtils.endsWith(DOWNLOAD_URL_PREFIX, DOWNLOAD_URL_SEPARATOR)) {
164 | DOWNLOAD_URL_PREFIX = DOWNLOAD_URL_PREFIX.substring(0, DOWNLOAD_URL_PREFIX.length() - 1);
165 | }
166 | }
167 | String downloadUrlSuffix = applicationVersionVo.getDownloadUrl().replace(FILE_BASE_URL, "");
168 | if (!StringUtils.startsWith(downloadUrlSuffix, DOWNLOAD_URL_SEPARATOR)) {
169 | downloadUrlSuffix = DOWNLOAD_URL_SEPARATOR + downloadUrlSuffix;
170 | }
171 | applicationVersionVo.setVersionFile("");
172 | applicationVersionVo.setDownloadUrl(DOWNLOAD_URL_PREFIX + downloadUrlSuffix);
173 | return applicationVersionVo;
174 | }
175 | }
176 |
--------------------------------------------------------------------------------
/code-update-server/src/main/java/site/chenwei/update/service/impl/SerialNoServiceImpl.java:
--------------------------------------------------------------------------------
1 | package site.chenwei.update.service.impl;
2 |
3 | import org.springframework.beans.factory.annotation.Autowired;
4 | import org.springframework.stereotype.Service;
5 | import site.chenwei.update.common.constant.CommonConstants;
6 | import site.chenwei.update.common.exception.BusinessException;
7 | import site.chenwei.update.common.exception.SerialException;
8 | import site.chenwei.update.common.model.SerialNo;
9 | import site.chenwei.update.common.serialNo.SerialNoGenerator;
10 | import site.chenwei.update.mapper.SerialNoMapper;
11 | import site.chenwei.update.service.SerialNoService;
12 |
13 | import javax.annotation.Resource;
14 | import java.util.HashMap;
15 | import java.util.List;
16 | import java.util.Map;
17 |
18 | /**
19 | * @author cw
20 | * @date 2022年03月16日 20:51
21 | */
22 | @Service
23 | public class SerialNoServiceImpl implements SerialNoService {
24 | private final Map generatorMap = new HashMap<>();
25 |
26 | @Resource
27 | SerialNoMapper serialNoMapper;
28 |
29 | @Autowired
30 | public void initGenerators() {
31 | List serialNos = serialNoMapper.selectAllSerialNos();
32 | serialNos.forEach(serialNo -> {
33 | generatorMap.put(serialNo.getName(), new SerialNoGenerator(serialNoMapper, serialNo));
34 | });
35 | }
36 |
37 |
38 | @Override
39 | public String generateSerialNo(String serialName) {
40 | SerialNoGenerator serialNoGenerator = generatorMap.get(serialName);
41 | if (serialNoGenerator == null) {
42 | throw new BusinessException(CommonConstants.Request.ERROR, "Serial不存在");
43 | }
44 | String serialStr;
45 | try {
46 | serialStr = serialNoGenerator.generate();
47 | } catch (SerialException e) {
48 | e.printStackTrace();
49 | throw new BusinessException(CommonConstants.Request.ERROR, "生成序列号失败");
50 | }
51 | return serialStr;
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/code-update-server/src/main/java/site/chenwei/update/service/impl/SystemConfigServiceImpl.java:
--------------------------------------------------------------------------------
1 | package site.chenwei.update.service.impl;
2 |
3 | import org.apache.commons.lang3.StringUtils;
4 | import org.springframework.stereotype.Service;
5 | import site.chenwei.update.common.constant.CommonConstants;
6 | import site.chenwei.update.common.constant.SerialNoConstant;
7 | import site.chenwei.update.common.exception.BusinessException;
8 | import site.chenwei.update.mapper.SystemConfigMapper;
9 | import site.chenwei.update.model.SystemConfig;
10 | import site.chenwei.update.service.SerialNoService;
11 | import site.chenwei.update.service.SystemConfigService;
12 |
13 | import javax.annotation.Resource;
14 |
15 | /**
16 | * @author cw
17 | * @date 2022年03月17日 16:22
18 | */
19 | @Service
20 | public class SystemConfigServiceImpl implements SystemConfigService {
21 | @Resource
22 | SystemConfigMapper systemConfigMapper;
23 | @Resource
24 | SerialNoService serialNoService;
25 |
26 | @Override
27 | public SystemConfig newConfig(SystemConfig systemConfig) {
28 | if (systemConfig == null || StringUtils.isAnyBlank(systemConfig.getName(), systemConfig.getValue())) {
29 | throw new BusinessException(CommonConstants.Request.PARAM_ERROR, CommonConstants.Request.PARAM_ERROR_MESSAGE);
30 | }
31 | SystemConfig systemConfigByName = systemConfigMapper.selectByName(systemConfig.getName());
32 | if (systemConfigByName != null) {
33 | throw new BusinessException(CommonConstants.Request.PARAM_ERROR, "参数名已存在!");
34 | }
35 | String serialNo = serialNoService.generateSerialNo(SerialNoConstant.SYSTEM_CONFIG);
36 | systemConfig.setId(serialNo);
37 | systemConfigMapper.insertSelective(systemConfig);
38 | return systemConfig;
39 | }
40 |
41 | @Override
42 | public SystemConfig getConfig(SystemConfig systemConfig) {
43 | if (systemConfig == null || StringUtils.isAllBlank(systemConfig.getName(), systemConfig.getId())) {
44 | throw new BusinessException(CommonConstants.Request.PARAM_ERROR, CommonConstants.Request.PARAM_ERROR_MESSAGE);
45 | }
46 | if (StringUtils.isNotBlank(systemConfig.getName())) {
47 | systemConfig = systemConfigMapper.selectByName(systemConfig.getName());
48 | }
49 | if (StringUtils.isNotBlank(systemConfig.getId())) {
50 | systemConfig = systemConfigMapper.selectByPrimaryKey(systemConfig.getId());
51 | }
52 | return systemConfig;
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/code-update-server/src/main/java/site/chenwei/update/service/impl/UpdateRecorderServiceImpl.java:
--------------------------------------------------------------------------------
1 | package site.chenwei.update.service.impl;
2 |
3 | import org.springframework.stereotype.Service;
4 | import site.chenwei.update.mapper.UpdateRecorderMapper;
5 | import site.chenwei.update.model.UpdateRecorder;
6 | import site.chenwei.update.service.UpdateRecorderService;
7 |
8 | import javax.annotation.Resource;
9 |
10 | /**
11 | * @author cw
12 | * @date 2022年03月18日 20:40
13 | */
14 | @Service
15 | public class UpdateRecorderServiceImpl implements UpdateRecorderService {
16 | @Resource
17 | private UpdateRecorderMapper updateRecorderMapper;
18 |
19 | @Override
20 | public UpdateRecorder addRecorder(UpdateRecorder updateRecorder) {
21 | return null;
22 | }
23 |
24 | @Override
25 | public UpdateRecorder syncStatus(UpdateRecorder updateRecorder) {
26 | return null;
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/code-update-server/src/main/resources/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/site-chenwei/code-update/d8d40ff1643f47509696f39433b4bce4214f78e7/code-update-server/src/main/resources/.DS_Store
--------------------------------------------------------------------------------
/code-update-server/src/main/resources/application.yaml:
--------------------------------------------------------------------------------
1 | spring:
2 | datasource:
3 | password: ZXLuXVDzy0WCwVUii4Nu
4 | username: root
5 | url: jdbc:mysql://localhost:3306/code_update
6 | driver-class-name: com.mysql.cj.jdbc.Driver
7 | servlet:
8 | multipart:
9 | max-file-size: 100MB
10 | max-request-size: 1024MB
11 | mybatis:
12 | mapper-locations: classpath:mapper/*.xml
13 | code:
14 | update:
15 | qiNiuSecretkey: 7YUnUUHcnmtK1U-WJJWU1q4VP0Zfz5U8cDsdfPyn
16 | qiNiuAccessKey: 2GMCkLwp97X70MLCkVnZq2NO21_PXyJawc11Wov6
17 |
18 |
19 |
--------------------------------------------------------------------------------
/code-update-server/src/main/resources/bsdiff/bsdiff:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/site-chenwei/code-update/d8d40ff1643f47509696f39433b4bce4214f78e7/code-update-server/src/main/resources/bsdiff/bsdiff
--------------------------------------------------------------------------------
/code-update-server/src/main/resources/bsdiff/bspatch:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/site-chenwei/code-update/d8d40ff1643f47509696f39433b4bce4214f78e7/code-update-server/src/main/resources/bsdiff/bspatch
--------------------------------------------------------------------------------
/code-update-server/src/main/resources/mapper/ApplicationMapper.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 | id, `name`, create_time, update_time, enable_status
16 |
17 |
24 |
25 |
26 | delete from tbl_application
27 | where id = #{id,jdbcType=VARCHAR}
28 |
29 |
30 |
31 | insert into tbl_application (id, `name`, create_time,
32 | update_time, enable_status)
33 | values (#{id,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP},
34 | #{updateTime,jdbcType=TIMESTAMP}, #{enableStatus,jdbcType=VARCHAR})
35 |
36 |
37 |
38 | insert into tbl_application
39 |
40 |
41 | id,
42 |
43 |
44 | `name`,
45 |
46 |
47 | create_time,
48 |
49 |
50 | update_time,
51 |
52 |
53 | enable_status,
54 |
55 |
56 |
57 |
58 | #{id,jdbcType=VARCHAR},
59 |
60 |
61 | #{name,jdbcType=VARCHAR},
62 |
63 |
64 | #{createTime,jdbcType=TIMESTAMP},
65 |
66 |
67 | #{updateTime,jdbcType=TIMESTAMP},
68 |
69 |
70 | #{enableStatus,jdbcType=VARCHAR},
71 |
72 |
73 |
74 |
75 |
76 | update tbl_application
77 |
78 |
79 | `name` = #{name,jdbcType=VARCHAR},
80 |
81 |
82 | create_time = #{createTime,jdbcType=TIMESTAMP},
83 |
84 |
85 | update_time = #{updateTime,jdbcType=TIMESTAMP},
86 |
87 |
88 | enable_status = #{enableStatus,jdbcType=VARCHAR},
89 |
90 |
91 | where id = #{id,jdbcType=VARCHAR}
92 |
93 |
94 |
95 | update tbl_application
96 | set `name` = #{name,jdbcType=VARCHAR},
97 | create_time = #{createTime,jdbcType=TIMESTAMP},
98 | update_time = #{updateTime,jdbcType=TIMESTAMP},
99 | enable_status = #{enableStatus,jdbcType=VARCHAR}
100 | where id = #{id,jdbcType=VARCHAR}
101 |
102 |
103 |
104 | update tbl_application
105 |
106 |
107 |
108 | when id = #{item.id,jdbcType=VARCHAR} then #{item.name,jdbcType=VARCHAR}
109 |
110 |
111 |
112 |
113 | when id = #{item.id,jdbcType=VARCHAR} then #{item.createTime,jdbcType=TIMESTAMP}
114 |
115 |
116 |
117 |
118 | when id = #{item.id,jdbcType=VARCHAR} then #{item.updateTime,jdbcType=TIMESTAMP}
119 |
120 |
121 |
122 |
123 | when id = #{item.id,jdbcType=VARCHAR} then #{item.enableStatus,jdbcType=VARCHAR}
124 |
125 |
126 |
127 | where id in
128 |
129 | #{item.id,jdbcType=VARCHAR}
130 |
131 |
132 |
133 |
134 | insert into tbl_application
135 | (id, `name`, create_time, update_time, enable_status)
136 | values
137 |
138 | (#{item.id,jdbcType=VARCHAR}, #{item.name,jdbcType=VARCHAR}, #{item.createTime,jdbcType=TIMESTAMP},
139 | #{item.updateTime,jdbcType=TIMESTAMP}, #{item.enableStatus,jdbcType=VARCHAR})
140 |
141 |
142 |
143 |
144 | insert into tbl_application
145 | (id, `name`, create_time, update_time, enable_status)
146 | values
147 | (#{id,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP},
148 | #{updateTime,jdbcType=TIMESTAMP}, #{enableStatus,jdbcType=VARCHAR})
149 | on duplicate key update
150 | id = #{id,jdbcType=VARCHAR},
151 | `name` = #{name,jdbcType=VARCHAR},
152 | create_time = #{createTime,jdbcType=TIMESTAMP},
153 | update_time = #{updateTime,jdbcType=TIMESTAMP},
154 | enable_status = #{enableStatus,jdbcType=VARCHAR}
155 |
156 |
157 |
158 | insert into tbl_application
159 |
160 |
161 | id,
162 |
163 |
164 | `name`,
165 |
166 |
167 | create_time,
168 |
169 |
170 | update_time,
171 |
172 |
173 | enable_status,
174 |
175 |
176 | values
177 |
178 |
179 | #{id,jdbcType=VARCHAR},
180 |
181 |
182 | #{name,jdbcType=VARCHAR},
183 |
184 |
185 | #{createTime,jdbcType=TIMESTAMP},
186 |
187 |
188 | #{updateTime,jdbcType=TIMESTAMP},
189 |
190 |
191 | #{enableStatus,jdbcType=VARCHAR},
192 |
193 |
194 | on duplicate key update
195 |
196 |
197 | id = #{id,jdbcType=VARCHAR},
198 |
199 |
200 | `name` = #{name,jdbcType=VARCHAR},
201 |
202 |
203 | create_time = #{createTime,jdbcType=TIMESTAMP},
204 |
205 |
206 | update_time = #{updateTime,jdbcType=TIMESTAMP},
207 |
208 |
209 | enable_status = #{enableStatus,jdbcType=VARCHAR},
210 |
211 |
212 |
213 |
--------------------------------------------------------------------------------
/code-update-server/src/main/resources/mapper/SerialNoMapper.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 | id, `name`, `value`, create_time, update_time, format
17 |
18 |
25 |
26 |
27 | delete
28 | from tbl_serial_no
29 | where id = #{id,jdbcType=VARCHAR}
30 |
31 |
32 |
33 | insert into tbl_serial_no (id, `name`, `value`,
34 | create_time, update_time, format)
35 | values (#{id,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, #{value,jdbcType=BIGINT},
36 | #{createTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP}, #{format,jdbcType=VARCHAR})
37 |
38 |
39 |
40 | insert into tbl_serial_no
41 |
42 |
43 | id,
44 |
45 |
46 | `name`,
47 |
48 |
49 | `value`,
50 |
51 |
52 | create_time,
53 |
54 |
55 | update_time,
56 |
57 |
58 | format,
59 |
60 |
61 |
62 |
63 | #{id,jdbcType=VARCHAR},
64 |
65 |
66 | #{name,jdbcType=VARCHAR},
67 |
68 |
69 | #{value,jdbcType=BIGINT},
70 |
71 |
72 | #{createTime,jdbcType=TIMESTAMP},
73 |
74 |
75 | #{updateTime,jdbcType=TIMESTAMP},
76 |
77 |
78 | #{format,jdbcType=VARCHAR},
79 |
80 |
81 |
82 |
83 |
84 | update tbl_serial_no
85 |
86 |
87 | `name` = #{name,jdbcType=VARCHAR},
88 |
89 |
90 | `value` = #{value,jdbcType=BIGINT},
91 |
92 |
93 | create_time = #{createTime,jdbcType=TIMESTAMP},
94 |
95 |
96 | update_time = #{updateTime,jdbcType=TIMESTAMP},
97 |
98 |
99 | format = #{format,jdbcType=VARCHAR},
100 |
101 |
102 | where id = #{id,jdbcType=VARCHAR}
103 |
104 |
105 |
106 | update tbl_serial_no
107 | set `name` = #{name,jdbcType=VARCHAR},
108 | `value` = #{value,jdbcType=BIGINT},
109 | create_time = #{createTime,jdbcType=TIMESTAMP},
110 | update_time = #{updateTime,jdbcType=TIMESTAMP},
111 | format = #{format,jdbcType=VARCHAR}
112 | where id = #{id,jdbcType=VARCHAR}
113 |
114 |
115 |
116 | update tbl_serial_no
117 |
118 |
119 |
120 | when id = #{item.id,jdbcType=VARCHAR} then #{item.name,jdbcType=VARCHAR}
121 |
122 |
123 |
124 |
125 | when id = #{item.id,jdbcType=VARCHAR} then #{item.value,jdbcType=BIGINT}
126 |
127 |
128 |
129 |
130 | when id = #{item.id,jdbcType=VARCHAR} then #{item.createTime,jdbcType=TIMESTAMP}
131 |
132 |
133 |
134 |
135 | when id = #{item.id,jdbcType=VARCHAR} then #{item.updateTime,jdbcType=TIMESTAMP}
136 |
137 |
138 |
139 |
140 | when id = #{item.id,jdbcType=VARCHAR} then #{item.format,jdbcType=VARCHAR}
141 |
142 |
143 |
144 | where id in
145 |
146 | #{item.id,jdbcType=VARCHAR}
147 |
148 |
149 |
150 |
151 | insert into tbl_serial_no
152 | (id, `name`, `value`, create_time, update_time, format)
153 | values
154 |
155 | (#{item.id,jdbcType=VARCHAR}, #{item.name,jdbcType=VARCHAR}, #{item.value,jdbcType=BIGINT},
156 | #{item.createTime,jdbcType=TIMESTAMP}, #{item.updateTime,jdbcType=TIMESTAMP},
157 | #{item.format,jdbcType=VARCHAR})
158 |
159 |
160 |
161 |
162 | insert into tbl_serial_no
163 | (id, `name`, `value`, create_time, update_time, format)
164 | values (#{id,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, #{value,jdbcType=BIGINT},
165 | #{createTime,jdbcType=TIMESTAMP},
166 | #{updateTime,jdbcType=TIMESTAMP}, #{format,jdbcType=VARCHAR}) on duplicate key
167 | update
168 | id = #{id,jdbcType=VARCHAR},
169 | `name` = #{name,jdbcType=VARCHAR},
170 | `value` = #{value,jdbcType=BIGINT},
171 | create_time = #{createTime,jdbcType=TIMESTAMP},
172 | update_time = #{updateTime,jdbcType=TIMESTAMP},
173 | format = #{format,jdbcType=VARCHAR}
174 |
175 |
176 |
177 | insert into tbl_serial_no
178 |
179 |
180 | id,
181 |
182 |
183 | `name`,
184 |
185 |
186 | `value`,
187 |
188 |
189 | create_time,
190 |
191 |
192 | update_time,
193 |
194 |
195 | format,
196 |
197 |
198 | values
199 |
200 |
201 | #{id,jdbcType=VARCHAR},
202 |
203 |
204 | #{name,jdbcType=VARCHAR},
205 |
206 |
207 | #{value,jdbcType=BIGINT},
208 |
209 |
210 | #{createTime,jdbcType=TIMESTAMP},
211 |
212 |
213 | #{updateTime,jdbcType=TIMESTAMP},
214 |
215 |
216 | #{format,jdbcType=VARCHAR},
217 |
218 |
219 | on duplicate key update
220 |
221 |
222 | id = #{id,jdbcType=VARCHAR},
223 |
224 |
225 | `name` = #{name,jdbcType=VARCHAR},
226 |
227 |
228 | `value` = #{value,jdbcType=BIGINT},
229 |
230 |
231 | create_time = #{createTime,jdbcType=TIMESTAMP},
232 |
233 |
234 | update_time = #{updateTime,jdbcType=TIMESTAMP},
235 |
236 |
237 | format = #{format,jdbcType=VARCHAR},
238 |
239 |
240 |
241 |
242 |
246 |
247 |
--------------------------------------------------------------------------------
/code-update-server/src/main/resources/mapper/SystemConfigMapper.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 | id, `name`, `value`, create_time, update_time, enable_status
17 |
18 |
25 |
26 |
27 | delete
28 | from tbl_system_config
29 | where id = #{id,jdbcType=VARCHAR}
30 |
31 |
32 |
33 | insert into tbl_system_config (id, `name`, `value`,
34 | create_time, update_time, enable_status)
35 | values (#{id,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, #{value,jdbcType=VARCHAR},
36 | #{createTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP}, #{enableStatus,jdbcType=VARCHAR})
37 |
38 |
39 |
40 | insert into tbl_system_config
41 |
42 |
43 | id,
44 |
45 |
46 | `name`,
47 |
48 |
49 | `value`,
50 |
51 |
52 | create_time,
53 |
54 |
55 | update_time,
56 |
57 |
58 | enable_status,
59 |
60 |
61 |
62 |
63 | #{id,jdbcType=VARCHAR},
64 |
65 |
66 | #{name,jdbcType=VARCHAR},
67 |
68 |
69 | #{value,jdbcType=VARCHAR},
70 |
71 |
72 | #{createTime,jdbcType=TIMESTAMP},
73 |
74 |
75 | #{updateTime,jdbcType=TIMESTAMP},
76 |
77 |
78 | #{enableStatus,jdbcType=VARCHAR},
79 |
80 |
81 |
82 |
83 |
84 | update tbl_system_config
85 |
86 |
87 | `name` = #{name,jdbcType=VARCHAR},
88 |
89 |
90 | `value` = #{value,jdbcType=VARCHAR},
91 |
92 |
93 | create_time = #{createTime,jdbcType=TIMESTAMP},
94 |
95 |
96 | update_time = #{updateTime,jdbcType=TIMESTAMP},
97 |
98 |
99 | enable_status = #{enableStatus,jdbcType=VARCHAR},
100 |
101 |
102 | where id = #{id,jdbcType=VARCHAR}
103 |
104 |
105 |
106 | update tbl_system_config
107 | set `name` = #{name,jdbcType=VARCHAR},
108 | `value` = #{value,jdbcType=VARCHAR},
109 | create_time = #{createTime,jdbcType=TIMESTAMP},
110 | update_time = #{updateTime,jdbcType=TIMESTAMP},
111 | enable_status = #{enableStatus,jdbcType=VARCHAR}
112 | where id = #{id,jdbcType=VARCHAR}
113 |
114 |
115 |
116 | update tbl_system_config
117 |
118 |
119 |
120 | when id = #{item.id,jdbcType=VARCHAR} then #{item.name,jdbcType=VARCHAR}
121 |
122 |
123 |
124 |
125 | when id = #{item.id,jdbcType=VARCHAR} then #{item.value,jdbcType=VARCHAR}
126 |
127 |
128 |
129 |
130 | when id = #{item.id,jdbcType=VARCHAR} then #{item.createTime,jdbcType=TIMESTAMP}
131 |
132 |
133 |
134 |
135 | when id = #{item.id,jdbcType=VARCHAR} then #{item.updateTime,jdbcType=TIMESTAMP}
136 |
137 |
138 |
139 |
140 | when id = #{item.id,jdbcType=VARCHAR} then #{item.enableStatus,jdbcType=VARCHAR}
141 |
142 |
143 |
144 | where id in
145 |
146 | #{item.id,jdbcType=VARCHAR}
147 |
148 |
149 |
150 |
151 | insert into tbl_system_config
152 | (id, `name`, `value`, create_time, update_time, enable_status)
153 | values
154 |
155 | (#{item.id,jdbcType=VARCHAR}, #{item.name,jdbcType=VARCHAR}, #{item.value,jdbcType=VARCHAR},
156 | #{item.createTime,jdbcType=TIMESTAMP}, #{item.updateTime,jdbcType=TIMESTAMP},
157 | #{item.enableStatus,jdbcType=VARCHAR})
158 |
159 |
160 |
161 |
162 | insert into tbl_system_config
163 | (id, `name`, `value`, create_time, update_time, enable_status)
164 | values (#{id,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, #{value,jdbcType=VARCHAR},
165 | #{createTime,jdbcType=TIMESTAMP},
166 | #{updateTime,jdbcType=TIMESTAMP}, #{enableStatus,jdbcType=VARCHAR})
167 | on duplicate key update id = #{id,jdbcType=VARCHAR},
168 | `name` = #{name,jdbcType=VARCHAR},
169 | `value` = #{value,jdbcType=VARCHAR},
170 | create_time = #{createTime,jdbcType=TIMESTAMP},
171 | update_time = #{updateTime,jdbcType=TIMESTAMP},
172 | enable_status = #{enableStatus,jdbcType=VARCHAR}
173 |
174 |
175 |
176 | insert into tbl_system_config
177 |
178 |
179 | id,
180 |
181 |
182 | `name`,
183 |
184 |
185 | `value`,
186 |
187 |
188 | create_time,
189 |
190 |
191 | update_time,
192 |
193 |
194 | enable_status,
195 |
196 |
197 | values
198 |
199 |
200 | #{id,jdbcType=VARCHAR},
201 |
202 |
203 | #{name,jdbcType=VARCHAR},
204 |
205 |
206 | #{value,jdbcType=VARCHAR},
207 |
208 |
209 | #{createTime,jdbcType=TIMESTAMP},
210 |
211 |
212 | #{updateTime,jdbcType=TIMESTAMP},
213 |
214 |
215 | #{enableStatus,jdbcType=VARCHAR},
216 |
217 |
218 | on duplicate key update
219 |
220 |
221 | id = #{id,jdbcType=VARCHAR},
222 |
223 |
224 | `name` = #{name,jdbcType=VARCHAR},
225 |
226 |
227 | `value` = #{value,jdbcType=VARCHAR},
228 |
229 |
230 | create_time = #{createTime,jdbcType=TIMESTAMP},
231 |
232 |
233 | update_time = #{updateTime,jdbcType=TIMESTAMP},
234 |
235 |
236 | enable_status = #{enableStatus,jdbcType=VARCHAR},
237 |
238 |
239 |
240 |
241 |
246 |
247 |
--------------------------------------------------------------------------------
/code-update-server/src/test/java/site/chenwei/update/CodeUpdateServerApplicationTests.java:
--------------------------------------------------------------------------------
1 | package site.chenwei.update;
2 |
3 | import org.junit.jupiter.api.Test;
4 | import org.springframework.boot.test.context.SpringBootTest;
5 |
6 | @SpringBootTest
7 | class CodeUpdateServerApplicationTests {
8 |
9 | @Test
10 | void contextLoads() {
11 | }
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/code-update-server/target/classes/META-INF/spring-configuration-metadata.json:
--------------------------------------------------------------------------------
1 | {
2 | "groups": [
3 | {
4 | "name": "code.update",
5 | "type": "site.chenwei.update.common.config.CodeUpdateConfig",
6 | "sourceType": "site.chenwei.update.common.config.CodeUpdateConfig"
7 | }
8 | ],
9 | "properties": [
10 | {
11 | "name": "code.update.qi-niu-access-key",
12 | "type": "java.lang.String",
13 | "sourceType": "site.chenwei.update.common.config.CodeUpdateConfig"
14 | },
15 | {
16 | "name": "code.update.qi-niu-secret-key",
17 | "type": "java.lang.String",
18 | "sourceType": "site.chenwei.update.common.config.CodeUpdateConfig"
19 | }
20 | ],
21 | "hints": []
22 | }
--------------------------------------------------------------------------------
/code-update-server/target/classes/application.yaml:
--------------------------------------------------------------------------------
1 | spring:
2 | datasource:
3 | password: ZXLuXVDzy0WCwVUii4Nu
4 | username: root
5 | url: jdbc:mysql://localhost:3306/code_update
6 | driver-class-name: com.mysql.cj.jdbc.Driver
7 | servlet:
8 | multipart:
9 | max-file-size: 100MB
10 | max-request-size: 1024MB
11 | mybatis:
12 | mapper-locations: classpath:mapper/*.xml
13 | code:
14 | update:
15 | qiNiuSecretkey: 7YUnUUHcnmtK1U-WJJWU1q4VP0Zfz5U8cDsdfPyn
16 | qiNiuAccessKey: 2GMCkLwp97X70MLCkVnZq2NO21_PXyJawc11Wov6
17 |
18 |
19 |
--------------------------------------------------------------------------------
/code-update-server/target/classes/bsdiff/bsdiff:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/site-chenwei/code-update/d8d40ff1643f47509696f39433b4bce4214f78e7/code-update-server/target/classes/bsdiff/bsdiff
--------------------------------------------------------------------------------
/code-update-server/target/classes/bsdiff/bspatch:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/site-chenwei/code-update/d8d40ff1643f47509696f39433b4bce4214f78e7/code-update-server/target/classes/bsdiff/bspatch
--------------------------------------------------------------------------------
/code-update-server/target/classes/mapper/ApplicationMapper.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 | id, `name`, create_time, update_time, enable_status
16 |
17 |
24 |
25 |
26 | delete from tbl_application
27 | where id = #{id,jdbcType=VARCHAR}
28 |
29 |
30 |
31 | insert into tbl_application (id, `name`, create_time,
32 | update_time, enable_status)
33 | values (#{id,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP},
34 | #{updateTime,jdbcType=TIMESTAMP}, #{enableStatus,jdbcType=VARCHAR})
35 |
36 |
37 |
38 | insert into tbl_application
39 |
40 |
41 | id,
42 |
43 |
44 | `name`,
45 |
46 |
47 | create_time,
48 |
49 |
50 | update_time,
51 |
52 |
53 | enable_status,
54 |
55 |
56 |
57 |
58 | #{id,jdbcType=VARCHAR},
59 |
60 |
61 | #{name,jdbcType=VARCHAR},
62 |
63 |
64 | #{createTime,jdbcType=TIMESTAMP},
65 |
66 |
67 | #{updateTime,jdbcType=TIMESTAMP},
68 |
69 |
70 | #{enableStatus,jdbcType=VARCHAR},
71 |
72 |
73 |
74 |
75 |
76 | update tbl_application
77 |
78 |
79 | `name` = #{name,jdbcType=VARCHAR},
80 |
81 |
82 | create_time = #{createTime,jdbcType=TIMESTAMP},
83 |
84 |
85 | update_time = #{updateTime,jdbcType=TIMESTAMP},
86 |
87 |
88 | enable_status = #{enableStatus,jdbcType=VARCHAR},
89 |
90 |
91 | where id = #{id,jdbcType=VARCHAR}
92 |
93 |
94 |
95 | update tbl_application
96 | set `name` = #{name,jdbcType=VARCHAR},
97 | create_time = #{createTime,jdbcType=TIMESTAMP},
98 | update_time = #{updateTime,jdbcType=TIMESTAMP},
99 | enable_status = #{enableStatus,jdbcType=VARCHAR}
100 | where id = #{id,jdbcType=VARCHAR}
101 |
102 |
103 |
104 | update tbl_application
105 |
106 |
107 |
108 | when id = #{item.id,jdbcType=VARCHAR} then #{item.name,jdbcType=VARCHAR}
109 |
110 |
111 |
112 |
113 | when id = #{item.id,jdbcType=VARCHAR} then #{item.createTime,jdbcType=TIMESTAMP}
114 |
115 |
116 |
117 |
118 | when id = #{item.id,jdbcType=VARCHAR} then #{item.updateTime,jdbcType=TIMESTAMP}
119 |
120 |
121 |
122 |
123 | when id = #{item.id,jdbcType=VARCHAR} then #{item.enableStatus,jdbcType=VARCHAR}
124 |
125 |
126 |
127 | where id in
128 |
129 | #{item.id,jdbcType=VARCHAR}
130 |
131 |
132 |
133 |
134 | insert into tbl_application
135 | (id, `name`, create_time, update_time, enable_status)
136 | values
137 |
138 | (#{item.id,jdbcType=VARCHAR}, #{item.name,jdbcType=VARCHAR}, #{item.createTime,jdbcType=TIMESTAMP},
139 | #{item.updateTime,jdbcType=TIMESTAMP}, #{item.enableStatus,jdbcType=VARCHAR})
140 |
141 |
142 |
143 |
144 | insert into tbl_application
145 | (id, `name`, create_time, update_time, enable_status)
146 | values
147 | (#{id,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP},
148 | #{updateTime,jdbcType=TIMESTAMP}, #{enableStatus,jdbcType=VARCHAR})
149 | on duplicate key update
150 | id = #{id,jdbcType=VARCHAR},
151 | `name` = #{name,jdbcType=VARCHAR},
152 | create_time = #{createTime,jdbcType=TIMESTAMP},
153 | update_time = #{updateTime,jdbcType=TIMESTAMP},
154 | enable_status = #{enableStatus,jdbcType=VARCHAR}
155 |
156 |
157 |
158 | insert into tbl_application
159 |
160 |
161 | id,
162 |
163 |
164 | `name`,
165 |
166 |
167 | create_time,
168 |
169 |
170 | update_time,
171 |
172 |
173 | enable_status,
174 |
175 |
176 | values
177 |
178 |
179 | #{id,jdbcType=VARCHAR},
180 |
181 |
182 | #{name,jdbcType=VARCHAR},
183 |
184 |
185 | #{createTime,jdbcType=TIMESTAMP},
186 |
187 |
188 | #{updateTime,jdbcType=TIMESTAMP},
189 |
190 |
191 | #{enableStatus,jdbcType=VARCHAR},
192 |
193 |
194 | on duplicate key update
195 |
196 |
197 | id = #{id,jdbcType=VARCHAR},
198 |
199 |
200 | `name` = #{name,jdbcType=VARCHAR},
201 |
202 |
203 | create_time = #{createTime,jdbcType=TIMESTAMP},
204 |
205 |
206 | update_time = #{updateTime,jdbcType=TIMESTAMP},
207 |
208 |
209 | enable_status = #{enableStatus,jdbcType=VARCHAR},
210 |
211 |
212 |
213 |
--------------------------------------------------------------------------------
/code-update-server/target/classes/mapper/SerialNoMapper.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 | id, `name`, `value`, create_time, update_time, format
17 |
18 |
25 |
26 |
27 | delete
28 | from tbl_serial_no
29 | where id = #{id,jdbcType=VARCHAR}
30 |
31 |
32 |
33 | insert into tbl_serial_no (id, `name`, `value`,
34 | create_time, update_time, format)
35 | values (#{id,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, #{value,jdbcType=BIGINT},
36 | #{createTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP}, #{format,jdbcType=VARCHAR})
37 |
38 |
39 |
40 | insert into tbl_serial_no
41 |
42 |
43 | id,
44 |
45 |
46 | `name`,
47 |
48 |
49 | `value`,
50 |
51 |
52 | create_time,
53 |
54 |
55 | update_time,
56 |
57 |
58 | format,
59 |
60 |
61 |
62 |
63 | #{id,jdbcType=VARCHAR},
64 |
65 |
66 | #{name,jdbcType=VARCHAR},
67 |
68 |
69 | #{value,jdbcType=BIGINT},
70 |
71 |
72 | #{createTime,jdbcType=TIMESTAMP},
73 |
74 |
75 | #{updateTime,jdbcType=TIMESTAMP},
76 |
77 |
78 | #{format,jdbcType=VARCHAR},
79 |
80 |
81 |
82 |
83 |
84 | update tbl_serial_no
85 |
86 |
87 | `name` = #{name,jdbcType=VARCHAR},
88 |
89 |
90 | `value` = #{value,jdbcType=BIGINT},
91 |
92 |
93 | create_time = #{createTime,jdbcType=TIMESTAMP},
94 |
95 |
96 | update_time = #{updateTime,jdbcType=TIMESTAMP},
97 |
98 |
99 | format = #{format,jdbcType=VARCHAR},
100 |
101 |
102 | where id = #{id,jdbcType=VARCHAR}
103 |
104 |
105 |
106 | update tbl_serial_no
107 | set `name` = #{name,jdbcType=VARCHAR},
108 | `value` = #{value,jdbcType=BIGINT},
109 | create_time = #{createTime,jdbcType=TIMESTAMP},
110 | update_time = #{updateTime,jdbcType=TIMESTAMP},
111 | format = #{format,jdbcType=VARCHAR}
112 | where id = #{id,jdbcType=VARCHAR}
113 |
114 |
115 |
116 | update tbl_serial_no
117 |
118 |
119 |
120 | when id = #{item.id,jdbcType=VARCHAR} then #{item.name,jdbcType=VARCHAR}
121 |
122 |
123 |
124 |
125 | when id = #{item.id,jdbcType=VARCHAR} then #{item.value,jdbcType=BIGINT}
126 |
127 |
128 |
129 |
130 | when id = #{item.id,jdbcType=VARCHAR} then #{item.createTime,jdbcType=TIMESTAMP}
131 |
132 |
133 |
134 |
135 | when id = #{item.id,jdbcType=VARCHAR} then #{item.updateTime,jdbcType=TIMESTAMP}
136 |
137 |
138 |
139 |
140 | when id = #{item.id,jdbcType=VARCHAR} then #{item.format,jdbcType=VARCHAR}
141 |
142 |
143 |
144 | where id in
145 |
146 | #{item.id,jdbcType=VARCHAR}
147 |
148 |
149 |
150 |
151 | insert into tbl_serial_no
152 | (id, `name`, `value`, create_time, update_time, format)
153 | values
154 |
155 | (#{item.id,jdbcType=VARCHAR}, #{item.name,jdbcType=VARCHAR}, #{item.value,jdbcType=BIGINT},
156 | #{item.createTime,jdbcType=TIMESTAMP}, #{item.updateTime,jdbcType=TIMESTAMP},
157 | #{item.format,jdbcType=VARCHAR})
158 |
159 |
160 |
161 |
162 | insert into tbl_serial_no
163 | (id, `name`, `value`, create_time, update_time, format)
164 | values (#{id,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, #{value,jdbcType=BIGINT},
165 | #{createTime,jdbcType=TIMESTAMP},
166 | #{updateTime,jdbcType=TIMESTAMP}, #{format,jdbcType=VARCHAR}) on duplicate key
167 | update
168 | id = #{id,jdbcType=VARCHAR},
169 | `name` = #{name,jdbcType=VARCHAR},
170 | `value` = #{value,jdbcType=BIGINT},
171 | create_time = #{createTime,jdbcType=TIMESTAMP},
172 | update_time = #{updateTime,jdbcType=TIMESTAMP},
173 | format = #{format,jdbcType=VARCHAR}
174 |
175 |
176 |
177 | insert into tbl_serial_no
178 |
179 |
180 | id,
181 |
182 |
183 | `name`,
184 |
185 |
186 | `value`,
187 |
188 |
189 | create_time,
190 |
191 |
192 | update_time,
193 |
194 |
195 | format,
196 |
197 |
198 | values
199 |
200 |
201 | #{id,jdbcType=VARCHAR},
202 |
203 |
204 | #{name,jdbcType=VARCHAR},
205 |
206 |
207 | #{value,jdbcType=BIGINT},
208 |
209 |
210 | #{createTime,jdbcType=TIMESTAMP},
211 |
212 |
213 | #{updateTime,jdbcType=TIMESTAMP},
214 |
215 |
216 | #{format,jdbcType=VARCHAR},
217 |
218 |
219 | on duplicate key update
220 |
221 |
222 | id = #{id,jdbcType=VARCHAR},
223 |
224 |
225 | `name` = #{name,jdbcType=VARCHAR},
226 |
227 |
228 | `value` = #{value,jdbcType=BIGINT},
229 |
230 |
231 | create_time = #{createTime,jdbcType=TIMESTAMP},
232 |
233 |
234 | update_time = #{updateTime,jdbcType=TIMESTAMP},
235 |
236 |
237 | format = #{format,jdbcType=VARCHAR},
238 |
239 |
240 |
241 |
242 |
246 |
247 |
--------------------------------------------------------------------------------