A file context allows saving, opening, and creating files.
Example #1
0
        /// <summary>
        /// Initialise the state.
        /// </summary>
        /// <param name="manager"></param>
        /// <param name="rootPath"></param>
        /// <param name="fileManager"></param>
        /// <param name="archive"></param>
        public State(AlexandriaManager manager, string rootPath, FileManager fileManager, Archive archive = null)
            : base(manager, rootPath, fileManager)
        {
            if (archive != null)
                ArchivesMutable.Add(archive);
            foreach(var path in Directory.EnumerateFiles(RootPath, "*.bhd5")) {

            }
        }
Example #2
0
		/// <summary>Initialise the <see cref="Asset"/> loader.</summary>
		/// <param name="assetManager"></param>
		/// <param name="reader"></param>
		/// <param name="name"></param>
		/// <param name="fileManager">The <see cref="FileManager"/> to use to load any attached files. If this is <c>null</c> (the default), then the system file manager (<see cref="Glare.Assets.FileManager.System"/>) is used.</param>
		/// <param name="contextResource"></param>
		/// <param name="length"></param>
		public AssetLoader(AssetManager assetManager, BinaryReader reader, string name, FileManager fileManager, Asset contextResource = null, long? length = null) {
			if (assetManager == null)
				throw new ArgumentNullException("assetManager");
			if (reader == null)
				throw new ArgumentNullException("reader");

			AssetManager = assetManager;
			Start = reader.BaseStream.Position;
			Reader = reader;
			Name = name;
			FileManager = fileManager ?? FileManager.System;
			Context = contextResource;
			Length = length.HasValue ? length.Value : reader.BaseStream.Length;
			Errors = new Codex<AssetLoadError>();
		}
Example #3
0
        internal Archive(AssetManager manager, BinaryReader reader, string name, FileManager fileManager)
            : base(manager, name)
        {
            Reader = reader;

            int headerSize = reader.ReadUInt16();
            int count = headerSize / ArchiveRecord.HeaderSize;
            RichDictionary<int, ArchiveRecord> recordsById = new RichDictionary<int, ArchiveRecord>();

            for (int index = 0; index < count; index++) {
                var record = new ArchiveRecord(this, reader, index, headerSize + 2);
                recordsById[record.Id] = record;
            }

            RecordsById = recordsById;
        }
Example #4
0
        /// <summary>Initialise the state.</summary>
        /// <param name="manager"></param>
        /// <param name="rootPath"></param>
        /// <param name="fileManager"></param>
        public State(AlexandriaManager manager, string rootPath, FileManager fileManager)
            : base(manager, rootPath, fileManager)
        {
            PackagePaths = new List<string>();
            Packages = new List<Package>();

            string Core = "Core", Class = "Class";

            RegisterTypes(Core, Class,
                typeof(BoolProperty), typeof(Brush), typeof(ByteProperty),
                typeof(ClassProperty), typeof(Const),
                typeof(Alexandria.Engines.Unreal.Core.Enum),
                typeof(FloatProperty), typeof(Function),
                typeof(IntProperty), typeof(InterpolationPoint),
                typeof(Level), typeof(LevelInfo), typeof(LevelSummary),
                typeof(Light),
                typeof(Model),
                typeof(NameProperty),
                typeof(ObjectProperty),
                typeof(Polys),
                typeof(Struct), typeof(StructProperty), typeof(StrProperty),
                typeof(TextBuffer),
                typeof(ZoneInfo));

            RegisterStateFrames(Core, Class,
                "AmbientSound",
                "Camera",
                "ElectricityEmitter",
                "HidePoint",
                "PathNode", "PatrolPoint", "PlayerStart",
                "Teleporter");

            RegisterStateFrames(Core, Class,
                "ATM",
                "Candybar", "CeilingFan", "CeilingFanMotor", "Chair1", "CigaretteMachine", "Cigarettes", "ComputerPublic",
                "DXLogo", "DXText", "DeusExLevelInfo", "DeusExMover",
                "Flowers",
                "EidosLogo",
                "IonStormLogo",
                "JordanShea",
                "MedKit",
                "NathanMadison",
                "Plant2",
                "SandraRenton", "Sodacan", "SoyFood",
                "Trashcan2");
        }
        /// <summary>Get a <see cref="PathState"/> for the given combination of parameters, creating one if necessary.</summary>
        /// <param name="game"></param>
        /// <param name="fileManager"></param>
        /// <param name="path"></param>
        /// <returns></returns>
        public PathState GetPathState(Game game, FileManager fileManager, string path)
        {
            if (game == null)
                throw new ArgumentNullException("game");
            if (fileManager == null)
                throw new ArgumentNullException("fileManager");

            var id = Aggregate.Create(fileManager.Id, game, path);
            PathState state;

            path = path.Replace('\\', '/');
            if (!PathStates.TryGetValue(id, out state)) {
                Type stateType = game.StateType;
                if (stateType == null)
                    throw new ArgumentException(string.Format("The game {0} does not have an accepted {1} state type.", game, typeof(State).Name));

                ConstructorInfo constructor = stateType.GetConstructor(new Type[] { typeof(AlexandriaManager), typeof(string), typeof(FileManager) });

                if (constructor == null)
                    throw new Exception(string.Format("State type {0} does not have an appropriate constructor, like the one for {1}.", stateType.FullName, typeof(State).FullName));

                state = (PathState)constructor.Invoke(new object[] { this, path, fileManager });
                PathStates[id] = state;
            }

            return state;
        }
Example #6
0
        public State2(AlexandriaManager manager, string rootPath, FileManager fileManager, string iniFileName)
            : base(manager, rootPath, fileManager)
        {
            IniFile = new IniFile(RootPath + iniFileName);

            IniFileSection section = IniFile["Core.System"];
            List<string> paths = section.GetMultiple("Paths");
            paths.AddRange(section.GetMultiple("Paths__t")); // Thief 3: Deadly Shadows
            foreach (var path in paths) {
                var fullPath = RootPath + "System/" + path;
                var simplePath = Path.GetFullPath(Path.GetDirectoryName(fullPath)) + "\\" + Path.GetFileName(fullPath);
                AddPackagePath(simplePath);
            }
        }
Example #7
0
 public State(AlexandriaManager manager, string rootPath, FileManager fileManager)
     : base(manager, rootPath, fileManager)
 {
     palettes = new PathStateAsset(this, "data/pals.dat");
 }
Example #8
0
 /// <summary>Initialise the <see cref="PathState"/>.</summary>
 /// <param name="manager"></param>
 /// <param name="rootPath"></param>
 /// <param name="fileManager"></param>
 public PathState(AlexandriaManager manager, string rootPath, FileManager fileManager)
     : base(manager, fileManager)
 {
     RootPath = rootPath;
 }
Example #9
0
 /// <summary>Initialise the <see cref="State"/>.</summary>
 /// <param name="manager"></param>
 /// <param name="fileManager"></param>
 public State(AlexandriaManager manager, FileManager fileManager)
     : base(manager, "State")
 {
     if (manager == null)
         throw new ArgumentNullException("manager");
     if (fileManager == null)
         throw new ArgumentNullException("fileManager");
     Manager = manager;
     FileManager = fileManager;
 }
Example #10
0
 /// <summary>Save the asset to the file.</summary>
 /// <param name="asset"></param>
 /// <param name="writer"></param>
 /// <param name="fileManager">The <see cref="FileManager"/> that might be necessary to save additional files. This can be <c>null</c> if it can't be supported.</param>
 public virtual void Save(Asset asset, BinaryWriter writer, FileManager fileManager)
 {
     if (CanSave)
         throw new InvalidOperationException("This " + typeof(AssetFormat).Name + " " + GetType().Name + " says it can save resources, but it doesn't work. Bug!");
     throw new InvalidOperationException("This " + typeof(AssetFormat).Name + " " + GetType().Name + " cannot save resources.");
 }
Example #11
0
 static Stream OpenOtherFile(string path, FileManager manager, string suffix, string suffix2 = null)
 {
     return (suffix2 != null ? manager.TryOpenRead(path + suffix2) : null) ?? manager.OpenRead(path + suffix);
 }
Example #12
0
        internal ResourceMap(AssetManager manager, AssetLoader loader)
            : base(manager, loader.Name)
        {
            var reader = loader.Reader;

            Path = loader.Name;
            FileManager = loader.FileManager;
            Version = DetectVersion(loader);

            Dictionary<ResourceType, FolderAsset> folders = new Dictionary<ResourceType, FolderAsset>();

            using (reader) {
                if (Version == ResourceMapVersion.Sci0) {
                    // Simple list of entries of type (short typeAndIndex, int offsetAndPage), terminated with a (-1, -1)
                    while (true) {
                        ResourceId id = new ResourceId(reader, Version);

                        if (id.IsEnd)
                            break;
                        AddResource(id, folders);
                    }
                } else if (Version == ResourceMapVersion.Sci1) {
                    List<KeyValuePair<ResourceType, int>> types = new List<KeyValuePair<ResourceType, int>>();

                    while (true) {
                        ResourceType type = (ResourceType)reader.ReadByte();
                        int offset = reader.ReadUInt16();

                        types.Add(new KeyValuePair<ResourceType, int>(type == ResourceType.End ? type : (ResourceType)((int)type & 0x7F), offset));
                        if (type == ResourceType.End)
                            break;
                    }

                    for (int typeIndex = 0; typeIndex < types.Count - 1; typeIndex++) {
                        ResourceType type = types[typeIndex].Key;
                        int end = types[typeIndex + 1].Value;

                        while (reader.BaseStream.Position < end) {
                            ResourceId id = new ResourceId(reader, Version, type);
                            AddResource(id, folders);
                        }
                    }
                } else if(Version == ResourceMapVersion.Sci2) {
                    List<KeyValuePair<ResourceType, int>> types = new List<KeyValuePair<ResourceType, int>>();

                    while (true) {
                        ResourceType type = (ResourceType)reader.ReadByte();
                        int offset = reader.ReadUInt16();

                        types.Add(new KeyValuePair<ResourceType, int>(type, offset));
                        if (type == ResourceType.End)
                            break;
                    }

                    Unknowns.ReadInt32s(reader, 1, "Post offsets");

                    for (int typeIndex = 0; typeIndex < types.Count - 1; typeIndex++) {
                        ResourceType type = types[typeIndex].Key;
                        int offset = types[typeIndex].Value;
                        int end = types[typeIndex + 1].Value;

                        if ((end - offset) % 6 != 0)
                            throw new InvalidDataException();
                        int count = (end - offset) / 6;
                        for (int index = 0; index < count; index++) {
                            ResourceId id = new ResourceId(reader, Version, type);
                            AddResource(id, folders);
                        }
                    }
                } else
                    throw new NotImplementedException();
            }

            SortChildrenRecursively();
        }
 /// <summary>
 /// Return whether the game file exists within the path or 
 /// </summary>
 /// <param name="path"></param>
 /// <param name="filename"></param>
 /// <param name="manager">The file manager to use for opening files.</param>
 /// <returns></returns>
 protected static bool MatchGameFile(string path, string filename, FileManager manager)
 {
     return false;
 }
 /// <summary>Attempt to match a game instance from a given path or a given file, returning the <see cref="GameInstance"/> or <c>null</c> if none could be found.</summary>
 /// <param name="path"></param>
 /// <param name="manager">The file manager to use for opening files.</param>
 /// <returns></returns>
 public virtual GameInstance MatchGame(string path, FileManager manager)
 {
     return null;
 }
 /// <summary>Attempt to detect a <see cref="GameInstance"/> from this file.</summary>
 /// <param name="collection"></param>
 /// <param name="path">The path to the file.</param>
 /// <param name="reader">The opened file reader. You do not need to reset the position afterwards.</param>
 /// <param name="manager">The <see cref="FileManager"/> to open any other files, if necessary.</param>
 public virtual void DetectFile(ICollection<GameInstance> collection, string path, BinaryReader reader, FileManager manager)
 {
 }