public void SetCurrentPlayTime(Game game)
        {
            GameHowLongToBeat gameHowLongToBeat = Database.Get(game.Id);

            if (gameHowLongToBeat != null)
            {
                TimeSpan time = TimeSpan.FromSeconds(game.Playtime);

                var platform = hltbPlatforms.FindAll(x => game.Platform.Name.ToLower().Contains(x.Name.ToLower())).First();

                if (platform != null)
                {
                    string Platform = platform.Name;

                    HltbPostData hltbPostData = new HltbPostData
                    {
                        user_id      = Database.UserHltbData.UserId,
                        game_id      = gameHowLongToBeat.GetData().Id,
                        custom_title = gameHowLongToBeat.GetData().Name,
                        platform     = Platform,

                        list_p = "1",

                        protime_h = time.Hours.ToString(),
                        protime_m = time.Minutes.ToString(),
                        protime_s = time.Seconds.ToString(),
                    };

                    howLongToBeatClient.PostData(hltbPostData);
                }
                else
                {
                    logger.Warn($"HowLongToBeat - No platform find for {game.Name}");
                }
            }
        }
Beispiel #2
0
        public async Task <bool> PostData(HltbPostData hltbPostData)
        {
            if (GetIsUserLoggedIn() && hltbPostData.user_id != 0 && hltbPostData.game_id != 0)
            {
                try
                {
                    Type           type       = typeof(HltbPostData);
                    PropertyInfo[] properties = type.GetProperties();
                    var            data       = new Dictionary <string, string>();
                    foreach (PropertyInfo property in properties)
                    {
                        switch (property.Name)
                        {
                        case "list_p":
                            if (property.GetValue(hltbPostData, null).ToString() != string.Empty)
                            {
                                data.Add(property.Name, property.GetValue(hltbPostData, null).ToString());
                            }
                            break;

                        case "list_b":
                            if (property.GetValue(hltbPostData, null).ToString() != string.Empty)
                            {
                                data.Add(property.Name, property.GetValue(hltbPostData, null).ToString());
                            }
                            break;

                        case "list_r":
                            if (property.GetValue(hltbPostData, null).ToString() != string.Empty)
                            {
                                data.Add(property.Name, property.GetValue(hltbPostData, null).ToString());
                            }
                            break;

                        case "list_c":
                            if (property.GetValue(hltbPostData, null).ToString() != string.Empty)
                            {
                                data.Add(property.Name, property.GetValue(hltbPostData, null).ToString());
                            }
                            break;

                        case "list_cp":
                            if (property.GetValue(hltbPostData, null).ToString() != string.Empty)
                            {
                                data.Add(property.Name, property.GetValue(hltbPostData, null).ToString());
                            }
                            break;

                        case "list_rt":
                            if (property.GetValue(hltbPostData, null).ToString() != string.Empty)
                            {
                                data.Add(property.Name, property.GetValue(hltbPostData, null).ToString());
                            }
                            break;


                        case "compmonth":
                            if (property.GetValue(hltbPostData, null).ToString() == string.Empty)
                            {
                                data.Add(property.Name, DateTime.Now.ToString("MM"));
                            }
                            else
                            {
                                data.Add(property.Name, property.GetValue(hltbPostData, null).ToString());
                            }
                            break;

                        case "compday":
                            if (property.GetValue(hltbPostData, null).ToString() == string.Empty)
                            {
                                data.Add(property.Name, DateTime.Now.ToString("dd"));
                            }
                            else
                            {
                                data.Add(property.Name, property.GetValue(hltbPostData, null).ToString());
                            }
                            break;

                        case "compyear":
                            if (property.GetValue(hltbPostData, null).ToString() == string.Empty)
                            {
                                data.Add(property.Name, DateTime.Now.ToString("yyyy"));
                            }
                            else
                            {
                                data.Add(property.Name, property.GetValue(hltbPostData, null).ToString());
                            }
                            break;

                        default:
                            data.Add(property.Name, WebUtility.UrlEncode(property.GetValue(hltbPostData, null).ToString()));
                            break;
                        }
                    }


                    if (hltbPostData.edit_id != 0)
                    {
                        string url = string.Format(UrlPostData + "?s=add&gid={0}", hltbPostData.game_id);
                        webViews.NavigateAndWait(url);
                    }
                    else
                    {
                    }


                    List <HttpCookie> Cookies = webViews.GetCookies();
                    Cookies = Cookies.Where(x => x.Domain.Contains("howlongtobeat")).ToList();
#if DEBUG
                    logger.Debug($"HowLongToBeat [Ignored] - Cookies: {JsonConvert.SerializeObject(Cookies)}");
#endif

                    var    formContent = new FormUrlEncodedContent(data);
                    string response    = Web.PostStringDataCookies(UrlPostData, formContent, Cookies).GetAwaiter().GetResult();

                    HtmlParser    parser       = new HtmlParser();
                    IHtmlDocument htmlDocument = parser.Parse(response);
                }
                catch (Exception ex)
                {
                    Common.LogError(ex, "HowLongToBeat");

                    _PlayniteApi.Notifications.Add(new NotificationMessage(
                                                       "HowLongToBeat-DataUpdate-Error",
                                                       "HowLongToBeat" + System.Environment.NewLine +
                                                       ex.Message,
                                                       NotificationType.Error,
                                                       () => _plugin.OpenSettingsView()));

                    return(false);
                }
            }
            else
            {
                _PlayniteApi.Notifications.Add(new NotificationMessage(
                                                   "HowLongToBeat-DataUpdate-Error",
                                                   "HowLongToBeat" + System.Environment.NewLine +
                                                   resources.GetString("LOCNotLoggedIn"),
                                                   NotificationType.Error,
                                                   () => _plugin.OpenSettingsView()));

                return(false);
            }

            return(false);
        }
Beispiel #3
0
        public void SetCurrentPlayTime(Game game, long elapsedSeconds)
        {
            try
            {
                if (howLongToBeatClient.GetIsUserLoggedIn())
                {
                    GameHowLongToBeat gameHowLongToBeat = Database.Get(game.Id);

                    if (gameHowLongToBeat != null)
                    {
                        TimeSpan time = TimeSpan.FromSeconds(game.Playtime + elapsedSeconds);

                        var platform = hltbPlatforms.FindAll(x => game.Platform.Name.ToLower().Contains(x.Name.ToLower())).First();

                        if (platform != null)
                        {
                            string Platform = platform.Name;

                            var          HltbData     = GetUserHltbData(gameHowLongToBeat.GetData().Id);
                            int          edit_id      = 0;
                            HltbPostData hltbPostData = new HltbPostData();
                            if (HltbData != null)
                            {
                                if (howLongToBeatClient.EditIdExist(HltbData.UserGameId))
                                {
                                    edit_id      = int.Parse(HltbData.UserGameId);
                                    hltbPostData = howLongToBeatClient.GetSubmitData(edit_id.ToString());
                                }
                            }
                            else
                            {
                                if (HltbData != null)
                                {
                                    string tmpEditId = howLongToBeatClient.FindIdExisting(edit_id.ToString());
                                    if (!tmpEditId.IsNullOrEmpty())
                                    {
                                        edit_id      = int.Parse(tmpEditId);
                                        hltbPostData = howLongToBeatClient.GetSubmitData(tmpEditId);
                                    }
                                }
                            }

                            if (hltbPostData == null)
                            {
                                logger.Warn($"HowLongToBeat - No hltbPostData for {game.Name}");
                                return;
                            }

                            hltbPostData.user_id      = Database.UserHltbData.UserId;
                            hltbPostData.edit_id      = edit_id;
                            hltbPostData.game_id      = gameHowLongToBeat.GetData().Id;
                            hltbPostData.custom_title = gameHowLongToBeat.GetData().Name;
                            hltbPostData.platform     = Platform;

                            hltbPostData.list_p = "1";

                            hltbPostData.protime_h = (time.Hours + (24 * time.Days)).ToString();
                            hltbPostData.protime_m = time.Minutes.ToString();
                            hltbPostData.protime_s = time.Seconds.ToString();


                            howLongToBeatClient.PostData(hltbPostData);
                        }
                        else
                        {
                            logger.Warn($"HowLongToBeat - No platform find for {game.Name}");
                        }
                    }
                }
                else
                {
                    _PlayniteApi.Notifications.Add(new NotificationMessage(
                                                       "HowLongToBeat-Import-Error",
                                                       "HowLongToBeat" + System.Environment.NewLine +
                                                       resources.GetString("LOCNotLoggedIn"),
                                                       NotificationType.Error,
                                                       () => _plugin.OpenSettingsView()));
                }
            }
            catch (Exception ex)
            {
                Common.LogError(ex, "HowLongToBeat");
                _PlayniteApi.Notifications.Add(new NotificationMessage(
                                                   "HowLongToBeat-Import-Error",
                                                   "HowLongToBeat" + System.Environment.NewLine +
                                                   ex.Message,
                                                   NotificationType.Error,
                                                   () => _plugin.OpenSettingsView()));
            }
        }