public ActionResult Index(SteamViewModel model) { string nfo = null; if (model.File != null && model.File.ContentLength > 0) { string path = System.IO.Path.Combine(System.IO.Path.GetTempPath(), System.IO.Path.GetTempFileName()); path = System.IO.Path.ChangeExtension(path, "nfo"); model.File.SaveAs(path); nfo = System.IO.File.ReadAllText(path); System.IO.File.Delete(path); } else if (!string.IsNullOrWhiteSpace(model.Text)) { nfo = model.Text; } if (string.IsNullOrWhiteSpace(nfo)) { ModelState.AddModelError("Error", "Must provide a file or put nfo content in textarea !"); return(View()); } string data = nfo.RemoveNonAscii(); string steamUrl = SteamManager.ExtractUrlFromString(data)?.TrimEnd('/'); if (string.IsNullOrWhiteSpace(steamUrl)) { ModelState.AddModelError("Error", "No steam url is found !"); return(View()); } var steamId = steamUrl.Split('/').Last(); SteamModel sm = SteamManager.LoadGameById(steamId); model.Result = sm.Data.Detailed_description; return(View(model)); }
private void btnGetData_Click(object sender, EventArgs e) { string steamUrl = txtSteamUrl.Text; if (string.IsNullOrWhiteSpace(steamUrl)) { MessageBox.Show("No steam url is provided"); return; } try { string steamId = SteamManager.GetId(steamUrl); if (string.IsNullOrWhiteSpace(steamId)) { MessageBox.Show("No id found !"); return; } SteamModel model = SteamManager.LoadGameById(steamId); if (!model.Success) { MessageBox.Show("No game found on steam"); return; } string screens = model.Data.Screenshots?.Length == 0 ? string.Empty : string.Join(" ", model.Data.Screenshots.Select(s => $"[url={s.Path_full.WithoutQueryString()}][img={s.Path_thumbnail.WithoutQueryString()}][/url]")); string video = YoutubeManager.GetVideoByKeyword(model.Data.Name); if (!string.IsNullOrWhiteSpace(video)) { video = $"[video={video}]"; } _gameGenre = string.Join(", ", model.Data.Genres.Select(g => g.Description)); IDictionary <string, string> dict = new Dictionary <string, string> { { "poster", $"[img={model.Data.Header_image.WithoutQueryString()}]" }, { "title", $"[size=4]{model.Data.Name}[/size]" }, { "genre", string.IsNullOrWhiteSpace(_gameGenre) ? string.Empty : $"[size=2]Genre: [color=orange]{string.Join(", ", model.Data.Genres.Select(g=>g.Description))}[/color][/size]" }, { "description", model.Data.Short_description.ToBbcode() }, { "pc_requirements", model.Data.Pc_requirements.Minimum.ToBbcode() }, { "screenshots", screens }, { "youtube", video }, { "url", $"http://store.steampowered.com/app/{model.Data.Steam_appid}/" } }; txtResult.Text = TemplateManager.RenderTemplate(dict); } catch (TemplateException templEx) { MessageBox.Show(templEx.Message); } catch (Exception ex) { Debug.WriteLine(ex.Message); MessageBox.Show("An error occurred"); } }