winimageiso.cs
来自「对ima、imz压缩文件修改」· CS 代码 · 共 727 行 · 第 1/3 页
CS
727 行
{
IsoObject curItem = new IsoObject();
curItem.LongName = new String(lpDi[i].longname).Trim('\0');
curItem.ShortName = new String(lpDi[i].szCompactName).Trim('\0');
if ((curItem.ShortName != "..") && (curItem.ShortName != "."))
{
curItem.Position = lpDi[i].uiPosInDir;
if (!lpDi[i].fIsSubDir)
{
curItem.ObjectType = IsoObject.ObjType.otFile;
curItem.Key = sParentID + ":F" + iFileID.ToString();
curItem.Size = (long)lpDi[i].dwSize;
iFileID++;
//Console.WriteLine(curItem.Key + "-" + curItem.LongName + "-" + curItem.Size.ToString());
}
else
{
curItem.ObjectType = IsoObject.ObjType.otDir;
curItem.Key = sParentID + ":D" + iFolderID.ToString();
iFolderID++;
Wimadll.ChszDir(iImgHandle, curItem.ShortName);
ReadFileList(curItem, curItem.Key);
Wimadll.ChDir(iImgHandle, Wimadll.CDM_UPPER);
}
isoCurRoot.Children.Add(curItem.Key,curItem);
}
}
}
}
#endregion
}
public class IsoObject
{
#region Declarations
public enum ObjType { otDir = 0, otFile = 1 };
private bool bSelected = false;
private IsoObjectCollection iChildren;
private ObjType iObjectType = ObjType.otDir;
private IsoObject ioParent = null;
private uint iPosition = 0;
private int iSelFiles = 0;
private int iSelFolders = 0;
private long lSelSize = 0;
private long lSize = 0;
private string sKey = "";
private string sLongName = "";
private string sShortName = "";
#endregion
#region Object Constructor/Destructor
internal IsoObject() { iChildren = new IsoObjectCollection(this); }
~IsoObject()
{
if (iChildren != null)
{
iChildren.Clear();
iChildren = null;
}
}
#endregion
#region Properties
public IsoObjectCollection Children
{
get { if (iObjectType == ObjType.otDir) { return iChildren; } else { return null; } }
}
public int FileCount { get { return (iChildren != null ? iChildren.iFiles : 0); } }
public int FolderCount { get { return (iChildren != null ? iChildren.iFolders : 0); } }
public string Key
{
get { return sKey; }
internal set { sKey = value; }
}
public string LongName
{
get { return sLongName; }
set
{
sLongName = value;
if (sLongName.IndexOf('\0') > 0) { sLongName = sLongName.Substring(0, sLongName.IndexOf('\0')); }
}
}
public ObjType ObjectType
{
get { return iObjectType; }
internal set
{
iObjectType = value;
if (iObjectType == ObjType.otFile)
{
iChildren.Clear();
iChildren = null;
iSelFiles = 0;
iSelFolders = 0;
}
else
{
if (iChildren == null) { iChildren = new IsoObjectCollection(this); }
}
}
}
public IsoObject Parent
{
get { return ioParent; }
internal set { ioParent = value; }
}
public uint Position
{
get { return iPosition; }
internal set { iPosition = value; }
}
public bool Selected
{
get { return bSelected; }
set
{
if (iObjectType == ObjType.otDir) { foreach (IsoObject Item in iChildren) { Item.Selected = value; } }
if (bSelected != value)
{
bSelected = value;
if (ioParent != null)
{
int Operator = value ? 1 : -1;
if (iObjectType == ObjType.otDir) { ioParent.SelectedFolders += Operator; }
else
{
ioParent.SelectedFiles += Operator;
ioParent.SelectedSize += (Operator * lSize);
}
}
}
}
}
internal bool SelectedChildren { get { return (iSelFolders + iSelFiles) > 0; } }
internal int SelectedFiles
{
get { return iSelFiles; }
set
{
int diff = value - iSelFiles;
iSelFiles = value;
if (ioParent != null) { ioParent.SelectedFiles += diff; }
}
}
internal int SelectedFolders
{
get { return iSelFolders; }
set
{
int diff = value - iSelFolders;
iSelFolders = value;
if (ioParent != null) { ioParent.SelectedFolders += diff; }
}
}
internal long SelectedSize
{
get { return lSelSize; }
set
{
long Diff = value - lSelSize;
lSelSize = value;
if (ioParent != null) { ioParent.SelectedSize += Diff; }
}
}
public string ShortName
{
get { return sShortName; }
set
{
sShortName = value;
if (sShortName.IndexOf('\0') > 0) { sShortName = sShortName.Substring(0, sShortName.IndexOf('\0')); }
}
}
public long Size
{
get { return lSize; }
internal set
{
long diff = value - lSize;
lSize = value;
if (ioParent != null) { ioParent.Size += diff; }
}
}
#endregion
#region Class OverRides
public override bool Equals(object obj)
{
if (obj.GetType().ToString() != "WinImage.IsoObject") { return false; } else { return ((obj as IsoObject).Key == Key); }
}
public override int GetHashCode() { return base.GetHashCode(); }
#endregion
}
public class IsoObjectCollection:Dictionary<string, IsoObject>
{
internal int iFiles = 0;
internal int iFolders = 0;
private IsoObject Parent = null;
internal IsoObjectCollection(IsoObject ParentObject)
{
Parent = ParentObject;
}
public new void Add(string Key, IsoObject Item)
{
Item.Parent = this.Parent;
if (Item.ObjectType == IsoObject.ObjType.otDir) { iFolders++; } else { iFiles++; }
if (Item.Parent != null) { Item.Parent.Size += Item.Size; }
base.Add(Key, Item);
}
public new void Clear()
{
foreach (IsoObject item in base.Values)
{
if ((item.ObjectType == IsoObject.ObjType.otDir) && (item.Children!=null)) { item.Children.Clear(); }
}
base.Clear();
}
public new bool ContainsKey(string Key)
{
string[] IDs = Key.Split(':');
string lKey = (Parent != null ? Parent.Key + ":" : "") + IDs[0];
if (base.ContainsKey(lKey))
{
string cKey = "";
for (int i = 1; i <= IDs.GetUpperBound(0); i++) { cKey += IDs[i] + (i < IDs.GetUpperBound(0) ? ":" : ""); }
if (cKey.Length == 0) { return true; } else { return base[lKey].Children.ContainsKey(cKey); }
}
else { return false; }
}
public new bool ContainsValue(IsoObject Item) { return this.ContainsValue(Item.LongName); }
public bool ContainsValue(string Item) { return (this.LocateValue(Item) != null); }
public new IEnumerator<IsoObject> GetEnumerator()
{
foreach (IsoObject item in base.Values) { yield return item; }
}
public IsoObject LocateValue(string ItemName)
{
ItemName.Replace('/', '\\');
string[] Folders = ItemName.Split('\\');
string bPath = Folders[0];
string cPath = "";
for (int i = 1; i <= Folders.GetUpperBound(0); i++) { cPath += Folders[i] + (i < Folders.GetUpperBound(0) ? "\\" : ""); }
foreach (IsoObject Item in base.Values)
{
if (Item.LongName.ToLower() == bPath.ToLower())
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?