public static void InstallAddIns(List<string> disabled)
{
if (!Directory.Exists(addInInstallTemp))
return;
LoggingService.Info("AddInManager.InstallAddIns started");
if (!Directory.Exists(userAddInPath))
Directory.CreateDirectory(userAddInPath);
string removeFile = Path.Combine(addInInstallTemp, "remove.txt");
bool allOK = true;
List<string> notRemoved = new List<string>();
if (File.Exists(removeFile)) {
using (StreamReader r = new StreamReader(removeFile)) {
string addInName;
while ((addInName = r.ReadLine()) != null) {
addInName = addInName.Trim();
if (addInName.Length == 0)
continue;
string targetDir = Path.Combine(userAddInPath, addInName);
if (!UninstallAddIn(disabled, addInName, targetDir)) {
notRemoved.Add(addInName);
allOK = false;
}
}
}
if (notRemoved.Count == 0) {
LoggingService.Info("Deleting remove.txt");
File.Delete(removeFile);
} else {
LoggingService.Info("Rewriting remove.txt");
using (StreamWriter w = new StreamWriter(removeFile)) {
notRemoved.ForEach(w.WriteLine);
}
}
}
foreach (string sourceDir in Directory.GetDirectories(addInInstallTemp)) {
string addInName = Path.GetFileName(sourceDir);
string targetDir = Path.Combine(userAddInPath, addInName);
if (notRemoved.Contains(addInName)) {
LoggingService.Info("Skipping installation of " + addInName + " because deinstallation failed.");
continue;
}
if (UninstallAddIn(disabled, addInName, targetDir)) {
LoggingService.Info("Installing " + addInName + "...");
Directory.Move(sourceDir, targetDir);
} else {
allOK = false;
}
}
if (allOK) {
try {
Directory.Delete(addInInstallTemp, false);
} catch (Exception ex) {
LoggingService.Warn("Error removing install temp", ex);
}
}
LoggingService.Info("AddInManager.InstallAddIns finished");
}