Exemple #1
0
        /// <summary>
        /// Return file crc of the specified file
        /// </summary>
        public static string GetFileCRC(string filename)
        {
            if (!FileEx.Exists(filename))
            {
                return("");
            }

            Fesersoft.Hashing.crc32 crc32 = new Fesersoft.Hashing.crc32();
            using (FileStreamEx stmcheck = FileEx.OpenRead(filename))
            {
                uint crchash = (uint)crc32.CRC(stmcheck);
                stmcheck.Close();
                return(ConvertToHex(crchash));
            }
        }
Exemple #2
0
        public static string GetFileMD5(string filename)
        {
            if (!FileEx.Exists(filename))
            {
                return("");
            }
            MD5CryptoServiceProvider csp = new MD5CryptoServiceProvider();

            using (FileStreamEx stmcheck = FileEx.OpenRead(filename))
            {
                byte[] hash = csp.ComputeHash(stmcheck);
                stmcheck.Close();

                return(BitConverter.ToString(hash).Replace("-", "").ToLower());
            }
        }
Exemple #3
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();
     }
 }
Exemple #4
0
        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;
        }
Exemple #5
0
        /// <summary>
        /// Load ID3 information from file
        /// </summary>
        /// <exception cref="FileNotFoundException">File Not Found</exception>
        public void Load()
        {
            FileStreamEx ID3File = new FileStreamEx(_FilePath, FileMode.Open);
            if (!ID3File.HaveID3v2()) // If file don't contain ID3v2 exit function
            {
                _HaveTag = false;
                ID3File.Close();
                return;
            }

            _ver = ID3File.ReadVersion(); // Read ID3v2 version           
            _Flags = (ID3v2Flags)ID3File.ReadByte();

            // Extended Header Must Read Here

            ReadFrames(ID3File, ID3File.ReadSize());
            ID3File.Close();
            _HaveTag = true;
        }
Exemple #6
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);
     }
     fs.Close();
 }
Exemple #7
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 = FS.ReadByte();
     FS.Close();
     _HaveTag = true;
 }