public bool WriteAsFileSystem(string pw, List <FileInfo> files)
        {
            var encoder   = new UnicodeEncoding();
            var fileInfos = new List <FileInfo>();

            var startPage = DATA_START_ADDR;

            foreach (var f in files)
            {
                f.StartPage = startPage;
                fileInfos.Add(f);
                startPage += f.GetBlockPage();
            }

            var fatBuffer = SerializeMetadata(fileInfos);

            if (WriteAll(FAT_START_ADDR, PublicEncryptor.C(pw, fatBuffer).ToList())) // Write the FAT 2 page = 512 byte
            {
                foreach (var f in files)
                {
                    if (WriteAll(f.StartPage, PublicEncryptor.C(pw, f.GetBufferInMutipleOfPage().ToArray()).ToList()))
                    {
                    }
                }
            }
            return(true);
        }
        public Dictionary <string, FileInfo> ReadFileSystem(string pw, bool loadFiles = true, params string [] fileToLoads)
        {
            var fileToLoads2 = fileToLoads.ToList().ConvertAll(d => d.ToLower());
            var files        = new Dictionary <string, FileInfo>();
            var encoder      = new UnicodeEncoding();
            var r            = base.ReadPage(0, FAT_END_ADDR); // Read FAT 2 pages
            var fileInfos    = DeSerializeMetadata(PublicEncryptor.DC(pw, r.Buffer));

            if (fileInfos == null)
            {
                return(null);
            }

            var addr = this.DATA_START_ADDR;

            for (int i = 0; i < fileInfos.Count; i++)
            {
                var fi = fileInfos[i];
                if (loadFiles || fileToLoads2.Contains(fi.FileName.ToLowerInvariant()))
                {
                    var rr = base.ReadPage(fi.StartPage, BinSerializer.ComputeFileSizePerSector(fi.Length, PAGE_SIZE));
                    if (rr.Succeeded)
                    {
                        var b = PublicEncryptor.DC(pw, rr.Buffer).ToList();
                        fi.Buffer = b.Take(fi.Length).ToArray();
                    }
                    else
                    {
                        throw new ApplicationException(string.Format("Cannot read data file content '{0}'", fi.FileName));
                    }
                }
                files.Add(fi.FileName, fi);
            }
            return(files);
        }
示例#3
0
        public bool WriteAsFileSystem()
        {
            var encoder    = new UnicodeEncoding();
            var fatBuffer  = SerializeFAT();
            var errorCount = 0;

            foreach (var f in FileInfos)
            {
                if (f.Dirty)
                {
                    if (WriteAll(f.StartPage, PublicEncryptor.C(this._pw, f.GetBufferInMutipleOfPage().ToArray()).ToList()))
                    {
                        f.Dirty = false;
                    }
                    else
                    {
                        errorCount++;
                    }
                }
            }
            if (errorCount == 0)
            {
                if (WriteAll(FAT_START_ADDR, PublicEncryptor.C(this._pw, fatBuffer).ToList())) // Write the FAT 2 page = 512 byte
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            return(false);
        }
示例#4
0
        public bool ReadFileSystem()
        {
            var encoder = new UnicodeEncoding();

            // Read the FAT
            var r = base.ReadPage(0, FAT_END_ADDR);

            FileInfos = DeSerializeFAT(PublicEncryptor.DC(this._pw, r.Buffer));
            return(FileInfos != null);
        }
        public bool ReadFileSystem()
        {
            var encoder = new UnicodeEncoding();
            var r       = GetFATWriterReader().LoadFAT(0, FAT_START_ADDR, FAT_END_ADDR);

            if (r == null)
            {
                return(false);
            }
            this.FileInfos = DeSerializeFAT(PublicEncryptor.DC(this._pw, r));
            return(FileInfos != null);
        }
示例#6
0
        public sFsFileInfo LoadFileContent(sFsFileInfo fi)
        {
            var rr = base.ReadPage(fi.StartPage, BinSerializer.ComputeFileSizePerSector(fi.Length, PAGE_SIZE));

            if (rr.Succeeded)
            {
                fi.Buffer = PublicEncryptor.DC(this._pw, rr.Buffer);
                return(fi);
            }
            else
            {
                throw new ApplicationException(string.Format("Cannot read data file content '{0}'", fi.FileName));
            }
        }
        public sFsFileInfo LoadFileContent(sFsFileInfo fi)
        {
            var rr = GetFATWriterReader().ReadFile(fi.StartAddr, (uint)BinSerializer.ComputeFileSizePerSector(fi.Length, (int)GetFATWriterReader().SectorSize));

            if (rr != null)
            {
                fi.Buffer = PublicEncryptor.DC(this._pw, rr).Take(fi.Length).ToArray();
                return(fi);
            }
            else
            {
                throw new ApplicationException(string.Format("Cannot read data file content '{0}'", fi.FileName));
            }
        }