Skip to content

Commit

Permalink
Merge pull request #76 from ZhuJHua/dev
Browse files Browse the repository at this point in the history
Fix can't start form old version
  • Loading branch information
ZhuJHua authored Dec 15, 2024
2 parents 8afda6e + f18fa85 commit d0beed5
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 11 deletions.
2 changes: 1 addition & 1 deletion lib/pages/home/media/media_logic.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class MediaLogic extends GetxController with GetSingleTickerProviderStateMixin {
Future<void> cleanFile() async {
state.isCleaning = true;
update(['modal']);
await FileUtil.cleanFile();
await FileUtil.cleanFile(FileUtil.getRealPath('database', ''));
await getFilePath(state.mediaType.value);
state.isCleaning = false;
update(['modal']);
Expand Down
2 changes: 1 addition & 1 deletion lib/utils/data/pref.dart
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ class PrefUtil {
/// 修复同步失败导致本地分类丢失
/// 视频缩略图重复生成
if (appVersion != null && appVersion.split('+')[0].compareTo('2.6.3') < 0) {
await FileUtil.cleanFile();
await FileUtil.cleanFile(FileUtil.getRealPath('database', ''));
await MediaUtil.regenerateMissingThumbnails();
await compute(IsarUtil.fixV2_6_3, FileUtil.getRealPath('database', ''));
}
Expand Down
12 changes: 9 additions & 3 deletions lib/utils/file_util.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ import 'dart:io';

import 'package:archive/archive_io.dart';
import 'package:get/get.dart';
import 'package:isar/isar.dart';
import 'package:path/path.dart';
import 'package:path_provider/path_provider.dart';

import '../common/models/isar/category.dart';
import '../common/models/isar/diary.dart';
import '../common/values/media_type.dart';
import '../components/audio_player/audio_player_logic.dart';
Expand Down Expand Up @@ -213,7 +215,11 @@ class FileUtil {
await deleteMediaFiles(oldDiary.videoName, newDiary.videoName, 'thumbnail');
}

static Future<void> cleanFile() async {
static Future<void> cleanFile(String dir) async {
var isar = Isar.open(
schemas: [DiarySchema, CategorySchema],
directory: dir,
);
// 获取各类型的所有文件路径并转换为Set以提高查找效率
final imageFiles = (await FileUtil.getDirFileName(MediaType.image.value)).toSet();
final audioFiles = (await FileUtil.getDirFileName(MediaType.audio.value)).toSet();
Expand All @@ -225,12 +231,12 @@ class FileUtil {
final usedVideos = <String>{};

// 获取日记总数
final count = IsarUtil.countAllDiary();
final count = isar.diarys.count();

// 分批获取日记并收集引用的文件名
const batchSize = 50;
for (int i = 0; i < count; i += batchSize) {
final diaryList = await IsarUtil.getDiary(i, batchSize);
final diaryList = await isar.diarys.where().findAllAsync(offset: i, limit: batchSize);
for (var diary in diaryList) {
usedImages.addAll(diary.imageName);
usedAudios.addAll(diary.audioName);
Expand Down
6 changes: 3 additions & 3 deletions windows/flutter/generated_plugin_registrant.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ void RegisterPlugins(flutter::PluginRegistry* registry) {
BitsdojoWindowPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("BitsdojoWindowPlugin"));
ConnectivityPlusWindowsPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("ConnectivityPlusWindowsPlugin"));
registry->GetRegistrarForPlugin("ConnectivityPlusWindowsPlugin"));
DynamicColorPluginCApiRegisterWithRegistrar(
registry->GetRegistrarForPlugin("DynamicColorPluginCApi"));
FcNativeVideoThumbnailPluginCApiRegisterWithRegistrar(
registry->GetRegistrarForPlugin("FcNativeVideoThumbnailPluginCApi"));
FileSelectorWindowsRegisterWithRegistrar(
registry->GetRegistrarForPlugin("FileSelectorWindows"));
GalPluginCApiRegisterWithRegistrar(
registry->GetRegistrarForPlugin("GalPluginCApi"));
registry->GetRegistrarForPlugin("GalPluginCApi"));
GeolocatorWindowsRegisterWithRegistrar(
registry->GetRegistrarForPlugin("GeolocatorWindows"));
IsarFlutterLibsPluginRegisterWithRegistrar(
Expand All @@ -61,7 +61,7 @@ void RegisterPlugins(flutter::PluginRegistry* registry) {
RecordWindowsPluginCApiRegisterWithRegistrar(
registry->GetRegistrarForPlugin("RecordWindowsPluginCApi"));
RivePluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("RivePlugin"));
registry->GetRegistrarForPlugin("RivePlugin"));
ScreenBrightnessWindowsPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("ScreenBrightnessWindowsPlugin"));
SharePlusWindowsPluginCApiRegisterWithRegistrar(
Expand Down
6 changes: 3 additions & 3 deletions windows/flutter/generated_plugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ list(APPEND FLUTTER_PLUGIN_LIST
app_links
audioplayers_windows
bitsdojo_window_windows
connectivity_plus
connectivity_plus
dynamic_color
fc_native_video_thumbnail
file_selector_windows
gal
gal
geolocator_windows
isar_flutter_libs
local_auth_windows
Expand All @@ -19,7 +19,7 @@ list(APPEND FLUTTER_PLUGIN_LIST
objectbox_flutter_libs
permission_handler_windows
record_windows
rive_common
rive_common
screen_brightness_windows
share_plus
url_launcher_windows
Expand Down

0 comments on commit d0beed5

Please sign in to comment.