/// <summary> /// Gets a resource using a path and ID. /// </summary> /// <param name="path">The path to the file. If this path is to an archive, assetID can be null.</param> /// <param name="assetID">The ID for the resource. Can be null if path doesn't point to an archive.</param> /// <returns></returns> public Stream GetResource(string path, ulong assetID) { if (path.EndsWith(".dat")) { /** Archive **/ if (!Archives.ContainsKey(path)) { FAR3Archive newArchive = new FAR3Archive(GetPath(path)); Archives.Add(path, newArchive); } var archive = Archives[path]; var bytes = archive.GetItemByID(assetID); return new MemoryStream(bytes, false); } if (path.EndsWith(".bmp") || path.EndsWith(".png") || path.EndsWith(".tga")) path = "uigraphics/" + path; return File.OpenRead(GetPath(path)); }
public static ContentResource GetResourceInfo(ulong ID) { /** Busy wait until we are ready **/ while (!initComplete) ; ContentResource result = null; if (!m_LoadedResources.TryGetValue(ID, out result)) { result = new ContentResource { ID = ID }; string path = m_Resources[ID]; result.FilePath = path; result.FileExtension = Path.GetExtension(path).ToLower(); if (!path.EndsWith(".dat")) { /** Isnt an archive **/ result.Data = File.ReadAllBytes(path); return result; } if (!m_Archives.ContainsKey(path)) { FAR3Archive Archive = new FAR3Archive(path); m_Archives.Add(path, Archive); } result.Data = m_Archives[path].GetItemByID(ID); return result; } else { return result; } }