Skip to content

Commit

Permalink
remove backup
Browse files Browse the repository at this point in the history
  • Loading branch information
MiaoMint committed Dec 11, 2023
1 parent 61457a2 commit 4bdd9bf
Show file tree
Hide file tree
Showing 9 changed files with 3 additions and 268 deletions.
16 changes: 1 addition & 15 deletions assets/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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}",
Expand Down Expand Up @@ -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"
}
}
161 changes: 0 additions & 161 deletions lib/utils/application.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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;
Expand Down Expand Up @@ -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<bool> 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<dynamic> 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<int>;
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<bool> archivefiles(List<String> 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;
}
}
5 changes: 0 additions & 5 deletions lib/utils/miru_storage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
53 changes: 0 additions & 53 deletions lib/views/pages/settings_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -163,59 +163,6 @@ class _SettingsPageState extends State<SettingsPage> {
),
),
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),
Expand Down
2 changes: 0 additions & 2 deletions macos/Flutter/GeneratedPluginRegistrant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"))
Expand Down
26 changes: 1 addition & 25 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ packages:
source: hosted
version: "4.0.3"
archive:
dependency: "direct main"
dependency: transitive
description:
name: archive
sha256: "7b875fd4a20b165a3084bd2d210439b22ebc653f21cea4842729c0c30c82596b"
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
4 changes: 1 addition & 3 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 0 additions & 3 deletions windows/flutter/generated_plugin_registrant.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#include <media_kit_video/media_kit_video_plugin_c_api.h>
#include <screen_brightness_windows/screen_brightness_windows_plugin.h>
#include <screen_retriever/screen_retriever_plugin.h>
#include <share_plus/share_plus_windows_plugin_c_api.h>
#include <url_launcher_windows/url_launcher_windows.h>
#include <window_manager/window_manager_plugin.h>

Expand All @@ -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(
Expand Down
1 change: 0 additions & 1 deletion windows/flutter/generated_plugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ list(APPEND FLUTTER_PLUGIN_LIST
media_kit_video
screen_brightness_windows
screen_retriever
share_plus
url_launcher_windows
window_manager
)
Expand Down

0 comments on commit 4bdd9bf

Please sign in to comment.