private FileSystemCommandResult WriteCommand(IReadOnlyList <string> arguments) { FileSystemCommandResult ret; string path = GetPathArgument(arguments); if (string.IsNullOrWhiteSpace(path)) { ret = FileSystemCommandResult.InvalidArguments; } else { IFileSystemObject write_file = CurrentDirectory.GetRelativeFileSystemObject(path); if (write_file is File) { if (((File)write_file).Write(GetContentArgument(arguments))) { ret = new FileSystemCommandResult(EFileSystemStatusCode.WrittenFileContents, write_file.FullPath); } else { ret = new FileSystemCommandResult(EFileSystemStatusCode.FailedWritingFileContents, write_file.FullPath); } } else if (write_file != null) { ret = new FileSystemCommandResult(EFileSystemStatusCode.IsFileMissing, write_file.FullPath); } else { ret = new FileSystemCommandResult(EFileSystemStatusCode.IsFileMissing, path); } } return(ret); }
private FileSystemCommandResult ReadCommand(IReadOnlyList <string> arguments) { FileSystemCommandResult ret; string path = GetPathArgument(arguments); if (string.IsNullOrWhiteSpace(path)) { ret = FileSystemCommandResult.InvalidArguments; } else { IFileSystemObject read_file = CurrentDirectory.GetRelativeFileSystemObject(path); if (read_file is File) { Me.CustomData = ((File)read_file).Read(); standardOutputLogger.AppendLine("Read file \"" + read_file.FullPath + "\"."); ret = new FileSystemCommandResult(EFileSystemStatusCode.CustomData, path); } else if (read_file != null) { Me.CustomData = string.Empty; path = read_file.FullPath; errorOutputLogger.AppendLine("\"" + read_file.FullPath + "\" is not a file."); ret = new FileSystemCommandResult(EFileSystemStatusCode.CustomData, path); } else { Me.CustomData = string.Empty; errorOutputLogger.AppendLine("\"" + path + "\" does not exist."); ret = new FileSystemCommandResult(EFileSystemStatusCode.CustomData, path); } } return(ret); }
private FileSystemCommandResult ChangeDirectoryCommand(IReadOnlyList <string> arguments) { FileSystemCommandResult ret; string path = GetPathArgument(arguments); if (string.IsNullOrWhiteSpace(path)) { ret = FileSystemCommandResult.InvalidArguments; } else { IFileSystemObject result_file_system_object = CurrentDirectory.GetRelativeFileSystemObject(path); if (result_file_system_object is Directory) { CurrentDirectory = (Directory)result_file_system_object; ret = new FileSystemCommandResult(EFileSystemStatusCode.ChangedDirectory, result_file_system_object.FullPath); } else if (result_file_system_object != null) { ret = new FileSystemCommandResult(EFileSystemStatusCode.FailedChangingDirectory, result_file_system_object.FullPath); } else { ret = new FileSystemCommandResult(EFileSystemStatusCode.FailedChangingDirectory, path); } } return(ret); }
private FileSystemCommandResult ListCommand(IReadOnlyList <string> arguments) { FileSystemCommandResult ret; Directory list_directory = ((arguments.Count > 0) ? CurrentDirectory.GetRelativeFileSystemObject(arguments[0]) : CurrentDirectory) as Directory; if (list_directory == null) { ret = new FileSystemCommandResult(EFileSystemStatusCode.IsDirectoryMissing, arguments[0]); } else { List <IFileSystemObject> sorted_file_system_objects = new List <IFileSystemObject>(list_directory.Children.Values); sorted_file_system_objects.Sort((left, right) => { int result = (left is Directory).CompareTo(right is Directory); if (result == 0) { result = left.Name.CompareTo(right.Name); } return(result); }); StringBuilder list_directory_string_builder = new StringBuilder(); list_directory_string_builder.AppendLine("/"); list_directory_string_builder.AppendLine("."); list_directory_string_builder.AppendLine(".."); foreach (IFileSystemObject sorted_file_system_object in sorted_file_system_objects) { list_directory_string_builder.Append(sorted_file_system_object.Name); if (sorted_file_system_object is Directory) { list_directory_string_builder.Append("/"); } list_directory_string_builder.AppendLine(); } Me.CustomData = list_directory_string_builder.ToString(); list_directory_string_builder.Clear(); ret = new FileSystemCommandResult(EFileSystemStatusCode.CustomData, list_directory.FullPath); } return(ret); }
private FileSystemCommandResult IsPathCommand(IReadOnlyList <string> arguments) { FileSystemCommandResult ret; string path = GetPathArgument(arguments); if (string.IsNullOrWhiteSpace(path)) { ret = FileSystemCommandResult.InvalidArguments; } else { if (CurrentDirectory.DoesPathExist(path)) { ret = new FileSystemCommandResult(EFileSystemStatusCode.IsPath, path); } else { ret = new FileSystemCommandResult(EFileSystemStatusCode.IsNotPath, path); } } return(ret); }
private FileSystemCommandResult CreateFileCommand(IReadOnlyList <string> arguments) { FileSystemCommandResult ret; string path = GetPathArgument(arguments); if (string.IsNullOrWhiteSpace(path)) { ret = FileSystemCommandResult.InvalidArguments; } else { IFileSystemObject created_file = CurrentDirectory.CreateFile(path); if (created_file == null) { ret = new FileSystemCommandResult(EFileSystemStatusCode.FailedCreatingFile, path); } else { ret = new FileSystemCommandResult(EFileSystemStatusCode.CreatedFile, created_file.FullPath); } } return(ret); }
private void Main(string argument, UpdateType updateSource) { string command_name; FileSystemCommandResult command_result = commands.Parse(argument, out command_name); switch (command_result.StatusCode) { case EFileSystemStatusCode.MissingArguments: LogHelp(command_name); break; case EFileSystemStatusCode.InvalidArguments: LogHelp(command_name); break; case EFileSystemStatusCode.IsFileMissing: errorOutputLogger.AppendLine("File \"" + command_result.Path + "\" is missing."); break; case EFileSystemStatusCode.IsFile: standardOutputLogger.AppendLine("\"" + command_result.Path + "\" is a file."); break; case EFileSystemStatusCode.IsNotFile: standardOutputLogger.AppendLine("\"" + command_result.Path + "\" is not a file."); break; case EFileSystemStatusCode.IsDirectory: standardOutputLogger.AppendLine("\"" + command_result.Path + "\" is a directory."); break; case EFileSystemStatusCode.IsNotDirectory: standardOutputLogger.AppendLine("\"" + command_result.Path + "\" is not a directory."); break; case EFileSystemStatusCode.IsPath: standardOutputLogger.AppendLine("\"" + command_result.Path + "\" is a path."); break; case EFileSystemStatusCode.IsNotPath: standardOutputLogger.AppendLine("\"" + command_result.Path + "\" is not a path."); break; case EFileSystemStatusCode.ChangedDirectory: standardOutputLogger.AppendLine("Changed directory to \"" + command_result.Path + "\""); break; case EFileSystemStatusCode.FailedChangingDirectory: errorOutputLogger.AppendLine("\"" + command_result.Path + "\" is not a directory."); break; case EFileSystemStatusCode.CreatedDirectory: standardOutputLogger.AppendLine("Successfully created directory \"" + command_result.Path + "\"."); break; case EFileSystemStatusCode.FailedCreatingDirectory: errorOutputLogger.AppendLine("Failed to create directory \"" + command_result.Path + "\"."); break; case EFileSystemStatusCode.CreatedFile: standardOutputLogger.AppendLine("Successfully created file \"" + command_result.Path + "\"."); break; case EFileSystemStatusCode.FailedCreatingFile: errorOutputLogger.AppendLine("Failed to create file \"" + command_result.Path + "\"."); break; case EFileSystemStatusCode.WrittenFileContents: standardOutputLogger.AppendLine("Successfully written contents to file \"" + command_result.Path + "\"."); break; case EFileSystemStatusCode.FailedWritingFileContents: errorOutputLogger.AppendLine("Failed to write contents to file \"" + command_result.Path + "\"."); break; case EFileSystemStatusCode.AppendedFileContents: standardOutputLogger.AppendLine("Successfully appended contents to file \"" + command_result.Path + "\"."); break; case EFileSystemStatusCode.FailedAppendingFileContents: errorOutputLogger.AppendLine("Failed to append contents to file \"" + command_result.Path + "\"."); break; case EFileSystemStatusCode.DeletedPath: standardOutputLogger.AppendLine("Successfully deleted \"" + command_result.Path + "\"."); break; case EFileSystemStatusCode.FailedDeletingPath: errorOutputLogger.AppendLine("Failed to delete \"" + command_result.Path + "\"."); break; case EFileSystemStatusCode.UnknownError: errorOutputLogger.AppendLine("Unknown error."); LogHelp(command_name); break; } if (command_result.StatusCode != EFileSystemStatusCode.CustomData) { Me.CustomData = command_result.StatusCode.ToString(); } }