93 lines
2.4 KiB
C#
93 lines
2.4 KiB
C#
using ModernWpf.Controls;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Net;
|
|
using System.Security.Cryptography;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
|
|
namespace EZPPClient_Installer
|
|
{
|
|
public class DownloadUtil
|
|
{
|
|
|
|
public static List<string> FilesToDownload(string pathToEZPP)
|
|
{
|
|
bool directoryExists = Directory.Exists(pathToEZPP);
|
|
|
|
List<string> downloadList = new List<string>();
|
|
List<MD5File> md5Files = new List<MD5File>();
|
|
|
|
try
|
|
{
|
|
|
|
using (WebClient wc = new WebClient())
|
|
{
|
|
var data = wc.DownloadString("https://ez-pp.farm/static/client/client.data");
|
|
string[] dataList = data.Split('\n');
|
|
foreach (string datastring in dataList)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(datastring))
|
|
continue;
|
|
|
|
string[] se = datastring.Split('#');
|
|
string md5 = se[0].Replace("\r\n", "").Replace("\r", "").Replace("\n", "");
|
|
string name = se[1].Replace("\r\n", "").Replace("\r", "").Replace("\n", "");
|
|
md5Files.Add(new MD5File(name, md5));
|
|
}
|
|
}
|
|
}catch(WebException error)
|
|
{
|
|
new ContentDialog()
|
|
{
|
|
Title = "Oops...",
|
|
Content = "A error occurred while trying to fetch all needed Files.\n" + error.Message,
|
|
PrimaryButtonText = "Okay"
|
|
}.ShowAsync();
|
|
}
|
|
|
|
if (!directoryExists)
|
|
{
|
|
foreach (MD5File md5File in md5Files)
|
|
downloadList.Add(md5File.getName());
|
|
}
|
|
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;
|
|
}
|
|
|
|
public async Task<bool> CheckForUpdate()
|
|
{
|
|
return false;
|
|
}
|
|
|
|
}
|
|
} |