public byte[] this[ulong FileID] { get { byte[] Resource; //Resource hasn't already been loaded... if (!m_LoadedResources.TryGetValue(FileID, out Resource)) { string path = m_Resources[FileID].Replace("./", ""); if (!File.Exists(path)) { string[] pathSections = path.Split(new char[] { '/' }); string directoryName = pathSections[pathSections.Length - 2]; string archivePath = GlobalSettings.Default.StartupPath + path.Remove(path.LastIndexOf('/') + 1) + directoryName + ".dat"; FAR3Archive archive = new FAR3Archive(archivePath); return(archive[pathSections[pathSections.Length - 1]]); } else { Resource = File.ReadAllBytes(GlobalSettings.Default.StartupPath + path); return(Resource); } } else { return(Resource); } } }
public void TestIncorrectFAR3Parsing() { string GameDir = GetInstallDir(); FAR3Archive Arch = new FAR3Archive(GameDir + "EP2.dat"); Assert.IsFalse(Arch.ReadArchive(false)); }
public void TestCorrectFAR3Parsing() { string GameDir = GetInstallDir(); string Delimiter = (IsLinux) ? "//" : "\\"; FAR3Archive Arch = new FAR3Archive(GameDir + "uigraphics" + Delimiter + "credits" + Delimiter + "credits.dat"); Assert.IsTrue(Arch.ReadArchive(false)); }
/// <summary> /// Gets a sim's thumbnail image. /// </summary> /// <returns></returns> private Bitmap GetThumbnail() { Outfit Oft = new Outfit(); Appearance Apr = new Appearance(); Bitmap Thumbnail = new Bitmap(1, 1); if (!File.Exists(GlobalSettings.Default.ClientPath + "avatardata\\heads\\outfits\\outfits.dat")) { Debug.WriteLine("WARNING: Couldn't find: " + GlobalSettings.Default.ClientPath + "avatardata\\heads\\outfits\\outfits.dat"); return(Thumbnail); } FAR3Archive Archive = new FAR3Archive(GlobalSettings.Default.ClientPath + "avatardata\\heads\\outfits\\outfits.dat"); Oft.Read(new MemoryStream(Archive.GetItemByID(HeadOutfitID))); Archive = new FAR3Archive(GlobalSettings.Default.ClientPath + "avatardata\\heads\\appearances\\appearances.dat"); TSO.Common.content.ContentID ApprID; switch (Appearance) { case AppearanceType.Light: ApprID = Oft.GetAppearance(AppearanceType.Light); Apr.Read(new MemoryStream(Archive.GetItemByID(ApprID.Shift()))); Archive = new FAR3Archive(GlobalSettings.Default.ClientPath + "avatardata\\heads\\thumbnails\\thumbnails.dat"); Thumbnail = new Bitmap(new MemoryStream(Archive.GetItemByID(Apr.ThumbnailID.Shift()))); break; case AppearanceType.Medium: ApprID = Oft.GetAppearance(AppearanceType.Medium); Apr.Read(new MemoryStream(Archive.GetItemByID(ApprID.Shift()))); Archive = new FAR3Archive(GlobalSettings.Default.ClientPath + "avatardata\\heads\\thumbnails\\thumbnails.dat"); Thumbnail = new Bitmap(new MemoryStream(Archive.GetItemByID(Apr.ThumbnailID.Shift()))); break; case AppearanceType.Dark: ApprID = Oft.GetAppearance(AppearanceType.Dark); Apr.Read(new MemoryStream(Archive.GetItemByID(ApprID.Shift()))); Archive = new FAR3Archive(GlobalSettings.Default.ClientPath + "avatardata\\heads\\thumbnails\\thumbnails.dat"); Thumbnail = new Bitmap(new MemoryStream(Archive.GetItemByID(Apr.ThumbnailID.Shift()))); break; } return(Thumbnail); }
public void Init() { if (Initialized) { return; } Initialized = true; Cache = new TimedReferenceCache <ulong, T>(); lock (Cache) { EntriesById = new Dictionary <ulong, Far3ProviderEntry <T> >(); EntriesByName = new Dictionary <string, Far3ProviderEntry <T> >(); if (FarFilePattern != null) { List <string> FarFiles = new List <string>(); foreach (var File in ContentManager.AllFiles) { if (FarFilePattern.IsMatch(File.Replace('\\', '/'))) { FarFiles.Add(File); } } m_FarFiles = FarFiles.ToArray(); } foreach (var FarPath in m_FarFiles) { var archive = new FAR3Archive(ContentManager.GetPath(FarPath)); var entries = archive.GetAllFAR3Entries(); foreach (var entry in entries) { var fileID = ((ulong)entry.FileID) << 32; var referenceItem = new Far3ProviderEntry <T>(this) { ID = fileID | entry.TypeID, Archive = archive, FarEntry = entry }; EntriesById.Add(referenceItem.ID, referenceItem); if (entry.Filename != null) { EntriesByName[entry.Filename.ToLowerInvariant()] = referenceItem; } } } } }
/// <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)); } 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); } }
public static byte[] GetResourceFromLongID(ulong ID) { byte[] Resource; while (!initComplete) { ; } //Resource hasn't already been loaded... if (!m_LoadedResources.TryGetValue(ID, out Resource)) { string path = m_Resources[ID]; FAR3Archive Archive = new FAR3Archive(path); Resource = Archive.GetItemByID(ID); return(Resource); } else { return(m_LoadedResources[ID]); } }
/// <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))); }
/// <summary> /// Adds files from a specified directory to a dictionary of entries. /// </summary> /// <param name="EntryDir">The directory to scan for entries.</param> /// <param name="Filetype">A fully qualified lowercase filetype to scan for (can be empty).</param> /// <param name="Entries">The Dictionary to add entries to.</param> private static void AddFilesFromDir(string EntryDir, string Filetype, ref Dictionary<Far3Entry, string> Entries) { string[] Dirs = Directory.GetDirectories(EntryDir); foreach(string Dir in Dirs) { if (Filetype != "") { if (Dir.Contains(Filetype)) { string[] Files = Directory.GetFiles(Dir); string[] SubDirs = Directory.GetDirectories(Dir); foreach (string Fle in Files) { if (Fle.Contains(".dat")) { FAR3Archive Archive = new FAR3Archive(Fle); foreach (Far3Entry Entry in Archive.GetAllFAR3Entries()) Entries.Add(Entry, Fle.Replace(GlobalSettings.Default.StartupPath, "")); } else { Far3Entry Entry = new Far3Entry(); Entry.Filename = Fle.Replace(GlobalSettings.Default.StartupPath, ""); Entry.FileID = HelperFuncs.GetFileID(Entry); Entry.TypeID = HelperFuncs.GetTypeID(Path.GetExtension(Fle)); HelperFuncs.CheckCollision(Entry.FileID, Entries); //Ignore fonts to minimize the risk of ID collisions. if (!Entry.Filename.Contains(".ttf")) { if (!Entry.Filename.Contains(".ffn")) Entries.Add(Entry, Entry.Filename); } } } foreach (string SubDir in SubDirs) { Files = Directory.GetFiles(SubDir); foreach (string SubFle in Files) { if (SubFle.Contains(".dat")) { FAR3Archive Archive = new FAR3Archive(SubFle); foreach (Far3Entry Entry in Archive.GetAllFAR3Entries()) Entries.Add(Entry, SubFle.Replace(GlobalSettings.Default.StartupPath, "")); } else { Far3Entry Entry = new Far3Entry(); Entry.Filename = SubFle.Replace(GlobalSettings.Default.StartupPath, ""); Entry.FileID = HelperFuncs.GetFileID(Entry); Entry.TypeID = HelperFuncs.GetTypeID(Path.GetExtension(SubFle)); HelperFuncs.CheckCollision(Entry.FileID, Entries); //Ignore fonts to minimize the risk of ID collisions. if (!Entry.Filename.Contains(".ttf")) { if (!Entry.Filename.Contains(".ffn")) Entries.Add(Entry, Entry.Filename); } } } } } } else //Filetype was empty, so just add all filetypes found... { string[] Files = Directory.GetFiles(Dir); string[] SubDirs = Directory.GetDirectories(Dir); foreach (string Fle in Files) { if (Fle.Contains(".dat")) { FAR3Archive Archive = new FAR3Archive(Fle); foreach (Far3Entry Entry in Archive.GetAllFAR3Entries()) Entries.Add(Entry, Fle.Replace(GlobalSettings.Default.StartupPath, "")); } else { Far3Entry Entry = new Far3Entry(); Entry.Filename = Fle.Replace(GlobalSettings.Default.StartupPath, ""); Entry.FileID = HelperFuncs.GetFileID(Entry); Entry.TypeID = HelperFuncs.GetTypeID(Path.GetExtension(Fle)); HelperFuncs.CheckCollision((ulong)(((ulong)Entry.FileID) << 32 | ((ulong)(Entry.TypeID >> 32))), Entries); //Ignore fonts to minimize the risk of ID collisions. if (!Entry.Filename.Contains(".ttf")) { if(!Entry.Filename.Contains(".ffn")) Entries.Add(Entry, Entry.Filename); } } } foreach (string SubDir in SubDirs) { Files = Directory.GetFiles(SubDir); foreach (string SubFle in Files) { if (SubFle.Contains(".dat")) { FAR3Archive Archive = new FAR3Archive(SubFle); foreach (Far3Entry Entry in Archive.GetAllFAR3Entries()) Entries.Add(Entry, SubFle.Replace(GlobalSettings.Default.StartupPath, "")); } else { Far3Entry Entry = new Far3Entry(); Entry.Filename = SubFle.Replace(GlobalSettings.Default.StartupPath, ""); Entry.FileID = HelperFuncs.GetFileID(Entry); Entry.TypeID = HelperFuncs.GetTypeID(Path.GetExtension(SubFle)); HelperFuncs.CheckCollision((ulong)(((ulong)Entry.FileID) << 32 | ((ulong)(Entry.TypeID >> 32))), Entries); //Ignore fonts to minimize the risk of ID collisions. if (!Entry.Filename.Contains(".ttf")) { if (!Entry.Filename.Contains(".ffn")) Entries.Add(Entry, Entry.Filename); } } } } } } }
/// <summary> /// Adds files from a specified directory to a dictionary of entries. /// </summary> /// <param name="EntryDir">The directory to scan for entries.</param> /// <param name="Filetype">A fully qualified lowercase filetype to scan for (can be empty).</param> /// <param name="Entries">The Dictionary to add entries to.</param> private static void AddFilesFromDir(string EntryDir, string Filetype, ref Dictionary <FAR3Entry, string> Entries) { string[] Dirs = Directory.GetDirectories(EntryDir); foreach (string Dir in Dirs) { if (Filetype != "") { if (Dir.Contains(Filetype)) { string[] Files = Directory.GetFiles(Dir); string[] SubDirs = Directory.GetDirectories(Dir); foreach (string Fle in Files) { if (Fle.Contains(".dat")) { FAR3Archive Archive = new FAR3Archive(Fle); Archive.ReadArchive(true); foreach (FAR3Entry Entry in Archive.GrabAllEntries()) { Entries.Add(Entry, Fle.Replace(GlobalSettings.Default.StartupPath, "")); } } else { FAR3Entry Entry = new FAR3Entry(); Entry.Filename = Fle.Replace(GlobalSettings.Default.StartupPath, ""); Entry.FileID = HelperFuncs.GetFileID(Entry); Entry.TypeID = HelperFuncs.GetTypeID(Path.GetExtension(Fle)); HelperFuncs.CheckCollision(Entry.FileID, Entries); //Ignore fonts to minimize the risk of ID collisions. if (!Entry.Filename.Contains(".ttf")) { if (!Entry.Filename.Contains(".ffn")) { Entries.Add(Entry, Entry.Filename); } } } } foreach (string SubDir in SubDirs) { Files = Directory.GetFiles(SubDir); foreach (string SubFle in Files) { if (SubFle.Contains(".dat")) { FAR3Archive Archive = new FAR3Archive(SubFle); Archive.ReadArchive(false); foreach (FAR3Entry Entry in Archive.GrabAllEntries()) { Entries.Add(Entry, SubFle.Replace(GlobalSettings.Default.StartupPath, "")); } } else { FAR3Entry Entry = new FAR3Entry(); Entry.Filename = SubFle.Replace(GlobalSettings.Default.StartupPath, ""); Entry.FileID = HelperFuncs.GetFileID(Entry); Entry.TypeID = HelperFuncs.GetTypeID(Path.GetExtension(SubFle)); HelperFuncs.CheckCollision(Entry.FileID, Entries); //Ignore fonts to minimize the risk of ID collisions. if (!Entry.Filename.Contains(".ttf")) { if (!Entry.Filename.Contains(".ffn")) { Entries.Add(Entry, Entry.Filename); } } } } } } } else //Filetype was empty, so just add all filetypes found... { string[] Files = Directory.GetFiles(Dir); string[] SubDirs = Directory.GetDirectories(Dir); foreach (string Fle in Files) { if (Fle.Contains(".dat")) { FAR3Archive Archive = new FAR3Archive(Fle); Archive.ReadArchive(true); foreach (FAR3Entry Entry in Archive.GrabAllEntries()) { Entries.Add(Entry, Fle.Replace(GlobalSettings.Default.StartupPath, "")); } } else { FAR3Entry Entry = new FAR3Entry(); Entry.Filename = Fle.Replace(GlobalSettings.Default.StartupPath, ""); Entry.FileID = HelperFuncs.GetFileID(Entry); Entry.TypeID = HelperFuncs.GetTypeID(Path.GetExtension(Fle)); HelperFuncs.CheckCollision((ulong)(((ulong)Entry.FileID) << 32 | ((ulong)(Entry.TypeID >> 32))), Entries); //Ignore fonts to minimize the risk of ID collisions. if (!Entry.Filename.Contains(".ttf")) { if (!Entry.Filename.Contains(".ffn")) { Entries.Add(Entry, Entry.Filename); } } } } foreach (string SubDir in SubDirs) { Files = Directory.GetFiles(SubDir); foreach (string SubFle in Files) { if (SubFle.Contains(".dat")) { FAR3Archive Archive = new FAR3Archive(SubFle); Archive.ReadArchive(true); foreach (FAR3Entry Entry in Archive.GrabAllEntries()) { Entries.Add(Entry, SubFle.Replace(GlobalSettings.Default.StartupPath, "")); } } else { FAR3Entry Entry = new FAR3Entry(); Entry.Filename = SubFle.Replace(GlobalSettings.Default.StartupPath, ""); Entry.FileID = HelperFuncs.GetFileID(Entry); Entry.TypeID = HelperFuncs.GetTypeID(Path.GetExtension(SubFle)); HelperFuncs.CheckCollision((ulong)(((ulong)Entry.FileID) << 32 | ((ulong)(Entry.TypeID >> 32))), Entries); //Ignore fonts to minimize the risk of ID collisions. if (!Entry.Filename.Contains(".ttf")) { if (!Entry.Filename.Contains(".ffn")) { Entries.Add(Entry, Entry.Filename); } } } } } } } }