Tool dedicated to isohacking for Xenosaga on Playstation 2
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

197 lines
4.7 KiB

8 years ago
  1. using System;
  2. using System.Collections.Generic;
  3. namespace Hack.Xenosaga.Common
  4. {
  5. public class listPathElement
  6. {
  7. private pathElement p_root;
  8. private List<pathElement> p_index;
  9. private Dictionary<string, pathElement> p_mappedIndex;
  10. public listPathElement()
  11. {
  12. p_root = new pathElement(true) { Name = "" };
  13. p_index = new List<pathElement>();
  14. p_mappedIndex = new Dictionary<string, pathElement>();
  15. addToIndex(p_root);
  16. }
  17. public void addToIndex(pathElement entry)
  18. {
  19. if (p_mappedIndex.ContainsKey(entry.FullPath))
  20. throw new Exception(String.Format("Entry {0} already exists", entry.FullPath));
  21. p_mappedIndex.Add(entry.FullPath, entry);
  22. p_index.Add(entry);
  23. }
  24. public IEnumerable<pathElement> getEntries()
  25. {
  26. foreach (pathElement entry in p_index)
  27. yield return entry;
  28. }
  29. public pathElement Root
  30. {
  31. get { return p_root; }
  32. set { p_root = value; }
  33. }
  34. private static int CompareElementBySector(pathElement A, pathElement B)
  35. {
  36. if (A.Sector == B.Sector)
  37. return 0;
  38. else if (A.Sector > B.Sector)
  39. return 1;
  40. else if (A.Sector < B.Sector)
  41. return -1;
  42. else
  43. return 0;
  44. }
  45. private static int CompareElementById(pathElement A, pathElement B)
  46. {
  47. if (A.Id == B.Id)
  48. return 0;
  49. else if (A.Id > B.Id)
  50. return 1;
  51. else if (A.Id < B.Id)
  52. return -1;
  53. else
  54. return 0;
  55. }
  56. public void SortBySector()
  57. {
  58. p_index.Sort(CompareElementBySector);
  59. }
  60. public void SortById()
  61. {
  62. p_index.Sort(CompareElementById);
  63. }
  64. }
  65. public class pathElement
  66. {
  67. private int p_id;
  68. private bool p_isDirectory;
  69. private bool p_isCompressed;
  70. private string p_name;
  71. private UInt32 p_position;
  72. private UInt32 p_sector;
  73. private UInt32 p_sizeIn;
  74. private UInt32 p_sizeOut;
  75. private string p_fullPath;
  76. private int p_level;
  77. private pathElement p_parent;
  78. private List<pathElement> p_entries;
  79. public pathElement(bool isDirectory)
  80. {
  81. p_parent = null;
  82. p_isDirectory = isDirectory;
  83. if (isDirectory)
  84. p_entries = new List<pathElement>();
  85. }
  86. public IEnumerable<pathElement> getEntries()
  87. {
  88. foreach (pathElement entry in p_entries)
  89. yield return entry;
  90. }
  91. public void addEntry(pathElement entry)
  92. {
  93. entry.Parent = this;
  94. p_entries.Add(entry);
  95. }
  96. private void computeFullPath()
  97. {
  98. p_fullPath = p_isDirectory ? p_name + "/" : p_name;
  99. pathElement parent = p_parent;
  100. while (parent != null)
  101. {
  102. p_fullPath = parent.Name + "/" + p_fullPath;
  103. parent = parent.Parent;
  104. }
  105. }
  106. public int Id
  107. {
  108. get { return p_id; }
  109. set { p_id = value; }
  110. }
  111. public int Level
  112. {
  113. get { return p_level; }
  114. set { p_level = value; }
  115. }
  116. public string Name
  117. {
  118. get { return p_name; }
  119. set { p_name = value; }
  120. }
  121. public UInt32 Position
  122. {
  123. get { return p_position; }
  124. set { p_position = value; }
  125. }
  126. public UInt32 Sector
  127. {
  128. get { return p_sector; }
  129. set { p_sector = value; }
  130. }
  131. public UInt32 SizeIn
  132. {
  133. get { return p_sizeIn; }
  134. set { p_sizeIn = value; }
  135. }
  136. public UInt32 SizeOut
  137. {
  138. get { return p_sizeOut; }
  139. set { p_sizeOut = value; }
  140. }
  141. public pathElement Parent
  142. {
  143. get { return p_parent; }
  144. private set { p_parent = value; }
  145. }
  146. public bool IsDirectory
  147. {
  148. get { return p_isDirectory; }
  149. private set { p_isDirectory = value; }
  150. }
  151. public bool IsCompressed
  152. {
  153. get { return p_isCompressed; }
  154. set { p_isCompressed = value; }
  155. }
  156. public string FullPath
  157. {
  158. get
  159. {
  160. if (p_fullPath == null)
  161. computeFullPath();
  162. return p_fullPath;
  163. }
  164. }
  165. }
  166. }