Skip to content

Commit

Permalink
Merge pull request #10 from giovanni-iannaccone/refactor/wordlist-man…
Browse files Browse the repository at this point in the history
…agement

Wordlist manager uses file's path
  • Loading branch information
giovanni-iannaccone authored Aug 6, 2024
2 parents aaa54e8 + 3b40e51 commit c25a21a
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 17 deletions.
3 changes: 2 additions & 1 deletion lib/features/hashing/presentation/hash_cracker_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,8 @@ class HashCrackerScreen extends HookConsumerWidget {

if(algorithmType == HashAlgorithmType.unknown) {
algorithmType = notifier.identifyHash(hash);

selectedAlgorithm.value = algorithmType;

if(algorithmType == HashAlgorithmType.unknown){

if(!context.mounted) return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class WordListChoiceScreen extends HookConsumerWidget {
pickedFilePath.value = wordListsState[index];
Navigator.of(context).pop();
},
child: Text(truncateFileName(wordListsState[index], 25)),
child: Text(truncateFileName(wordListsState[index].split('/').last, 25)),
),
),
),
Expand Down
8 changes: 4 additions & 4 deletions lib/features/wordlists/presentation/word_lists_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -103,17 +103,17 @@ class WordListsScreen extends HookConsumerWidget {
child: ListView.builder(
itemCount: wordListsScreenState.wordLists.length,
itemBuilder: (context, index) => WordListItem(
wordListName: wordListsScreenState.wordLists[index],
wordListName: wordListsScreenState.wordLists[index].split('/').last,
onEditPressed: () => navigateTo(
context,
routes.editWordList,
arguments: wordListsScreenState.wordLists[index],
arguments: wordListsScreenState.wordLists[index].split('/').last,
).whenComplete(
() => notifier.loadWordListsName()
),
onDeletePressed: () {
final name = wordListsScreenState.wordLists[index];
notifier.deleteWordList(name);
final path = wordListsScreenState.wordLists[index];
notifier.deleteWordList(path);
}
),
),
Expand Down
16 changes: 5 additions & 11 deletions lib/shared/data/word_list_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ class WordListManager {
await file.create();
}

Future<void> deleteWordList(String name) async {
final file = await _getLocalFile(name);
Future<void> deleteWordList(path) async {
final file = File(path);
await file.delete();
}

Expand All @@ -29,7 +29,7 @@ class WordListManager {

return await directory.list(recursive: false)
.where((entity) => entity is File)
.map((entity) => entity.path.split('/').last)
.map((entity) => entity.path)
.toList();
}

Expand All @@ -42,14 +42,8 @@ class WordListManager {
);
}

Future<List<String>> loadWordList(String fileName) async {

var file = File(fileName);

if(file.parent.path == '.'){
file = await _getLocalFile(fileName);
}

Future<List<String>> loadWordList(String filePath) async {
var file = File(filePath);
return await file.readAsLines();
}

Expand Down

0 comments on commit c25a21a

Please sign in to comment.