Skip to content

Commit

Permalink
Optimize for large file
Browse files Browse the repository at this point in the history
  • Loading branch information
ewwink committed Jun 4, 2017
1 parent 9073f60 commit e792607
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 23 deletions.
Binary file modified MD5HashChanger.v11.suo
Binary file not shown.
46 changes: 25 additions & 21 deletions MD5HashChanger/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,13 @@ private void changeMD5(string[] fileNames)
break;
}
int num = random.Next(2, 7);
byte[] array = new byte[num];
byte[] extraByte = new byte[num];
for (int j = 0; j < num; j++)
{
array[j] = (byte)0;
extraByte[j] = (byte)0;
}
bool flag = new FileInfo(fileNames[i]).Length == 0L;
if (flag)
long fileSize = new FileInfo(fileNames[i]).Length;
if (fileSize == 0L)
{
this.Invoke((MethodInvoker)delegate()
{
Expand All @@ -118,27 +118,29 @@ private void changeMD5(string[] fileNames)
{
using (FileStream fileStream = new FileStream(fileNames[i], FileMode.Append))
{
fileStream.Write(array, 0, array.Length);
fileStream.Write(extraByte, 0, extraByte.Length);
}
int bufferSize = fileSize > 1048576L ? 1048576 : 4096;
string md5hash = "";
using (MD5 md = MD5.Create())
{
using (FileStream fileStream2 = File.OpenRead(fileNames[i]))
using (FileStream fileStream2 = new FileStream(fileNames[i], FileMode.Open, FileAccess.Read, FileShare.Read, bufferSize))
{
string value = BitConverter.ToString(md.ComputeHash(fileStream2)).Replace("-", "");
this.Invoke((MethodInvoker)delegate()
{
bool flag2 = this.dgvMD5.Rows[i].Cells[2].Value.ToString() != "";
if (flag2)
{
this.dgvMD5.Rows[i].Cells[1].Value = this.dgvMD5.Rows[i].Cells[2].Value;
}
this.labelItem.Text = (i + 1).ToString();
this.progressBarStatus.Value = i + 1;
this.dgvMD5.Rows[i].Cells[2].Value = value;
this.dgvMD5.Rows[i].Cells[3].Value = "OK";
});
md5hash = BitConverter.ToString(md.ComputeHash(fileStream2)).Replace("-", "");
}
}
this.Invoke((MethodInvoker)delegate()
{
bool flag2 = this.dgvMD5.Rows[i].Cells[2].Value.ToString() != "";
if (flag2)
{
this.dgvMD5.Rows[i].Cells[1].Value = this.dgvMD5.Rows[i].Cells[2].Value;
}
this.labelItem.Text = (i + 1).ToString();
this.progressBarStatus.Value = i + 1;
this.dgvMD5.Rows[i].Cells[2].Value = md5hash;
this.dgvMD5.Rows[i].Cells[3].Value = "OK";
});
}
}
this.Invoke((MethodInvoker)delegate()
Expand All @@ -154,16 +156,18 @@ private void checkMD5(string[] fileNames)
foreach (string name in fileNames)
{
string md5hash = "";
long fileSize = new FileInfo(name).Length;
int bufferSize = fileSize > 1048576L ? 1048576 : 4096;
using (MD5 md = MD5.Create())
{
using (FileStream fileStream = File.OpenRead(name))
using (FileStream fileStream = new FileStream(name, FileMode.Open, FileAccess.Read, FileShare.Read, bufferSize))
{
md5hash = BitConverter.ToString(md.ComputeHash(fileStream)).Replace("-", "");
}
}
index++;
this.Invoke((MethodInvoker)delegate()
{
index++;
this.labelItem.Text = index.ToString();
this.progressBarStatus.Value = index;
this.dgvMD5.Rows.Add(new object[] { name, md5hash, "", "idle" });
Expand Down
4 changes: 2 additions & 2 deletions MD5HashChanger/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyVersion("1.1.0.0")]
[assembly: AssemblyFileVersion("1.1.0.0")]

0 comments on commit e792607

Please sign in to comment.