Skip to content

Commit

Permalink
Update: cleanup old dll/exe
Browse files Browse the repository at this point in the history
  • Loading branch information
meee1 committed Jul 25, 2018
1 parent 0ad7d7f commit 8bfa8a5
Showing 1 changed file with 36 additions and 19 deletions.
55 changes: 36 additions & 19 deletions Utilities/Update.cs
Original file line number Diff line number Diff line change
Expand Up @@ -267,34 +267,52 @@ static void CheckMD5(IProgressReporterDialogue frmProgressReporter, string md5ur

if (regex.IsMatch(responseFromServer))
{
// background md5
List<Tuple<string, string, Task<bool>>> tasklist = new List<Tuple<string, string, Task<bool>>>();

if (frmProgressReporter != null)
frmProgressReporter.UpdateProgressAndStatus(-1,"Hashing Files");

// cleanup dll's with the same exe name
var dlls = Directory.GetFiles(Settings.GetRunningDirectory(), "*.dll");
var exes = Directory.GetFiles(Settings.GetRunningDirectory(), "*.exe");
var dlls = Directory.GetFiles(Settings.GetRunningDirectory(), "*.dll", SearchOption.TopDirectoryOnly);
var exes = Directory.GetFiles(Settings.GetRunningDirectory(), "*.exe", SearchOption.TopDirectoryOnly);
List<string> files = new List<string>();

// hash everything
MatchCollection matchs = regex.Matches(responseFromServer);
for (int i = 0; i < matchs.Count; i++)
{
string hash = matchs[i].Groups[1].Value.ToString();
string file = matchs[i].Groups[2].Value.ToString();

files.Add(file);
}

// cleanup unused dlls and exes
dlls.ForEach(dll =>
{
exes.ForEach(exe =>
try
{
if (Path.GetFileNameWithoutExtension(dll.ToLower())
.Equals(Path.GetFileNameWithoutExtension(exe.ToLower())))
{
try
{
File.Delete(dll);
} catch { }
return;
}
});
var result = files.Any(task => Path.Combine(Settings.GetRunningDirectory(), task).ToLower().Equals(dll.ToLower()));
if (result == false)
File.Delete(dll);
}
catch { }
});

// hash everything
MatchCollection matchs = regex.Matches(responseFromServer);
exes.ForEach(exe =>
{
try
{
var result = files.Any(task => Path.Combine(Settings.GetRunningDirectory(), task).ToLower().Equals(exe.ToLower()));
if (result == false)
File.Delete(exe);
}
catch { }
});

// background md5
List<Tuple<string, string, Task<bool>>> tasklist = new List<Tuple<string, string, Task<bool>>>();

for (int i = 0; i < matchs.Count; i++)
{
string hash = matchs[i].Groups[1].Value.ToString();
Expand All @@ -304,7 +322,6 @@ static void CheckMD5(IProgressReporterDialogue frmProgressReporter, string md5ur

tasklist.Add(new Tuple<string, string, Task<bool>>(file, hash, ismatch));
}

// get count and wait for all hashing to be done
int count = tasklist.Count(a =>
{
Expand Down

0 comments on commit 8bfa8a5

Please sign in to comment.