public bool Add(string addonName) { addonName = addonName.ToLower(); if (!AptL.IsInstalled(addonName)) { return(false); } Queue.Add(addonName); // don't delete dependencies if (!AptEnv.FetchRequiredDeps) { return(true); } // add unused dependencies to remove queue RepositoryAddonInfo info = AptRepo.GetAddonInfo(addonName); if (info.RequiredDeps != null) { // fetch list of needed dependencies List <string> usedDependecies = new List <string>(); foreach (LocalAddonInfo depInfo in AptL) { if (depInfo.Name.ToLower() != addonName) { List <string> deps = AptRepo.GetAddonInfo(depInfo.Name).RequiredDeps; if (deps != null) { foreach (string dependency in deps) { if (!usedDependecies.Contains(dependency.ToLower())) { usedDependecies.Add(dependency.ToLower()); } } } } } foreach (string dependency in info.RequiredDeps) { string name = dependency.ToLower(); if (!usedDependecies.Contains(name) && AptL.IsInstalled(name)) { Queue.Add(name); } } } return(true); }
// code borrowed from CmdAceUpdater courtesy of lys // http://www.wowace.com/forums/index.php?topic=4778.0 public bool DownloadZip(RepositoryAddonInfo addonInfo) { using (WebClient client = GetWebClient()) { SendDebugMessage("remote.download.zip", addonInfo.Name, addonInfo.EnclosureUrl); try { string saveTo = Path.Combine(AptEnv.AptZipPath, addonInfo.ZipFileName); client.DownloadFile(addonInfo.EnclosureUrl, saveTo); SendDebugMessage("remote.download.zip.success", addonInfo.Name, saveTo); return(true); } catch (WebException e) { SendDebugMessage("remote.download.zip.failed", addonInfo.Name, addonInfo.EnclosureUrl, e.Message); return(false); } } }
public int Prepare() { UpdateQueue = new List <string>(); bool usePatterns = NamePatterns.Count > 0; foreach (LocalAddonInfo local in AptL) { string name = local.Name.ToLower(); bool match = false; SendDebugMessage("upgrade.prepare", name); // excluded? if (ExcludedAddons.Contains(name)) { SendDebugMessage("upgrade.prepare.excluded", name); continue; } // use name patterns? if (usePatterns) { for (int i = 0; i < NamePatterns.Count; ++i) { // * if (NamePatterns[i].Contains("*")) { if (name.Contains(NamePatterns[i].Replace("*", ""))) { match = true; SendDebugMessage("upgrade.prepare.pattern.match", name, NamePatterns[i]); break; } } else { if (name == NamePatterns[i]) { match = true; SendDebugMessage("upgrade.prepare.pattern.match", name, NamePatterns[i]); break; } } } } // addon doesn't match -> next one if (usePatterns && !match) { SendDebugMessage("upgrade.prepare.pattern.nomatch", name); continue; } // check if it's a module of some addon RepositoryAddonInfo update = AptRepo.GetAddonInfo(name); string parent = AptL.IsModule(local.Name); // if it's a module, add parent to queue if (parent != null) { SendDebugMessage("upgrade.prepare.ismodule", name, parent); // addon in repository? if (!AptRepo.IsAddonInRepository(parent)) { SendDebugMessage("upgrade.prepare.parent.notinrepo", parent); SendStatus("notinrepo"); continue; } // no new version -> next one if (AptL.GetAddonInfo(parent).Version >= AptRepo.GetAddonInfo(parent).Version) { SendDebugMessage("upgrade.prepare.parent.noewnewversion", parent); SendStatus("nonewversion"); continue; } AddToQueue(parent); } else { // addon in repository? if (!AptRepo.IsAddonInRepository(name)) { SendDebugMessage("upgrade.prepare.notinrepo", name); SendStatus("notinrepo"); continue; } // no new version -> next one if (local.Version >= update.Version) { SendDebugMessage("upgrade.prepare.nonewversion", name); SendStatus("nonewversion"); continue; } AddToQueue(name); } // fetch dependencies? if (!AptEnv.UseExternals && AptEnv.FetchRequiredDeps) { SendDebugMessage("upgrade.prepare.dependencies.resolve" + name); SendStatus("resolvedeps"); if (update.RequiredDeps != null) { bool depError = false; for (int i = 0; i < update.RequiredDeps.Count; ++i) { if (AptRepo.IsAddonInRepository(update.RequiredDeps[i])) { SendDebugMessage("upgrade.prepare.dependencies.add", update.RequiredDeps[i]); AddDependency(update.RequiredDeps[i]); } else { SendDebugMessage("upgrade.prepare.dependencies.unresolved", update.RequiredDeps[i]); UnresolvedDeps.Add(update.RequiredDeps[i]); depError = true; } } if (depError) { SendStatus("unresolveddeps"); } } else { SendDebugMessage("upgrade.prepare.dependencies.nodeps"); SendStatus("nodeps"); } } } return(UpdateQueue.Count + DependencyQueue.Count); }
public bool Install(string addonName, bool skipDependencies) { RepositoryAddonInfo info = AptRepo.GetAddonInfo(addonName); SendStatus("install", info.Name); bool success = false; // remove old if (AptL.IsInstalled(addonName)) { SendStatus("uninstall"); if (AptL.Uninstall(addonName)) { SendStatus("uninstall.success"); } else { SendStatus("uninstall.failed"); } } // download zip string zipFile = Path.Combine(AptEnv.AptZipPath, info.ZipFileName); if (!File.Exists(zipFile)) { SendStatus("zip.download"); if (AptR.DownloadZip(info)) { SendStatus("zip.download.success"); } else { SendStatus("zip.download.failed"); } } else { SendStatus("zip.cache"); } // install locally SendStatus("zip.extract"); if (AptL.Install(zipFile)) { SendStatus("install.success"); success = true; } else { SendStatus("install.failed"); } // use externals? if not, shall we download the deps? if (!skipDependencies && !AptEnv.UseExternals && AptEnv.FetchRequiredDeps) { bool successDeps = true; SendStatus("install.dependencies"); if (info.RequiredDeps != null) { for (int i = 0; i < info.RequiredDeps.Count; ++i) { SendDebugMessage("install.dependency", info.RequiredDeps[i]); // dep not in repository -> skip if (!AptRepo.IsAddonInRepository(info.RequiredDeps[i])) { continue; } // already installed? check version if (AptL.IsInstalled(info.RequiredDeps[i])) { if (AptL.GetAddonInfo(info.RequiredDeps[i]).Version >= AptRepo.GetAddonInfo(info.RequiredDeps[i]).Version) { continue; } } if (Install(info.RequiredDeps[i], true)) { SendStatus("install.dependency.success", info.RequiredDeps[i]); } else { SendStatus("install.dependency.failed", info.RequiredDeps[i]); successDeps = false; } } SendStatus("install.dependencies.finished", successDeps.ToString()); } else { SendStatus("install.dependencies.none"); } } // unpack? if (AptEnv.UnpackPackages) { SendStatus("unpack"); if (AptL.IsPackage(addonName)) { if (AptL.Unpack(addonName)) { SendStatus("unpack.success"); } else { SendStatus("unpack.failed"); } } else { SendStatus("unpack.nopackage"); } } // remove zip file? if (!AptEnv.KeepZips) { SendStatus("clear"); try { File.Delete(Path.Combine(AptEnv.AptZipPath, info.ZipFileName)); SendStatus("clear.success"); } catch (IOException e) { SendStatus("clear.failed"); } } if (success) { SendStatus("success"); } else { SendStatus("failed"); } return(success); }