Skip to content

Commit

Permalink
AminBhst#10 Check for disk space before adding a download item AminBh…
Browse files Browse the repository at this point in the history
  • Loading branch information
Norman-w committed Sep 19, 2023
1 parent e81454f commit b7cb57b
Show file tree
Hide file tree
Showing 8 changed files with 329 additions and 279 deletions.
12 changes: 10 additions & 2 deletions lib/util/download_addition_ui_util.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,23 @@ class DownloadAdditionUiUtil {
context.loaderOverlay.hide();
}

static void handleDownloadAddition(BuildContext context, String url,
{bool updateDialog = false, int? downloadId, additionalPop = false}) {
static Future<void> handleDownloadAddition(BuildContext context, String url,
{bool updateDialog = false, int? downloadId, additionalPop = false}) async {
if (!isUrlValid(url)) {
showDialog(
context: context,
builder: (_) => const ErrorDialog(text: 'Invalid URL'),
);
} else {
final item = DownloadItem.fromUrl(url);
var isValidDiskSpace = await FileUtil.checkDiskSpace(item.contentLength,item.filePath);
if(!isValidDiskSpace){
showDialog(
context: context,
builder: (_) => const ErrorDialog(text: 'Not enough disk space'),
);
return;
}
_spawnFileInfoRetrieverIsolate(item).then((rPort) {
context.loaderOverlay.show();
retrieveFileInfo(rPort).then((fileInfo) {
Expand Down
15 changes: 15 additions & 0 deletions lib/util/file_util.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'package:brisk/util/file_extensions.dart';
import 'package:flutter/material.dart';
import 'package:path_provider/path_provider.dart';
import 'package:path/path.dart';
import 'package:universal_disk_space/universal_disk_space.dart';

import '../constants/file_type.dart';
import '../model/isolate/isolate_args_pair.dart';
Expand Down Expand Up @@ -202,4 +203,18 @@ class FileUtil {
final filePath = join(SettingsCache.saveDir.path, subDir, fileName);
return File(filePath).existsSync();
}

static Future<bool> checkDiskSpace(int contentLength, String fileName) async {
var dir = Directory(SettingsCache.saveDir.path);
var disk = await DiskSpace().getDisk(dir);
var availableSpace = disk.availableSpace;
var fileSize = contentLength;
var fileNameSize = fileName.length;
var totalSize = fileSize + fileNameSize;
if (availableSpace > totalSize) {
return true;
} else {
return false;
}
}
}
1 change: 1 addition & 0 deletions macos/Flutter/Flutter-Debug.xcconfig
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"
#include "ephemeral/Flutter-Generated.xcconfig"
1 change: 1 addition & 0 deletions macos/Flutter/Flutter-Release.xcconfig
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"
#include "ephemeral/Flutter-Generated.xcconfig"
2 changes: 1 addition & 1 deletion macos/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0920;
LastUpgradeCheck = 1300;
LastUpgradeCheck = 1430;
ORGANIZATIONNAME = "";
TargetAttributes = {
33CC10EC2044A3C60003C045 = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1300"
LastUpgradeVersion = "1430"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Loading

0 comments on commit b7cb57b

Please sign in to comment.