public static String GetMainAssetName(ModType modType) { if (!mainAssets.ContainsKey(modType)) { throw new System.InvalidOperationException($"Unknown Mod Type \"{modType.ToString()}\""); } return(mainAssets[modType]); }
public static string GetModsFolder(ModType modType) { var path = Path.Combine(GetModsfolderPath(), modType.ToString()); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } return(path); }
private List <Mod> GetModList(ModType modType) { switch (modType) { case ModType.Gun: return(loadedGunMods); case ModType.LevelTile: return(loadedLevelMods); case ModType.Tapes: return(loadedTapeMods); default: throw new System.InvalidOperationException($"Unknown Mod Type \"{modType.ToString()}\""); } }
public string QueryLatestVersion(ModType modType) { try { string responseJson = WebClient.DownloadString($"{ApiUrl}/version/{modType.ToString().ToLowerInvariant()}"); var modVersion = JsonConvert.DeserializeObject <ModVersion>(responseJson); return(modVersion.Version); } catch (WebException ex) { var httpWebResponse = ex.Response as HttpWebResponse; if (httpWebResponse == null) { throw new ApiRequestFailedException("Failed to query the api: " + ex.Message, ex); } if (httpWebResponse.StatusCode != HttpStatusCode.BadRequest) { throw new ApiRequestFailedException("Failed to query the api: " + ex.Message, ex); } using (var responseStream = httpWebResponse.GetResponseStream()) { if (responseStream == null) { throw; } byte[] responseBytes = new byte[responseStream.Length]; string responseJson = Encoding.UTF8.GetString(responseBytes); ErrorResponse errorResponse = JsonConvert.DeserializeObject <ErrorResponse>(responseJson); if (errorResponse.Error != null) { throw new ApiRequestFailedException(errorResponse.Error, ex); } throw new ApiRequestFailedException("Failed to query the api: " + ex.Message, ex); } } catch (Exception ex) { throw new ApiRequestFailedException("Failed to query the api: " + ex.Message, ex); } }
public async Task DownloadFileAsync(string filePath, string targetFilePath, ModType modType, string version, Action <DownloadProgressChangedEventArgs> onProgress = null) { string directory = Path.GetDirectoryName(targetFilePath); if (directory != string.Empty && !Directory.Exists(directory)) { Directory.CreateDirectory(directory); } void ProgressChanged(object sender, DownloadProgressChangedEventArgs args) { onProgress?.Invoke(args); } WebClient.DownloadProgressChanged += ProgressChanged; string address = $"{ApiUrl}/version/{modType.ToString().ToLowerInvariant()}/{version}/file/{filePath}"; await WebClient.DownloadFileTaskAsync(address, targetFilePath); WebClient.DownloadProgressChanged -= ProgressChanged; }
public override void Initialize(GameObject go) { mod = new RPGStats.Modifier(ModType.ToString(), EffectedStat.Name, ModifiedValue); }
public ModConfig(ModType type) { name = type.ToString(); mod = type; }
public override string ToString() { return(AssociatedModData.DisplayedName + " : " + MyType.ToString().ToUpper()); }
public async Task <ModVersion> QueryLatestVersionAsync(ModType modType) { try { string responseJson = await WebClient.DownloadStringTaskAsync($"{ApiUrl}/version/{modType.ToString().ToLowerInvariant()}"); ModVersion modVersion = JsonConvert.DeserializeObject <ModVersion>(responseJson); return(modVersion); } catch (WebException ex) { var httpWebResponse = ex.Response as HttpWebResponse; if (httpWebResponse == null) { throw; } if (httpWebResponse.StatusCode != HttpStatusCode.BadRequest) { throw; } using (var responseStream = httpWebResponse.GetResponseStream()) { if (responseStream == null) { throw; } byte[] responseBytes = new byte[responseStream.Length]; string responseJson = Encoding.UTF8.GetString(responseBytes); dynamic response = JObject.Parse(responseJson); if (response.error != null) { string errorMessage = response.error; throw new ApiRequestFailedException(errorMessage, ex); } throw new ApiRequestFailedException("Failed to query the api. No error message was given.", ex); } } }