/// <summary> /// Opens the specified file readonly, and *only* this file. Does not search in alternative paths; returns null if not found /// </summary> public static Stream OpenExactly(string file, params object[] args) { if (GamePath == null) { return(null); } if (args.Length > 0) { file = string.Format(file, args); } string fileSystemPath = GamePath; string[] components = file.ToLower().Split('\\', '/'); string nifPath = null; // sub path within a NPK // Split the path into pre/post NIF paths foreach (var comp in components) { if (nifPath != null) { nifPath = Path.Combine(nifPath, comp); } else { fileSystemPath = Path.Combine(fileSystemPath, comp); if (new[] { ".npk", ".mpk" }.Any(ext => comp.EndsWith(ext, StringComparison.InvariantCultureIgnoreCase))) { nifPath = ""; // start parsing the nif subtree now } } } // Return early if the file does not exist if (!File.Exists(fileSystemPath)) { return(null); } // If this is a nif, look inside to find the file if (nifPath != null) { TinyMPK mpk = TinyMPK.FromFile(fileSystemPath); MPKFileEntry subfile = mpk.GetFile(nifPath); return(subfile == null ? null : new MemoryStream(subfile.Data)); } return(new FileStream(fileSystemPath, FileMode.Open, FileAccess.Read)); }
/// <summary> /// Loads a .mpk file /// </summary> /// <param name="file"></param> /// <returns></returns> public static TinyMPK FromFile(string file) { var mpk = new TinyMPK(); return(mpk.Load(file)); }