} // end callParentUpdateCache private async Task <repoParentData> returnParentRepoData(string uri, IProgress <taskProgressMsg> progressMessages) { repoParentData repo = new repoParentData(); try { HttpResponseMessage webConnectorResponse = await webConnector.GetAsync(uri); if (webConnectorResponse.IsSuccessStatusCode) { string resultString = await webConnectorResponse.Content.ReadAsStringAsync(); repo = JsonConvert.DeserializeObject <repoParentData>(resultString); } else { progressMessages.Report(new taskProgressMsg { currentMsg = "Error in returnParentRepoData: ", showAsPopup = true, exceptionContent = new HttpRequestException() }); } webConnectorResponse.Dispose(); } catch (Exception ex) { progressMessages.Report(new taskProgressMsg { currentMsg = "Error in returnParentRepoData: ", showAsPopup = true, exceptionContent = ex }); } return(repo); } // end returnParentRepoData
} // end returnChildRepoData internal async Task <bool> checkAndInstallDependencies(IProgress <taskProgressMsg> progressMessages) { try { progressMessages.Report(new taskProgressMsg { currentMsg = "Downloading/Refreshing Dependencies" }); repoParentData repoSource = new repoParentData(); HttpResponseMessage webConnectorResponse = await webConnector.GetAsync("https://raw.githubusercontent.com/JTosAddon/Addons/master/managers.json"); if (webConnectorResponse.IsSuccessStatusCode) { string resultString = await webConnectorResponse.Content.ReadAsStringAsync(); repoSource = JsonConvert.DeserializeObject <repoParentData>(resultString); } else { progressMessages.Report(new taskProgressMsg { currentMsg = "Error in returnParentRepoData: ", showAsPopup = true, exceptionContent = new HttpRequestException() }); } if (repoSource.Dependencies != null && repoSource.Dependencies.Count > 0) { foreach (Dependency q in repoSource.Dependencies) { // Currently, we will just overwrite existing files since there isn't recorded version information. string depFilename = System.IO.Path.GetFileName(q.Url.AbsolutePath); progressMessages.Report(new taskProgressMsg { currentMsg = $"Downloading {depFilename}" }); webConnectorResponse = await webConnector.GetAsync(q.Url); if (webConnectorResponse.IsSuccessStatusCode) { System.IO.FileStream fs = new System.IO.FileStream($"{rootDir}/release/lua/{depFilename}", System.IO.FileMode.Create); await webConnectorResponse.Content.CopyToAsync(fs); fs.Close(); fs.Dispose(); } } } webConnectorResponse.Dispose(); } catch (Exception ex) { progressMessages.Report(new taskProgressMsg { currentMsg = "Dependency Download Error", exceptionContent = ex, showAsPopup = true }); } return(true); } // end checkAndInstallDependencies
} // end returnParentRepoData private async Task <List <addonDataFromRepo> > returnAddonData(repoParentData repo, IProgress <taskProgressMsg> progressMessages) { List <addonDataFromRepo> addonCollection = new List <addonDataFromRepo>(); try { foreach (Source repoSource in repo.Sources) { progressMessages.Report(new taskProgressMsg { currentMsg = $"Checking Addons at repo: {repoSource.Repo}" }); // Pull Atom data before hitting repo, so we can attempt to match Atom(XML) data with the release(JSON) data from Github. List <atomDataResult> atomData = returnAtomData(repoSource.Repo, progressMessages); List <addonDataFromRepo> foo = await returnChildRepoData(repoSource.Repo, atomData, progressMessages); addonCollection = addonCollection.Concat(foo).ToList(); } } catch (Exception ex) { progressMessages.Report(new taskProgressMsg { currentMsg = "Error in returnAddonData", showAsPopup = true, exceptionContent = ex }); } return(addonCollection); } // end returnAddonData
internal async Task <List <addonDataFromRepo> > callParentUpdateCache(IProgress <taskProgressMsg> progressMessages, int mode) { List <addonDataFromRepo> addonCollection = new List <addonDataFromRepo>(); try { switch (mode) { case 0: progressMessages.Report(new taskProgressMsg { currentMsg = "Checking iToS Addons" }); repoParentData iToSRepo = await returnParentRepoData("https://raw.githubusercontent.com/JTosAddon/Addons/itos/managers.json", progressMessages); addonCollection = await returnAddonData(iToSRepo, progressMessages); break; case 1: progressMessages.Report(new taskProgressMsg { currentMsg = "Checking jToS Addons" }); repoParentData jToSRepo = await returnParentRepoData("https://raw.githubusercontent.com/JTosAddon/Addons/master/managers.json", progressMessages); addonCollection = await returnAddonData(jToSRepo, progressMessages); break; } } catch (Exception ex) { progressMessages.Report(new taskProgressMsg { currentMsg = "Error in callParentUpdateCache", showAsPopup = true, exceptionContent = ex }); } progressMessages.Report(new taskProgressMsg { currentMsg = "Completed Cache Update" }); return(addonCollection); } // end callParentUpdateCache