Esempio n. 1
0
        public static void FS_Start()
        {
            SuperBlock sb;

            ushort[]      listCl;
            List <myFile> listFiles;

            curDir = 0;
            //     int countOfFiles = CLUST_SIZE * (FILES_FIRST_CLUST - ROOT_FIRST_CLUST + 1) / FILE_STRUCT_SIZE; // 487 files can be created

            if (!File.Exists("MyFS.dat"))
            {
                sb = new SuperBlock("MyFS", CLUST_SIZE, FAT_FIRST_CLUST, ROOT_FIRST_CLUST, FILES_FIRST_CLUST, FILES_CLUST_COUNT);
                //   listCl = new ushort[CLUST_SIZE * (FILES_CLUST_COUNT - FILES_FIRST_CLUST + 1) / (CLUST_SIZE + FILE_STRUCT_SIZE)];
                //   listCl = new ushort[FILES_CLUST_COUNT - FILES_FIRST_CLUST+1];
                listCl    = new ushort[FILES_CLUST_COUNT];
                listFiles = new List <myFile>();
            }
            else
            {
                BinaryReader br = new BinaryReader(File.Open("MyFS.dat", FileMode.Open), Encoding.UTF8);

                sb = new SuperBlock(br.ReadString(), br.ReadUInt16(), br.ReadUInt16(), br.ReadUInt16(), br.ReadUInt16(), br.ReadUInt16());
                //  listCl = new ushort[CLUST_SIZE * (FILES_CLUST_COUNT - FILES_FIRST_CLUST + 1) / (CLUST_SIZE + FILE_STRUCT_SIZE)];
                listCl = new ushort[FILES_CLUST_COUNT - FILES_FIRST_CLUST + 1];
                br.BaseStream.Seek((FAT_FIRST_CLUST - 1) * CLUST_SIZE, SeekOrigin.Begin);
                int iCl = 0;                       // number of cluster
                while (iCl < listCl.Length && br.BaseStream.Position < (ROOT_FIRST_CLUST - 1) * CLUST_SIZE)
                {                                  //br.PeekChar() != -1 &&
                    listCl[iCl] = br.ReadUInt16(); // value for cluster iCl
                    iCl++;
                }
                listFiles = new List <myFile>();
                br.BaseStream.Seek((ROOT_FIRST_CLUST - 1) * CLUST_SIZE, SeekOrigin.Begin);
                int iFile = 0;  // number of file
                while (br.PeekChar() != -1 && ((FILES_FIRST_CLUST - 1) * CLUST_SIZE) >= br.BaseStream.Position + FILE_STRUCT_SIZE)
                {
                    myFile temp = new myFile();
                    listFiles.Add(temp);
                    listFiles[iFile].id = br.ReadInt32();
                    if (listFiles[iFile].id == -1)
                    {
                        listFiles.Remove(temp);
                        break;
                    }
                    listFiles[iFile].Name = br.ReadString();

                    /*  if (listFiles[iFile].Name == "")
                     * {
                     *    listFiles.Remove(temp);
                     *    break;
                     * } */
                    listFiles[iFile].Extend      = br.ReadString();
                    listFiles[iFile].Date_time   = br.ReadString();
                    listFiles[iFile].First_clust = br.ReadUInt16();
                    listFiles[iFile].Size        = br.ReadInt32();
                    listFiles[iFile].Rights      = br.ReadString();
                    listFiles[iFile].Parent_dir  = br.ReadInt32();
                    listFiles[iFile].Owner       = br.ReadString(); // ...
                    iFile++;
                }
                br.Close();
            }
            MainProgram.fs = new FS(sb, listCl, listFiles);
            if (MainProgram.fs.files.Count == 0)
            {
                createRootDir(); FS_Save();
            }
        }