コード例 #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
ファイル: ID3v1.cs プロジェクト: sadig41/Media_Player
 /// <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);
     }
     fs.Close();
 }
コード例 #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;
        }
コード例 #4
0
ファイル: frmMain.cs プロジェクト: Chemiculs/Shredder
 private void ShredderBW_DoWork(object sender, DoWorkEventArgs e)
 {
     if (Globalvariables.Filepath.Length == 0)
     {
         Log("No file open!");
     }
     else
     {
         Log("Initializing stream...");
         for (int i = 0; i < Globalvariables.Passes.Count; i++)
         {
             byte val = Globalvariables.Passes[i];
             using (FileStreamEx Wiper = new FileStreamEx(Globalvariables.Filepath, System.IO.FileMode.Open))
             {
                 Log("Executing Pass " + (i + 1).ToString() + " - 0x" + val.ToString("X2"));
                 if (Globalvariables.FullBuffer)
                 {
                     byte[] buffer = new byte[Wiper.Length];
                     Utils.FillBuffer(ref buffer, val);
                     Wiper.Write(buffer);
                 }
                 if(Globalvariables.CustomBuffer)
                 {
                     int Blocksize = Globalvariables.BufferSize;
                     long Progress = 0;
                     byte[] buffer = new byte[Blocksize];
                     Utils.FillBuffer(ref buffer, val);
                     while (Progress < Wiper.Length)
                     {
                         if ((Progress + Blocksize) <= Wiper.Length)
                         {
                             Wiper.Write(buffer);
                             Progress += Blocksize;
                         }
                         else
                         {
                             int Remaining = (int)(Wiper.Length - Progress);
                             byte[] FinalBlock = new byte[Remaining];
                             Utils.FillBuffer(ref FinalBlock, val);
                             Wiper.Write(FinalBlock);
                             Progress += Remaining;
                         }
                     }
                 }
                 if (Globalvariables.OneByte)
                 {
                     while (!Wiper.eof())
                     {
                         Wiper.Write(val);
                     }
                 }
             }
         }
     }
 }