diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0066531e..9c9b1681 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -5,7 +5,6 @@ on: branches: [development, master, main] paths: - 'app/**' - - 'packages/**' - 'tools/generate_icons.py' - 'packaging/windows/assets/**' - '.github/workflows/**' diff --git a/.github/workflows/linux-packaging.yml b/.github/workflows/linux-packaging.yml index c34ce4b3..64ef6bf6 100644 --- a/.github/workflows/linux-packaging.yml +++ b/.github/workflows/linux-packaging.yml @@ -5,7 +5,6 @@ on: pull_request: paths: - 'app/**' - - 'packages/**' - 'tools/run_packaged_smoke.py' - 'tools/check_packaged_reader.*' - 'tools/install_linux_build_dependencies.sh' diff --git a/.github/workflows/release-checks.yml b/.github/workflows/release-checks.yml index cf3910d8..ab2144a0 100644 --- a/.github/workflows/release-checks.yml +++ b/.github/workflows/release-checks.yml @@ -2,10 +2,10 @@ name: Release configuration checks on: pull_request: - paths: ['tools/**', '.github/workflows/**', 'app/pubspec.yaml', 'app/android/**', 'app/lib/updates/**', 'app/linux/**', 'app/windows/**', 'packaging/**', 'packages/**'] + paths: ['tools/**', '.github/workflows/**', 'app/pubspec.yaml', 'app/android/**', 'app/lib/updates/**', 'app/linux/**', 'app/windows/**', 'packaging/**'] push: branches: [development, master] - paths: ['tools/**', '.github/workflows/**', 'app/pubspec.yaml', 'app/android/**', 'app/lib/updates/**', 'app/linux/**', 'app/windows/**', 'packaging/**', 'packages/**'] + paths: ['tools/**', '.github/workflows/**', 'app/pubspec.yaml', 'app/android/**', 'app/lib/updates/**', 'app/linux/**', 'app/windows/**', 'packaging/**'] permissions: contents: read diff --git a/.github/workflows/windows-packaging.yml b/.github/workflows/windows-packaging.yml index 39177410..a9cb2c7e 100644 --- a/.github/workflows/windows-packaging.yml +++ b/.github/workflows/windows-packaging.yml @@ -5,7 +5,6 @@ on: pull_request: paths: - 'app/**' - - 'packages/**' - 'tools/run_packaged_smoke.py' - 'tools/check_packaged_reader.*' - 'tools/package_windows.ps1' diff --git a/README.md b/README.md index 0c8db277..3be130bc 100644 --- a/README.md +++ b/README.md @@ -66,6 +66,13 @@ selection-based reader annotations remain future work. - Flutter 3.41.2, matching the CI SDK: [installation guide](https://docs.flutter.dev/get-started/install) +### Patched dependencies + +`unrar_file` is maintained in the [Papyrus compatibility fork](https://github.com/PapyrusReader/unrar_file) +and pinned to a full commit SHA in `app/pubspec.yaml`. Its build fixes and upstream +provenance are documented in that repository's `PAPYRUS_PATCHES.md`. Update the +manifest and lockfile together after validating metadata tests and Android builds. + ### Installation > [!IMPORTANT] diff --git a/app/pubspec.lock b/app/pubspec.lock index 2ff7532c..0a1ecfeb 100644 --- a/app/pubspec.lock +++ b/app/pubspec.lock @@ -1032,9 +1032,11 @@ packages: unrar_file: dependency: "direct main" description: - path: "../packages/unrar_file" - relative: true - source: path + path: "." + ref: c3ad6a4ac4c732f081b9262bbf6b95ee2c1f5759 + resolved-ref: c3ad6a4ac4c732f081b9262bbf6b95ee2c1f5759 + url: "https://github.com/PapyrusReader/unrar_file.git" + source: git version: "1.1.0" url_launcher: dependency: "direct main" diff --git a/app/pubspec.yaml b/app/pubspec.yaml index d4f7e9dd..46ebeef2 100644 --- a/app/pubspec.yaml +++ b/app/pubspec.yaml @@ -33,7 +33,9 @@ dependencies: dart_mobi: ^1.0.2 archive: ^4.0.7 unrar_file: - path: ../packages/unrar_file + git: + url: https://github.com/PapyrusReader/unrar_file.git + ref: c3ad6a4ac4c732f081b9262bbf6b95ee2c1f5759 xml: ^6.6.1 image: ^4.7.2 path: ^1.9.1 diff --git a/packages/unrar_file/LICENSE b/packages/unrar_file/LICENSE deleted file mode 100644 index 261eeb9e..00000000 --- a/packages/unrar_file/LICENSE +++ /dev/null @@ -1,201 +0,0 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. diff --git a/packages/unrar_file/PAPYRUS_PATCHES.md b/packages/unrar_file/PAPYRUS_PATCHES.md deleted file mode 100644 index 673f06d9..00000000 --- a/packages/unrar_file/PAPYRUS_PATCHES.md +++ /dev/null @@ -1,20 +0,0 @@ -# Vendored unrar_file 1.1.0 - -Source: https://pub.dev/packages/unrar_file/versions/1.1.0 -Upstream: https://github.com/syedecryptr/unrar_file -License: Apache-2.0, retained in LICENSE. - -The upstream Android plugin predates AGP namespaces and imports the removed -Flutter v1 Registrar API. The release build failed on both. This copy retains -the Dart decoder, channel implementation and iOS implementation unchanged, except -for removing that unused Java import. The Android module declares its namespace, -removes the obsolete manifest package attribute, uses the host's Gradle plugin -and repositories, and compiles against API 36/Java 11/minimum API 24. The Dart SDK -range allows the existing null-safe code on the pinned Dart 3 toolchain. - -No archive parsing or extraction behavior is changed. This is a reviewed, -repository-owned compatibility patch, not a mutation of a developer's pub cache. -Replace with an upstream compatible release when available. - -The host app supplies an SLF4J 1.7 NOP binding for Junrar, so R8 resolves its -optional StaticLoggerBinder without disabling shrinking or hiding missing classes. diff --git a/packages/unrar_file/README.md b/packages/unrar_file/README.md deleted file mode 100644 index 09ae01bc..00000000 --- a/packages/unrar_file/README.md +++ /dev/null @@ -1,44 +0,0 @@ -# unrar_file - -flutter wrapper around [junrar](https://github.com/junrar/junrar) library for extracting RAR files. - -It additionally supports **RAR5** which junrar don't. - - - - -## Usage - -```dart - Future extract_file(input_file_path,destination_path, {password=""}) async { - // Extraction may fail, so we use a try/catch PlatformException. - try { - await UnrarFile.extract_rar(input_file_path, destination_path, password: password); - } catch(e) { - print("extraction failed $e"); - } - return; - } - -``` - -## Getting Started - -This project is a starting point for a Flutter application. - -A few resources to get you started if this is your first Flutter project: - -- [Lab: Write your first Flutter app](https://flutter.dev/docs/get-started/codelab) -- [Cookbook: Useful Flutter samples](https://flutter.dev/docs/cookbook) - -For help getting started with Flutter, view our -[online documentation](https://flutter.dev/docs), which offers tutorials, -samples, guidance on mobile development, and a full API reference. - - -## Contributing -Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change. - - -## License -[Apache-2.0 License](https://github.com/syedecryptr/unrar_file/blob/master/LICENSE) diff --git a/packages/unrar_file/android/build.gradle b/packages/unrar_file/android/build.gradle deleted file mode 100644 index afbadc71..00000000 --- a/packages/unrar_file/android/build.gradle +++ /dev/null @@ -1,22 +0,0 @@ -group 'com.syed.unrar_file' -version '1.0' - -apply plugin: 'com.android.library' - -android { - namespace 'com.syed.unrar_file' - compileSdk 36 - - defaultConfig { - minSdkVersion 24 - } - - compileOptions { - sourceCompatibility JavaVersion.VERSION_11 - targetCompatibility JavaVersion.VERSION_11 - } -} - -dependencies { - implementation 'com.github.junrar:junrar:7.4.0' -} diff --git a/packages/unrar_file/android/src/main/AndroidManifest.xml b/packages/unrar_file/android/src/main/AndroidManifest.xml deleted file mode 100644 index 94cbbcfc..00000000 --- a/packages/unrar_file/android/src/main/AndroidManifest.xml +++ /dev/null @@ -1 +0,0 @@ - diff --git a/packages/unrar_file/android/src/main/java/com/syed/unrar_file/UnrarFilePlugin.java b/packages/unrar_file/android/src/main/java/com/syed/unrar_file/UnrarFilePlugin.java deleted file mode 100644 index 99d45d10..00000000 --- a/packages/unrar_file/android/src/main/java/com/syed/unrar_file/UnrarFilePlugin.java +++ /dev/null @@ -1,74 +0,0 @@ -package com.syed.unrar_file; - -import android.util.Log; - -import androidx.annotation.NonNull; - -import com.github.junrar.Junrar; -import com.github.junrar.exception.RarException; -import com.github.junrar.exception.UnsupportedRarV5Exception; - -import java.io.IOException; - -import io.flutter.embedding.engine.plugins.FlutterPlugin; -import io.flutter.plugin.common.MethodCall; -import io.flutter.plugin.common.MethodChannel; -import io.flutter.plugin.common.MethodChannel.MethodCallHandler; -import io.flutter.plugin.common.MethodChannel.Result; - -/** UnrarFilePlugin */ -public class UnrarFilePlugin implements FlutterPlugin, MethodCallHandler { - /// The MethodChannel that will the communication between Flutter and native Android - /// - /// This local reference serves to register the plugin with the Flutter Engine and unregister it - /// when the Flutter Engine is detached from the Activity - private MethodChannel channel; - - public static boolean isNullOrEmpty(String str) { - if(str != null && !str.isEmpty()) - return false; - return true; - } - @Override - public void onAttachedToEngine(@NonNull FlutterPluginBinding flutterPluginBinding) { - channel = new MethodChannel(flutterPluginBinding.getBinaryMessenger(), "unrar_file"); - channel.setMethodCallHandler(this); - } - - @Override - public void onMethodCall(@NonNull MethodCall call, @NonNull Result result) { - if (call.method.equals("extractRAR")) { - final String file_path = call.argument("file_path"); - final String destination_path = call.argument("destination_path"); - final String password = call.argument("password"); -// result.success("extraction done"); - try { - if(isNullOrEmpty(password)) { - Junrar.extract(file_path, destination_path); - } - else{ - Junrar.extract(file_path, destination_path, password); - } - result.success("Extraction Success"); - - } - catch (UnsupportedRarV5Exception e ){ - - result.error("extractionRAR5Error", e.toString(), null); - - } - catch (IOException | RarException e){ - - result.error("extractionError", e.toString(), null); - } - } else { - result.notImplemented(); - } - } - - - @Override - public void onDetachedFromEngine(@NonNull FlutterPluginBinding binding) { - channel.setMethodCallHandler(null); - } -} diff --git a/packages/unrar_file/ios/.gitignore b/packages/unrar_file/ios/.gitignore deleted file mode 100644 index aa479fd3..00000000 --- a/packages/unrar_file/ios/.gitignore +++ /dev/null @@ -1,37 +0,0 @@ -.idea/ -.vagrant/ -.sconsign.dblite -.svn/ - -.DS_Store -*.swp -profile - -DerivedData/ -build/ -GeneratedPluginRegistrant.h -GeneratedPluginRegistrant.m - -.generated/ - -*.pbxuser -*.mode1v3 -*.mode2v3 -*.perspectivev3 - -!default.pbxuser -!default.mode1v3 -!default.mode2v3 -!default.perspectivev3 - -xcuserdata - -*.moved-aside - -*.pyc -*sync/ -Icon? -.tags* - -/Flutter/Generated.xcconfig -/Flutter/flutter_export_environment.sh \ No newline at end of file diff --git a/packages/unrar_file/ios/Assets/.gitkeep b/packages/unrar_file/ios/Assets/.gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/packages/unrar_file/ios/Classes/UnrarFilePlugin.h b/packages/unrar_file/ios/Classes/UnrarFilePlugin.h deleted file mode 100644 index 31b2b779..00000000 --- a/packages/unrar_file/ios/Classes/UnrarFilePlugin.h +++ /dev/null @@ -1,4 +0,0 @@ -#import - -@interface UnrarFilePlugin : NSObject -@end diff --git a/packages/unrar_file/ios/Classes/UnrarFilePlugin.m b/packages/unrar_file/ios/Classes/UnrarFilePlugin.m deleted file mode 100644 index b9b1be9d..00000000 --- a/packages/unrar_file/ios/Classes/UnrarFilePlugin.m +++ /dev/null @@ -1,39 +0,0 @@ -#import "UnrarFilePlugin.h" -@import UnrarKit; - -static inline NSString* NSStringFromBOOL(BOOL aBool) { - return aBool? @"SUCCESS" : @"FAILURE"; -} - -@implementation UnrarFilePlugin -+ (void)registerWithRegistrar:(NSObject*)registrar { - FlutterMethodChannel* channel = [FlutterMethodChannel - methodChannelWithName:@"unrar_file" - binaryMessenger:[registrar messenger]]; - UnrarFilePlugin* instance = [[UnrarFilePlugin alloc] init]; - [registrar addMethodCallDelegate:instance channel:channel]; -} - -- (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result { - if ([@"extractRAR" isEqualToString:call.method]) { - NSString* file_path = call.arguments[@"file_path"]; - NSString* destination_path = call.arguments[@"destination_path"]; - NSString* password = call.arguments[@"password"]; - NSError *archiveError = nil; - URKArchive *archive = [[URKArchive alloc] initWithPath:file_path - error:&archiveError]; - NSError *error = nil; - BOOL extractFilesSuccessful; - if (archive.isPasswordProtected && password.length!=0) { - archive.password = password; - } - extractFilesSuccessful = [archive extractFilesTo:destination_path overwrite:NO - error:&error]; - - result(NSStringFromBOOL(extractFilesSuccessful)); - } else { - result(FlutterMethodNotImplemented); - } -} - -@end diff --git a/packages/unrar_file/ios/unrar_file.podspec b/packages/unrar_file/ios/unrar_file.podspec deleted file mode 100644 index 4ef09192..00000000 --- a/packages/unrar_file/ios/unrar_file.podspec +++ /dev/null @@ -1,27 +0,0 @@ -# -# To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html -# -Pod::Spec.new do |s| - s.name = 'unrar_file' - s.version = '0.0.1' - s.summary = 'Archive a rar file using junrar android and Unrarkit in ios code on github.' - s.description = <<-DESC -A new flutter plugin project. - DESC - s.homepage = 'https://github.com/syedecryptr/unrar_file' - s.license = { :file => '../LICENSE' } - s.author = { 'syedecryptr' => 'syedecryptr@gmail.com' } - s.source = { :path => '.' } - - - s.source_files = [ - 'Classes/**/*', - ] - - s.dependency 'Flutter' - - s.dependency 'UnrarKit' - s.ios.deployment_target = '9.0' - - -end diff --git a/packages/unrar_file/lib/src/rarFile.dart b/packages/unrar_file/lib/src/rarFile.dart deleted file mode 100644 index c364d4ef..00000000 --- a/packages/unrar_file/lib/src/rarFile.dart +++ /dev/null @@ -1,35 +0,0 @@ -import 'dart:convert'; -import 'dart:typed_data'; - -import 'rar_decoder.dart'; - -class RarFile { - String? name; - String? path; - late List hierarchy; - Uint8List? content; - Uint8List? extra; - int? _flags; - int? _compressionInfo; - String? parent; - List children = []; - - int get compressionVersion => _compressionInfo! & 0x003f; - - bool get solidFlag => (_compressionInfo! & 0x0040) == 1; - - int get compressionMethod => _compressionInfo! & 0x0380; - - bool get isDirectory => (_flags! & 1) == 1; - - RarFile(FILE_SERVICE_BLOCK block) { - hierarchy = utf8.decode(block.NAME!).split('/'); - path = utf8.decode(block.NAME!); - name = hierarchy.last; - parent = (hierarchy.length > 1) ? hierarchy.sublist(0, hierarchy.length - 1).join('/') : null; - extra = block.EXTRA_AREA; - content = block.DATA_AREA; - _flags = block.FILE_FLAGS; - _compressionInfo = block.COMPRESSION_INFO; - } -} diff --git a/packages/unrar_file/lib/src/rar_decoder.dart b/packages/unrar_file/lib/src/rar_decoder.dart deleted file mode 100644 index 2c4eeb04..00000000 --- a/packages/unrar_file/lib/src/rar_decoder.dart +++ /dev/null @@ -1,194 +0,0 @@ -import 'dart:convert'; -import 'dart:io'; -import 'dart:typed_data'; - -import 'rarFile.dart'; -import 'vint.dart'; - -class RAR5 { - static const SIGNATURE = 0x0001071A21726152; //[0x52, 0x61, 0x72, 0x21, 0x1A, 0x07, 0x01, 0x00]; - MAIN_ARCHIVE_HEADER? MAIN_HEAD; - ARCHIVE_ENCRYPTION? ARCHIVE_ENCRYPTION_BLOCK; - List SERVICE_BLOCKS = []; - List _files = []; - END_OF_ARCHIVE? END_OF_ARCHIVE_BLOCK; - - List hierarchy = []; - - String get comment => utf8.decode(SERVICE_BLOCKS.first.DATA_AREA!); - - get files => _files; - - RAR5(path) { - var file = File(path); - var randomAccessFile = file.openSync(mode: FileMode.read); - - var signature = randomAccessFile.readSync(8).merge(true); - if (signature != SIGNATURE) { - throw RAR5Exception('Wrong signature'); - } - - // assert(signature == [0x52, 0x61, 0x72, 0x21, 0x1A, 0x07, 0x00].merge(true), - // '$path is not a .rar file version 4.'); - - while (randomAccessFile.positionSync() < randomAccessFile.lengthSync()) { - var header = Header(randomAccessFile); - - // Check HEAD_TYPE and create a block object accordingly - switch (header.HEAD_TYPE) { - case 1: - MAIN_HEAD = MAIN_ARCHIVE_HEADER(randomAccessFile, header); - break; - case 2: - FILE_SERVICE_BLOCK block = FILE_SERVICE_BLOCK(randomAccessFile, header); - RarFile file = RarFile(block); - _files.add(file); - break; - case 3: - SERVICE_BLOCKS.add(FILE_SERVICE_BLOCK(randomAccessFile, header)); - break; - case 4: - ARCHIVE_ENCRYPTION_BLOCK = ARCHIVE_ENCRYPTION(randomAccessFile, header); - break; - case 5: - END_OF_ARCHIVE_BLOCK = END_OF_ARCHIVE(randomAccessFile, header); - break; - default: - throw Exception('Unknown block'); - } - } - _createHierarchy(); - randomAccessFile.closeSync(); - } - - /// Joins files inside a directory to their parent directory - void _createHierarchy() { - List removed = []; - for (RarFile file in _files) { - if (removed.contains(file)) { - continue; - } - if (file.parent != null) { - int i = _files.indexWhere((f) => f.path == file.parent); - _files[i].children.add(file); - removed.add(file); - } - } - for (RarFile r in removed) { - _files.remove(r); - } - } - - /// Prints file hierarchy inside the archive - void showFiles([List? listOfNodes, int? level]) { - if (listOfNodes == null) { - listOfNodes = _files; - } - - if (level == null) { - level = 0; - } - for (var file in listOfNodes) { - print('${'\t' * level}${file.name}'); - - if (!file.children.isEmpty) { - showFiles(file.children, level + 1); - } - } - } -} - -class Header { - int? HEAD_CRC; // 4 bytes - int? HEAD_TYPE; // vint - late int HEAD_FLAGS; // vint - int? HEAD_SIZE; // vint - - Header(RandomAccessFile file) { - HEAD_CRC = file.readSync(4).merge(true); - HEAD_SIZE = VINT.fromFile(file).result; - HEAD_TYPE = VINT.fromFile(file).result; - HEAD_FLAGS = VINT.fromFile(file).result; - } -} - -abstract class Block { - Header header; - - Block(this.header); -} - -class MAIN_ARCHIVE_HEADER extends Block { - int? EXTRA_AREA_SIZE, ARCHIVE_FLAGS, VOLUME_NUMBER; - var EXTRA_AREA; - - MAIN_ARCHIVE_HEADER(RandomAccessFile file, Header header) : super(header) { - EXTRA_AREA_SIZE = (super.header.HEAD_FLAGS & 0x0001 != 0) ? VINT.fromFile(file).result : null; - ARCHIVE_FLAGS = VINT.fromFile(file).result; - VOLUME_NUMBER = (super.header.HEAD_FLAGS & 0x0002 != 0) ? VINT.fromFile(file).result : null; - EXTRA_AREA = (super.header.HEAD_FLAGS & 0x0001 != 0) ? file.readSync(EXTRA_AREA_SIZE!) : null; - } -} - -class FILE_SERVICE_BLOCK extends Block { - int? EXTRA_AREA_SIZE, - DATA_SIZE, - FILE_FLAGS, - UNP_SIZE, - ATTRIBUTES, - MTIME, - DATA_CRC, - COMPRESSION_INFO, - HOST_OS, - NAME_SIZE; - - Uint8List? EXTRA_AREA; - - Uint8List? DATA_AREA, NAME; - - FILE_SERVICE_BLOCK(RandomAccessFile file, Header header) : super(header) { - EXTRA_AREA_SIZE = (super.header.HEAD_FLAGS & 0x0001 != 0) ? VINT.fromFile(file).result : null; - DATA_SIZE = (super.header.HEAD_FLAGS & 0x0002 != 0) ? VINT.fromFile(file).result : null; - FILE_FLAGS = VINT.fromFile(file).result; - UNP_SIZE = VINT.fromFile(file).result; - ATTRIBUTES = VINT.fromFile(file).result; - MTIME = (FILE_FLAGS! & 0x0002 != 0) ? file.readSync(4).merge(true) : null; - DATA_CRC = (FILE_FLAGS! & 0x0004 != 0) ? file.readSync(4).merge(true) : null; - COMPRESSION_INFO = VINT.fromFile(file).result; - HOST_OS = VINT.fromFile(file).result; - NAME_SIZE = VINT.fromFile(file).result; - NAME = file.readSync(NAME_SIZE!); - EXTRA_AREA = (super.header.HEAD_FLAGS & 0x0001 != 0) ? file.readSync(EXTRA_AREA_SIZE!) : null; - DATA_AREA = (super.header.HEAD_FLAGS & 0x0002 != 0) ? file.readSync(DATA_SIZE!) : null; - } -} - -class END_OF_ARCHIVE extends Block { - int? END_OF_ARCHIVE_FLAGS; - - END_OF_ARCHIVE(RandomAccessFile file, Header header) : super(header) { - END_OF_ARCHIVE_FLAGS = VINT.fromFile(file).result; - } -} - -class ARCHIVE_ENCRYPTION extends Block { - int? ENCYRPTION_VERSION; // vint - int? ENCYRPTION_FLAGS; // vint - int? KDF_COUNT; // 1 byte - int? SALT; // 16 bytes - int? CHECK_VALUE; // 12 bytes - - ARCHIVE_ENCRYPTION(RandomAccessFile file, Header header) : super(header) { - ENCYRPTION_VERSION = VINT.fromFile(file).result; - ENCYRPTION_FLAGS = VINT.fromFile(file).result; - KDF_COUNT = file.readSync(1).merge(true); - SALT = file.readSync(16).merge(true); - CHECK_VALUE = file.readSync(12).merge(true); - } -} - -class RAR5Exception implements Exception { - String cause; - - RAR5Exception(this.cause); -} diff --git a/packages/unrar_file/lib/src/records.dart b/packages/unrar_file/lib/src/records.dart deleted file mode 100644 index a15e4954..00000000 --- a/packages/unrar_file/lib/src/records.dart +++ /dev/null @@ -1,27 +0,0 @@ -import 'dart:typed_data'; -import 'vint.dart'; - -class Record { - int? size; - int? type; - - Record(Uint8List list) { - size = VINT.fromList(list).result; - type = VINT.fromList(list).result; - } -} - -class FileEncryption { - Record header; - int? version; // vint 0 - int? flags; // vint 3 - int? kdf_count; // 1 byte 15 - int? salt; // 16 bytes 155, 174, 90, 241, 142, 25, 221, 158, 100, 169, 176, 200, 60, 216, 77, 163 - int? iv; // 16 bytes 245, 65, 228, 101, 246, 0, 154, 224, 32, 47, 115, 92, 207, 125, 112, 134 - int? check_value; // 12 bytes 99, 133, 127, 218, 35, 87, 250, 141, 50, 57, 103, 183 - - FileEncryption(Uint8List extra, this.header) { - version = VINT.fromList(extra).result; - flags = VINT.fromList(extra).result; - } -} diff --git a/packages/unrar_file/lib/src/vint.dart b/packages/unrar_file/lib/src/vint.dart deleted file mode 100644 index 1d9d1931..00000000 --- a/packages/unrar_file/lib/src/vint.dart +++ /dev/null @@ -1,45 +0,0 @@ -import 'dart:io'; -import 'dart:typed_data'; - -class VINT { - final List _ints = []; - - int get result => Uint8List.fromList(_ints).merge(true); - - VINT.fromFile(RandomAccessFile file) { - bool continuationFlag = false; - do { - // Read byte - int byte = file.readByteSync(); - - // Clear the most significant bit [continuation_flag] and add to list of integers - _ints.add(byte & ~(0x80)); - - // Get the most significant bit (continuation_flag) - continuationFlag = (byte & 0x80 != 0) ? true : false; - } while (continuationFlag); - } - - VINT.fromList(Uint8List list) { - int index = 0; - bool continuationFlag = false; - do { - // Read byte - int byte = list[index++]; - - // Clear the most significant bit [continuation_flag] and add to list of integers - _ints.add(byte & ~(0x80)); - - // Get the most significant bit (continuation_flag) - continuationFlag = (byte & 0x80 != 0) ? true : false; - } while (continuationFlag); - list.removeRange(0, index); - } -} - -extension Bytes on List { - int merge([bool littleEndian = false]) { - return Uint8List.fromList(littleEndian ? this.reversed.toList() as List : this as List) - .reduce((value, newElement) => newElement | (value << 8)); - } -} diff --git a/packages/unrar_file/lib/unrar_file.dart b/packages/unrar_file/lib/unrar_file.dart deleted file mode 100644 index 2fd7023e..00000000 --- a/packages/unrar_file/lib/unrar_file.dart +++ /dev/null @@ -1,37 +0,0 @@ - -import 'dart:async'; -import 'package:unrar_file/src/rarFile.dart'; -import 'package:unrar_file/src/rar_decoder.dart'; -import 'dart:io'; -import 'package:flutter/services.dart'; -import 'package:path/path.dart'; -class UnrarFile { - static const MethodChannel _channel = - const MethodChannel('unrar_file'); - - static Future extract_rar(file_path, destination_path, {password=""}) async { - try { - var result = await _channel.invokeMethod('extractRAR', {"file_path": file_path, "destination_path": destination_path, "password":password}); - return result; - } - on PlatformException catch(e){ - if(e.code == "extractionRAR5Error"){ - try { - var rar_file = RAR5(file_path); - var files = rar_file.files; - for (RarFile file in files) { - var file_to_save = File(join(destination_path, file.name)); - file_to_save.writeAsBytesSync(file.content!); - } - return "Extraction Success"; - } - catch(e){ - throw e.toString(); - } - } - else{ - throw e.message!; - } - } - } -} diff --git a/packages/unrar_file/pubspec.yaml b/packages/unrar_file/pubspec.yaml deleted file mode 100644 index 52712f58..00000000 --- a/packages/unrar_file/pubspec.yaml +++ /dev/null @@ -1,23 +0,0 @@ -name: unrar_file -description: Vendored unrar_file with Android build compatibility fixes. -version: 1.1.0 -publish_to: none -homepage: https://github.com/syedecryptr/unrar_file - -environment: - sdk: '>=3.3.0 <4.0.0' - flutter: '>=3.19.0' - -dependencies: - flutter: - sdk: flutter - path: ^1.8.0 - -flutter: - plugin: - platforms: - android: - package: com.syed.unrar_file - pluginClass: UnrarFilePlugin - ios: - pluginClass: UnrarFilePlugin