Esempio n. 1
0
        private void CreateTree(GameFolder currentFolder, GameFile[] listFile)
        {
            int folderId = ((ushort)currentFolder.Tags["Id"] > 0x0FFF) ?
                            (ushort)currentFolder.Tags["Id"] & 0x0FFF : 0;

            // Add files
            foreach (ElementInfo fileInfo in this.tables[folderId].Files) {
                listFile[fileInfo.Id].Name = fileInfo.Name;
                currentFolder.AddFile(listFile[fileInfo.Id]);
            }

            // Add subfolders
            foreach (ElementInfo folderInfo in this.tables[folderId].Folders) {
                GameFolder subFolder = new GameFolder(folderInfo.Name);
                subFolder.Tags["Id"] =  folderInfo.Id;
                this.CreateTree(subFolder, listFile);
                currentFolder.AddFolder(subFolder);
            }
        }
Esempio n. 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;
        }