private async Task OnCommand(string command, string args) { using var containerStream = new FileStream(_path, FileMode.OpenOrCreate); using var container = new CryptoContainer(containerStream, _key); switch (command) { case "add": case "get": var opts = args.Split("path=", StringSplitOptions.TrimEntries); var name = opts[0]; var path = opts[1]; path = path.Trim('"'); var get = command == "get"; var mode = get ? FileMode.Create : FileMode.Open; var access = get ? FileAccess.Write : FileAccess.Read; using (var stream = File.Open(path, mode, access)) { if (get) { await container.GetAsync(name, stream, Aretha.WriteProgress()); } else { await container.AddAsync(name, stream, true, Aretha.WriteProgress()); } } return; case "delete": var deleted = container.Delete(args); if (deleted) { Speak("File deleted successfully"); } else { Speak("Deletion failed."); } break; case "extract": if (args.ToLower().StartsWith("path=")) { args = args.Remove(0, "path=".Length); } args = args.Trim('"'); await container.ExtractContainerAsync(args, Aretha.WriteProgress()); break; } }
public async Task Inject(Jector jector) { var inputPath = GetPath("Provide path to file to be written into:", true); var dataPath = GetPath("Provide a path to the file to be hidden:", true); var outputPath = GetPath("Provide a path where the file copy with hidden data will be saved:", false); if (inputPath == outputPath) { Speak("The input file cannot be the same as the save file!"); await Inject(jector); return; } else if (inputPath == dataPath) { Speak("The input file cannot be the same as the data file. What will be the point?"); await Inject(jector); return; } else if (dataPath == outputPath) { Speak("The data file cannot be the same as the save file"); await Inject(jector); } Speak("Executing Command. Please Wait"); try { using var source = File.OpenRead(inputPath); using var destination = File.OpenWrite(outputPath); using var data = File.OpenRead(dataPath); await jector.InjectAsync(source, destination, data, Aretha.WriteProgress()); Speak($"Command Executed Successfully!"); } catch (Exception ex) { Aretha.SoulFailed(Soul.Anubis, ex); } }
public async Task Eject(Jector jector) { var inputPath = GetPath("Provide a path to file containing hidden data:", true); if (inputPath == null) { return; } var outputPath = GetPath("Provide a path where the hidden file will be saved: ", false); if (outputPath == null) { return; } if (inputPath == outputPath) { Speak("The input file cannot be the same as the save file!"); await Inject(jector); return; } Speak("Executing Command. Please Wait"); try { using var source = File.OpenRead(inputPath); using var destination = File.OpenWrite(outputPath); await jector.EjectAsync(source, destination, Aretha.WriteProgress()); Speak($"Command Executed Successfully!"); } catch (Exception ex) { Aretha.SoulFailed(Soul.Anubis, ex); } }