Skip to content

Commit

Permalink
some notes on moving cus im too lazy to actually fix this
Browse files Browse the repository at this point in the history
  • Loading branch information
TheLastGimbus committed Dec 4, 2023
1 parent 1c17c70 commit 6ddd94a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
7 changes: 3 additions & 4 deletions lib/interactive.dart
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ Future<List<File>> 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);
}
Expand Down Expand Up @@ -150,7 +150,8 @@ Future<List<File>> getZips() async {

/// Asks user for output folder with ui dialogs
Future<Directory> 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:');
Expand Down Expand Up @@ -223,12 +224,10 @@ Future<bool> 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
Expand Down
17 changes: 14 additions & 3 deletions lib/moving.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -130,9 +131,19 @@ Stream<int> 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) {
Expand Down
2 changes: 1 addition & 1 deletion lib/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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]');
Expand Down

0 comments on commit 6ddd94a

Please sign in to comment.