Exemple #1
0
        internal static void CacheAllModInfoAsyncSafe()
        {
            if (GetModInfo._IsCachedFailsafe)
            {
                return;
            }
            GetModInfo._IsCachedFailsafe = true;

            bool isLocalCachedFailsafe = false;                 // wtf

            ThreadPool.QueueUserWorkItem(_ => {
                lock (GetModInfo.MyLock) {
                    if (isLocalCachedFailsafe)
                    {
                        return;
                    }
                    isLocalCachedFailsafe = true;

                    GetModInfo.CacheAllModInfoAsync();
                }
            });

            //string username = ModMetaDataManager.GetGithubUserName( mod );
            //string projname = ModMetaDataManager.GetGithubProjectName( mod );
            //string url = "https://api.github.com/repos/" + username + "/" + projname + "/releases";
        }
Exemple #2
0
        private static void CacheAllModInfoAsync()
        {
            var mymod       = ModHelpersMod.Instance;
            var modInfoArgs = new ModInfoListPromiseArguments();

            GetModInfo.RetrieveAllModInfoAsync((modInfo, found) => {
                modInfoArgs.ModInfo = modInfo;
                modInfoArgs.Found   = found;

                Promises.TriggerValidatedPromise(GetModInfo.ModInfoListPromiseValidator, GetModInfo.PromiseValidatorKey, modInfoArgs);
            });

            Promises.AddValidatedPromise <ModInfoListPromiseArguments>(GetModInfo.ModInfoListPromiseValidator, (modInfoArgs2) => {
                if (modInfoArgs2.Found)
                {
                    GetModInfo.RetrieveBadModsAsync((badMods, found) => {
                        if (found)
                        {
                            GetModInfo.RegisterBadMods(modInfoArgs2, badMods);
                        }

                        Promises.TriggerValidatedPromise(GetModInfo.BadModsListPromiseValidator, GetModInfo.PromiseValidatorKey, modInfoArgs2);
                    });
                }

                return(true);
            });
        }
Exemple #3
0
        ////////////////

        internal void OnPostModsLoad()
        {
            if (!ModHelpersMod.Config.DisableModMenuUpdates)
            {
                GetModInfo.CacheAllModInfoAsyncSafe();

                /*GetModVersion.CacheAllModVersionsAsync( () => {
                 *      LogHelpers.Log( "Mod versions successfully retrieved and cached." );
                 * } );*/
            }
        }
Exemple #4
0
        ////////////////

        internal void OnPostSetupContent()
        {
            if (ModHelpersMod.Instance.Config.IsCheckingModVersions)
            {
                GetModInfo.CacheAllModInfoAsyncSafe();

                /*GetModVersion.CacheAllModVersionsAsync( () => {
                 *      LogHelpers.Log( "Mod versions successfully retrieved and cached." );
                 * } );*/
            }
        }
Exemple #5
0
        private static void CacheAllModInfoAsync()
        {
            var mymod       = ModHelpersMod.Instance;
            var modInfoArgs = new ModInfoListLoadHookArguments();

            GetModInfo.RetrieveAllModInfoAsync((found, modInfo) => {
                modInfoArgs.ModInfo = modInfo;
                modInfoArgs.Found   = found;

                Timers.SetTimer("CacheAllModInfoAsyncFailsafe", 2, () => {
                    if (GetModInfo.ModInfoListLoadHookValidator == null)
                    {
                        return(true);
                    }

                    CustomLoadHooks.TriggerHook(
                        GetModInfo.ModInfoListLoadHookValidator,
                        GetModInfo.LoadHookValidatorKey,
                        modInfoArgs
                        );
                    return(false);
                });
            });

            CustomLoadHooks.AddHook(GetModInfo.ModInfoListLoadHookValidator, (modInfoArgs2) => {
                Thread.Sleep(2000);

                if (modInfoArgs2.Found)
                {
                    GetModInfo.RetrieveBadModsAsync((found, badMods) => {
                        if (found)
                        {
                            GetModInfo.RegisterBadMods(modInfoArgs2, badMods);
                        }

                        CustomLoadHooks.TriggerHook(
                            GetModInfo.BadModsListLoadHookValidator,
                            GetModInfo.LoadHookValidatorKey,
                            modInfoArgs2
                            );
                    });
                }

                return(true);
            });
        }
        private static void RetrieveAllModInfoAsync(Action <bool, BasicModInfoDatabase> onCompletion)
        {
            Action <Exception, string> onError = (e, jsonStr) => {
                if (e == null)
                {
                    LogHelpers.Alert((jsonStr.Trunc(64) ?? "") + " - Invalid exception?");
                }
                else if (e is JsonReaderException)
                {
                    LogHelpers.Alert("Bad JSON: " + jsonStr.Trunc(256));
                }
                else if (e is WebException || e is NullReferenceException)
                {
                    LogHelpers.Alert(("'" + jsonStr.Trunc(64) + "'" ?? "...") + " - " + e.Message);
                }
                else
                {
                    LogHelpers.Alert(("'" + jsonStr.Trunc(64) + "'" ?? "...") + " - " + e.ToString());
                }
            };

            Action <bool, string> onWrappedCompletion = (success, jsonStr) => {
                BasicModInfoDatabase modInfoDb;

                if (success)
                {
                    try {
                        success = GetModInfo.HandleModInfoReceipt(jsonStr, out modInfoDb);
                    } catch (Exception e) {
                        modInfoDb = new BasicModInfoDatabase();
                        onError(e, jsonStr);
                    }
                }
                else
                {
                    modInfoDb = new BasicModInfoDatabase();
                }

                onCompletion(success, modInfoDb);
            };

            WebConnectionHelpers.MakeGetRequestAsync(GetModInfo.ModInfoUrl, e => onError(e, ""), onWrappedCompletion);
        }