From 6ddd94ac0af5ad032d7b317c624b1fa979ecdc87 Mon Sep 17 00:00:00 2001 From: TheLastGimbus Date: Mon, 4 Dec 2023 17:02:47 +0100 Subject: [PATCH] some notes on moving cus im too lazy to actually fix this --- lib/interactive.dart | 7 +++---- lib/moving.dart | 17 ++++++++++++++--- lib/utils.dart | 2 +- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/lib/interactive.dart b/lib/interactive.dart index a8f948340..97198790f 100644 --- a/lib/interactive.dart +++ b/lib/interactive.dart @@ -119,7 +119,7 @@ Future> getZips() async { error('Duh, something went wrong with selecting - try again!'); quit(69); } - if (files!.count == 0) { + if (files.count == 0) { error('No files selected - try again :/'); quit(6969); } @@ -150,7 +150,8 @@ Future> getZips() async { /// Asks user for output folder with ui dialogs Future getOutput() async { - print('Now, select output folder - all photos will be extracted there'); + print('Now, select output folder - all photos will be moved there\n' + '(note: GPTH will *move* your photos - no extra space will be taken ;)'); await sleep(1); pressEnterToContinue(); final dir = await getDirectoryPath(dialogTitle: 'Select output folder:'); @@ -223,12 +224,10 @@ Future askForCleanOutput() async { case '3': print('Okay, exiting...'); quit(0); - break; default: error('Invalid answer - try again'); return askForCleanOutput(); } - throw 'WTF this should never happen - go tell @TheLastGimbus'; } /// Checks free space on disk and notifies user accordingly diff --git a/lib/moving.dart b/lib/moving.dart index 92255a8fa..358d2b37b 100644 --- a/lib/moving.dart +++ b/lib/moving.dart @@ -6,6 +6,7 @@ import 'dart:io'; import 'package:collection/collection.dart'; import 'package:gpth/interactive.dart' as interactive; +import 'package:gpth/utils.dart'; import 'package:path/path.dart' as p; import 'media.dart'; @@ -130,9 +131,19 @@ Stream moveFiles( moveFile() async { final freeFile = findNotExistingName( File(p.join(folder.path, p.basename(file.value.path)))); - return copy - ? await file.value.copy(freeFile.path) - : await file.value.rename(freeFile.path); + try { + return copy + ? await file.value.copy(freeFile.path) + : await file.value.rename(freeFile.path); + } on FileSystemException { + print( + "Uh-uh, it looks like you selected other output drive than\n" + "input one - gpth can't move files between them. But, you don't have\n" + "to do this! Gpth *moves* files, so this doesn't take any extra space!\n" + "Please run again and select different output location <3", + ); + quit(1); + } } if (file.key == null) { diff --git a/lib/utils.dart b/lib/utils.dart index e7befe77b..41ee7e4d0 100644 --- a/lib/utils.dart +++ b/lib/utils.dart @@ -17,7 +17,7 @@ const maxFileSize = 64 * 1024 * 1024; /// convenient print for errors void error(Object? object) => stderr.write('$object\n'); -void quit([int code = 1]) { +Never quit([int code = 1]) { if (interactive.indeed) { print('[gpth ${code != 0 ? 'quitted :(' : 'finished :)'} (code $code) - ' 'press enter to close]');