Parsing MD5 Values of existent files to determine which files are out of date
This commit is contained in:
parent
01584ad263
commit
abd5b1b98f
|
@ -32,8 +32,8 @@ namespace EZPPClient_Installer
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
string[] se = datastring.Split('#');
|
string[] se = datastring.Split('#');
|
||||||
string md5 = se[0];
|
string md5 = se[0].Replace("\r\n", "").Replace("\r", "").Replace("\n", "");
|
||||||
string name = se[1];
|
string name = se[1].Replace("\r\n", "").Replace("\r", "").Replace("\n", "");
|
||||||
md5Files.Add(new MD5File(name, md5));
|
md5Files.Add(new MD5File(name, md5));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -54,9 +54,33 @@ namespace EZPPClient_Installer
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
/*string[] files = Directory.GetFiles(pathToEZPP, "*");
|
||||||
|
foreach (var file in files)
|
||||||
|
{
|
||||||
|
|
||||||
|
}*/
|
||||||
|
foreach(MD5File md5file in md5Files)
|
||||||
|
{
|
||||||
|
string file = pathToEZPP + @"\" + md5file.getName();
|
||||||
|
bool doesExistOnPC = File.Exists(file);
|
||||||
|
if (!doesExistOnPC)
|
||||||
|
{
|
||||||
|
downloadList.Add(md5file.getName());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
string onlineHash = md5file.getMD5();
|
||||||
|
string pcHash = MD5Util.CalculateMD5(file);
|
||||||
|
if(!string.Equals(onlineHash, pcHash))
|
||||||
|
{
|
||||||
|
downloadList.Add(md5file.getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MessageBox.Show(downloadList.Count + "/" + md5Files.Count + " Files need for update");
|
||||||
|
|
||||||
return downloadList;
|
return downloadList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -76,6 +76,7 @@
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="MD5File.cs" />
|
<Compile Include="MD5File.cs" />
|
||||||
<Compile Include="DownloadUtil.cs" />
|
<Compile Include="DownloadUtil.cs" />
|
||||||
|
<Compile Include="MD5Util.cs" />
|
||||||
<Compile Include="UpdateState.cs" />
|
<Compile Include="UpdateState.cs" />
|
||||||
<Compile Include="Util.cs" />
|
<Compile Include="Util.cs" />
|
||||||
<Compile Include="MainWindow.xaml.cs">
|
<Compile Include="MainWindow.xaml.cs">
|
||||||
|
|
25
EZPPClient Installer/MD5Util.cs
Normal file
25
EZPPClient Installer/MD5Util.cs
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Security.Cryptography;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace EZPPClient_Installer
|
||||||
|
{
|
||||||
|
class MD5Util
|
||||||
|
{
|
||||||
|
public static string CalculateMD5(string filename)
|
||||||
|
{
|
||||||
|
using (var md5 = MD5.Create())
|
||||||
|
{
|
||||||
|
using (var stream = File.OpenRead(filename))
|
||||||
|
{
|
||||||
|
var hash = md5.ComputeHash(stream);
|
||||||
|
return BitConverter.ToString(hash).Replace("-", "").ToUpperInvariant();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user