예제 #1
0
        public static bool MoveFile(MFSDisk mfsDisk, string filepathin, string filepathout)
        {
            MFSFile file = GetFileFromPath(mfsDisk, filepathin);

            if (file != null)
            {
                if (filepathout.StartsWith("/"))
                {
                    MFSDirectory dir = GetDirectoryFromPath(mfsDisk, filepathout);
                    if (dir != null)
                    {
                        file.ParentDirectory = dir.DirectoryID;
                    }
                    else
                    {
                        return(false);
                    }
                }
                if (!filepathout.EndsWith("/"))
                {
                    file.Name = Path.GetFileNameWithoutExtension(filepathout);
                    string newext = Path.GetExtension(filepathout);
                    if (newext != "")
                    {
                        newext = newext.Substring(1);
                    }
                    file.Ext = newext;
                }
                return(true);
            }
            else
            {
                return(false);
            }
        }
예제 #2
0
        // Additional Methods
        public static byte[] ReadFile(MFSDisk mfsDisk, string filepath)
        {
            MFSFile file = GetFileFromPath(mfsDisk, filepath);

            if (file != null)
            {
                return(ReadFile(mfsDisk, file));
            }
            else
            {
                return(null);
            }
        }
예제 #3
0
        public static bool DeleteFile(MFSDisk mfsDisk, string filepath)
        {
            MFSFile file = GetFileFromPath(mfsDisk, filepath);

            if (file != null)
            {
                return(DeleteFile(mfsDisk, file));
            }
            else
            {
                return(false);
            }
        }
예제 #4
0
        public static bool WriteFile(MFSDisk mfsDisk, byte[] filedata, string name, ushort dir = 0)
        {
            string _name = Path.GetFileNameWithoutExtension(name);
            string _ext  = Path.GetExtension(name);

            if (_ext.StartsWith("."))
            {
                _ext = _ext.Substring(1);
            }

            MFSFile file = new MFSFile(_name, mfsDisk.RAMVolume.Entries[0].CompanyCode, mfsDisk.RAMVolume.Entries[0].GameCode, _ext, (uint)filedata.Length, dir);

            return(WriteFile(mfsDisk, filedata, file));
        }
예제 #5
0
        public static bool WriteFile(MFSDisk mfsDisk, byte[] filedata, MFSFile file)
        {
            if (CheckIfFileAlreadyExists(mfsDisk, file.Name, file.Ext, file.ParentDirectory))
            {
                return(false);
            }
            if (GetFreeSpaceSize(mfsDisk) < filedata.Length)
            {
                return(false);
            }

            int FATentry     = -1;
            int lastFATentry = -1;
            int offset       = 0;

            for (int i = 6; i < Leo.SIZE_LBA - Leo.RamStartLBA[mfsDisk.RAMVolume.DiskType]; i++)
            {
                if (mfsDisk.RAMVolume.FAT[i] == (ushort)MFS.FAT.Unused)
                {
                    if (FATentry == -1)
                    {
                        FATentry      = i;
                        file.FATEntry = (ushort)i;
                    }
                    //Write File Data
                    Array.Copy(filedata, offset, mfsDisk.Data, mfsDisk.OffsetToMFSRAM + Leo.LBAToByte(mfsDisk.RAMVolume.DiskType, Leo.RamStartLBA[mfsDisk.RAMVolume.DiskType], i), Math.Min(Leo.LBAToByte(mfsDisk.RAMVolume.DiskType, Leo.RamStartLBA[mfsDisk.RAMVolume.DiskType] + i, 1), filedata.Length - offset));
                    offset += Math.Min(Leo.LBAToByte(mfsDisk.RAMVolume.DiskType, Leo.RamStartLBA[mfsDisk.RAMVolume.DiskType] + i, 1), filedata.Length - offset);
                    if (lastFATentry != -1)
                    {
                        mfsDisk.RAMVolume.FAT[lastFATentry] = (ushort)i;
                    }
                    if (offset == filedata.Length)
                    {
                        mfsDisk.RAMVolume.FAT[i] = (ushort)MFS.FAT.LastFileBlock;

                        mfsDisk.RAMVolume.Entries.Add(file);
                        return(true);
                    }
                    lastFATentry = i;
                }
            }
            return(false);
        }
예제 #6
0
        public static bool DeleteFile(MFSDisk mfsDisk, MFSFile file)
        {
            //Delete FAT Entries
            ushort nextblock = file.FATEntry;
            ushort lastblock = 0;

            do
            {
                lastblock = nextblock;
                nextblock = mfsDisk.RAMVolume.FAT[nextblock];
                mfsDisk.RAMVolume.FAT[lastblock] = 0;
            }while (nextblock != (ushort)MFS.FAT.LastFileBlock);

            //Delete File Data
            if (mfsDisk.RAMVolume.Entries.Remove(file))
            {
                Console.WriteLine("found");
            }

            return(true);
        }
예제 #7
0
        public static byte[] ReadFile(MFSDisk mfsDisk, MFSFile file)
        {
            byte[] filedata = new byte[file.Size];

            //Add FAT Entries and Copy to data to blocks
            ushort nextblock = file.FATEntry;
            uint   offset    = 0;
            uint   size      = file.Size;

            do
            {
                int blocksrc  = Leo.LBAToByte(mfsDisk.RAMVolume.DiskType, Leo.RamStartLBA[mfsDisk.RAMVolume.DiskType], nextblock);
                int blocksize = Leo.LBAToByte(mfsDisk.RAMVolume.DiskType, Leo.RamStartLBA[mfsDisk.RAMVolume.DiskType] + nextblock, 1);

                Array.Copy(mfsDisk.Data, mfsDisk.OffsetToMFSRAM + blocksrc, filedata, offset, Math.Min(blocksize, size));
                offset += (uint)Math.Min(blocksize, size);
                size   -= (uint)Math.Min(blocksize, size);

                nextblock = mfsDisk.RAMVolume.FAT[nextblock];
            }while (nextblock != (ushort)MFS.FAT.LastFileBlock);

            return(filedata);
        }
예제 #8
0
        public void Load(byte[] Data, int Offset)
        {
            Attributes.isWriteProtected       = (Data[Offset + 0x0E] & 0x80) != 0;
            Attributes.isVolumeReadProtected  = (Data[Offset + 0x0E] & 0x40) != 0;
            Attributes.isVolumeWriteProtected = (Data[Offset + 0x0E] & 0x20) != 0;
            DiskType = Data[Offset + 0x0F];
            Name     = Util.ReadStringN(Data, Offset + 0x10, 0x14);
            Date     = new MFS.Date(Util.ReadBEU32(Data, Offset + 0x24));
            Renewal  = Util.ReadBEU16(Data, Offset + 0x28);
            Country  = Data[Offset + 0x2A];

            //Get All FAT Entries
            FAT = new ushort[MFS.FAT_MAX];
            for (int i = 0; i < MFS.FAT_MAX; i++)
            {
                FAT[i] = Util.ReadBEU16(Data, Offset + 0x3C + (i * 2));
            }

            //Get All File Entries
            Entries = new List <MFSEntry>();
            for (int i = 0; i < MFS.EntryLimit[DiskType]; i++)
            {
                int check = (Data[Offset + 0x16B0 + (i * 0x30)] & 0xC0);
                if (check == 0x80)
                {
                    //Directory
                    MFSDirectory dir = new MFSDirectory(Data, Offset + 0x16B0 + (i * 0x30));
                    Entries.Add(dir);
                }
                else if (check == 0x40)
                {
                    //File
                    MFSFile file = new MFSFile(Data, Offset + 0x16B0 + (i * 0x30));
                    Entries.Add(file);
                }
            }
        }