public CompilingServices(CodeLang codeLang) { this.codeLang = codeLang; this.Parameters = new CompilerParameters(); this.filenames = new List<string>(); this.references = new List<string>(); }
public CompilingServices(CodeLang codeLang) { this.codeLang = codeLang; this.parameters = new CompilerParameters(); this.filenames = new List <string>(); this.references = new List <string>(); }
public XboxAchievements(IPlayniteAPI PlayniteApi, SuccessStorySettings settings, string PluginUserDataPath) : base(PlayniteApi, settings, PluginUserDataPath) { LocalLang = CodeLang.GetXboxLang(_PlayniteApi.ApplicationSettings.Language); liveTokensPath = Path.Combine(_PluginUserDataPath + "\\..\\7e4fbb5e-2ae3-48d4-8ba0-6b30e7a4e287", "login.json"); xstsLoginTokesPath = Path.Combine(_PluginUserDataPath + "\\..\\7e4fbb5e-2ae3-48d4-8ba0-6b30e7a4e287", "xsts.json"); }
public static ICodeFilter GetCodeFilter(CodeLang codeLang) { switch (codeLang) { case CodeLang.CSharp: return new CSharpCodeFilter(); default: throw new NotSupportedException("Do not support source filters for: " + codeLang); } }
internal static GameStoreDataResponse GetGameStoreData(string gameId, IPlayniteAPI PlayniteApi) { string lang = CodeLang.GetOriginLang(PlayniteApi.ApplicationSettings.Language); string langShort = CodeLang.GetOriginLangCountry(PlayniteApi.ApplicationSettings.Language); var url = string.Format(@"https://api2.origin.com/ecommerce2/public/supercat/{0}/{1}?country={2}", gameId, lang, langShort); string stringData = Web.DownloadStringData(url).GetAwaiter().GetResult(); return(JsonConvert.DeserializeObject <GameStoreDataResponse>(stringData)); }
public static ICodeFilter GetCodeFilter(CodeLang codeLang) { switch (codeLang) { case CodeLang.CSharp: return(new CSharpCodeFilter()); default: throw new NotSupportedException("Do not support source filters for: " + codeLang); } }
internal static GameStoreDataResponse GetGameStoreData(string gameId, IPlayniteAPI PlayniteApi) { string lang = CodeLang.GetOriginLang(Localization.GetPlayniteLanguageConfiguration(PlayniteApi.Paths.ConfigurationPath)); string langShort = CodeLang.GetOriginLangCountry(Localization.GetPlayniteLanguageConfiguration(PlayniteApi.Paths.ConfigurationPath)); var url = string.Format(@"https://api2.origin.com/ecommerce2/public/supercat/{0}/{1}?country={2}", gameId, lang, langShort); var stringData = Encoding.UTF8.GetString(HttpDownloader.DownloadData(url)); return(JsonConvert.DeserializeObject <GameStoreDataResponse>(stringData)); }
public static string GetFileExtension(CodeLang codeLang) { switch (codeLang) { case CodeLang.CSharp: return ".cs"; case CodeLang.VisualBasic: return ".vb"; default: return string.Empty; } }
public static string GetFileExtension(CodeLang codeLang) { switch (codeLang) { case CodeLang.CSharp: return FILE_EXTENSION_CSHARP; case CodeLang.VisualBasic: return FILE_EXTENSION_VISUALBASIC; default: return string.Empty; } }
public static string GetFileExtension(CodeLang codeLang) { switch (codeLang) { case CodeLang.CSharp: return(".cs"); case CodeLang.VisualBasic: return(".vb"); default: return(string.Empty); } }
public static string GetFileExtension(CodeLang codeLang) { switch (codeLang) { case CodeLang.CSharp: return(FILE_EXTENSION_CSHARP); case CodeLang.VisualBasic: return(FILE_EXTENSION_VISUALBASIC); default: return(string.Empty); } }
public async Task <WebStoreModels.ProductResponse> GetProductInfo(string productSlug, string PlayniteLanguage) { string EpicLangCountry = CodeLang.GetEpicLangCountry(PlayniteLanguage); if (PlayniteLanguage == "es_ES" || PlayniteLanguage == "zh_TW") { EpicLangCountry = CodeLang.GetEpicLang(PlayniteLanguage); } var slugUri = productSlug.Split('/').First(); var productUrl = string.Format(ProductUrlBase, slugUri, EpicLangCountry); var str = await httpClient.GetStringAsync(productUrl); return(Serialization.FromJson <WebStoreModels.ProductResponse>(str)); }
private void _btnOK_Click(object sender, EventArgs e) { if (!(_treeView.SelectedNode is TreeNodeInstType)) { return; } TreeNodeInstType node = _treeView.SelectedNode as TreeNodeInstType; _instType = node.InstrumentType; _codeLang = node.CodeEditorLang; this.DialogResult = DialogResult.OK; this.Close(); }
public static string GetSteamData(uint appId, string PlayniteLanguage) { string url = string.Empty; try { string SteamLangCode = CodeLang.GetSteamLang(PlayniteLanguage); url = $"https://store.steampowered.com/api/appdetails?appids={appId}&l={SteamLangCode}"; return(Web.DownloadStringData(url).GetAwaiter().GetResult()); } catch (Exception ex) { Common.LogError(ex, "MetadataLocal", $"Failed to load {url}"); return(string.Empty); } }
public static string GetOriginData(string gameId, string PlayniteLanguage) { string url = string.Empty; try { string OriginLang = CodeLang.GetOriginLang(PlayniteLanguage); string OriginLangCountry = CodeLang.GetOriginLangCountry(PlayniteLanguage); url = string.Format(@"https://api2.origin.com/ecommerce2/public/supercat/{0}/{1}?country={2}", gameId, OriginLang, OriginLangCountry); var stringData = Web.DownloadStringData(url).GetAwaiter().GetResult(); return(JsonConvert.DeserializeObject <GameStoreDataResponse>(stringData).i18n.longDescription); } catch (Exception ex) { Common.LogError(ex, "MetadataLocal", $"Failed to load {url}"); return(string.Empty); } }
public void FileNew() { NewInstrumentsForm form = new NewInstrumentsForm(); if (form.ShowDialog() != DialogResult.OK) { return; } InstrumentType instType = form.InstrumentType; CodeLang lang = form.CodeLang; string instName = form.InstrumentName; string codeTemplateName = ""; DirectoryInfo dir = null; if (instType == InstrumentType.Indicator) { codeTemplateName = "Indicator"; dir = Global.Setup.IndicatorsDirectory; } else if (instType == InstrumentType.Strategy) { codeTemplateName = "Strategy"; dir = Global.Setup.StrategyDirectory; } string ext = "." + (lang == CodeLang.CSharp ? "cs" : "vb"); FileInfo file = new FileInfo(Path.Combine(dir.FullName, instName + ext)); if (!file.Exists) { codeTemplateName += ext; string template = ""; FileInfo fileTemplate = new FileInfo(Path.Combine(Global.Setup.TemplateDirectory.FullName, codeTemplateName)); if (fileTemplate.Exists) { template = File.ReadAllText(fileTemplate.FullName); } File.WriteAllText(file.FullName, template); file.Refresh(); } this.FileOpen(file); }
// Override Xbox function GetTitleInfo in WebApiClient on XboxLibrary. public static async Task <string> GetXboxData(string pfn, string PlayniteLanguage, string PluginUserDataPath, MetadataLocal plugin) { var xstsLoginTokesPath = Path.Combine(PluginUserDataPath + "\\..\\7e4fbb5e-2ae3-48d4-8ba0-6b30e7a4e287", "xsts.json"); var tokens = Serialization.FromJsonFile <AuthorizationData>(xstsLoginTokesPath); using (var client = new HttpClient()) { client.DefaultRequestHeaders.Add("x-xbl-contract-version", "2"); client.DefaultRequestHeaders.Add("Authorization", $"XBL3.0 x={tokens.DisplayClaims.xui[0].uhs};{tokens.Token}"); client.DefaultRequestHeaders.Add("Accept-Language", CodeLang.GetEpicLang(PlayniteLanguage)); var requestData = new Dictionary <string, List <string> > { { "pfns", new List <string> { pfn } }, { "windowsPhoneProductIds", new List <string>() }, }; var response = await client.PostAsync( @"https://titlehub.xboxlive.com/titles/batch/decoration/detail", new StringContent(Serialization.ToJson(requestData), Encoding.UTF8, "application/json")); if (response.StatusCode != System.Net.HttpStatusCode.OK) { logger.Warn("Metadatalocal - Xbox user is not connected"); plugin.PlayniteApi.Notifications.Add(new NotificationMessage( $"metadalocal-xbox-error", "Xbox - " + resources.GetString("LOCNotLoggedIn"), NotificationType.Error )); return(string.Empty); } else { var cont = await response.Content.ReadAsStringAsync(); var titleHistory = Serialization.FromJson <TitleHistoryResponse>(cont); return(titleHistory.titles.First().detail.description); } } }
public static ICodeGenerator CreateGenerator(CodeLang langType) { //Need to comment out the languages that require external dependencies otherwise the program can't run without them switch (langType) { case CodeLang.CSharp: return(new CSharpCodeProvider().CreateGenerator()); //case CodeLang.FSharp: // return new FSharpCodeProvider().CreateGenerator(); case CodeLang.JScript: return(new JScriptCodeProvider().CreateGenerator()); case CodeLang.Vb: return(new VBCodeProvider().CreateGenerator()); //case CodeLang.Boo: // return new BooCodeProvider().CreateGenerator(); default: throw new NotSupportedException(string.Format("{0} is not currently supported", langType)); } }
/// <summary> /// Get all achievements for a GOG game. /// </summary> /// <param name="PlayniteApi"></param> /// <param name="Id"></param> /// <returns></returns> public override GameAchievements GetAchievements(Game game) { List <Achievements> AllAchievements = new List <Achievements>(); string GameName = game.Name; string ClientId = game.GameId; bool HaveAchivements = false; int Total = 0; int Unlocked = 0; int Locked = 0; GameAchievements Result = SuccessStory.PluginDatabase.GetDefault(game); Result.Items = AllAchievements; string ResultWeb = string.Empty; // Only if user is logged. if (gogAPI.GetIsUserLoggedIn()) { string accessToken = gogAPI.GetAccountInfo().accessToken; string userId = gogAPI.GetAccountInfo().userId; string lang = CodeLang.GetGogLang(_PlayniteApi.ApplicationSettings.Language); // Achievements string url = string.Format(@"https://gameplay.gog.com/clients/{0}/users/{1}/achievements", ClientId, userId); try { string urlLang = string.Format(@"https://www.gog.com/user/changeLanguage/{0}", lang.ToLower()); ResultWeb = DonwloadStringData(urlLang, url, accessToken).GetAwaiter().GetResult(); } catch (WebException ex) { if (ex.Status == WebExceptionStatus.ProtocolError && ex.Response != null) { var resp = (HttpWebResponse)ex.Response; switch (resp.StatusCode) { case HttpStatusCode.ServiceUnavailable: // HTTP 503 Common.LogError(ex, "SuccessStory", $"HTTP 503 to load from {url}"); break; default: Common.LogError(ex, "SuccessStory", $"Failed to load from {url}"); break; } } return(Result); } // Parse data if (ResultWeb != string.Empty) { JObject resultObj = JObject.Parse(ResultWeb); try { JArray resultItems = (JArray)resultObj["items"]; if (resultItems.Count > 0) { HaveAchivements = true; for (int i = 0; i < resultItems.Count; i++) { Achievements temp = new Achievements { ApiName = (string)resultItems[i]["achievement_key"], Name = (string)resultItems[i]["name"], Description = (string)resultItems[i]["description"], UrlUnlocked = (string)resultItems[i]["image_url_unlocked"], UrlLocked = (string)resultItems[i]["image_url_locked"], DateUnlocked = ((string)resultItems[i]["date_unlocked"] == null) ? default(DateTime) : (DateTime)resultItems[i]["date_unlocked"], Percent = (float)resultItems[i]["rarity"] }; Total += 1; if ((string)resultItems[i]["date_unlocked"] == null) { Locked += 1; } else { Unlocked += 1; } AllAchievements.Add(temp); } } } catch (Exception ex) { Common.LogError(ex, "SuccessStory", $"Failed to parse"); return(Result); } } } else { _PlayniteApi.Notifications.Add(new NotificationMessage( "SuccessStory-Gog-NoAuthenticate", $"SuccessStory\r\n{resources.GetString("LOCSuccessStoryNotificationsGogNoAuthenticate")}", NotificationType.Error )); logger.Warn("SuccessStory - GOG user is not Authenticate"); } Result.Name = GameName; Result.HaveAchivements = HaveAchivements; Result.Total = Total; Result.Unlocked = Unlocked; Result.Locked = Locked; Result.Progression = (Total != 0) ? (int)Math.Ceiling((double)(Unlocked * 100 / Total)) : 0; Result.Items = AllAchievements; return(Result); }
/// <summary> /// Get all achievements for a Origin game. /// </summary> /// <param name="PlayniteApi"></param> /// <param name="Id"></param> /// <returns></returns> public override GameAchievements GetAchievements(Game game) { List <Achievements> AllAchievements = new List <Achievements>(); string GameName = game.Name; bool HaveAchivements = false; int Total = 0; int Unlocked = 0; int Locked = 0; GameAchievements Result = SuccessStory.PluginDatabase.GetDefault(game); Result.Items = AllAchievements; // Only if user is logged. if (originAPI.GetIsUserLoggedIn()) { // Get informations from Origin plugin. string accessToken = originAPI.GetAccessToken().access_token; string personasId = GetPersonas(originAPI.GetAccessToken()); string origineGameId = GetOrigineGameAchievementId(_PlayniteApi, game.Id); #if DEBUG logger.Debug($"SuccessStory [Ignored] - Origin token: {accessToken}"); #endif string lang = CodeLang.GetOriginLang(_PlayniteApi.ApplicationSettings.Language); // Achievements (default return in english) var url = string.Format(@"https://achievements.gameservices.ea.com/achievements/personas/{0}/{1}/all?lang={2}&metadata=true&fullset=true", personasId, origineGameId, lang); using (var webClient = new WebClient { Encoding = Encoding.UTF8 }) { try { webClient.Headers.Add("X-AuthToken", accessToken); webClient.Headers.Add("accept", "application/vnd.origin.v3+json; x-cache/force-write"); var stringData = webClient.DownloadString(url); JObject AchievementsData = JObject.Parse(stringData); foreach (var item in (JObject)AchievementsData["achievements"]) { var val = item.Value; HaveAchivements = true; AllAchievements.Add(new Achievements { Name = (string)item.Value["name"], Description = (string)item.Value["desc"], UrlUnlocked = (string)item.Value["icons"]["208"], UrlLocked = string.Empty, DateUnlocked = ((string)item.Value["state"]["a_st"] == "ACTIVE") ? default(DateTime) : new DateTime(1970, 1, 1, 0, 0, 0, 0).AddSeconds((int)item.Value["u"]), Percent = (float)item.Value["achievedPercentage"] }); Total += 1; if ((string)item.Value["state"]["a_st"] == "ACTIVE") { Locked += 1; } else { Unlocked += 1; } } } catch (WebException ex) { if (ex.Status == WebExceptionStatus.ProtocolError && ex.Response != null) { var resp = (HttpWebResponse)ex.Response; switch (resp.StatusCode) { case HttpStatusCode.NotFound: // HTTP 404 break; default: Common.LogError(ex, "SuccessStory", $"Failed to load from {url}. "); break; } return(Result); } } } } Result.Name = GameName; Result.HaveAchivements = HaveAchivements; Result.Total = Total; Result.Unlocked = Unlocked; Result.Locked = Locked; Result.Progression = (Total != 0) ? (int)Math.Ceiling((double)(Unlocked * 100 / Total)) : 0; Result.Items = AllAchievements; return(Result); }
public TreeNodeInstType(string text, InstrumentType instType, CodeLang codeLang) { _instType = instType; _codeLang = codeLang; this.Text = text; }
public TranslatorClassGenerator(CodeLang lang) { this.generator = CodeDomUtils.CreateGenerator(lang); }
/// <summary> /// Get all achievements for a Steam game. /// </summary> /// <param name="PlayniteApi"></param> /// <param name="Id"></param> /// <param name="PluginUserDataPath"></param> /// <returns></returns> public GameAchievements GetAchievements(IPlayniteAPI PlayniteApi, Guid Id, string PluginUserDataPath, bool isLocal = false) { List <Achievements> Achievements = new List <Achievements>(); string GameName = PlayniteApi.Database.Games.Get(Id).Name; string ClientId = PlayniteApi.Database.Games.Get(Id).GameId; bool HaveAchivements = false; int Total = 0; int Unlocked = 0; int Locked = 0; GameAchievements Result = new GameAchievements { Name = GameName, HaveAchivements = HaveAchivements, Total = Total, Unlocked = Unlocked, Locked = Locked, Progression = 0, Achievements = Achievements }; var url = ""; string ResultWeb = ""; // Get Steam configuration if exist. string userId = ""; string apiKey = ""; string SteamUser = ""; try { JObject SteamConfig = JObject.Parse(File.ReadAllText(PluginUserDataPath + "\\..\\CB91DFC9-B977-43BF-8E70-55F46E410FAB\\config.json")); userId = (string)SteamConfig["UserId"]; apiKey = (string)SteamConfig["ApiKey"]; SteamUser = (string)SteamConfig["UserName"]; } catch { } if (userId == "" || apiKey == "" || SteamUser == "") { logger.Error($"SuccessStory - No Steam configuration."); AchievementsDatabase.ListErrors.Add($"Error on SteamAchievements: no Steam configuration and/or API key in settings menu for Steam Library."); return(null); } if (!isLocal) { string lang = CodeLang.GetSteamLang(Localization.GetPlayniteLanguageConfiguration(PlayniteApi.Paths.ConfigurationPath)); // List acheviements (default return in english) url = string.Format(@"https://api.steampowered.com/ISteamUserStats/GetPlayerAchievements/v0001/?appid={0}&key={1}&steamid={2}&l={3}", ClientId, apiKey, userId, lang); ResultWeb = ""; try { ResultWeb = HttpDownloader.DownloadString(url, Encoding.UTF8); } catch (WebException ex) { if (ex.Status == WebExceptionStatus.ProtocolError && ex.Response != null) { var resp = (HttpWebResponse)ex.Response; switch (resp.StatusCode) { case HttpStatusCode.BadRequest: // HTTP 400 break; case HttpStatusCode.ServiceUnavailable: // HTTP 503 break; default: Common.LogError(ex, "SuccessStory", $"Failed to load from {url}. "); break; } return(Result); } } if (ResultWeb != "") { JObject resultObj = new JObject(); JArray resultItems = new JArray(); try { resultObj = JObject.Parse(ResultWeb); if ((bool)resultObj["playerstats"]["success"]) { resultItems = (JArray)resultObj["playerstats"]["achievements"]; if (resultItems.Count > 0) { HaveAchivements = true; for (int i = 0; i < resultItems.Count; i++) { Achievements temp = new Achievements { Name = (string)resultItems[i]["name"], ApiName = (string)resultItems[i]["apiname"], Description = (string)resultItems[i]["description"], UrlUnlocked = "", UrlLocked = "", DateUnlocked = ((int)resultItems[i]["unlocktime"] == 0) ? default(DateTime) : new DateTime(1970, 1, 1, 0, 0, 0, 0).AddSeconds((int)resultItems[i]["unlocktime"]) }; // Achievement without unlocktime but achieved = 1 if ((int)resultItems[i]["achieved"] == 1 && temp.DateUnlocked == new DateTime(1970, 1, 1, 0, 0, 0, 0)) { temp.DateUnlocked = new DateTime(1982, 12, 15, 0, 0, 0, 0); } Total += 1; if ((int)resultItems[i]["unlocktime"] == 0) { Locked += 1; } else { Unlocked += 1; } Achievements.Add(temp); } } else { logger.Info($"SuccessStory - No list achievement for {ClientId}. "); return(Result); } } else { logger.Info($"SuccessStory - No Succes for {ClientId}. "); return(Result); } } catch (Exception ex) { Common.LogError(ex, "SuccessStory", $"[{ClientId}] Failed to parse {ResultWeb}"); return(Result); } // List details acheviements url = string.Format(@"https://api.steampowered.com/ISteamUserStats/GetSchemaForGame/v2/?key={0}&appid={1}&l={2}", apiKey, ClientId, lang); ResultWeb = ""; try { ResultWeb = HttpDownloader.DownloadString(url, Encoding.UTF8); } catch (WebException ex) { if (ex.Status == WebExceptionStatus.ProtocolError && ex.Response != null) { var resp = (HttpWebResponse)ex.Response; switch (resp.StatusCode) { case HttpStatusCode.BadRequest: // HTTP 400 break; case HttpStatusCode.ServiceUnavailable: // HTTP 503 break; default: Common.LogError(ex, "SuccessStory", $"Failed to load from {url}"); break; } return(Result); } } if (ResultWeb != "") { resultObj = JObject.Parse(ResultWeb); try { resultItems = (JArray)resultObj["game"]["availableGameStats"]["achievements"]; for (int i = 0; i < resultItems.Count; i++) { for (int j = 0; j < Achievements.Count; j++) { if (Achievements[j].ApiName.ToLower() == ((string)resultItems[i]["name"]).ToLower()) { Achievements temp = new Achievements { Name = (string)resultItems[i]["displayName"], ApiName = Achievements[j].ApiName, Description = Achievements[j].Description, UrlUnlocked = (string)resultItems[i]["icon"], UrlLocked = (string)resultItems[i]["icongray"], DateUnlocked = Achievements[j].DateUnlocked }; if ((int)resultItems[i]["hidden"] == 1) { temp.Description = FindHiddenDescription(SteamUser, userId, ClientId, temp.Name, lang); } Achievements[j] = temp; j = Achievements.Count; } } } } catch (Exception ex) { Common.LogError(ex, "SuccessStory", $"Failed to parse"); return(Result); } } } //logger.Info($"SuccessStory - No data for {ClientId}. "); Result = new GameAchievements { Name = GameName, HaveAchivements = HaveAchivements, Total = Total, Unlocked = Unlocked, Locked = Locked, Progression = (Total != 0) ? (int)Math.Ceiling((double)(Unlocked * 100 / Total)) : 0, Achievements = Achievements }; } else { SteamEmulators se = new SteamEmulators(PlayniteApi, PluginUserDataPath); ClientId = se.GetSteamId().ToString(); var temp = se.GetAchievementsLocal(GameName, apiKey); if (temp.Achievements.Count > 0) { Result.HaveAchivements = true; Result.Total = temp.Total; Result.Locked = temp.Locked; Result.Unlocked = temp.Unlocked; Result.Progression = temp.Progression; for (int i = 0; i < temp.Achievements.Count; i++) { Result.Achievements.Add(new Achievements { Name = temp.Achievements[i].Name, Description = temp.Achievements[i].Description, UrlUnlocked = temp.Achievements[i].UrlUnlocked, UrlLocked = temp.Achievements[i].UrlLocked, DateUnlocked = temp.Achievements[i].DateUnlocked }); } } } // Percentages url = string.Format(@"http://api.steampowered.com/ISteamUserStats/GetGlobalAchievementPercentagesForApp/v0002/?gameid={0}&format=json", ClientId); ResultWeb = ""; try { ResultWeb = HttpDownloader.DownloadString(url, Encoding.UTF8); } catch (WebException ex) { if (ex.Status == WebExceptionStatus.ProtocolError && ex.Response != null) { var resp = (HttpWebResponse)ex.Response; switch (resp.StatusCode) { case HttpStatusCode.BadRequest: // HTTP 400 break; case HttpStatusCode.ServiceUnavailable: // HTTP 503 break; default: Common.LogError(ex, "SuccessStory", $"Failed to load from {url}. "); break; } return(Result); } } if (ResultWeb != "") { JObject resultObj = new JObject(); JArray resultItems = new JArray(); try { resultObj = JObject.Parse(ResultWeb); if (resultObj["achievementpercentages"]["achievements"] != null) { foreach (JObject data in resultObj["achievementpercentages"]["achievements"]) { for (int i = 0; i < Result.Achievements.Count; i++) { if (Result.Achievements[i].ApiName == (string)data["name"]) { Result.Achievements[i].Percent = (float)data["percent"]; i = Result.Achievements.Count; } } } } else { logger.Info($"SuccessStory - No percentages for {ClientId}. "); return(Result); } } catch (Exception ex) { Common.LogError(ex, "SuccessStory", $"[{ClientId}] Failed to parse {ResultWeb}"); return(Result); } } return(Result); }
protected virtual string GetScriptCodeTemplate(CodeLang codeLang) { return(string.Empty); }
public ExtensionTranslatorClassGenerator(CodeLang codeLang) { this.codeLang = codeLang; this.generator = CodeDomUtils.CreateGenerator(codeLang); }
/// <summary> /// Get all achievements for a GOG game. /// </summary> /// <param name="PlayniteApi"></param> /// <param name="Id"></param> /// <returns></returns> public GameAchievements GetAchievements(IPlayniteAPI PlayniteApi, Guid Id) { List <Achievements> Achievements = new List <Achievements>(); string GameName = PlayniteApi.Database.Games.Get(Id).Name; string ClientId = PlayniteApi.Database.Games.Get(Id).GameId; bool HaveAchivements = false; int Total = 0; int Unlocked = 0; int Locked = 0; GameAchievements Result = new GameAchievements { Name = GameName, HaveAchivements = HaveAchivements, Total = Total, Unlocked = Unlocked, Locked = Locked, Progression = 0, Achievements = Achievements }; string ResultWeb = ""; // Only if user is logged. if (gogAPI.GetIsUserLoggedIn()) { string accessToken = gogAPI.GetAccountInfo().accessToken; string userId = gogAPI.GetAccountInfo().userId; string lang = CodeLang.GetGogLang(Localization.GetPlayniteLanguageConfiguration(PlayniteApi.Paths.ConfigurationPath)); // Only languages available string[] arrayLang = { "de", "en", "fr", "ru", "zh", "zh-Hans" }; if (!arrayLang.ContainsString(lang)) { lang = "en"; } // Achievements string url = string.Format(@"https://gameplay.gog.com/clients/{0}/users/{1}/achievements", ClientId, userId); try { string urlLang = string.Format(@"https://www.gog.com/user/changeLanguage/{0}", lang.ToLower()); ResultWeb = DonwloadStringData(urlLang, url, accessToken).GetAwaiter().GetResult(); } // TODO Environnement //catch (Exception e) when (!Environment.IsDebugBuild) catch (WebException ex) { if (ex.Status == WebExceptionStatus.ProtocolError && ex.Response != null) { var resp = (HttpWebResponse)ex.Response; switch (resp.StatusCode) { case HttpStatusCode.ServiceUnavailable: // HTTP 503 Common.LogError(ex, "SuccessStory", $"HTTP 503 to load from {url}"); break; default: Common.LogError(ex, "SuccessStory", $"Failed to load from {url}"); break; } } return(Result); } if (ResultWeb != "") { JObject resultObj = JObject.Parse(ResultWeb); try { JArray resultItems = (JArray)resultObj["items"]; if (resultItems.Count > 0) { HaveAchivements = true; for (int i = 0; i < resultItems.Count; i++) { Achievements temp = new Achievements { ApiName = (string)resultItems[i]["achievement_key"], Name = (string)resultItems[i]["name"], Description = (string)resultItems[i]["description"], UrlUnlocked = (string)resultItems[i]["image_url_unlocked"], UrlLocked = (string)resultItems[i]["image_url_locked"], DateUnlocked = ((string)resultItems[i]["date_unlocked"] == null) ? default(DateTime) : (DateTime)resultItems[i]["date_unlocked"], Percent = (float)resultItems[i]["rarity"] }; Total += 1; if ((string)resultItems[i]["date_unlocked"] == null) { Locked += 1; } else { Unlocked += 1; } Achievements.Add(temp); } } } catch (Exception ex) { Common.LogError(ex, "SuccessStory", $"Failed to parse. "); return(Result); } } } Result = new GameAchievements { Name = GameName, HaveAchivements = HaveAchivements, Total = Total, Unlocked = Unlocked, Locked = Locked, Progression = (Total != 0) ? (int)Math.Ceiling((double)(Unlocked * 100 / Total)) : 0, Achievements = Achievements }; return(Result); }
public static ICodeGenerator CreateGenerator(CodeLang langType) { //Need to comment out the languages that require external dependencies otherwise the program can't run without them switch (langType) { case CodeLang.CSharp: return new CSharpCodeProvider().CreateGenerator(); //case CodeLang.FSharp: // return new FSharpCodeProvider().CreateGenerator(); case CodeLang.JScript: return new JScriptCodeProvider().CreateGenerator(); case CodeLang.Vb: return new VBCodeProvider().CreateGenerator(); //case CodeLang.Boo: // return new BooCodeProvider().CreateGenerator(); default: throw new NotSupportedException(string.Format("{0} is not currently supported", langType)); } }
public CodeLangItem(CodeLang codeLang) { this.CodeLang = codeLang; }
protected virtual string GetScriptCodeTemplate(CodeLang codeLang) { return string.Empty; }
protected override void OnInit() { this.file = ((EditorKey)this.Key).File; CodeLang codeLang = CodeHelper.GetCodeLang(this.file); switch (codeLang) { case CodeLang.CSharp: if (this.BuildOptions != null) { foreach (BuildReference buildReference in this.BuildOptions.GetReferences()) { if (buildReference.Valid) { try { this.csParser.RegisterAssembly(Assembly.Load(buildReference.Assembly)); } catch { } } } } this.textEditor.Lexer = (ILexer)this.csParser; this.TabImage = (Image)OpenQuant.Shared.Properties.Resources.code_cs; break; case CodeLang.VisualBasic: if (this.BuildOptions != null) { foreach (BuildReference buildReference in this.BuildOptions.GetReferences()) { if (buildReference.Valid) { try { this.vbParser.RegisterAssembly(Assembly.Load(buildReference.Assembly)); } catch { } } } } this.textEditor.Lexer = (ILexer)this.vbParser; this.TabImage = (Image)OpenQuant.Shared.Properties.Resources.code_vb; break; default: throw new ArgumentException(string.Format("Unsupported code language - {0}", (object)codeLang)); } if (this.EditorOptions != null) { if (this.EditorOptions.DisplayLineNumbers) { this.textEditor.Gutter.Options |= GutterOptions.PaintLineNumbers; } this.textEditor.Outlining.AllowOutlining = this.EditorOptions.AllowOutlining; } this.textEditor.Source.Text = System.IO.File.ReadAllText(this.file.FullName); this.textEditor.Source.FormatText(); this.textEditor.Outlining.CollapseToDefinitions(); List <IRange> list = new List <IRange>(); this.textEditor.Outlining.GetOutlineRanges((IList <IRange>)list); foreach (IOutlineRange outlineRange in list) { if (outlineRange.Level > 1) { outlineRange.Visible = false; } } this.UpdateTitle(); this.textEditor.TextChanged += new EventHandler(this.textEditor_TextChanged); this.textEditor.SourceStateChanged += new NotifyEvent(this.textEditor_SourceStateChanged); this.textEditor.Selection.SelectionChanged += new EventHandler(this.Selection_SelectionChanged); if (this.EditorOptions == null || !this.EditorOptions.AutoSaveEnabled) { return; } Global.TimerManager.Start((ITimerItem)this); }
public SteamAchievements(IPlayniteAPI PlayniteApi, SuccessStorySettings settings, string PluginUserDataPath) : base(PlayniteApi, settings, PluginUserDataPath) { LocalLang = CodeLang.GetSteamLang(_PlayniteApi.ApplicationSettings.Language); }
/// <summary> /// Get all achievements for a Origin game. /// </summary> /// <param name="PlayniteApi"></param> /// <param name="Id"></param> /// <returns></returns> public GameAchievements GetAchievements(IPlayniteAPI PlayniteApi, Guid Id) { List <Achievements> Achievements = new List <Achievements>(); string GameName = PlayniteApi.Database.Games.Get(Id).Name; bool HaveAchivements = false; int Total = 0; int Unlocked = 0; int Locked = 0; GameAchievements Result = new GameAchievements { Name = GameName, HaveAchivements = HaveAchivements, Total = Total, Unlocked = Unlocked, Locked = Locked, Progression = 0, Achievements = Achievements }; // Only if user is logged. if (originAPI.GetIsUserLoggedIn()) { // Get informations from Origin plugin. string accessToken = originAPI.GetAccessToken().access_token; string personasId = GetPersonas(originAPI.GetAccessToken()); string origineGameId = GetOrigineGameAchievementId(PlayniteApi, Id); string lang = CodeLang.GetOriginLang(Localization.GetPlayniteLanguageConfiguration(PlayniteApi.Paths.ConfigurationPath)); // Achievements (default return in english) var url = string.Format(@"https://achievements.gameservices.ea.com/achievements/personas/{0}/{1}/all?lang={2}&metadata=true&fullset=true", personasId, origineGameId, lang); using (var webClient = new WebClient { Encoding = Encoding.UTF8 }) { try { webClient.Headers.Add("X-AuthToken", accessToken); webClient.Headers.Add("accept", "application/vnd.origin.v3+json; x-cache/force-write"); var stringData = webClient.DownloadString(url); JObject AchievementsData = JObject.Parse(stringData); foreach (var item in (JObject)AchievementsData["achievements"]) { var val = item.Value; HaveAchivements = true; Achievements.Add(new Achievements { Name = (string)item.Value["name"], Description = (string)item.Value["desc"], UrlUnlocked = (string)item.Value["icons"]["208"], UrlLocked = "", DateUnlocked = ((string)item.Value["state"]["a_st"] == "ACTIVE") ? default(DateTime) : new DateTime(1970, 1, 1, 0, 0, 0, 0).AddSeconds((int)item.Value["u"]) }); Total += 1; if ((string)item.Value["state"]["a_st"] == "ACTIVE") { Locked += 1; } else { Unlocked += 1; } } } catch (WebException ex) { if (ex.Status == WebExceptionStatus.ProtocolError && ex.Response != null) { var resp = (HttpWebResponse)ex.Response; switch (resp.StatusCode) { case HttpStatusCode.NotFound: // HTTP 404 break; default: var LineNumber = new StackTrace(ex, true).GetFrame(0).GetFileLineNumber(); string FileName = new StackTrace(ex, true).GetFrame(0).GetFileName(); logger.Error(ex, $"SuccessStory [{FileName} {LineNumber}] - Failed to load from {url}. "); break; } return(Result); } } } } Result = new GameAchievements { Name = GameName, HaveAchivements = HaveAchivements, Total = Total, Unlocked = Unlocked, Locked = Locked, Progression = (Total != 0) ? (int)Math.Ceiling((double)(Unlocked * 100 / Total)) : 0, Achievements = Achievements }; return(Result); }