|
| 1 | +using System; |
| 2 | +using System.IO; |
| 3 | +using Deodexer.PathPlaceholders; |
| 4 | + |
| 5 | +namespace Deodexer.Commands |
| 6 | +{ |
| 7 | + abstract class FileProcessingComand : FolderProcessingCommand |
| 8 | + { |
| 9 | + protected abstract string fileTypes {get;} |
| 10 | + |
| 11 | + protected FileProcessingComand() { |
| 12 | + description = "Used for file operations"; |
| 13 | + detailedDescription = "fileN - path of a file or a folder or one of the constants:" + Environment.NewLine + |
| 14 | + "\t%ASK% - shows a dialog for picking file" + Environment.NewLine + |
| 15 | + "\t? - alias for ask" + Environment.NewLine; |
| 16 | + defaultPlaceholder = new FileDialogPlaceholder(fileTypes, title); |
| 17 | + placeholders.Add(defaultPlaceholder); |
| 18 | + } |
| 19 | + |
| 20 | + protected void processFileOrDir(string fn) { |
| 21 | + if (Directory.Exists(fn)) { |
| 22 | + var dirInfo = new DirectoryInfo(fn); |
| 23 | + var dirs = dirInfo.GetDirectories(); |
| 24 | + var files = dirInfo.GetFiles(); |
| 25 | + foreach (var file in files) { |
| 26 | + if(filter(file.FullName)) |
| 27 | + processFileOrDir(file.FullName); |
| 28 | + } |
| 29 | + foreach (var dir in dirs) |
| 30 | + processFileOrDir(dir.FullName); |
| 31 | + } else if (File.Exists(fn)) { |
| 32 | + processFile(Path.GetFullPath(fn)); |
| 33 | + } else { |
| 34 | + var prevCol = Console.ForegroundColor; |
| 35 | + Console.ForegroundColor = ConsoleColor.Red; |
| 36 | + Console.WriteLine("File " + fn + " doesn't exist!"); |
| 37 | + Console.ForegroundColor = prevCol; |
| 38 | + } |
| 39 | + } |
| 40 | + |
| 41 | + protected virtual bool filter(string filename) { |
| 42 | + return true; |
| 43 | + } |
| 44 | + |
| 45 | + protected virtual void processFile(string filename){ |
| 46 | + } |
| 47 | + } |
| 48 | +} |
0 commit comments