Compare commits
5 Commits
7e13bce767
...
master
Author | SHA1 | Date | |
---|---|---|---|
9744b2a788 | |||
c4e8945371 | |||
97e564d352 | |||
21365d81bf | |||
1899e284a0 |
@@ -1,3 +1,4 @@
|
||||
using System.Diagnostics.Contracts;
|
||||
using TBDel.Models;
|
||||
using TBDel.Services;
|
||||
|
||||
@@ -7,9 +8,6 @@ namespace TBDel.Commands
|
||||
{
|
||||
public static async Task AddEntry(string[] args)
|
||||
{
|
||||
// TODO: Add duplicate path check
|
||||
// TODO: Add support for multiple paths
|
||||
|
||||
if (args.Length > 1)
|
||||
{
|
||||
string workingDirectory = Directory.GetCurrentDirectory();
|
||||
@@ -19,6 +17,12 @@ namespace TBDel.Commands
|
||||
if (File.Exists(absolutePath))
|
||||
{
|
||||
Console.WriteLine($"Adding: {absolutePath}");
|
||||
if (await dbService.EtryExists(absolutePath))
|
||||
{
|
||||
Console.ForegroundColor = ConsoleColor.Yellow;
|
||||
Console.WriteLine("File already exists in the list - No actions performed.");
|
||||
return;
|
||||
}
|
||||
var entry = new FileEntry { Id = GenerateUniqueId(dbService), Path = absolutePath, DateAdded = DateTime.Now };
|
||||
if (await dbService.AddFileEntryAsync(entry))
|
||||
{
|
||||
@@ -38,6 +42,12 @@ namespace TBDel.Commands
|
||||
else if (Directory.Exists(absolutePath))
|
||||
{
|
||||
Console.WriteLine($"Adding: {absolutePath}");
|
||||
if (await dbService.EtryExists(absolutePath))
|
||||
{
|
||||
Console.ForegroundColor = ConsoleColor.Yellow;
|
||||
Console.WriteLine("Folder already exists in the list - No actions performed.");
|
||||
return;
|
||||
}
|
||||
var entry = new FolderEntry() { Id = GenerateUniqueId(dbService), Path = absolutePath, DateAdded = DateTime.Now };
|
||||
if (await dbService.AddFolderEntryAsync(entry))
|
||||
{
|
||||
|
@@ -1,49 +1,92 @@
|
||||
using TBDel.Services;
|
||||
|
||||
namespace TBDel.Commands
|
||||
{
|
||||
public class DeleteAllCommand
|
||||
{
|
||||
public static async Task DeleteAll()
|
||||
{
|
||||
var dbService = new DbService();
|
||||
var allFiles = await dbService.GetFileEntriesAsync();
|
||||
var allFolders = await dbService.GetFolderEntriesAsync();
|
||||
namespace TBDel.Commands;
|
||||
|
||||
if (allFiles.Count == 0 && allFolders.Count == 0)
|
||||
public class DeleteAllCommand
|
||||
{
|
||||
public static async Task DeleteAll()
|
||||
{
|
||||
var dbService = new DbService();
|
||||
var allFiles = await dbService.GetFileEntriesAsync();
|
||||
var allFolders = await dbService.GetFolderEntriesAsync();
|
||||
|
||||
if (allFiles.Count == 0 && allFolders.Count == 0)
|
||||
{
|
||||
Console.WriteLine("No files or folders found.");
|
||||
return;
|
||||
}
|
||||
|
||||
Console.ForegroundColor = ConsoleColor.Yellow;
|
||||
Console.Write(
|
||||
$"Are you sure you want to permanently delete {allFiles.Count} file(s) and {allFolders.Count} folder(s)? (y/N) ");
|
||||
Console.ResetColor();
|
||||
var input = Console.ReadLine();
|
||||
if (input != "y")
|
||||
{
|
||||
Console.ForegroundColor = ConsoleColor.Red;
|
||||
Console.WriteLine("Operation cancelled.");
|
||||
Console.ResetColor();
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var file in allFiles)
|
||||
{
|
||||
if (!File.Exists(file.Path))
|
||||
{
|
||||
Console.WriteLine("No files or folders found.");
|
||||
return;
|
||||
Console.ForegroundColor = ConsoleColor.Yellow;
|
||||
Console.WriteLine($"File {file.Path} does not exist, removing from list.");
|
||||
Console.ResetColor();
|
||||
await dbService.RemoveFileEntryAsync(file.Id);
|
||||
continue;
|
||||
}
|
||||
|
||||
Console.ForegroundColor = ConsoleColor.Yellow;
|
||||
Console.Write($"Are you sure you want to permanently delete {allFiles.Count} file(s) and {allFolders.Count} folder(s)? (y/N) ");
|
||||
Console.ResetColor();
|
||||
var input = Console.ReadLine();
|
||||
if (input != "y")
|
||||
Console.WriteLine($"Deleting file: {file.Path}");
|
||||
try
|
||||
{
|
||||
File.Delete(file.Path);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.ForegroundColor = ConsoleColor.Red;
|
||||
Console.WriteLine("Operation cancelled.");
|
||||
Console.WriteLine("Something went wrong while deleting the file.");
|
||||
Console.WriteLine(e.Message);
|
||||
Console.ResetColor();
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var file in allFiles)
|
||||
await dbService.RemoveFileEntryAsync(file.Id);
|
||||
}
|
||||
|
||||
foreach (var folder in allFolders)
|
||||
{
|
||||
if (!Directory.Exists(folder.Path))
|
||||
{
|
||||
Console.WriteLine($"Deleting file: {file.Path}");
|
||||
File.Delete(file.Path);
|
||||
await dbService.RemoveFileEntryAsync(file.Id);
|
||||
}
|
||||
foreach (var folder in allFolders)
|
||||
{
|
||||
Console.WriteLine($"Deleting directory: {folder.Path}");
|
||||
Directory.Delete(folder.Path, true);
|
||||
Console.ForegroundColor = ConsoleColor.Yellow;
|
||||
Console.WriteLine($"Directory {folder.Path} does not exist, removing from list.");
|
||||
Console.ResetColor();
|
||||
await dbService.RemoveFolderEntryAsync(folder.Id);
|
||||
continue;
|
||||
}
|
||||
|
||||
Console.ForegroundColor = ConsoleColor.Green;
|
||||
Console.WriteLine("All files and folders deleted successfully.");
|
||||
Console.ResetColor();
|
||||
Console.WriteLine($"Deleting directory: {folder.Path}");
|
||||
try
|
||||
{
|
||||
Directory.Delete(folder.Path, true);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.ForegroundColor = ConsoleColor.Red;
|
||||
Console.WriteLine("Something went wrong while deleting the directory.");
|
||||
Console.WriteLine(e.Message);
|
||||
Console.ResetColor();
|
||||
return;
|
||||
}
|
||||
|
||||
await dbService.RemoveFolderEntryAsync(folder.Id);
|
||||
}
|
||||
|
||||
Console.ForegroundColor = ConsoleColor.Green;
|
||||
Console.WriteLine("All files and folders deleted successfully.");
|
||||
Console.ResetColor();
|
||||
}
|
||||
}
|
@@ -44,7 +44,25 @@ namespace TBDel.Commands
|
||||
}
|
||||
else if (Directory.Exists(filePath))
|
||||
{
|
||||
Directory.Delete(filePath);
|
||||
try
|
||||
{
|
||||
Directory.Delete(filePath, true);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.ForegroundColor = ConsoleColor.Red;
|
||||
if (e.Message.Contains("Directory not empty"))
|
||||
{
|
||||
Console.WriteLine("Directory is not empty. It must be empty before it can be deleted or deleted manually.");
|
||||
|
||||
}
|
||||
|
||||
Console.WriteLine("Something went wrong while deleting the directory.");
|
||||
Console.ResetColor();
|
||||
Console.WriteLine(e.Message);
|
||||
return;
|
||||
}
|
||||
|
||||
if (await dbService.RemoveFolderEntryAsync(id))
|
||||
{
|
||||
Console.ForegroundColor = ConsoleColor.Green;
|
||||
|
@@ -22,6 +22,7 @@ public static class HelpCommand
|
||||
Console.WriteLine(" add <path to file or folder> Add a file or folder to the list");
|
||||
Console.WriteLine(" delete <file or folder ID> Deletes a file or folder");
|
||||
Console.WriteLine(" deleteall Deletes all items in the list");
|
||||
Console.WriteLine(" rmflist Remove an entry ONLY from the list");
|
||||
Console.WriteLine(" list Lists all items in the list");
|
||||
Console.WriteLine(" help Shows this help message");
|
||||
}
|
||||
|
41
Commands/RemoveFromListCommand.cs
Normal file
41
Commands/RemoveFromListCommand.cs
Normal file
@@ -0,0 +1,41 @@
|
||||
using TBDel.Services;
|
||||
|
||||
namespace TBDel.Commands;
|
||||
|
||||
public class RemoveFromListCommand
|
||||
{
|
||||
public static async Task DeleteEntryFromList(String[] args)
|
||||
{
|
||||
var dbService = new DbService();
|
||||
if (args.Length > 1 && uint.TryParse(args[1], out uint id))
|
||||
{
|
||||
Console.ForegroundColor = ConsoleColor.Yellow;
|
||||
Console.Write($"Are you sure you want to remove the entry with ID {id} ONLY from the list? (y/N) ");
|
||||
Console.ResetColor();
|
||||
var input = Console.ReadLine();
|
||||
|
||||
if (input != "y")
|
||||
{
|
||||
Console.ForegroundColor = ConsoleColor.Red;
|
||||
Console.WriteLine("Operation cancelled.");
|
||||
Console.ResetColor();
|
||||
return;
|
||||
}
|
||||
|
||||
if (await dbService.RemoveFileEntryAsync(id) || await dbService.RemoveFolderEntryAsync(id))
|
||||
{
|
||||
Console.ForegroundColor = ConsoleColor.Green;
|
||||
Console.WriteLine("Entry removed from the list.");
|
||||
Console.ResetColor();
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.ForegroundColor = ConsoleColor.Red;
|
||||
Console.WriteLine("Something went wrong while removing the entry from list.");
|
||||
Console.ResetColor();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
@@ -4,8 +4,6 @@ namespace TBDel
|
||||
{
|
||||
internal class Program
|
||||
{
|
||||
// TODO: Add a command to show the Db path
|
||||
// TODO: Add a command to remove a file or folder only from the list
|
||||
static async Task Main(string[] args)
|
||||
{
|
||||
// Show the help message if no arguments are provided
|
||||
@@ -28,6 +26,9 @@ namespace TBDel
|
||||
case "deleteall":
|
||||
await DeleteAllCommand.DeleteAll();
|
||||
break;
|
||||
case "rmflist":
|
||||
await RemoveFromListCommand.DeleteEntryFromList(args);
|
||||
break;
|
||||
case "list":
|
||||
await ListCommand.List(args);
|
||||
break;
|
||||
|
19
README.md
19
README.md
@@ -3,7 +3,10 @@
|
||||
|
||||
## Installation
|
||||
|
||||
Soon...
|
||||
- Install on Arch Linux (aur)
|
||||
```shell
|
||||
paru -S tbdel
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
@@ -13,6 +16,7 @@ Usage: tbdel <command> [arguments]
|
||||
Available commands:
|
||||
add <path to file or folder> Add a file or folder to the list
|
||||
delete <file or folder ID> Deletes a file or folder
|
||||
rmflist Remove an entry ONLY from the list
|
||||
deleteall Deletes all items in the list
|
||||
list Lists all items in the list
|
||||
help Shows this help message
|
||||
@@ -33,10 +37,15 @@ help Shows this help message
|
||||
```shell
|
||||
tbdel list
|
||||
```
|
||||
|
||||
* Delete an entry (using its ID):
|
||||
|
||||
* Remove an entry ONLY from the list: **(Assuming '12345' is the ID of the entry you want to remove from the list)**
|
||||
```shell
|
||||
tbdel delete 12345 (Assuming '12345' is the ID of the entry you want to delete)
|
||||
tbdel rmflist 12345
|
||||
```
|
||||
|
||||
* Delete an entry (using its ID): **(Assuming '12345' is the ID of the entry you want to delete)**
|
||||
```shell
|
||||
tbdel delete 12345
|
||||
```
|
||||
|
||||
* Delete all entries:
|
||||
@@ -55,4 +64,4 @@ help Shows this help message
|
||||
|
||||
## License
|
||||
|
||||
This project is licensed under the GNU Affero General Public License v3.0 - see the [LICENSE](LICENSE) file for details.
|
||||
This project is licensed under the GNU Affero General Public License v3.0 - see the [LICENSE](LICENSE) file for details.
|
||||
|
@@ -106,6 +106,16 @@ namespace TBDel.Services
|
||||
return String.Empty;
|
||||
}
|
||||
|
||||
public async Task<bool> EtryExists(String path)
|
||||
{
|
||||
if (_fileCollection.Find(f => f.Path == path) is not null || _folderCollection.Find(f => f.Path == path) is not null)
|
||||
{
|
||||
return await Task.FromResult(true);
|
||||
}
|
||||
return await Task.FromResult(false);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public class DatabaseContent
|
||||
|
Reference in New Issue
Block a user