예제 #1
0
        private void GiveFormat(Queue <CdIndexEntry> entries, FileContainer folder)
        {
            CdIndexEntry entry = entries.Dequeue();

            if (!entry.IsFolder)
            {
                folder.AddFile(new GameFile(
                                   entry.Name,
                                   new DataStream(this.File.Stream, entry.Offset, entry.Size)
                                   ));
                return;
            }

            // Create the folder
            GameFolder currFolder = new GameFolder(entry.Name, folder);

            // Add files and folders
            for (int i = 0; i < entry.SubEntries - 1; i++)
            {
                GiveFormat(entries, currFolder);
            }
        }
예제 #2
0
        /// <summary>
        /// Write the file system to the stream.
        /// </summary>
        /// <param name="str">Stream to write to.</param>
        public override void Write(DataStream str)
        {
            // The order is: ARM9 - Overlays9 - ARM7 - Overlays7 - FNT - FAT
            this.WriteArm(str, true);                   // Write ARM9
            this.WriteArm(str, false);                  // Write ARM7

            // To get the first ROM file ID
            int numOverlays = this.CountOverlays(false) + this.CountOverlays(true);

            // Create a new File Name Table...
            Fnt fnt = new Fnt();

            fnt.Initialize(null, this.root, numOverlays);

            // ... and writes it
            this.header.FntOffset = (uint)(this.header.HeaderSize + str.Position);
            long fntStartOffset = str.Position;

            fnt.Write(str);
            this.header.FntSize = (uint)(str.Position - fntStartOffset);
            str.WritePadding(FileSystem.PaddingByte, FileSystem.PaddingAddress);

            // Create a temp dir with every file to be register in the FAT (Game + System)
            GameFolder tmpFolder = new GameFolder(string.Empty);

            tmpFolder.AddFolders(this.sysFolder.Folders);               // Overlay folders
            tmpFolder.AddFolder(this.root);                             // Game files

            // Write File Allocation Table
            Fat fat = new Fat();

            fat.Initialize(null, tmpFolder, Banner.Size + this.header.HeaderSize);              // First file offset after banner
            this.header.FatOffset = (uint)(this.header.HeaderSize + str.Position);
            fat.Write(str);
            str.WritePadding(FileSystem.PaddingByte, FileSystem.PaddingAddress);
            this.header.FatSize = fat.Size;
        }
예제 #3
0
파일: Fat.cs 프로젝트: pleonex/modime
        public override void Initialize(GameFile file, params object[] parameters)
        {
            base.Initialize(file, parameters);

            if (parameters.Length >= 1)
            {
                // Get a list with all files...
                GameFolder      root     = parameters[0] as GameFolder;
                List <GameFile> fileList = new List <GameFile>();
                foreach (FileContainer f in root.GetFilesRecursive(false))
                {
                    fileList.Add(f as GameFile);
                }

                // ... and sort them by Id
                fileList.OrderBy(f => (ushort)f.Tags["Id"]);
                this.files = fileList.ToArray();
            }

            if (parameters.Length == 2)
            {
                this.firstOffset = (uint)parameters[1];
            }
        }