Esempio n. 1
0
        public int Init()
        {
            // 初始化落地文件
            file = new FileStream(@"./filetemp", FileMode.OpenOrCreate);
            file.Seek(0, SeekOrigin.Begin);
            cache = new byte[128][];
            for (int i = 0; i < 128; ++i)
            {
                cache[i] = new byte[72];
            }
            if (file.Length == 0)
            {
                // 初始化位图
                fileTable    = new byte[128];
                fileTable[0] = 255;
                fileTable[1] = 255;
                fileTable[2] = 255;
                for (int i = 0; i < 72; i += 9)
                {
                    FileAttribute oneFileAttribute = new FileAttribute();
                    oneFileAttribute.fileName1 = '$';
                    int pos = 0;
                    foreach (byte attribute in oneFileAttribute.ToByte())
                    {
                        cache[2][i + pos] = attribute;
                        ++pos;
                    }
                    pos = 0;
                }
                byte[] testFileAttribute = new FileAttribute('F', 'T', 'D', '\0', '\0', 1, 0, 3, 1).ToByte();
                for (int i = 0; i < 9; ++i)
                {
                    cache[2][i] = testFileAttribute[i];
                }
                for (int i = 0; i < 72; i += 9)
                {
                    FileAttribute oneFileAttribute = new FileAttribute();
                    oneFileAttribute.fileName1 = '$';
                    int pos = 0;
                    foreach (byte attribute in oneFileAttribute.ToByte())
                    {
                        cache[3][i + pos] = attribute;
                        ++pos;
                    }
                    pos = 0;
                }

                this.fileTable[3] = 255;
                this.dataLand();
            }
            else
            {
                // 载入位图
                fileTable = new byte[128];
                file.Read(fileTable, 0, 128);
                for (int i = 2; i < 128; i++)
                {
                    cache[i] = new byte[72];
                    file.Read(cache[i], 0, 72);
                }
            }
            file.Flush();
            return(0);
        }
Esempio n. 2
0
 public int CreateFile(string parentPath, string fileName, string fileExpend, int fileProperty)
 {
     if (subFileCount(parentPath) < 8)
     {
         int             currentPos     = FindDiskPiece(parentPath);
         FileAttribute[] fileAttributes = FindByFullPath(parentPath);
         foreach (FileAttribute fa in fileAttributes)
         {
             if (fa.fileOrDirctory == 1)
             {
                 continue;
             }
             string tempFileName = "";
             tempFileName += fa.fileName1;
             tempFileName += fa.fileName2;
             tempFileName += fa.fileName3;
             tempFileName  = tempFileName.Trim();
             string tempFileExpend = "";
             tempFileExpend += fa.fileType1;
             tempFileExpend += fa.fileType2;
             tempFileExpend  = tempFileExpend.Trim();
             if (tempFileName == fileName.Trim() && tempFileExpend == fileExpend.Trim())
             {
                 MessageBox.Show("不能有重复命名。");
                 return(-1);
             }
         }
         foreach (FileAttribute fa in fileAttributes)
         {
             if (fa.fileName1 == '$')
             {
                 char[] cffileName = fileName.ToCharArray();
                 fa.fileName1 = cffileName[0];
                 fa.fileName2 = cffileName[1];
                 fa.fileName3 = cffileName[2];
                 char[] cffileExpend = fileExpend.ToCharArray();
                 if (cffileExpend.Length > 0 && !String.IsNullOrWhiteSpace(Convert.ToString(cffileExpend[0])))
                 {
                     if (cffileExpend.Length == 2)
                     {
                         fa.fileType1 = cffileExpend[0];
                         fa.fileType2 = cffileExpend[1];
                     }
                     else
                     {
                         fa.fileType1 = cffileExpend[0];
                         fa.fileType2 = ' ';
                     }
                 }
                 else
                 {
                     fa.fileType1 = ' ';
                     fa.fileType2 = ' ';
                 }
                 fa.fileOrDirctory = 0;
                 fa.isReadOnly     = Convert.ToByte(fileProperty);
                 fa.pieceLength    = 1;
                 for (int i = 2; i < 128; ++i)
                 {
                     if (fileTable[i] == 0)
                     {
                         fileTable[i]  = 255;
                         fa.beginPiece = Convert.ToByte(i);
                         for (int j = 0; j < 72; j += 9)
                         {
                             FileAttribute oneFileAttribute = new FileAttribute();
                             oneFileAttribute.fileName1 = '$';
                             int pos = 0;
                             foreach (byte attribute in oneFileAttribute.ToByte())
                             {
                                 cache[currentPos][j + pos] = attribute;
                                 ++pos;
                             }
                             pos = 0;
                         }
                         break;
                     }
                 }
                 break;
             }
         }
         AttributesInCache(currentPos, fileAttributes);
         dataLand();
         return(0);
     }
     return(-1);
 }