From 4bdd9bff47ed0681b6534e82cd09b798d5f2a704 Mon Sep 17 00:00:00 2001 From: MiaoMint <1981324730@qq.com> Date: Mon, 11 Dec 2023 23:16:00 +0800 Subject: [PATCH] remove backup --- assets/i18n/en.json | 16 +- lib/utils/application.dart | 161 ------------------ lib/utils/miru_storage.dart | 5 - lib/views/pages/settings_page.dart | 53 ------ macos/Flutter/GeneratedPluginRegistrant.swift | 2 - pubspec.lock | 26 +-- pubspec.yaml | 4 +- .../flutter/generated_plugin_registrant.cc | 3 - windows/flutter/generated_plugins.cmake | 1 - 9 files changed, 3 insertions(+), 268 deletions(-) diff --git a/assets/i18n/en.json b/assets/i18n/en.json index 61c84a17..bb4a6177 100644 --- a/assets/i18n/en.json +++ b/assets/i18n/en.json @@ -109,11 +109,7 @@ "source-code": "Open Source", "source-code-training": "Give Star", "license": "License", - "license-subtitle": "License", - "export-file":"Export", - "import-file":"Import", - "backup":"Backup", - "backup-subtitle":"Backup or restore data from local" + "license-subtitle": "License" }, "external-player-launching": "Launching {player}", @@ -216,15 +212,5 @@ "stop": "Stop", "upgrade": "Upgrade", "start": "Start" - }, - "backup": { - "import-unzip-success" : "recover success :", - "import-unzip-success-sub":"data recover success please restart the app", - "import-unzip-fail" : "recover fail", - "export-success":"export success", - "export-fail":"export fail", - "export-success-sub":"data export success choose the folder", - "import-filePath-failed":"failed at getting file in this path please switch to the another folder", - "select-folder":"select the folder to store save file" } } diff --git a/lib/utils/application.dart b/lib/utils/application.dart index d2788a2e..bc11c005 100644 --- a/lib/utils/application.dart +++ b/lib/utils/application.dart @@ -1,12 +1,10 @@ // ignore_for_file: use_build_context_synchronously import 'dart:io'; -import 'package:archive/archive.dart'; import 'package:dio/dio.dart'; import 'package:flutter/material.dart'; import 'package:flutter_i18n/flutter_i18n.dart'; import 'package:flutter_markdown/flutter_markdown.dart'; -import 'package:miru_app/utils/miru_storage.dart'; import 'package:get/get.dart'; import 'package:miru_app/utils/i18n.dart'; import 'package:miru_app/utils/router.dart'; @@ -15,9 +13,6 @@ import 'package:miru_app/views/widgets/messenger.dart'; import 'package:url_launcher/url_launcher.dart'; import 'package:package_info_plus/package_info_plus.dart'; import 'package:device_info_plus/device_info_plus.dart'; -import 'package:file_picker/file_picker.dart'; -import 'package:share_plus/share_plus.dart'; -import 'package:path_provider/path_provider.dart'; late PackageInfo packageInfo; late AndroidDeviceInfo androidDeviceInfo; @@ -140,160 +135,4 @@ class ApplicationUtils { ); } } - - static Future exportSaveFile( - BuildContext context, - ) async { - final directory = await getApplicationDocumentsDirectory(); - final archive = Archive(); - DateTime now = DateTime.now(); - //android backup function - if (Platform.isAndroid) { - bool result = await archivefiles([ - "${directory.path}/miru/default.isar", - "${directory.path}/miru/settings.hive" - ], "${directory.path}/miru-backup-${now.year}-${now.month}-${now.day}_${now.hour}:${now.minute}.zip", - archive, ZipEncoder()); - if (result) { - return showPlatformSnackbar( - context: context, - title: 'backup.export-success'.i18n, - content: "backup.export-success".i18n, - ); - } - return showPlatformSnackbar( - context: context, - title: 'backup.export-failed'.i18n, - content: "backup.export-failed".i18n, - ); - } - //desktop backup function - else { - String? folderPath = await FilePicker.platform - .getDirectoryPath(dialogTitle: "backup.select-folder".i18n); - if (folderPath == null) { - return showPlatformSnackbar( - context: context, - title: 'backup.import-filePath-failed'.i18n, - content: "backup.import-failed".i18n, - ); - } - bool result = await archivefiles([ - "${directory.path}/miru/default.isar", - "${directory.path}/miru/settings.hive" - ], "$folderPath\\miru-backup-${now.year}-${now.month}-${now.day}_${now.hour}-${now.minute}.zip", - archive, ZipEncoder()); - if (result) { - return showPlatformSnackbar( - context: context, - title: 'backup.export-success'.i18n, - content: "backup.export-success".i18n, - ); - } - return showPlatformSnackbar( - context: context, - title: 'backup.export-failed'.i18n, - content: "backup.export-failed".i18n, - ); - } - } - - static Future importSaveFile( - BuildContext context, - ) async { - final directory = await getApplicationDocumentsDirectory(); - FilePickerResult? folderPath = await FilePicker.platform.pickFiles(); - if (folderPath == null) { - return showPlatformSnackbar( - context: context, - title: 'backup.import-filePath-failed'.i18n, - content: "backup.import-failed".i18n, - ); - } - debugPrint("${folderPath.files.single.path}"); - debugPrint("unZip: $directory"); - //clear database - MiruStorage.deleteAll(); - final unZip = await unarchivefiles( - folderPath.files.single.path!, "${directory.path}/miru", ZipDecoder()); - - //unzip succeeded 解壓成功 - if (unZip == null) { - return showPlatformSnackbar( - context: context, - title: 'backup.import-unzip-success'.i18n, - content: "backup.import-unzip-success-sub".i18n, - ); - } - //unzip failed 解壓失敗 - return showPlatformSnackbar( - context: context, - title: 'backup.import-unzip-failed'.i18n, - content: unZip, - ); - } - - static Future copyFile( - String sourcePath, String destinationPath) async { - File sourceFile = File(sourcePath); - File destinationFile = File(destinationPath); - try { - await sourceFile.copy(destinationFile.path); - return true; - } catch (e) { - return false; - } - } - - static Future unarchivefiles( - String path, String targetPath, dynamic encoder) async { - try { - final bytes = await File(path).readAsBytes(); - final archive = ZipDecoder().decodeBytes(bytes); - for (final file in archive) { - final filename = file.name; - if (file.isFile) { - final data = file.content as List; - debugPrint("$path/$filename"); - File("$targetPath/$filename") - ..createSync(recursive: true) - ..writeAsBytesSync(data); - } else { - Directory('$path/$filename').create(recursive: true); - } - } - return; - } catch (e) { - debugPrint("$e"); - return e; - } - } - - static Future archivefiles(List paths, String targetPath, - Archive archive, dynamic encoder) async { - for (final path in paths) { - final bytes = await File(path).readAsBytes(); - final fileName = File(path).path.split('/').last; - final archiveFile = ArchiveFile(fileName, bytes.length, bytes); - archive.addFile(archiveFile); - debugPrint("${bytes.length}"); - } - final output = encoder.encode(archive); - if (output == null) { - debugPrint("encode failed"); - return false; - } - if (Platform.isAndroid) { - File(targetPath).writeAsBytesSync(output); - await Share.shareXFiles( - [XFile(targetPath)], - ); - File(targetPath).delete(); - return true; - } - File(targetPath).writeAsBytesSync(output); - debugPrint(targetPath); - // - return true; - } } diff --git a/lib/utils/miru_storage.dart b/lib/utils/miru_storage.dart index 53efb287..8b393f8d 100644 --- a/lib/utils/miru_storage.dart +++ b/lib/utils/miru_storage.dart @@ -134,11 +134,6 @@ class MiruStorage { static getSetting(String key) { return settings.get(key); } - - static deleteAll() async { - final re = await database.close(deleteFromDisk: true); - debugPrint('Database closed: $re'); - } } class SettingKey { diff --git a/lib/views/pages/settings_page.dart b/lib/views/pages/settings_page.dart index 4582238e..2c3fc71a 100644 --- a/lib/views/pages/settings_page.dart +++ b/lib/views/pages/settings_page.dart @@ -163,59 +163,6 @@ class _SettingsPageState extends State { ), ), const SizedBox(height: 8), - SettingsTile( - icon: const PlatformWidget( - androidWidget: Icon(Icons.backup), - desktopWidget: Icon(fluent.FluentIcons.update_restore, size: 24), - ), - title: 'settings.backup'.i18n, - buildSubtitle: () => FlutterI18n.translate( - context, - 'settings.backup-subtitle', - translationParams: { - 'version': packageInfo.version, - }, - ), - trailing: PlatformWidget( - androidWidget: Row( - mainAxisSize: MainAxisSize.min, - children: [ - TextButton( - onPressed: () { - ApplicationUtils.exportSaveFile(context); - }, - child: Text('settings.export-file'.i18n), - ), - TextButton( - onPressed: () { - ApplicationUtils.importSaveFile(context); - }, - child: Text('settings.import-file'.i18n), - ) - ], - ), - desktopWidget: Row(children: [ - fluent.FilledButton( - onPressed: () { - ApplicationUtils.exportSaveFile( - context, - ); - }, - child: Text('settings.export-file'.i18n), - ), - const SizedBox(width: 16), - fluent.Button( - onPressed: () { - ApplicationUtils.importSaveFile( - context, - ); - }, - child: Text('settings.import-file'.i18n), - ) - ]), - ), - ), - const SizedBox(height: 8), SettingsSwitchTile( icon: const PlatformWidget( androidWidget: Icon(Icons.autorenew_sharp), diff --git a/macos/Flutter/GeneratedPluginRegistrant.swift b/macos/Flutter/GeneratedPluginRegistrant.swift index 1249d6d1..f71d65fb 100644 --- a/macos/Flutter/GeneratedPluginRegistrant.swift +++ b/macos/Flutter/GeneratedPluginRegistrant.swift @@ -16,7 +16,6 @@ import package_info_plus import path_provider_foundation import screen_brightness_macos import screen_retriever -import share_plus import sqflite import url_launcher_macos import wakelock_plus @@ -34,7 +33,6 @@ func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin")) ScreenBrightnessMacosPlugin.register(with: registry.registrar(forPlugin: "ScreenBrightnessMacosPlugin")) ScreenRetrieverPlugin.register(with: registry.registrar(forPlugin: "ScreenRetrieverPlugin")) - SharePlusMacosPlugin.register(with: registry.registrar(forPlugin: "SharePlusMacosPlugin")) SqflitePlugin.register(with: registry.registrar(forPlugin: "SqflitePlugin")) UrlLauncherPlugin.register(with: registry.registrar(forPlugin: "UrlLauncherPlugin")) WakelockPlusMacosPlugin.register(with: registry.registrar(forPlugin: "WakelockPlusMacosPlugin")) diff --git a/pubspec.lock b/pubspec.lock index 92ab7f98..9905a1da 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -26,7 +26,7 @@ packages: source: hosted version: "4.0.3" archive: - dependency: "direct main" + dependency: transitive description: name: archive sha256: "7b875fd4a20b165a3084bd2d210439b22ebc653f21cea4842729c0c30c82596b" @@ -225,14 +225,6 @@ packages: url: "https://pub.dev" source: hosted version: "4.0.8" - cross_file: - dependency: transitive - description: - name: cross_file - sha256: fedaadfa3a6996f75211d835aaeb8fede285dae94262485698afd832371b9a5e - url: "https://pub.dev" - source: hosted - version: "0.3.3+8" crypto: dependency: "direct main" description: @@ -1109,22 +1101,6 @@ packages: url: "https://pub.dev" source: hosted version: "0.3.8" - share_plus: - dependency: "direct main" - description: - name: share_plus - sha256: f74fc3f1cbd99f39760182e176802f693fa0ec9625c045561cfad54681ea93dd - url: "https://pub.dev" - source: hosted - version: "7.2.1" - share_plus_platform_interface: - dependency: transitive - description: - name: share_plus_platform_interface - sha256: df08bc3a07d01f5ea47b45d03ffcba1fa9cd5370fb44b3f38c70e42cced0f956 - url: "https://pub.dev" - source: hosted - version: "3.3.1" shelf: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 45510610..4325b793 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -57,9 +57,7 @@ dependencies: crypto: ^3.0.3 extended_image: ^8.2.0 flutter_hls_parser: ^2.0.1 - archive: ^3.4.9 - # permission_handler: ^11.1.0 - share_plus: ^7.2.1 + dev_dependencies: flutter_test: sdk: flutter diff --git a/windows/flutter/generated_plugin_registrant.cc b/windows/flutter/generated_plugin_registrant.cc index 4ed5ca7b..c697e2b2 100644 --- a/windows/flutter/generated_plugin_registrant.cc +++ b/windows/flutter/generated_plugin_registrant.cc @@ -14,7 +14,6 @@ #include #include #include -#include #include #include @@ -35,8 +34,6 @@ void RegisterPlugins(flutter::PluginRegistry* registry) { registry->GetRegistrarForPlugin("ScreenBrightnessWindowsPlugin")); ScreenRetrieverPluginRegisterWithRegistrar( registry->GetRegistrarForPlugin("ScreenRetrieverPlugin")); - SharePlusWindowsPluginCApiRegisterWithRegistrar( - registry->GetRegistrarForPlugin("SharePlusWindowsPluginCApi")); UrlLauncherWindowsRegisterWithRegistrar( registry->GetRegistrarForPlugin("UrlLauncherWindows")); WindowManagerPluginRegisterWithRegistrar( diff --git a/windows/flutter/generated_plugins.cmake b/windows/flutter/generated_plugins.cmake index 7d0a2d91..7fbaee51 100644 --- a/windows/flutter/generated_plugins.cmake +++ b/windows/flutter/generated_plugins.cmake @@ -11,7 +11,6 @@ list(APPEND FLUTTER_PLUGIN_LIST media_kit_video screen_brightness_windows screen_retriever - share_plus url_launcher_windows window_manager )