feat: delete old versions of plugins before load

This commit is contained in:
goat 2020-07-21 16:07:35 +02:00
parent 721527dd11
commit 62bd3af459
2 changed files with 59 additions and 26 deletions

View file

@ -241,5 +241,36 @@ namespace Dalamud.Plugin
return (!hasError, updatedList);
}
public void CleanupPlugins() {
try
{
var pluginsDirectory = new DirectoryInfo(this.pluginDirectory);
foreach (var installed in pluginsDirectory.GetDirectories())
{
var versions = installed.GetDirectories();
if (versions.Length == 0)
{
Log.Information("[PLUGINR] Has no versions: {0}", installed.FullName);
continue;
}
var sortedVersions = versions.OrderBy(x => int.Parse(x.Name.Replace(".", ""))).ToArray();
for (var i = 0; i < sortedVersions.Length - 1; i++) {
Log.Information("[PLUGINR] Trying to delete old {0} at ", installed.Name, sortedVersions[i].FullName);
try {
sortedVersions[i].Delete(true);
} catch (Exception ex) {
Log.Error(ex, "[PLUGINR] Could not delete old version");
}
}
}
}
catch (Exception ex)
{
Log.Error(ex, "[PLUGINR] Plugin cleanup failed.");
}
}
}
}