public static bool RemoveNotCollected(DatBase inDat) { if (inDat is DatFile dFile) { return(dFile.DatStatus == DatFileStatus.InDatCollect || dFile.DatStatus == DatFileStatus.InDatBad); } DatDir dDir = inDat as DatDir; DatBase[] children = dDir?.ToArray(); if (children == null || children.Length == 0) { return(false); } dDir.ChildrenClear(); bool found = false; foreach (DatBase child in children) { bool keep = RemoveNotCollected(child); if (keep) { found = true; dDir.ChildAdd(child); } } return(found); }
private static void CleanFilename(DatBase db) { string name = db.Name; if (string.IsNullOrEmpty(name)) { return; } string retName = name; retName = retName.TrimStart(); retName = retName.TrimEnd(new[] { '.', ' ' }); retName = retName.Replace("/", "\\"); retName = retName.Replace("\\ ", "\\"); retName = retName.Replace(".\\", "\\"); char[] charName = retName.ToCharArray(); for (int i = 0; i < charName.Length; i++) { int c = charName[i]; if (c == ':' || c == '*' || c == '?' || c == '<' || c == '>' || c == '|' || c < 32) { charName[i] = '-'; } } db.Name = new string(charName); }
public static bool RemoveEmptySets(DatBase inDat) { if (inDat is DatFile) { return(true); } DatDir dDir = inDat as DatDir; DatBase[] children = dDir?.ToArray(); if (children == null || children.Length == 0) { return(false); } dDir.ChildrenClear(); bool found = false; foreach (DatBase child in children) { bool keep = RemoveEmptySets(child); if (keep) { found = true; dDir.ChildAdd(child); } } return(found); }
private void ProcessDir(DatDir dd, int depth, bool inGame) { bool dirIsGame = dd.DGame != null; inGame |= dirIsGame; if (dd.DGame != null) { if (!string.IsNullOrWhiteSpace(dd.DGame.CloneOf)) { cloneOf = true; } if (!string.IsNullOrWhiteSpace(dd.DGame.RomOf)) { romOf = true; } } if (!inGame && depth > 0) { subDirFound = true; subDirContainsDir |= dd.Name.Contains(@"/") || dd.Name.Contains(@"\"); } if (dirIsGame) { gameContainsdir |= dd.Name.Contains(@"/") || dd.Name.Contains(@"\"); } if (inGame && !dirIsGame) { subDirFoundInGame = true; subDirInGameContainsDir |= dd.Name.Contains(@"/") || dd.Name.Contains(@"\"); } // Debug.WriteLine(depth + " " + dd.Name + " " + inGame); int iCount = dd.ChildCount; for (int i = 0; i < iCount; i++) { DatBase db = dd.Child(i); DatDir ddc = db as DatDir; if (ddc != null) { ProcessDir(ddc, depth + 1, inGame); } DatFile dfc = db as DatFile; if (dfc != null) { ProcessFile(dfc); } } }
public static void SetFile(DatBase inDat) { if (inDat.Name != null) { inDat.Name = inDat.Name.TrimStart(new[] { ' ' }); inDat.Name = inDat.Name.TrimEnd(new[] { '.', ' ' }); if (string.IsNullOrWhiteSpace(inDat.Name)) { inDat.Name = "_"; } } if (inDat is DatFile dFile) { //if (dFile.DatFileType == DatFileType.UnSet) dFile.DatFileType = DatFileType.File; return; } if (!(inDat is DatDir dDir)) { return; } if (dDir.DGame == null) { //if (dDir.DatFileType == DatFileType.UnSet) dDir.DatFileType = DatFileType.Dir; } else { //if (dDir.DatFileType == DatFileType.UnSet) dDir.DatFileType = DatFileType.Dir; } DatBase[] children = dDir.ToArray(); if (children == null) { return; } dDir.ChildrenClear(); foreach (DatBase child in children) { SetFile(child); dDir.ChildAdd(child); } }
private static bool CheckDir(DatBase db) { DatFileType dft = db.DatFileType; switch (dft) { // files inside of zips/7zips do not need to be expanded case DatFileType.File7Zip: case DatFileType.FileTorrentZip: return(false); // everything else should be fully expanded default: return(true); } }
private static bool CheckDir(DatBase db) { if (db is DatDir) { return(true); } if (db is DatFile tFile) { if (tFile.DatFileType == DatFileType.File) { return(true); } } return(false); }
public static void Set7Zip(DatBase inDat) { if (inDat is DatFile dFile) { dFile.Name = dFile.Name.Replace(@"\", @"/"); dFile.DatFileType = DatFileType.File7Zip; return; } if (!(inDat is DatDir dDir)) { return; } if (dDir.DGame == null) { dDir.DatFileType = DatFileType.Dir; } else { dDir.DatFileType = DatFileType.Dir7Zip; } DatBase[] children = dDir.ToArray(); if (children == null) { return; } dDir.ChildrenClear(); foreach (DatBase child in children) { Set7Zip(child); dDir.ChildAdd(child); } }
public static void SetFile(DatBase inDat) { if (inDat is DatFile dFile) { dFile.DatFileType = DatFileType.File; return; } if (!(inDat is DatDir dDir)) { return; } if (dDir.DGame == null) { dDir.DatFileType = DatFileType.Dir; } else { dDir.DatFileType = DatFileType.Dir; } DatBase[] children = dDir.ToArray(); if (children == null) { return; } dDir.ChildrenClear(); foreach (DatBase child in children) { SetFile(child); dDir.ChildAdd(child); } }
public static int CompareName(DatBase var1, DatBase var2) { int retv = Math.Abs(System.String.Compare(var1.Name, var2.Name, StringComparison.Ordinal)); return(retv); }
public static void SetZip(DatBase inDat, bool is7Zip = false) { int parentCount = _parents.Count; if (inDat is DatFile dFile) { if (dFile.isDisk) { //go up 2 levels to find the directory of the game DatDir dir = _parents[parentCount - 2]; DatDir zipDir = _parents[parentCount - 1]; DatDir tmpFile = new DatDir(DatFileType.Dir) { Name = zipDir.Name, DGame = zipDir.DGame }; if (dir.ChildNameSearch(tmpFile, out int index) != 0) { dir.ChildAdd(tmpFile); } else { tmpFile = (DatDir)dir.Child(index); } dFile.DatFileType = DatFileType.File; tmpFile.ChildAdd(dFile); } else { dFile.Name = dFile.Name.Replace("\\", "/"); dFile.DatFileType = is7Zip ? DatFileType.File7Zip : DatFileType.FileTorrentZip; _parents[parentCount - 1].ChildAdd(dFile); } return; } if (!(inDat is DatDir dDir)) { return; } if (_parents.Count > 0) { _parents[parentCount - 1].ChildAdd(inDat); } dDir.DatFileType = dDir.DGame == null ? DatFileType.Dir : (is7Zip ? DatFileType.Dir7Zip : DatFileType.DirTorrentZip); DatBase[] children = dDir.ToArray(); if (children == null) { return; } dDir.ChildrenClear(); _parents.Add(dDir); foreach (DatBase child in children) { SetZip(child, is7Zip); } _parents.RemoveAt(parentCount); }
public static void SetZip(DatBase inDat, bool is7Zip = false) { SetZip(inDat, is7Zip, new List <DatDir>()); }
private static void SetZip(DatBase inDat, bool is7Zip, List <DatDir> parents) { if (parents == null) { parents = new List <DatDir>(); } int parentCount = parents.Count; if (inDat is DatFile dFile) { if (dFile.isDisk) { //go up 2 levels to find the directory of the game DatDir dir = parents[parentCount - 2]; DatDir zipDir = parents[parentCount - 1]; DatDir tmpFile = new DatDir(DatFileType.Dir) { Name = zipDir.Name, DGame = zipDir.DGame }; if (dir.ChildNameSearch(tmpFile, out int index) != 0) { dir.ChildAdd(tmpFile); } else { tmpFile = (DatDir)dir.Child(index); } dFile.DatFileType = DatFileType.File; tmpFile.ChildAdd(dFile); } else { dFile.Name = dFile.Name.Replace("\\", "/"); dFile.DatFileType = is7Zip ? DatFileType.File7Zip : DatFileType.FileTorrentZip; parents[parentCount - 1].ChildAdd(dFile); } return; } if (!(inDat is DatDir dDir)) { return; } if (inDat.Name != null) { inDat.Name = inDat.Name.TrimStart(new[] { ' ' }); inDat.Name = inDat.Name.TrimEnd(new[] { ' ' }); if (string.IsNullOrWhiteSpace(inDat.Name)) { inDat.Name = "_"; } } if (parents.Count > 0) { parents[parentCount - 1].ChildAdd(inDat); } dDir.DatFileType = dDir.DGame == null ? DatFileType.Dir : (is7Zip ? DatFileType.Dir7Zip : DatFileType.DirTorrentZip); DatBase[] children = dDir.ToArray(); if (children == null) { return; } dDir.ChildrenClear(); parents.Add(dDir); foreach (DatBase child in children) { SetZip(child, is7Zip, parents); } parents.RemoveAt(parentCount); }