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);
        }
        public string ReadFile(int addr, int size)
        {
            var r       = base.ReadPage(addr, BinSerializer.ComputeFileSizePerSector(size, PAGE_SIZE));
            var encoder = new UnicodeEncoding();
            var s       = encoder.GetString(r.Buffer.Take(size).ToArray());

            return(s);
        }
Esempio n. 3
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));
            }
        }
 public int GetBlockPage()
 {
     return(BinSerializer.ComputeFileSizePerSector(this.Length, PAGE_SIZE));
 }
Esempio n. 6
0
 /// <summary>
 /// Return the size of the file in multiple of the page size.
 /// ((File.Length / PAGE_SIZE) + 1) * PAGE_SIZE;
 /// </summary>
 /// <returns></returns>
 public int ComputeFileSizeInPageMultiple()
 {
     return(BinSerializer.ComputeFileSizePerSector(this.Length, PAGE_SIZE));
 }