//////////////// public void LoadModListAsync() { //Task.Run( () => { ThreadPool.QueueUserWorkItem(_ => { this.IsPopulatingList = true; lock (UIControlPanel.ModDataListLock) { this.ModDataList.Clear(); } int i = 1; foreach (var mod in ModHelpers.GetAllMods()) { UIModData moditem = this.CreateModListItem(i++, mod); lock (UIControlPanel.ModDataListLock) { this.ModDataList.Add(moditem); } //if( ModMetaDataManager.HasGithub( moditem.Mod ) ) { moditem.CheckForNewVersionAsync(); } this.ModListUpdateRequired = true; this.IsPopulatingList = false; }); }
public static void ReportIssue(Mod mod, string issue_title, string issue_body, Action <string> on_success, Action <Exception, string> on_error, Action on_completion = null) { if (!ModMetaDataManager.HasGithub(mod)) { throw new Exception("Mod is not eligable for submitting issues."); } int max_lines = HamstarHelpersMod.Instance.Config.ModIssueReportErrorLogMaxLines; IEnumerable <Mod> mods = ModHelpers.GetAllMods(); string body_info = string.Join("\n \n", InfoHelpers.GetGameData(mods).ToArray()); string body_errors = string.Join("\n", InfoHelpers.GetErrorLog(max_lines).ToArray()); string url = "http://hamstar.pw/hamstarhelpers/issue_submit/"; string title = "In-game: " + issue_title; string body = body_info; body += "\n \n \n \n" + "Recent error logs:\n```\n" + body_errors + "\n```"; body += "\n \n" + issue_body; var json = new GithubModIssueReportData { githubuser = ModMetaDataManager.GetGithubUserName(mod), githubproject = ModMetaDataManager.GetGithubProjectName(mod), title = title, body = body }; string json_str = JsonConvert.SerializeObject(json, Formatting.Indented); byte[] json_bytes = Encoding.UTF8.GetBytes(json_str); Action <String> on_response = (output) => { JObject resp_json = JObject.Parse(output); //JToken data = resp_json.SelectToken( "Data.html_url" ); JToken msg = resp_json.SelectToken("Msg"); /*if( data != null ) { * string post_at_url = data.ToObject<string>(); * if( !string.IsNullOrEmpty( post_at_url ) ) { * SystemHelpers.Start( post_at_url ); * } * }*/ if (msg == null) { on_success("Failure."); } else { on_success(msg.ToObject <string>()); } }; NetHelpers.NetHelpers.MakePostRequestAsync(url, json_bytes, on_response, on_error, on_completion); }
//////////////// public override void Action(CommandCaller caller, string input, string[] args) { IList <Mod> mods = ModHelpers.GetAllMods().ToList(); int arg_idx = 1; string title = CommandsHelpers.GetQuotedStringFromArgsAt(args, arg_idx, out arg_idx); if (arg_idx == -1) { caller.Reply("Invalid issue report title string", Color.Red); return; } string body = CommandsHelpers.GetQuotedStringFromArgsAt(args, arg_idx, out arg_idx); if (arg_idx == -1) { caller.Reply("Invalid issue report description string", Color.Red); return; } int mod_idx; if (!int.TryParse(args[0], out mod_idx)) { caller.Reply(args[arg_idx] + " is not an integer", Color.Red); return; } if (mod_idx <= 0 || mod_idx > mods.Count) { caller.Reply(args[arg_idx] + " is not a mod entry; out of range", Color.Red); return; } Action <string> on_success = delegate(string output) { if (output != "Done?") { caller.Reply(output, Color.GreenYellow); } else { caller.Reply("Issue report was not sent", Color.Red); } }; Action <Exception, string> on_fail = (e, output) => { caller.Reply(e.Message, Color.Red); }; GithubModIssueReports.ReportIssue(mods[mod_idx - 1], title, body, on_success, on_fail); }