Skip to content

Commit

Permalink
Merge branch 'master' into limwa/refactor/send-request-information-fo…
Browse files Browse the repository at this point in the history
…r-bus-debug
  • Loading branch information
DGoiana authored Mar 8, 2024
2 parents 86649b0 + 7f8f2b3 commit 6f37a0d
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 36 deletions.
2 changes: 1 addition & 1 deletion uni/app_version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.8.6+266
1.8.7+268
62 changes: 28 additions & 34 deletions uni/lib/controller/cleanup.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'dart:async';
import 'dart:io';

import 'package:flutter/material.dart';
import 'package:path/path.dart' as path;
import 'package:path_provider/path_provider.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:uni/controller/local_storage/database/app_bus_stop_database.dart';
Expand All @@ -22,24 +23,19 @@ Future<void> cleanupStoredData(BuildContext context) async {
final faculties = PreferencesController.getUserFaculties();
await prefs.clear();

unawaited(
Future.wait([
AppLecturesDatabase().deleteLectures(),
AppExamsDatabase().deleteExams(),
AppCoursesDatabase().deleteCourses(),
AppUserDataDatabase().deleteUserData(),
AppLastUserInfoUpdateDatabase().deleteLastUpdate(),
AppBusStopDatabase().deleteBusStops(),
AppCourseUnitsDatabase().deleteCourseUnits(),
NetworkRouter.killSigarraAuthentication(faculties),
]),
);
await Future.wait([
AppLecturesDatabase().deleteLectures(),
AppExamsDatabase().deleteExams(),
AppCoursesDatabase().deleteCourses(),
AppUserDataDatabase().deleteUserData(),
AppLastUserInfoUpdateDatabase().deleteLastUpdate(),
AppBusStopDatabase().deleteBusStops(),
AppCourseUnitsDatabase().deleteCourseUnits(),
NetworkRouter.killSigarraAuthentication(faculties),
]);

final path = (await getApplicationDocumentsDirectory()).path;
final directory = Directory(path);
if (directory.existsSync()) {
directory.deleteSync(recursive: true);
}
final toCleanDirectory = await getApplicationDocumentsDirectory();
await cleanDirectory(toCleanDirectory, DateTime.now());
}

Future<void> cleanupCachedFiles() async {
Expand All @@ -53,26 +49,24 @@ Future<void> cleanupCachedFiles() async {

final toCleanDirectory = await getApplicationDocumentsDirectory();
final threshold = DateTime.now().subtract(const Duration(days: 30));
final directories = toCleanDirectory.listSync(followLinks: false);

for (final directory in directories) {
if (directory is Directory) {
final files = directory.listSync(recursive: true, followLinks: false);
await cleanDirectory(toCleanDirectory, threshold);

final oldFiles = files.where((file) {
try {
final fileDate = File(file.path).lastModifiedSync();
return fileDate.isBefore(threshold);
} catch (e) {
return false;
}
});
await PreferencesController.setLastCleanUpDate(DateTime.now());
}

for (final file in oldFiles) {
await File(file.path).delete();
}
Future<void> cleanDirectory(Directory directory, DateTime threshold) async {
final entities = directory.listSync(recursive: true, followLinks: false);
final toDeleteEntities = entities.whereType<File>().where((file) {
try {
final fileDate = file.lastModifiedSync();
return fileDate.isBefore(threshold) && path.extension(file.path) != '.db';
} catch (e) {
return false;
}
}
});

await PreferencesController.setLastCleanUpDate(DateTime.now());
for (final entity in toDeleteEntities) {
entity.deleteSync();
}
}
2 changes: 1 addition & 1 deletion uni/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ publish_to: "none" # We do not publish to pub.dev
# To change it manually, override the value in app_version.txt.
# The app version code is automatically also bumped by CI.
# Do not change it manually.
version: 1.8.6+266
version: 1.8.7+268


environment:
Expand Down

0 comments on commit 6f37a0d

Please sign in to comment.