public static void Load() { var time = FileManager.GetTime(); if (FileManager.Exists("Temp/FileManager.data")) { int mode = 0; string extension = ""; string lastPath = ""; var lines = File.ReadAllLines("Temp/FileManager.data"); for (int index = 0; index < lines.Length; ++index) { var line = lines[index]; if (line.Contains("[Files]")) { mode = 1; } else if (line.Contains("[Folders]")) { mode = 2; } else if (line.StartsWith("(")) { extension = line.Parse("(", ")"); } else if (line.StartsWith("=")) { lastPath = line.Remove("=").Replace("$", FileManager.path); } else if (line.StartsWith("+")) { lastPath += line.Remove("+"); } else { var fileData = new FileData(); fileData.directory = lastPath; fileData.name = line; if (mode == 1) { fileData.fullName = fileData.name + "." + extension; fileData.path = fileData.directory + "/" + fileData.fullName; fileData.extension = extension; } else if (mode == 2) { fileData.path = fileData.directory + "/" + fileData.name; fileData.isFolder = true; } FileManager.BuildCache(fileData); } } } if (FileManager.clock) { Debug.Log("[FileManager] : Load cache complete -- " + (FileManager.GetTime() - time) + " seconds."); } }
public static void WriteFile(string path, byte[] bytes) { if (!FileManager.Exists(path)) { FileManager.Create(path); } FileStream stream = new FileStream(path, FileMode.Create); BinaryWriter file = new BinaryWriter(stream); file.Write(bytes); file.Close(); stream.Close(); }
public static void WriteFile(string path, byte[] bytes) { var folder = path.GetDirectory(); if (!FileManager.Exists(folder)) { FileManager.Create(folder); } FileStream stream = new FileStream(path, FileMode.Create); BinaryWriter file = new BinaryWriter(stream); file.Write(bytes); file.Close(); stream.Close(); }
public static void Load() { var time = FileManager.GetTime(); var cachePath = Application.isEditor ? "Temp/FileManager.data" : FileManager.root + "/FileManager.data"; if (FileManager.Exists(cachePath)) { string extension = ""; string lastPath = ""; var lines = File.ReadAllLines(cachePath); for (int index = 0; index < lines.Length; ++index) { var line = lines[index]; if (line.StartsWith("(")) { extension = line.Parse("(", ")"); } else if (line.StartsWith("=") || line.StartsWith("+")) { lastPath = line.StartsWith("=") ? line.TrimLeft("=").Replace("$", FileManager.root) : lastPath + line.TrimLeft("+"); var folderData = new FileData(); folderData.name = lastPath.GetPathTerm(); folderData.directory = lastPath.GetDirectory(); folderData.path = lastPath; folderData.isFolder = true; FileManager.BuildCache(folderData); } else { var fileData = new FileData(); fileData.directory = lastPath; fileData.name = line; fileData.fullName = fileData.name + "." + extension; fileData.path = fileData.directory + "/" + fileData.fullName; fileData.extension = extension; FileManager.BuildCache(fileData); } } } if (FileManager.clock) { Debug.Log("[FileManager] : Load cache complete -- " + (FileManager.GetTime() - time) + " seconds."); } }
public static void SaveFonts(this GUISkin current, string path, bool includeBuiltin = true) { foreach (var style in current.GetStyles()) { if (!style.font.IsNull()) { string assetPath = FileManager.GetPath(style.font); string savePath = path + "/" + assetPath.GetPathTerm(); if (!includeBuiltin && assetPath.Contains("unity editor resources")) { continue; } if (!FileManager.Exists(savePath)) { AssetDatabase.CopyAsset(assetPath, savePath); } } } }
public static FileData Create(string path) { path = Path.GetFullPath(path).Replace("\\", "/"); var data = new FileData(path); if (!data.name.IsEmpty()) { var folder = path.GetDirectory(); if (!FileManager.Exists(folder)) { FileManager.Create(folder); } File.Create(path).Dispose(); } else { data.isFolder = true; Directory.CreateDirectory(path); } FileManager.BuildCache(data); return(data); }
public static void SaveBackgrounds(this GUISkin current, string path, bool includeBuiltin = true) { foreach (var style in current.GetStyles()) { foreach (var state in style.GetStates()) { if (!state.background.IsNull()) { string assetPath = FileManager.GetPath(state.background); string savePath = path + "/" + state.background.name + ".png"; if (!includeBuiltin && assetPath.Contains("unity editor resources")) { continue; } if (!FileManager.Exists(savePath)) { state.background.SaveAs(savePath, true); } } } } }