public DownloadedBuild Download(ComponentInfo component_info, bool force = false) { var component = TryGetComponent(component_info.Name); if (component != null) { ETGModVersion version = null; if (component_info.Version != null) { foreach (var ver in component.Versions) { if (ver.Key == component_info.Version) { version = ver; break; } } if (version == null) { throw new InstallationFailedException($"Version {component_info.Version} of component {component.Name} doesn't exist."); } } else { version = component.Versions[0]; } var dest = version.DisplayName; if (Directory.Exists(dest)) { if (force) { Directory.Delete(dest, recursive: true); } else { throw new InstallationFailedException($"Version is already downloaded in the '{dest}' folder (use --force to redownload)"); } } try { _Logger.Info($"OPERATION: Download. Target: {dest}"); var dl = _Downloader.Download(version, dest); _Logger.Info($"OPERATION COMPLETED SUCCESSFULLY"); return(dl); } catch (System.Net.WebException e) { var resp = e.Response as System.Net.HttpWebResponse; if (resp?.StatusCode == System.Net.HttpStatusCode.NotFound) { throw new InstallationFailedException($"Error 404 while downloading version {version.DisplayName} of component {component.Name}."); } else { throw new InstallationFailedException($"Unhandled error occured while downloading version {version.DisplayName} of component {component.Name}: {e.Message}."); } } } throw new InstallationFailedException($"Component {component_info.Name} doesn't exist."); }
public DownloadedBuild Download(ETGModVersion version) { if (version.URL == null && version.Path == null) { throw new ArgumentException("Version has neither a URL nor a file path"); } return(Download(version, GenerateUniqueDestination())); }
public InstallableComponent(ETGModComponent component, ETGModVersion ver, DownloadedBuild dl) : this( component.Name, ver.Key, ver.DisplayName, dl.ExtractedPath, ver.SupportedGungeon, ver.RequiresPatchedExe, Directory.GetFileSystemEntries(dl.ExtractedPath) ) { }
public void Install(IEnumerable <ComponentInfo> components, string exe_path = null) { exe_path = _GetExePath(exe_path); var real_components = new List <ComponentVersion>(); var used_components = new HashSet <ETGModComponent>(); var gungeon_version = Autodetector.GetVersionIn(exe_path); foreach (var com in components) { ETGModComponent component = _Downloader.TryGet(com.Name.Trim()); if (component != null) { if (used_components.Contains(component)) { throw new InstallationFailedException($"Duplicate {component.Name} component."); } used_components.Add(component); ETGModVersion version = null; if (com.Version == null) { version = component.Versions[0]; } else { foreach (var ver in component.Versions) { if (ver.Key == com.Version.Trim()) { version = ver; break; } } if (version == null) { throw new InstallationFailedException($"Version {com.Version} of component {com.Name} doesn't exist."); } } real_components.Add(new ComponentVersion(component, version)); } else { throw new InstallationFailedException($"Component {com.Name} doesn't exist in the list of components."); } } Install(real_components, exe_path); }
public ComponentVersion(ETGModComponent component, ETGModVersion version) { Component = component; Version = version; }
public DownloadedBuild Download(ETGModVersion version, string destination) { return(Download(version.Path ?? version.URL, destination, version.DisplayName, version.Path != null)); }