private int PieceToFileAttributes(byte[] piece, FileAttribute[] fileAttributes) { int fileOrder = 0; for (int i = 0; i < 72; i += 9) { byte[] oneAttribute = new byte[9]; for (int j = 0; j < 9; ++j) { oneAttribute[j] = piece[i + j]; } fileAttributes[fileOrder] = new FileAttribute(); fileAttributes[fileOrder].ToFileAttribute(oneAttribute); ++fileOrder; } return(0); }
private void listView2_DoubleClick(object sender, EventArgs e) { if (listView2.SelectedIndices.Count > 0) { if (currentPath == @"/") { if (listView2.SelectedItems[0].ImageIndex == 0) { ViewFlush(currentPath + listView2.SelectedItems[0].Text); } else { oneOpenFile = new OFile(); FileAttribute fa = fe.FindFileByFullPath(currentPath, listView2.SelectedItems[0].Text); oneOpenFile.beginNum = fa.beginPiece; oneOpenFile.flag = fa.isReadOnly; Editor editor = new Editor(); editor.Show(); } } else { if (listView2.SelectedItems[0].ImageIndex == 0) { ViewFlush(currentPath + @"/" + listView2.SelectedItems[0].Text); } else { oneOpenFile = new OFile(); FileAttribute fa = fe.FindFileByFullPath(currentPath, listView2.SelectedItems[0].Text); oneOpenFile.beginNum = fa.beginPiece; oneOpenFile.flag = fa.isReadOnly; Editor editor = new Editor(); editor.Show(); } } } }
private FileAttribute[] FindByFullPath(string fullPath) { if (fullPath == @"/") { FileAttribute[] fileAttributes = new FileAttribute[8]; PieceToFileAttributes(fe.cache[2], fileAttributes); currentPath = fullPath; return(fileAttributes); } else { Queue <string> parts = new Queue <string>(fullPath.Split(new char[] { '/' }).ToList()); parts.Dequeue(); FileAttribute[] fileAttributes = new FileAttribute[8]; byte[] currentPiece = fe.cache[2]; while (parts.Count > 0) { string partName = parts.Dequeue(); PieceToFileAttributes(currentPiece, fileAttributes); if (parts.Count == 0) { char[] nameChars = new char[3]; foreach (FileAttribute fa in fileAttributes) { nameChars[0] = fa.fileName1; nameChars[1] = fa.fileName2; nameChars[2] = fa.fileName3; string name = new string(nameChars); name = name.Trim(); if (name == partName) { if (fa.fileOrDirctory == 0) { // 弹出文件编辑窗口 //MessageBox.Show("打开" + listView2.SelectedItems[0].Text); return(FindByFullPath(currentPath)); } else { FileAttribute[] retFileAttributes = new FileAttribute[8]; PieceToFileAttributes(fe.cache[fa.beginPiece], retFileAttributes); currentPath = fullPath; return(retFileAttributes); } } } } foreach (FileAttribute fa in fileAttributes) { char[] nameChars = new char[3]; if (fa.fileOrDirctory == 1) { nameChars[0] = fa.fileName1; nameChars[1] = fa.fileName2; nameChars[2] = fa.fileName3; string name = new string(nameChars); name = name.Trim(); if (name == partName) { currentPiece = fe.cache[fa.beginPiece]; } } } } // return } return(null); }
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); }
public int FindDiskPiece(string fullPath) { if (fullPath == @"/") { return(2); } else { Queue <string> parts = new Queue <string>(fullPath.Split(new char[] { '/' }).ToList()); parts.Dequeue(); FileAttribute[] fileAttributes = new FileAttribute[8]; byte[] currentPiece = FileSystem.fe.cache[2]; while (parts.Count > 0) { string partName = parts.Dequeue(); PieceToFileAttributes(currentPiece, fileAttributes); if (parts.Count == 0) { char[] nameChars = new char[3]; foreach (FileAttribute fa in fileAttributes) { nameChars[0] = fa.fileName1; nameChars[1] = fa.fileName2; nameChars[2] = fa.fileName3; string name = new string(nameChars); name = name.Trim(); if (name == partName) { if (fa.fileOrDirctory == 0) { return(fa.beginPiece); } else { return(fa.beginPiece); } } } } else { foreach (FileAttribute fa in fileAttributes) { char[] nameChars = new char[3]; if (fa.fileOrDirctory == 1) { nameChars[0] = fa.fileName1; nameChars[1] = fa.fileName2; nameChars[2] = fa.fileName3; string name = new string(nameChars); if (name == partName) { currentPiece = FileSystem.fe.cache[fa.beginPiece]; } } } } } // return } return(-1); }
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); }