Пример #1
0
        //Utilities
        public static MFSFile GetFileFromPath(MFSDisk mfsDisk, string filepath)
        {
            MFSDirectory dir = GetDirectoryFromPath(mfsDisk, filepath);

            string[] path = filepath.Split('/');
            path[0] = "/";

            string filename = Path.GetFileNameWithoutExtension(filepath);
            string ext      = Path.GetExtension(filepath);

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

            foreach (MFSFile file in GetAllFilesFromDirID(mfsDisk, dir.DirectoryID))
            {
                if (file.Name.Equals(filename) && file.Ext.Equals(ext))
                {
                    return(file);
                }
            }

            return(null);
        }
Пример #2
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);
            }
        }
Пример #3
0
        public static string GetParentDirectoryPath(MFSDisk mfsDisk, MFSEntry file)
        {
            string       temp   = "";
            ushort       dir_id = 0;
            MFSDirectory dir    = GetDirectoryFromID(mfsDisk, file.ParentDirectory);

            while (dir != null)
            {
                dir_id = dir.ParentDirectory;
                temp   = dir.Name + (dir_id != 0xFFFE ? "/" : "") + temp;
                dir    = GetDirectoryFromID(mfsDisk, dir_id);
            }

            return(temp);
        }
Пример #4
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);
                }
            }
        }
Пример #5
0
        public static bool WriteFile(MFSDisk mfsDisk, byte[] filedata, string filepath)
        {
            MFSDirectory _dir = GetDirectoryFromPath(mfsDisk, filepath);

            return(WriteFile(mfsDisk, filedata, Path.GetFileName(filepath), _dir.DirectoryID));
        }