DiskImage.cs 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. using System;
  2. using System.IO;
  3. using System.Text;
  4. using static DiskAccessLibrary.Mod.Consts;
  5. namespace DiskAccessLibrary
  6. {
  7. public abstract partial class DiskImage
  8. {
  9. public static string GetDiskImageInfo(string path)
  10. {
  11. if (path == null) throw new ArgumentNullException(nameof(path));
  12. var info = new StringBuilder();
  13. if (false == File.Exists(path))
  14. {
  15. info.AppendLine("** File not found **");
  16. }
  17. else
  18. {
  19. var extension = System.IO.Path.GetExtension(path).ToLower();
  20. switch (extension)
  21. {
  22. default:
  23. info.AppendLine($"No info for extension {extension}");
  24. break;
  25. case ".img":
  26. var rawLength = new FileInfo(path).Length;
  27. info.AppendLine("Raw Disk Image");
  28. info.AppendLine($"Size: {rawLength / MegaByte:N0} MB");
  29. break;
  30. case ".bdd":
  31. info.AppendLine("Block Differencing Disk Image");
  32. var bdd = new BddInfo(path, false);
  33. if (null == bdd.BasedImagePath)
  34. {
  35. info.AppendLine("** No Base Image Mode **");
  36. }
  37. else
  38. {
  39. if (false == File.Exists(bdd.BasedImagePath))
  40. {
  41. info.AppendLine("** Based image file not found **");
  42. info.AppendLine($"Based on: {bdd.BasedImagePath}");
  43. break;
  44. }
  45. var baseLength = IoUtility.GetRealFileSize(bdd.BasedImagePath);
  46. info.AppendLine($"Based on: {bdd.BasedImagePath}");
  47. info.AppendLine($"Based Size: {baseLength / MegaByte:N0} MB");
  48. if (baseLength != bdd.Length)
  49. {
  50. info.AppendLine("** Fully Size not match to base **");
  51. break;
  52. }
  53. }
  54. info.AppendLine($"Block Size: {bdd.BlockSize / KiloByte:N0} KB");
  55. info.AppendLine($"Block Count: {bdd.NumberOfBlocks:N0}");
  56. info.AppendLine($"Fully Size: {bdd.Length / MegaByte:N0} MB");
  57. break;
  58. }
  59. }
  60. return info.ToString();
  61. }
  62. }
  63. }