Exemple #1
0
        /// <summary>
        /// Sector refers to physical disk blocks, we can only read complete blocks
        /// </summary>
        public byte[] ReadSectorsUnbuffered(long sectorIndex, int sectorCount)
        {
            bool           releaseHandle;
            SafeFileHandle handle = PhysicalDiskHandlePool.ObtainHandle(m_physicalDiskIndex, FileAccess.Read, ShareMode.ReadWrite, out releaseHandle);

            if (!handle.IsInvalid)
            {
                FileStreamEx stream = new FileStreamEx(handle, FileAccess.Read);
                byte[]       buffer = new byte[m_bytesPerSector * sectorCount];
                try
                {
                    stream.Seek(sectorIndex * m_bytesPerSector, SeekOrigin.Begin);
                    stream.Read(buffer, 0, m_bytesPerSector * sectorCount);
                }
                finally
                {
                    stream.Close(releaseHandle);
                    if (releaseHandle)
                    {
                        PhysicalDiskHandlePool.ReleaseHandle(m_physicalDiskIndex);
                    }
                }
                return(buffer);
            }
            else
            {
                // we always release invalid handle
                PhysicalDiskHandlePool.ReleaseHandle(m_physicalDiskIndex);
                // get error code and throw
                int    errorCode = Marshal.GetLastWin32Error();
                string message   = String.Format("Failed to read sector {0} from disk {1}.", sectorIndex, m_physicalDiskIndex);
                IOExceptionHelper.ThrowIOError(errorCode, message);
                return(null); // this line will not be reached
            }
        }
Exemple #2
0
 public void Save(FileStreamEx f)
 {
     f.Write16(id);
     f.Write8(type);
     f.Write8(dummy);
     f.WriteString(name, 0x10);
 }
Exemple #3
0
 public void Load(FileStreamEx f)
 {
     id    = f.ReadUShort();
     type  = f.Read8();
     dummy = f.Read8();
     name  = f.ReadString(0x10);
 }
Exemple #4
0
        public void SaveProject(string filename)
        {
            FileStreamEx f = new FileStreamEx(filename, System.IO.FileMode.Create, System.IO.FileAccess.Write);

            f.Write8((byte)animList.Count);
            f.Write8((byte)animList[0].source.Resolution);
            f.Write16((ushort)(animList[0].source.BitsPerPixel * animList[0].source.Resolution * 16 * 16 / 8));
            for (int i = 0; i < animList.Count; i++)
            {
                animList[i].Save(f);
            }
            for (int i = 0; i < animList.Count; i++)
            {
                int j = 0;
                do
                {
                    f.Write8(animList[i].pat[j]);
                } while (animList[i].pat[j] != 0xFF);
            }
            for (int i = 0; i < animList.Count; i++)
            {
                animList[i].source.SaveRawData(ref animList[i].bmp, f);
            }
            f.Close();
        }
Exemple #5
0
        /// <summary>
        /// Create new AttachedPictureFrame
        /// </summary>
        /// <param name="FrameID">4 Characters tag identifier</param>
        /// <param name="Flags">2 Bytes flags identifier</param>
        /// <param name="Data">Contain Data for this frame</param>
        /// <param name="Length">MaxLength of frame</param>
        internal AttachedPictureFrame(string FrameID, FrameFlags Flags, FileStreamEx Data, int Length, Version version)
            : base(FrameID, Flags)
        {
            _TextEncoding = (TextEncodings)Data.ReadByte();
            Length--;
            if (!IsValidEnumValue(_TextEncoding, ValidatingErrorTypes.ID3Error))
            {
                _MustDrop = true;
                return;
            }

            if (version.Major == 2 && version.Minor == 2)
            {
                _MIMEType = Data.ReadText(3, TextEncodings.Ascii, ref Length, true);
            }
            else
            {
                _MIMEType = Data.ReadText(Length, TextEncodings.Ascii, ref Length, true);
            }

            _PictureType = (PictureTypes)Data.ReadByte();
            Length--;

            _Description = Data.ReadText(Length, _TextEncoding, ref Length, true);

            _Data = Data.ReadData(Length);
        }
Exemple #6
0
 public static AffixConfig ReadFile(string filePath, AffixConfig.Builder builder = null)
 {
     using (var stream = FileStreamEx.OpenReadFileStream(filePath))
     {
         return(Read(stream, builder));
     }
 }
Exemple #7
0
 public void Save(FileStreamEx f)
 {
     f.Write8(left);
     f.Write8(top);
     f.Write8(right);
     f.Write8(bottom);
 }
Exemple #8
0
        public static IPreviewHandler InitalizePreviewHandler(FileInfoEx file)
        {
            IPreviewHandler retVal    = null;
            PreviewerInfo   previewer = getPreviewer(file.FullName);

            if (previewer != null)
            {
                bool   isInitialized = false;
                Type   a             = Type.GetTypeFromCLSID(previewer.CLSID, true);
                object o             = Activator.CreateInstance(a);

                IInitializeWithFile   fileInit   = o as IInitializeWithFile;
                IInitializeWithStream streamInit = o as IInitializeWithStream;

                if (fileInit != null)
                {
                    fileInit.Initialize(file.FullName, 0);
                    isInitialized = true;
                }
                else if (streamInit != null)
                {
                    FileStreamEx stream = file.OpenRead();
                    streamInit.Initialize((IStream)stream, 0);
                    isInitialized = true;
                }

                if (isInitialized)
                {
                    retVal = o as IPreviewHandler;
                }
            }
            return(retVal);
        }
Exemple #9
0
        /// <summary>
        /// Create new UserTextFrameClass
        /// </summary>
        /// <param name="FrameID">4 Characters tag identifier</param>
        /// <param name="Flags">Frame Flagsr</param>
        /// <param name="Data">MemoryStream to read information from</param>
        internal UserTextFrame(string FrameID, FrameFlags Flags, FileStreamEx Data, int Length)
            : base(FrameID, Flags)
        {
            TextEncoding = (TextEncodings)Data.ReadByte();
            Length--;
            if (!IsValidEnumValue(TextEncoding, ValidatingErrorTypes.ID3Error))
            {
                _MustDrop = true;
                return;
            }

            _Description = Data.ReadText(Length, TextEncoding, ref Length, true);

            if (!IsUrl) // is text frame
            {
                Text = Data.ReadText(Length, TextEncoding);
            }
            else
            {
                Text = Data.ReadText(Length, TextEncodings.Ascii);
            }

            // User URL frames use this class and use Text property as URL
            // URL property must be in AScii format
            // all URL frames start with W and text frames with T
        }
Exemple #10
0
        /// <summary>
        /// Create new OwnershipFrame
        /// </summary>
        /// <param name="FrameID">4 Characters tag identifier</param>
        /// <param name="Flags">2 Bytes flags identifier</param>
        /// <param name="Data">Contain Data for this frame</param>
        internal OwnershipFrame(string FrameID, FrameFlags Flags, FileStreamEx Data, int Length)
            : base(FrameID, Flags)
        {
            TextEncoding = (TextEncodings)Data.ReadByte();
            Length--;
            if (!IsValidEnumValue(TextEncoding, ValidatingErrorTypes.ID3Error))
            {
                return;
            }

            _Price  = new Price(Data, Length);
            Length -= _Price.Length;
            if (!_Price.IsValid)
            {
                ErrorOccur("Price is not valid value. ownership frame will not read", true);
                return;
            }

            if (Length >= 8)
            {
                _DateOfPurch = new SDate(Data);
                Length      -= 8;
            }
            else
            {
                ErrorOccur("Date is not valid for this frame", true);
                return;
            }

            Seller = Data.ReadText(Length, TextEncoding);
        }
Exemple #11
0
        /// <summary>
        /// Create new Equalisation frame
        /// </summary>
        /// <param name="FrameID"></param>
        /// <param name="Flags"></param>
        /// <param name="Data"></param>
        /// <param name="Length"></param>
        internal Equalisation(string FrameID, FrameFlags Flags, FileStreamEx Data, int Length)
            : base(FrameID, Flags)
        {
            _Frequensies = new FramesCollection <FrequencyAdjustmentFrame>();

            _AdjustmentBits = Data.ReadByte();
            Length--;

            if (_AdjustmentBits == 0)
            {
                ErrorOccur("Adjustment bit of Equalisation is zero. this frame is invalid", true);
                return;
            }

            if (_AdjustmentBits % 8 != 0 || _AdjustmentBits > 32)
            {
                ErrorOccur("AdjustmentBit of Equalisation Frame is out of supported range of this program", true);
                return;
            }

            int AdLen = _AdjustmentBits / 8;

            int  FreqBuf;
            uint AdjBuf;

            while (Length > 3)
            {
                FreqBuf = Convert.ToInt32(Data.ReadUInt(2));

                AdjBuf = Data.ReadUInt(AdLen);
                _Frequensies.Add(new FrequencyAdjustmentFrame(FreqBuf, AdjBuf));

                Length -= 2 + AdLen;
            }
        }
Exemple #12
0
        /// <summary>
        /// Create new STempoCodes
        /// </summary>
        /// <param name="FrameID">4 Characters tag identifier</param>
        /// <param name="Flags">2 Bytes flags identifier</param>
        /// <param name="Data">Contain Data for this frame</param>
        /// <param name="Length"></param>
        internal SynchronisedTempoFrame(string FrameID, FrameFlags Flags, FileStreamEx Data, int Length)
            : base(FrameID, Flags)
        {
            _TempoCodes = new FramesCollection <TempoCode>();

            _TimeStamp = (TimeStamps)Data.ReadByte();
            if (IsValidEnumValue(_TimeStamp, ValidatingErrorTypes.ID3Error))
            {
                _MustDrop = true;
                return;
            }
            int  Tempo;
            uint Time;

            while (Length > 4)
            {
                Tempo = Data.ReadByte();
                Length--;

                if (Tempo == 0xFF)
                {
                    Tempo += Data.ReadByte();
                    Length--;
                }

                Time    = Data.ReadUInt(4);
                Length -= 4;

                _TempoCodes.Add(new TempoCode(Tempo, Time));
            }
        }
Exemple #13
0
        private void bOpen_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.Filter          = "XeEngine entity definition|*.ent";
            openFileDialog.AddExtension    = true;
            openFileDialog.CheckPathExists = true;
            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                FileStreamEx f;
                try
                {
                    f        = new FileStreamEx(openFileDialog.FileName, System.IO.FileMode.Open, System.IO.FileAccess.Read);
                    FileName = openFileDialog.FileName;
                }
                catch (System.Exception ex)
                {
                    LaunchError(ex.Message);
                    return;
                }
                entity.Load(f);
                f.Close();
                RefreshGUI();
            }
        }
Exemple #14
0
 public static async Task <AffixConfig> ReadFileAsync(string filePath, AffixConfig.Builder builder = null)
 {
     using (var stream = FileStreamEx.OpenAsyncReadFileStream(filePath))
     {
         return(await ReadAsync(stream, builder).ConfigureAwait(false));
     }
 }
Exemple #15
0
 public void Load(FileStreamEx f)
 {
     count  = f.Read8();
     childs = f.Read8();
     speed  = f.Read8();
     loop   = f.Read8();
 }
        /// <summary>
        /// Sector refers to physical disk blocks, we can only read complete blocks
        /// </summary>
        public byte[] ReadSectorsUnbuffered(long sectorIndex, int sectorCount)
        {
            bool           releaseHandle;
            SafeFileHandle handle = VolumeHandlePool.ObtainHandle(m_volumeGuid, FileAccess.Read, ShareMode.ReadWrite, out releaseHandle);

            if (!handle.IsInvalid)
            {
                FileStreamEx stream = new FileStreamEx(handle, FileAccess.Read);
                byte[]       buffer = new byte[m_bytesPerSector * sectorCount];
                try
                {
                    stream.Seek(sectorIndex * m_bytesPerSector, SeekOrigin.Begin);
                    stream.Read(buffer, 0, m_bytesPerSector * sectorCount);
                }
                finally
                {
                    stream.Close(releaseHandle);
                    if (releaseHandle)
                    {
                        VolumeHandlePool.ReleaseHandle(m_volumeGuid);
                    }
                }
                return(buffer);
            }
            else
            {
                // we always release invalid handle
                VolumeHandlePool.ReleaseHandle(m_volumeGuid);
                // get error code and throw
                int    errorCode = Marshal.GetLastWin32Error();
                string message   = String.Format("Can't read sector {0} from volume {1}, Win32 Error: {2}", sectorIndex, m_volumeGuid, errorCode);
                throw new IOException(message);
            }
        }
Exemple #17
0
        /// <summary>
        /// New CommercialFrame
        /// </summary>
        /// <param name="FrameID">FrameID</param>
        /// <param name="Flags">Frame Flags</param>
        /// <param name="Data">Data of frame</param>
        /// <param name="Length">MaxLength of frame</param>
        internal CommercialFrame(string FrameID, FrameFlags Flags, FileStreamEx Data, int Length)
            : base(FrameID, Flags)
        {
            _TextEncoding = (TextEncodings)Data.ReadByte();
            Length--;
            if (!IsValidEnumValue(_TextEncoding, ValidatingErrorTypes.ID3Error))
            {
                return;
            }

            _Price  = new Price(Data, Length);
            Length -= _Price.Length;

            _ValidUntil = new SDate(Data);
            Length     -= 8;


            _ContactUrl = Data.ReadText(Length, TextEncodings.Ascii, ref Length, true);

            _RecievedAs = (RecievedAsEnum)Data.ReadByte();
            Length--;

            _SellerName = Data.ReadText(Length, _TextEncoding, ref Length, true);

            _Description = Data.ReadText(Length, _TextEncoding, ref Length, true);

            if (Length < 1) // Data finished
            {
                return;
            }

            _MIMEType = Data.ReadText(Length, TextEncodings.Ascii, ref Length, true);

            _Data = Data.ReadData(Length);
        }
Exemple #18
0
 public void Load(FileStreamEx f)
 {
     left   = f.Read8();
     top    = f.Read8();
     right  = f.Read8();
     bottom = f.Read8();
 }
Exemple #19
0
        /// <summary>
        /// New PrivateFrame
        /// </summary>
        /// <param name="FrameID">FrameID</param>
        /// <param name="Flags">Frame Flags</param>
        /// <param name="Data">FileStream to read frame data from</param>
        internal PrivateFrame(string FrameID, FrameFlags Flags, FileStreamEx Data, int Length)
            : base(FrameID, Flags)
        {
            _Owner = Data.ReadText(Length, TextEncodings.Ascii, ref Length, true);

            _Data = Data.ReadData(Length); // Read Data
        }
Exemple #20
0
        /// <summary>
        /// Create new RaltiveVolumeFrame
        /// </summary>
        /// <param name="FrameID">4 Characters tag identifier</param>
        /// <param name="Flags">2 Bytes flags identifier</param>
        /// <param name="Data">Contain Data for this frame</param>
        /// <param name="Lenght">Length to read from FileStream</param>
        internal RelativeVolumeFrame(string FrameID, FrameFlags Flags, FileStreamEx Data, int Length)
            : base(FrameID, Flags)
        {
            _Descriptors = new uint[12];

            _IncDec = Data.ReadByte();                  // Read Increment Decrement Byte

            _BitForVolumeDescription = Data.ReadByte(); // Read Volume Description Length
            Length -= 2;

            if (_BitForVolumeDescription == 0)
            {
                ErrorOccur("BitForVolumeDescription of Relative volume information frame can't be zero", true);
                return;
            }

            if (_BitForVolumeDescription / 8 > 4 ||
                _BitForVolumeDescription % 8 != 0)
            {
                ErrorOccur("This program don't support " + _BitForVolumeDescription.ToString() +
                           " Bits of description for Relative Volume information", true);
                return;
            }

            int DesLen  = _BitForVolumeDescription / 8; // Length of each volume descriptor
            int Counter = 0;

            while (CanContinue(Length, DesLen, 2))
            {
                _Descriptors[Counter++] = Data.ReadUInt(DesLen);
                _Descriptors[Counter++] = Data.ReadUInt(DesLen);
                Length -= 2;
            }
        }
Exemple #21
0
        /// <summary>
        /// Load ID3v1 information from file
        /// </summary>
        public void Load()
        {
            FileStreamEx FS = new FileStreamEx(_FilePath, FileMode.Open);

            if (!FS.HaveID3v1())
            {
                FS.Close();
                _HaveTag = false;
                return;
            }
            _Title = FS.ReadText(30, TextEncodings.Ascii);
            FS.Seek(-95, SeekOrigin.End);
            _Artist = FS.ReadText(30, TextEncodings.Ascii);
            FS.Seek(-65, SeekOrigin.End);
            _Album = FS.ReadText(30, TextEncodings.Ascii);
            FS.Seek(-35, SeekOrigin.End);
            _Year = FS.ReadText(4, TextEncodings.Ascii);
            FS.Seek(-31, SeekOrigin.End);
            _Comment = FS.ReadText(28, TextEncodings.Ascii);
            FS.Seek(-2, SeekOrigin.End);
            _TrackNumber = FS.ReadByte();
            _Genre       = (Genre)FS.ReadByte();
            FS.Close();
            _HaveTag = true;
        }
Exemple #22
0
 public static WordList ReadFile(string dictionaryFilePath, AffixConfig affix, WordList.Builder builder = null)
 {
     using (var stream = FileStreamEx.OpenReadFileStream(dictionaryFilePath))
     {
         return(Read(stream, affix, builder));
     }
 }
Exemple #23
0
 public static async Task <WordList> ReadFileAsync(string dictionaryFilePath, AffixConfig affix, WordList.Builder builder = null)
 {
     using (var stream = FileStreamEx.OpenAsyncReadFileStream(dictionaryFilePath))
     {
         return(await ReadAsync(stream, affix, builder).ConfigureAwait(false));
     }
 }
Exemple #24
0
        public void Load(FileStreamEx f)
        {
            m_animcount  = f.ReadUShort();
            m_framecount = f.ReadUShort();

            m_animationframes.Clear();
            m_animationentries.Clear();
            m_animationid.Clear();
            for (int i = 0; i < m_framecount; i++)
            {
                AnimationFrame frame = new AnimationFrame();
                frame.Load(f);
                m_animationframes.Add(frame);
            }
            for (int i = 0; i < m_animcount; i++)
            {
                m_animationid.Add(f.ReadUShort());
            }
            for (int i = 0; i < m_animcount; i++)
            {
                AnimationEntry entry = new AnimationEntry();
                entry.Load(f);
                m_animationentries.Add(entry);
            }
            for (int i = 0; i < m_animcount; i++)
            {
                m_animationentries[i].LoadFrameList(f);
            }
        }
Exemple #25
0
        /// <summary>
        /// Save ID3v1 information to file
        /// </summary>
        public void Save()
        {
            FileStreamEx fs   = new FileStreamEx(_FilePath, FileMode.Open);
            bool         HTag = fs.HaveID3v1();

            if (HTag && !_HaveTag)             // just delete ID3
            {
                fs.SetLength(fs.Length - 128);
            }
            else if (!HTag && _HaveTag)
            {
                fs.Seek(0, SeekOrigin.End);
                fs.Write(GetTagBytes, 0, 128);
            }
            else if (HTag && _HaveTag)
            {
                fs.Seek(-128, SeekOrigin.End);
                fs.Write(GetTagBytes, 0, 128);
            }
            else
            {
                fs.Seek(0, SeekOrigin.End);
                fs.Write(GetTagBytes, 0, 128);
            }
            fs.Close();
        }
Exemple #26
0
 public void Save(FileStreamEx f)
 {
     f.Write8((byte)FramesCount);
     f.Write8((byte)ChildsCount);
     f.Write8(speed);
     f.Write8(loop);
 }
Exemple #27
0
        private void bSave_Click(object sender, EventArgs e)
        {
            SaveFileDialog saveFileDialog = new SaveFileDialog();

            saveFileDialog.Filter          = "XeEngine entity definition|*.ent";
            saveFileDialog.AddExtension    = true;
            saveFileDialog.CheckPathExists = true;
            saveFileDialog.FileName        = filename;
            if (saveFileDialog.ShowDialog() == DialogResult.OK)
            {
                FileStreamEx f;
                try
                {
                    f        = new FileStreamEx(saveFileDialog.FileName, System.IO.FileMode.Create, System.IO.FileAccess.Write);
                    FileName = saveFileDialog.FileName;
                }
                catch (System.Exception ex)
                {
                    LaunchError(ex.Message);
                    return;
                }
                entity.Animation.RemoveEmptyAnimations();
                entity.Save(f);
                f.Close();
            }
        }
Exemple #28
0
 public static async Task <List <string> > ReadLinesAsync(string filePath, Encoding defaultEncoding)
 {
     using (var stream = FileStreamEx.OpenAsyncReadFileStream(filePath))
         using (var reader = new DynamicEncodingLineReader(stream, defaultEncoding))
         {
             return(await reader.ReadLinesAsync().ConfigureAwait(false));
         }
 }
Exemple #29
0
 public static List <string> ReadLines(string filePath, Encoding defaultEncoding)
 {
     using (var stream = FileStreamEx.OpenReadFileStream(filePath))
         using (var reader = new DynamicEncodingLineReader(stream, defaultEncoding))
         {
             return(reader.ReadLines().ToList());
         }
 }
Exemple #30
0
        public void LoadProject(string filename)
        {
            FileStreamEx f = new FileStreamEx(filename, System.IO.FileMode.Open, System.IO.FileAccess.Read);



            f.Close();
        }
Exemple #31
0
 static void FileStreamEx(string filename)
 {
     Console.WriteLine("FileStreamEx");
     var sw = new Stopwatch();
     sw.Start();
     var count = 0;
     using (var reader = new FileStreamEx(filename))
     {
         Line line;
         while ((line = reader.ReadLine()) != null)
         {
             count++;
             var cols = line.Split('\t');
             //var x = line.Text;
         }
     }
     sw.Stop();
     Console.WriteLine($"Count: {count:N0}");
     Console.WriteLine($"Lines per sec: {count/sw.ElapsedMilliseconds * 1000}");
     Console.WriteLine("Time: " + sw.ElapsedMilliseconds);
 }
Exemple #32
0
 private void BWPumper_DoWork(object sender, DoWorkEventArgs e)
 {
     using (FileStreamEx Pumper = new FileStreamEx(_Path, System.IO.FileMode.Open))
     {
         long Progress = 0;
         int Blocksize = 65536;
         byte[] buffer = new byte[Blocksize];
         Pumper.Position = Pumper.Length;
         Utils.FillBuffer(ref buffer, _Value);
         while (Progress < _Size)
         {
             if (Progress + Blocksize <= Pumper.Length)
             {
                 Pumper.Write(buffer);
                 Progress += Blocksize;
             }
             else
             {
                 int Remaining = (int)(_Size - Progress);
                 byte[] LastBuffer = new byte[Remaining];
                 Utils.FillBuffer(ref LastBuffer, _Value);
                 Pumper.Write(LastBuffer);
                 Progress += Remaining;
             }
         }
     }
 }