|
|
- using System;
- using System.Collections.Generic;
-
- namespace Hack.Xenosaga.Common
- {
- public class listPathElement
- {
- private pathElement p_root;
- private List<pathElement> p_index;
- private Dictionary<string, pathElement> p_mappedIndex;
-
- public listPathElement()
- {
- p_root = new pathElement(true) { Name = "" };
- p_index = new List<pathElement>();
- p_mappedIndex = new Dictionary<string, pathElement>();
-
- addToIndex(p_root);
- }
-
- public void addToIndex(pathElement entry)
- {
- if (p_mappedIndex.ContainsKey(entry.FullPath))
- throw new Exception(String.Format("Entry {0} already exists", entry.FullPath));
-
- p_mappedIndex.Add(entry.FullPath, entry);
- p_index.Add(entry);
- }
-
- public IEnumerable<pathElement> getEntries()
- {
- foreach (pathElement entry in p_index)
- yield return entry;
- }
-
- public pathElement Root
- {
- get { return p_root; }
- set { p_root = value; }
- }
-
- private static int CompareElementBySector(pathElement A, pathElement B)
- {
- if (A.Sector == B.Sector)
- return 0;
- else if (A.Sector > B.Sector)
- return 1;
- else if (A.Sector < B.Sector)
- return -1;
- else
- return 0;
- }
-
- private static int CompareElementById(pathElement A, pathElement B)
- {
- if (A.Id == B.Id)
- return 0;
- else if (A.Id > B.Id)
- return 1;
- else if (A.Id < B.Id)
- return -1;
- else
- return 0;
- }
-
- public void SortBySector()
- {
- p_index.Sort(CompareElementBySector);
- }
-
- public void SortById()
- {
- p_index.Sort(CompareElementById);
- }
- }
-
- public class pathElement
- {
- private int p_id;
- private bool p_isDirectory;
- private bool p_isCompressed;
- private string p_name;
- private UInt32 p_position;
- private UInt32 p_sector;
- private UInt32 p_sizeIn;
- private UInt32 p_sizeOut;
- private string p_fullPath;
- private int p_level;
- private pathElement p_parent;
- private List<pathElement> p_entries;
-
- public pathElement(bool isDirectory)
- {
- p_parent = null;
- p_isDirectory = isDirectory;
-
- if (isDirectory)
- p_entries = new List<pathElement>();
- }
-
- public IEnumerable<pathElement> getEntries()
- {
- foreach (pathElement entry in p_entries)
- yield return entry;
- }
-
- public void addEntry(pathElement entry)
- {
- entry.Parent = this;
- p_entries.Add(entry);
- }
-
- private void computeFullPath()
- {
- p_fullPath = p_isDirectory ? p_name + "/" : p_name;
- pathElement parent = p_parent;
- while (parent != null)
- {
- p_fullPath = parent.Name + "/" + p_fullPath;
- parent = parent.Parent;
- }
- }
-
- public int Id
- {
- get { return p_id; }
- set { p_id = value; }
- }
-
- public int Level
- {
- get { return p_level; }
- set { p_level = value; }
- }
-
- public string Name
- {
- get { return p_name; }
- set { p_name = value; }
- }
-
- public UInt32 Position
- {
- get { return p_position; }
- set { p_position = value; }
- }
-
- public UInt32 Sector
- {
- get { return p_sector; }
- set { p_sector = value; }
- }
-
- public UInt32 SizeIn
- {
- get { return p_sizeIn; }
- set { p_sizeIn = value; }
- }
-
- public UInt32 SizeOut
- {
- get { return p_sizeOut; }
- set { p_sizeOut = value; }
- }
-
- public pathElement Parent
- {
- get { return p_parent; }
- private set { p_parent = value; }
- }
-
- public bool IsDirectory
- {
- get { return p_isDirectory; }
- private set { p_isDirectory = value; }
- }
-
- public bool IsCompressed
- {
- get { return p_isCompressed; }
- set { p_isCompressed = value; }
- }
-
- public string FullPath
- {
- get
- {
- if (p_fullPath == null)
- computeFullPath();
-
- return p_fullPath;
- }
- }
-
- }
-
- }
|