public static string FetchThirdPartyModdesc(string name) { using var wc = new ShortTimeoutWebClient(); string moddesc = wc.DownloadStringAwareOfEncoding(ThirdPartyModDescURL + name); return(moddesc); }
public static string FetchExeTransform(string name) { using var wc = new ShortTimeoutWebClient(); string moddesc = wc.DownloadStringAwareOfEncoding(ExeTransformBaseURL + name); return(moddesc); }
public static string FetchRemoteString(string url) { try { using var wc = new ShortTimeoutWebClient(); return(wc.DownloadStringAwareOfEncoding(url)); } catch (Exception e) { Log.Error("Error downloading string: " + e.Message); return(null); } }
public static string FetchRemoteString(string url, string authorizationToken = null) { try { using var wc = new ShortTimeoutWebClient(); if (authorizationToken != null) { wc.Headers.Add(@"Authorization", authorizationToken); } return(wc.DownloadStringAwareOfEncoding(url)); } catch (Exception e) { Log.Error(@"Error downloading string: " + e.Message); return(null); } }
public static Dictionary <string, string> QueryModRelay(string md5, long size) { //Todo: Finish implementing relay service string finalRelayURL = $"{ModInfoRelayEndpoint}?modmanagerversion={App.BuildNumber}&md5={md5.ToLowerInvariant()}&size={size}"; try { using (var wc = new ShortTimeoutWebClient()) { Debug.WriteLine(finalRelayURL); string json = wc.DownloadStringAwareOfEncoding(finalRelayURL); //todo: Implement response format serverside return(JsonConvert.DeserializeObject <Dictionary <string, string> >(json)); } } catch (Exception e) { Log.Error("Error querying relay service from ME3Tweaks: " + App.FlattenException(e)); } return(null); }
public static Dictionary <string, CaseInsensitiveDictionary <List <BasegameFileIdentificationService.BasegameCloudDBFile> > > FetchBasegameFileIdentificationServiceManifest(bool overrideThrottling = false) { Log.Information(@"Fetching basegame file identification manifest"); //read cached first. string cached = null; if (File.Exists(Utilities.GetBasegameIdentificationCacheFile())) { try { cached = File.ReadAllText(Utilities.GetBasegameIdentificationCacheFile()); } catch (Exception e) { var attachments = new List <ErrorAttachmentLog>(); string log = LogCollector.CollectLatestLog(true); if (log != null && log.Length < ByteSizeLib.ByteSize.BytesInMegaByte * 7) { attachments.Add(ErrorAttachmentLog.AttachmentWithText(log, @"applog.txt")); } Crashes.TrackError(e, new Dictionary <string, string>() { { @"Error type", @"Error reading cached online content" }, { @"Service", @"Basegame File Identification Service" }, { @"Message", e.Message } }, attachments.ToArray()); } } if (!File.Exists(Utilities.GetBasegameIdentificationCacheFile()) || overrideThrottling || OnlineContent.CanFetchContentThrottleCheck()) { var urls = new[] { BasegameFileIdentificationServiceURL, BasegameFileIdentificationServiceBackupURL }; foreach (var staticurl in urls) { Uri myUri = new Uri(staticurl); string host = myUri.Host; try { using var wc = new ShortTimeoutWebClient(); string json = wc.DownloadStringAwareOfEncoding(staticurl); File.WriteAllText(Utilities.GetBasegameIdentificationCacheFile(), json); return(JsonConvert.DeserializeObject <Dictionary <string, CaseInsensitiveDictionary <List <BasegameFileIdentificationService.BasegameCloudDBFile> > > >(json)); } catch (Exception e) { //Unable to fetch latest help. Log.Error($"Error fetching online basegame file identification service from endpoint {host}: {e.Message}"); } } if (cached == null) { Log.Error("Unable to load basegame file identification service and local file doesn't exist. Returning a blank copy."); Dictionary <string, CaseInsensitiveDictionary <List <BasegameFileIdentificationService.BasegameCloudDBFile> > > d = new Dictionary <string, CaseInsensitiveDictionary <List <BasegameFileIdentificationService.BasegameCloudDBFile> > > { ["ME1"] = new CaseInsensitiveDictionary <List <BasegameFileIdentificationService.BasegameCloudDBFile> >(), ["ME2"] = new CaseInsensitiveDictionary <List <BasegameFileIdentificationService.BasegameCloudDBFile> >(), ["ME3"] = new CaseInsensitiveDictionary <List <BasegameFileIdentificationService.BasegameCloudDBFile> >() }; return(d); } } Log.Information("Using cached BGFIS instead"); try { return(JsonConvert.DeserializeObject <Dictionary <string, CaseInsensitiveDictionary <List <BasegameFileIdentificationService.BasegameCloudDBFile> > > >(cached)); } catch (Exception e) { Log.Error("Could not parse cached basegame file identification service file. Returning blank BFIS data instead. Reason: " + e.Message); return(new Dictionary <string, CaseInsensitiveDictionary <List <BasegameFileIdentificationService.BasegameCloudDBFile> > > { ["ME1"] = new CaseInsensitiveDictionary <List <BasegameFileIdentificationService.BasegameCloudDBFile> >(), ["ME2"] = new CaseInsensitiveDictionary <List <BasegameFileIdentificationService.BasegameCloudDBFile> >(), ["ME3"] = new CaseInsensitiveDictionary <List <BasegameFileIdentificationService.BasegameCloudDBFile> >() }); } }
public static Dictionary <long, List <ThirdPartyServices.ThirdPartyImportingInfo> > FetchThirdPartyImportingService(bool overrideThrottling = false) { string cached = null; if (File.Exists(Utilities.GetThirdPartyImportingCachedFile())) { try { cached = File.ReadAllText(Utilities.GetThirdPartyImportingCachedFile()); } catch (Exception e) { var attachments = new List <ErrorAttachmentLog>(); string log = LogCollector.CollectLatestLog(true); if (log != null && log.Length < ByteSizeLib.ByteSize.BytesInMegaByte * 7) { attachments.Add(ErrorAttachmentLog.AttachmentWithText(log, "applog.txt")); } Crashes.TrackError(e, new Dictionary <string, string>() { { "Error type", "Error reading cached online content" }, { "Service", "Third Party Importing Service" }, { "Message", e.Message } }, attachments.ToArray()); } } if (!File.Exists(Utilities.GetThirdPartyImportingCachedFile()) || overrideThrottling || OnlineContent.CanFetchContentThrottleCheck()) { try { using var wc = new ShortTimeoutWebClient(); string json = wc.DownloadStringAwareOfEncoding(ThirdPartyImportingServiceURL); File.WriteAllText(Utilities.GetThirdPartyImportingCachedFile(), json); return(JsonConvert.DeserializeObject <Dictionary <long, List <ThirdPartyServices.ThirdPartyImportingInfo> > >(json)); } catch (Exception e) { //Unable to fetch latest help. Log.Error("Error fetching latest importing service file: " + e.Message); if (cached != null) { Log.Warning("Using cached third party importing service file instead"); } else { Log.Error("Unable to fetch latest third party importing service file from server and local file doesn't exist. Returning a blank copy."); return(new Dictionary <long, List <ThirdPartyServices.ThirdPartyImportingInfo> >()); } } } try { return(JsonConvert.DeserializeObject <Dictionary <long, List <ThirdPartyServices.ThirdPartyImportingInfo> > >(cached)); } catch (Exception e) { Log.Error("Unable to parse cached importing service file: " + e.Message); return(new Dictionary <long, List <ThirdPartyServices.ThirdPartyImportingInfo> >()); } }
public static List <IntroTutorial.TutorialStep> FetchTutorialManifest(bool overrideThrottling = false) { Log.Information(@"Fetching tutorial manifest"); string cached = null; // Read cached first. if (File.Exists(Utilities.GetTutorialServiceCacheFile())) { try { cached = File.ReadAllText(Utilities.GetTutorialServiceCacheFile()); } catch (Exception e) { var attachments = new List <ErrorAttachmentLog>(); string log = LogCollector.CollectLatestLog(true); if (log != null && log.Length < FileSize.MebiByte * 7) { attachments.Add(ErrorAttachmentLog.AttachmentWithText(log, @"applog.txt")); } Crashes.TrackError(e, new Dictionary <string, string>() { { @"Error type", @"Error reading cached online content" }, { @"Service", @"Tutorial Service" }, { @"Message", e.Message } }, attachments.ToArray()); } } if (!File.Exists(Utilities.GetTutorialServiceCacheFile()) || overrideThrottling || OnlineContent.CanFetchContentThrottleCheck()) { string[] urls = new[] { TutorialServiceURL, TutorialServiceBackupURL }; foreach (var staticurl in urls) { Uri myUri = new Uri(staticurl); string host = myUri.Host; try { using var wc = new ShortTimeoutWebClient(); string json = wc.DownloadStringAwareOfEncoding(staticurl); File.WriteAllText(Utilities.GetTutorialServiceCacheFile(), json); return(JsonConvert.DeserializeObject <List <IntroTutorial.TutorialStep> >(json)); } catch (Exception e) { //Unable to fetch latest help. Log.Error($@"Error fetching latest tutorial service file from endpoint {host}: {e.Message}"); } } if (cached == null) { Log.Error(@"Unable to fetch latest tutorial service file from server and local file doesn't exist. Returning a blank copy."); return(new List <IntroTutorial.TutorialStep>()); } } Log.Information(@"Using cached tutorial service file"); try { return(JsonConvert.DeserializeObject <List <IntroTutorial.TutorialStep> >(cached)); } catch (Exception e) { Log.Error(@"Unable to parse cached importing service file: " + e.Message); return(new List <IntroTutorial.TutorialStep>()); } }
public static Dictionary <string, CaseInsensitiveDictionary <ThirdPartyServices.ThirdPartyModInfo> > FetchThirdPartyIdentificationManifest(bool overrideThrottling = false) { string cached = null; if (File.Exists(Utilities.GetThirdPartyIdentificationCachedFile())) { try { cached = File.ReadAllText(Utilities.GetThirdPartyIdentificationCachedFile()); } catch (Exception e) { var attachments = new List <ErrorAttachmentLog>(); string log = LogCollector.CollectLatestLog(true); if (log != null && log.Length < FileSize.MebiByte * 7) { attachments.Add(ErrorAttachmentLog.AttachmentWithText(log, @"applog.txt")); } Crashes.TrackError(e, new Dictionary <string, string>() { { @"Error type", @"Error reading cached online content" }, { @"Service", @"Third Party Identification Service" }, { @"Message", e.Message } }, attachments.ToArray()); } } if (!File.Exists(Utilities.GetThirdPartyIdentificationCachedFile()) || overrideThrottling || OnlineContent.CanFetchContentThrottleCheck()) { try { using var wc = new ShortTimeoutWebClient(); string json = wc.DownloadStringAwareOfEncoding(ThirdPartyIdentificationServiceURL); File.WriteAllText(Utilities.GetThirdPartyIdentificationCachedFile(), json); return(JsonConvert.DeserializeObject <Dictionary <string, CaseInsensitiveDictionary <ThirdPartyServices.ThirdPartyModInfo> > >(json)); } catch (Exception e) { //Unable to fetch latest help. Log.Error(@"Error fetching online third party identification service: " + e.Message); if (cached != null) { Log.Warning(@"Using cached third party identification service file instead"); } else { Log.Error(@"Unable to load third party identification service and local file doesn't exist. Returning a blank copy."); Dictionary <string, CaseInsensitiveDictionary <ThirdPartyServices.ThirdPartyModInfo> > d = new Dictionary <string, CaseInsensitiveDictionary <ThirdPartyServices.ThirdPartyModInfo> > { [@"ME1"] = new CaseInsensitiveDictionary <ThirdPartyServices.ThirdPartyModInfo>(), [@"ME2"] = new CaseInsensitiveDictionary <ThirdPartyServices.ThirdPartyModInfo>(), [@"ME3"] = new CaseInsensitiveDictionary <ThirdPartyServices.ThirdPartyModInfo>() }; return(d); } } } try { return(JsonConvert.DeserializeObject <Dictionary <string, CaseInsensitiveDictionary <ThirdPartyServices.ThirdPartyModInfo> > >(cached)); } catch (Exception e) { Log.Error(@"Could not parse cached third party identification service file. Returning blank TPMI data instead. Reason: " + e.Message); return(new Dictionary <string, CaseInsensitiveDictionary <ThirdPartyServices.ThirdPartyModInfo> > { [@"ME1"] = new CaseInsensitiveDictionary <ThirdPartyServices.ThirdPartyModInfo>(), [@"ME2"] = new CaseInsensitiveDictionary <ThirdPartyServices.ThirdPartyModInfo>(), [@"ME3"] = new CaseInsensitiveDictionary <ThirdPartyServices.ThirdPartyModInfo>() }); } }
public static Dictionary <string, CaseInsensitiveDictionary <List <BasegameFileIdentificationService.BasegameCloudDBFile> > > FetchBasegameFileIdentificationServiceManifest(bool overrideThrottling = false) { string cached = null; if (File.Exists(Utilities.GetBasegameIdentificationCacheFile())) { try { cached = File.ReadAllText(Utilities.GetBasegameIdentificationCacheFile()); } catch (Exception e) { var attachments = new List <ErrorAttachmentLog>(); string log = LogCollector.CollectLatestLog(true); if (log.Length < ByteSizeLib.ByteSize.BytesInMegaByte * 7) { attachments.Add(ErrorAttachmentLog.AttachmentWithText(log, "applog.txt")); } Crashes.TrackError(e, new Dictionary <string, string>() { { "Error type", "Error reading cached online content" }, { "Service", "Basegame File Identification Service" }, { "Message", e.Message } }, attachments.ToArray()); } } if (!File.Exists(Utilities.GetBasegameIdentificationCacheFile()) || overrideThrottling || Utilities.CanFetchContentThrottleCheck()) { try { using var wc = new ShortTimeoutWebClient(); string json = wc.DownloadStringAwareOfEncoding(BasegameFileIdentificationServiceURL); File.WriteAllText(Utilities.GetBasegameIdentificationCacheFile(), json); return(JsonConvert.DeserializeObject <Dictionary <string, CaseInsensitiveDictionary <List <BasegameFileIdentificationService.BasegameCloudDBFile> > > >(json)); } catch (Exception e) { //Unable to fetch latest help. Log.Error("Error fetching online basegame file identification service: " + e.Message); if (cached != null) { Log.Warning("Using cached basegame file identification service file instead"); } else { Log.Error("Unable to load basegame file identification service and local file doesn't exist. Returning a blank copy."); Dictionary <string, CaseInsensitiveDictionary <List <BasegameFileIdentificationService.BasegameCloudDBFile> > > d = new Dictionary <string, CaseInsensitiveDictionary <List <BasegameFileIdentificationService.BasegameCloudDBFile> > > { ["ME1"] = new CaseInsensitiveDictionary <List <BasegameFileIdentificationService.BasegameCloudDBFile> >(), ["ME2"] = new CaseInsensitiveDictionary <List <BasegameFileIdentificationService.BasegameCloudDBFile> >(), ["ME3"] = new CaseInsensitiveDictionary <List <BasegameFileIdentificationService.BasegameCloudDBFile> >() }; return(d); } } } try { return(JsonConvert.DeserializeObject <Dictionary <string, CaseInsensitiveDictionary <List <BasegameFileIdentificationService.BasegameCloudDBFile> > > >(cached)); } catch (Exception e) { Log.Error("Could not parse cached basegame file identification service file. Returning blank BFIS data instead. Reason: " + e.Message); return(new Dictionary <string, CaseInsensitiveDictionary <List <BasegameFileIdentificationService.BasegameCloudDBFile> > > { ["ME1"] = new CaseInsensitiveDictionary <List <BasegameFileIdentificationService.BasegameCloudDBFile> >(), ["ME2"] = new CaseInsensitiveDictionary <List <BasegameFileIdentificationService.BasegameCloudDBFile> >(), ["ME3"] = new CaseInsensitiveDictionary <List <BasegameFileIdentificationService.BasegameCloudDBFile> >() }); } }