コード例 #1
0
 /// <summary>
 /// Copy directory or file, take full path of source and dest as parameter.
 /// </summary>
 public static void CopyFile(string source, string dest, FileCancelDelegate cancel)
 {
     using (FileStreamEx srcStream = FileEx.OpenRead(source))
     {
         byte[] buffer = new byte[Math.Min(1024 * 1024 * 32, srcStream.Length)];  //32MB
         int    readCount;
         ushort completePercent = 0;
         long   completeCount   = 0;
         using (FileStreamEx destStream = FileEx.Create(dest))
         {
             while ((readCount = srcStream.Read(buffer, 0, buffer.Length)) > 0 && !IsCancelTriggered(cancel, completePercent))
             {
                 completeCount += readCount;
                 destStream.Write(buffer, 0, readCount);
                 completePercent = srcStream.Length == 0 ? (ushort)100 : (ushort)((float)completeCount / (float)srcStream.Length * 100.0);
             }
             destStream.Flush();
             destStream.Close();
         }
         srcStream.Close();
     }
 }
コード例 #2
0
ファイル: TextFrame.cs プロジェクト: justwee/WPF-Projects
        /// <summary>
        /// New PopularimeterFrame
        /// </summary>
        /// <param name="FrameID">4 Characters tag identifier</param>
        /// <param name="Flags">Frame Flags</param>
        /// <param name="Data">FileStream contain frame data</param>
        internal PopularimeterFrame(string FrameID, FrameFlags Flags, FileStreamEx Data, int Length)
            : base(FrameID, Flags)
        {
            EMail = Data.ReadText(Length, TextEncodings.Ascii, ref Length, true); // Read Email Address

            _Rating = Data.ReadByte(); // Read Rating
            Length--;

            if (Length > 8)
            {
                ErrorOccur("Counter value for Popularimeter frame is more than 8 byte." +
                    " this is not supported by this program", true);
                return;
            }

            byte[] LBuf = new byte[8];
            byte[] Buf = new byte[Length];

            Data.Read(Buf, 0, Length);
            Buf.CopyTo(LBuf, 8 - Buf.Length);
            Array.Reverse(LBuf);

            _Counter = BitConverter.ToInt64(LBuf, 0);
        }
コード例 #3
0
ファイル: ID3v2.cs プロジェクト: justwee/WPF-Projects
        private void SaveRestOfFile(int StartIndex, FileStreamEx Orgin,
            FileStreamEx Temp, int Ver)
        {
            Orgin.Seek(StartIndex, SeekOrigin.Begin);

            byte[] Buf = new byte[Orgin.Length - StartIndex];
            Orgin.Read(Buf, 0, Buf.Length);
            Temp.Write(Buf, 0, Buf.Length);
            Orgin.Close();
            Temp.Close();

            if (Ver != 0)
                SetMinorVersion(Ver);

            File.Delete(Orgin.Name);
            string FinallyName = Temp.Name.Remove(Temp.Name.Length - 5);
            File.Move(Temp.Name, FinallyName);
            _FilePath = FinallyName;
        }