|
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using System.IO; |
| 4 | +using System.Linq; |
| 5 | +using System.Text; |
| 6 | +using System.Threading.Tasks; |
| 7 | +using DFO.Common; |
| 8 | +using DFO.Npk; |
| 9 | + |
| 10 | +namespace DFO.npkdiff |
| 11 | +{ |
| 12 | + class Program |
| 13 | + { |
| 14 | + static void Main(string[] args) |
| 15 | + { |
| 16 | + CommandLineArgs cmdline = new CommandLineArgs(args); |
| 17 | + |
| 18 | + // read *.NPK in NpkDir1 |
| 19 | + // read *.NPK in NpkDir2 |
| 20 | + // Compare |
| 21 | + |
| 22 | + NpkDirContents dir1Contents = GetNpkDirContents(cmdline.NpkDir1); |
| 23 | + NpkDirContents dir2Contents = GetNpkDirContents(cmdline.NpkDir2); |
| 24 | + NpkDirDifferences differences = dir1Contents.GetDifferences(dir2Contents); |
| 25 | + DisplayDifferences(differences); |
| 26 | + } |
| 27 | + |
| 28 | + static NpkDirContents GetNpkDirContents(string npkDir) |
| 29 | + { |
| 30 | + NpkDirContents allContents = new NpkDirContents(); |
| 31 | + foreach (string npkFilePath in Directory.GetFiles(npkDir, "*.NPK", SearchOption.TopDirectoryOnly)) |
| 32 | + { |
| 33 | + NpkDirContents npkContents = GetNpkContents(npkFilePath); |
| 34 | + allContents.Add(npkContents); |
| 35 | + } |
| 36 | + return allContents; |
| 37 | + } |
| 38 | + |
| 39 | + static NpkDirContents GetNpkContents(string npkFilePath) |
| 40 | + { |
| 41 | + using (NpkReader npk = new NpkReader(npkFilePath)) |
| 42 | + { |
| 43 | + return new NpkDirContents(Path.GetFileName(npkFilePath), npk.Frames); |
| 44 | + } |
| 45 | + } |
| 46 | + |
| 47 | + static void DisplayDifferences(NpkDirDifferences differences) |
| 48 | + { |
| 49 | + foreach (ImgInfo img in differences.ImgsInSecondButNotFirst.OrderBy(x => x.Path.Path)) |
| 50 | + { |
| 51 | + Console.WriteLine("+{0} ({1}): {2}", img.Path, img.FrameCount, img.NpkFileName); |
| 52 | + } |
| 53 | + foreach (NpkPath imgPath in differences.ImgsWithMoreFramesInSecond.Keys.OrderBy(x => x.Path)) |
| 54 | + { |
| 55 | + string npkFileNameDisplay; |
| 56 | + string npkFileName1 = differences.ImgsWithMoreFramesInSecond[imgPath].NpkFileName1; |
| 57 | + string npkFileName2 = differences.ImgsWithMoreFramesInSecond[imgPath].NpkFileName2; |
| 58 | + if (npkFileName1.Equals(npkFileName2, StringComparison.OrdinalIgnoreCase)) |
| 59 | + { |
| 60 | + npkFileNameDisplay = npkFileName1; |
| 61 | + } |
| 62 | + else |
| 63 | + { |
| 64 | + npkFileNameDisplay = string.Format("{0}->{1}", npkFileName1, npkFileName2); |
| 65 | + } |
| 66 | + Console.WriteLine(">{0} {1}->{2} {3}", imgPath, differences.ImgsWithMoreFramesInSecond[imgPath].FrameCount1, differences.ImgsWithMoreFramesInSecond[imgPath].FrameCount2, npkFileNameDisplay); |
| 67 | + } |
| 68 | + foreach (NpkPath imgPath in differences.ImgsWithFewerFramesInSecond.Keys.OrderBy(x => x.Path)) |
| 69 | + { |
| 70 | + string npkFileNameDisplay; |
| 71 | + string npkFileName1 = differences.ImgsWithFewerFramesInSecond[imgPath].NpkFileName1; |
| 72 | + string npkFileName2 = differences.ImgsWithFewerFramesInSecond[imgPath].NpkFileName2; |
| 73 | + if (npkFileName1.Equals(npkFileName2, StringComparison.OrdinalIgnoreCase)) |
| 74 | + { |
| 75 | + npkFileNameDisplay = npkFileName1; |
| 76 | + } |
| 77 | + else |
| 78 | + { |
| 79 | + npkFileNameDisplay = string.Format("{0}->{1}", npkFileName1, npkFileName2); |
| 80 | + } |
| 81 | + Console.WriteLine("<{0} {1}->{2}", imgPath, differences.ImgsWithFewerFramesInSecond[imgPath].FrameCount1, differences.ImgsWithFewerFramesInSecond[imgPath].FrameCount2, npkFileNameDisplay); |
| 82 | + } |
| 83 | + foreach (ImgInfo img in differences.ImgsInFirstButNotSecond.OrderBy(x => x.Path.Path)) |
| 84 | + { |
| 85 | + Console.WriteLine("-{0} ({1}): {2}", img, img.FrameCount, img.NpkFileName); |
| 86 | + } |
| 87 | + } |
| 88 | + } |
| 89 | +} |
0 commit comments