Esempio n. 1
0
 private void splash_OnHashingStatusUpdate(object sender, HashingStatusUpdateEventArgs e)
 {
     if (e.Complete < 100)
     {
         this.Invoke(new HideDelegate(this.Hide));
     }
 }
Esempio n. 2
0
 public void UpdateProgress(HashingStatusUpdateEventArgs e)
 {
     if (DisplayedStatus == null)
     {
         DisplayedStatus     = e;
         DateOfStatus        = DateTime.Now;
         pbCalculation.Value = (int)Math.Floor(e.Complete);
         lblPosition.Text    = e.Complete + "% - " + e.Position.ToString() + "/" + e.Size.ToString();
         lblSpeed.Text       = String.Empty;
     }
     else
     {
         if (DisplayedStatus.Complete + 2 < e.Complete)
         {
             DateTime CurrentTime = DateTime.Now;
             pbCalculation.Value = (int)Math.Floor(e.Complete);
             lblPosition.Text    = e.Complete + "% - " + e.Position.ToString() + "/" + e.Size.ToString();
             long     BytesSinceLast = e.Position - DisplayedStatus.Position;
             FileSize fs             = new FileSize(BytesSinceLast);
             String   DataSinceLast  = fs.ToString();
             lblSpeed.Text   = DataSinceLast + "/second";
             DisplayedStatus = e;
             DateOfStatus    = CurrentTime;
         }
     }
 }
Esempio n. 3
0
 void SplashForm_OnHashingStatusUpdate(object sender, HashingStatusUpdateEventArgs e)
 {
     this.Invoke(new UpdateStatusDelegate(this.UpdateProgress), e);
 }
Esempio n. 4
0
        public void GetMD5(Object strFilePath)
        {
            String     FilePath  = strFilePath.ToString();
            MD5        MD5Hasher = MD5.Create();
            long       offset    = 0;
            FileStream fs        = null;

            try
            {
                fs = new FileStream(FilePath, FileMode.Open);
            }
            catch (Exception)
            {
                // If an exception is thrown, it's likely that the file is in use.
                MessageBox.Show("File is currently in use by another application.");
                Application.Exit();
            }

            if (fs == null)
            {
                // I can't think of a single reason why it would still be null...
                // But just in case, let's handle it.
                // NOTE: I realize this is a very poor way of "handling" exceptions.
                Application.Exit();
            }

            long   filesize   = fs.Length;
            double onePercent = filesize / 100D;
            HashingStatusUpdateEventArgs update;

            byte[] buffer = new byte[bufferSize];
            while (fs.Read(buffer, 0, buffer.Length) > 0)
            {
                long length        = filesize - offset;
                int  currentLength = buffer.Length;
                if (buffer.Length > length)
                {
                    currentLength = (int)length;
                }
                offset += MD5Hasher.TransformBlock(buffer, 0, currentLength, buffer, 0);
                double percentComplete = Math.Round((fs.Position / onePercent), 2);
                update = new HashingStatusUpdateEventArgs(percentComplete, fs.Length, fs.Position);
                HashingStatusUpdate(this, update);
            }
            fs.Close();
            MD5Hasher.TransformFinalBlock(new Byte[0], 0, 0);
            byte[] bHash = MD5Hasher.Hash;
            update = new HashingStatusUpdateEventArgs(100, filesize, filesize); // Finished.
            HashingStatusUpdate(this, update);

            StringBuilder sb = new StringBuilder();

            for (int i = 0; i < bHash.Length; i++)
            {
                sb.Append(bHash[i].ToString("x2")); // Return as Hex, duh.
            }
            String sHash = sb.ToString();

            HashingEventArgs e = new HashingEventArgs(sHash);

            if (HashingFinished != null)
            {
                HashingFinished(this, e);
            }
        }
Esempio n. 5
0
 private void splash_OnHashingStatusUpdate(object sender, HashingStatusUpdateEventArgs e)
 {
     if (e.Complete < 100)
     {
         this.Invoke(new HideDelegate(this.Hide));
     }
 }
Esempio n. 6
0
        public void GetMD5(Object strFilePath)
        {
            String FilePath = strFilePath.ToString();
            MD5 MD5Hasher = MD5.Create();
            long offset = 0;
            FileStream fs = null;

            try
            {
                fs = new FileStream(FilePath, FileMode.Open);
            }
            catch (Exception)
            {
                // If an exception is thrown, it's likely that the file is in use.
                MessageBox.Show("File is currently in use by another application.");
                Application.Exit();
            }

            if (fs == null)
            {
                // I can't think of a single reason why it would still be null...
                // But just in case, let's handle it.
                // NOTE: I realize this is a very poor way of "handling" exceptions.
                Application.Exit();
            }

            long filesize = fs.Length;
            double onePercent = filesize / 100D;
            HashingStatusUpdateEventArgs update;

            byte[] buffer = new byte[bufferSize];
            while (fs.Read(buffer, 0, buffer.Length) > 0)
            {
                long length = filesize - offset;
                int currentLength = buffer.Length;
                if (buffer.Length > length)
                {
                    currentLength = (int)length;
                }
                offset += MD5Hasher.TransformBlock(buffer, 0, currentLength, buffer, 0);
                double percentComplete = Math.Round((fs.Position / onePercent), 2);
                update = new HashingStatusUpdateEventArgs(percentComplete, fs.Length, fs.Position);
                HashingStatusUpdate(this, update);
            }
            fs.Close();
            MD5Hasher.TransformFinalBlock(new Byte[0], 0, 0);
            byte[] bHash = MD5Hasher.Hash;
            update = new HashingStatusUpdateEventArgs(100, filesize, filesize); // Finished.
            HashingStatusUpdate(this, update);

            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < bHash.Length; i++)
            {
                sb.Append(bHash[i].ToString("x2")); // Return as Hex, duh.
            }
            String sHash = sb.ToString();

            HashingEventArgs e = new HashingEventArgs(sHash);
            if (HashingFinished != null)
            {
                HashingFinished(this, e);
            }
        }
Esempio n. 7
0
 void SplashForm_OnHashingStatusUpdate(object sender, HashingStatusUpdateEventArgs e)
 {
     this.Invoke(new UpdateStatusDelegate(this.UpdateProgress), e);
 }
Esempio n. 8
0
 public void UpdateProgress(HashingStatusUpdateEventArgs e)
 {
     if (DisplayedStatus == null)
     {
         DisplayedStatus = e;
         DateOfStatus = DateTime.Now;
         pbCalculation.Value = (int)Math.Floor(e.Complete);
         lblPosition.Text = e.Complete + "% - " + e.Position.ToString() + "/" + e.Size.ToString();
         lblSpeed.Text = String.Empty;
     }
     else
     {
         if (DisplayedStatus.Complete + 2 < e.Complete)
         {
             DateTime CurrentTime = DateTime.Now;
             pbCalculation.Value = (int)Math.Floor(e.Complete);
             lblPosition.Text = e.Complete + "% - " + e.Position.ToString() + "/" + e.Size.ToString();
             long BytesSinceLast = e.Position - DisplayedStatus.Position;
             FileSize fs = new FileSize(BytesSinceLast);
             String DataSinceLast = fs.ToString();
             lblSpeed.Text = DataSinceLast + "/second";
             DisplayedStatus = e;
             DateOfStatus = CurrentTime;
         }
     }
 }