private static void TreverseDir(DirectoryInfo dir) { var currentFolder = new CustomFolder(dir.Name); folderStructure.Add(currentFolder); var folders = dir.GetDirectories(); var files = dir.GetFiles(); try { foreach (var file in files) { var currentFile = new CustomFile(file.Name, file.Length); currentFolder.AddFile(currentFile); } foreach (var folder in folders) { var childFolder = new CustomFolder(folder.Name); currentFolder.AddFolder(childFolder); TreverseDir(folder); } } catch (Exception) { Console.WriteLine("Access denied! "); } }
public static long GetSize(CustomFolder folder) { foreach (var file in folder.Files) { folder.Size += file.Size; } foreach (var currentFolder in folder.ChildFolders) { GetSize(currentFolder); } return folder.Size; }
public void AddFolder(CustomFolder dir) { this.ChildFolders.Add(dir); }
/// <summary> /// Builds a folder path. It will return a specific file if specified, otherwise it will end with backslash. /// </summary> /// <param name="regionPackFolder"> Folder name of the region pack. Use null for vanilla path. </param> /// <param name="folderEnum"> Folder which to retreive.</param> /// <param name="regionID"> Region ID needed for Rooms or RegionID folder.</param> /// <param name="file"> If specified, it will append a file after the folder path.</param> /// <param name="folder"> If specified, it will append an additional folder path.</param> /// <returns>Path built.</returns> public static string BuildPath(string regionPackFolder, CustomFolder folderEnum, string regionID = null, string file = null, string folder = null, bool includeRoot = true, bool recursive = false) { char div = Path.DirectorySeparatorChar; if (folderEnum == CustomFolder.RegionID || folderEnum == CustomFolder.Rooms) { if (string.IsNullOrEmpty(regionID)) { CustomWorldMod.Log($"Called BuildPath without regionID", true); return(null); } } string path = string.Empty; string recursivePath = string.Empty; switch (folderEnum) { // Depth 1 case CustomFolder.None: case CustomFolder.Assets: case CustomFolder.Levels: case CustomFolder.World: case CustomFolder.PackDependencies: if (includeRoot) { // Rain World/ path = RWCustom.Custom.RootFolderDirectory() + path; } // Requesting custom folder if (regionPackFolder != null) { // includeRoot?/Mods/CustomResources/RegionPack path = path + CustomWorldMod.resourcePath + regionPackFolder; } if (folderEnum != CustomFolder.None) { path = path + div + folderEnum.ToString(); } break; // Depth 2 case CustomFolder.Gates_Shelters: case CustomFolder.Gates: case CustomFolder.Regions: recursivePath = BuildPath(regionPackFolder, CustomFolder.World, includeRoot: includeRoot, recursive: true); path = recursivePath + div + folderEnum.ToString().Replace("_", " "); break; case CustomFolder.Futile: case CustomFolder.Text: recursivePath = BuildPath(regionPackFolder, CustomFolder.Assets, includeRoot: includeRoot, recursive: true); path = recursivePath + div + folderEnum.ToString(); break; // Special case case CustomFolder.RegionID: recursivePath = BuildPath(regionPackFolder, CustomFolder.Regions, includeRoot: includeRoot, recursive: true); path = recursivePath + div + regionID; break; case CustomFolder.Rooms: recursivePath = BuildPath(regionPackFolder, CustomFolder.RegionID, regionID: regionID, includeRoot: includeRoot, recursive: true); path = recursivePath + div + folderEnum.ToString(); break; // Depth 3 case CustomFolder.Resources: recursivePath = BuildPath(regionPackFolder, CustomFolder.Futile, includeRoot: includeRoot, recursive: true); path = recursivePath + div + folderEnum.ToString(); break; // Depth 4 case CustomFolder.Illustrations: case CustomFolder.LoadedSoundEffects: case CustomFolder.Scenes: case CustomFolder.Atlases: case CustomFolder.Music: case CustomFolder.Decals: case CustomFolder.Palettes: recursivePath = BuildPath(regionPackFolder, CustomFolder.Resources, includeRoot: includeRoot, recursive: true); path = recursivePath + div + folderEnum.ToString(); break; // Depth 5.1 case CustomFolder.Ambient: recursivePath = BuildPath(regionPackFolder, CustomFolder.LoadedSoundEffects, includeRoot: includeRoot, recursive: true); path = recursivePath + div + folderEnum.ToString(); break; // Depth 5.2 case CustomFolder.Procedural: case CustomFolder.Songs: recursivePath = BuildPath(regionPackFolder, CustomFolder.Music, includeRoot: includeRoot, recursive: true); path = recursivePath + div + folderEnum.ToString(); break; default: path = null; break; } if (path == null) { CustomWorldMod.Log($"[PathBuilder] Could not find request folder [{folderEnum}]", true); return(string.Empty); } if (!recursive) { path += folder != null ? (div.ToString() + folder + div.ToString()) : div.ToString(); path += file != null ? file : string.Empty; } return(path); }