private void Init(string fileName)
 {
     if (nonPersistent)
     {
         var tempFile = TemporaryFilesManager.Instance.GetTemporaryFile();
         FileCopier.Copy(fileName, tempFile, true);
         fileName = tempFile;
     }
     stream = new SerializableFileStreamWrapper(fileName);
     CheckUnderlyingFile();
     size2n = (byte)Misc.Logarithm2(size);
     buffer = new byte[DesiredBufferSize];
 }
示例#2
0
        public SDCard(string imageFile, long?cardSize, bool persistent)
        {
            if (String.IsNullOrEmpty(imageFile))
            {
                throw new ConstructionException("No card image file provided.");
            }
            else
            {
                if (!persistent)
                {
                    var tempFileName = TemporaryFilesManager.Instance.GetTemporaryFile();
                    FileCopier.Copy(imageFile, tempFileName, true);
                    imageFile = tempFileName;
                }
                file = new SerializableFileStreamWrapper(imageFile);
            }

            CardSize = cardSize ?? file.Stream.Length;

            var cardIdentificationBytes = new byte[] { 0x01, 0x00, 0x00, 0x00,       // 1b always one + 7b CRC (ignored) + 12b manufacturing date + 4b reserved
                                                       0x00, 0x00, 0x00, 0x00,       // 32b product serial number + 8b product revision
                                                       0x45, 0x44, 0x43, 0x42, 0x41, // Product name, 5 character string. "ABCDE" (backwards)
                                                       0x00, 0x00, 0x00              // 16b application ID + 8b manufacturer ID
            };

            cardIdentification    = new uint[4];
            cardIdentification[0] = BitConverter.ToUInt32(cardIdentificationBytes, 0);
            cardIdentification[1] = BitConverter.ToUInt32(cardIdentificationBytes, 4);
            cardIdentification[2] = BitConverter.ToUInt32(cardIdentificationBytes, 8);
            cardIdentification[3] = BitConverter.ToUInt32(cardIdentificationBytes, 12);

            cardSpecificData = new uint[4];
            uint deviceSize = (uint)(CardSize / 0x80000 - 1);

            cardSpecificData[0] = 0x0a4040af;
            cardSpecificData[1] = 0x3b377f80 | ((deviceSize & 0xffff) << 16);
            cardSpecificData[2] = 0x5b590000 | ((deviceSize >> 16) & 0x3f);
            cardSpecificData[3] = 0x400e0032;
        }