Ejemplo n.º 1
0
        private List <ServerVersion> GetVanillaVersionsFromCache(Manifest.VersionType versionType)
        {
            if (vanillaDict.ContainsKey(versionType) && VanillaCacheUpToDate(versionType))
            {
                return(vanillaDict[versionType]);
            }
            string path = Path.Combine(App.ApplicationPath, "persistence", "vanilla-" + versionType + ".json");

            if (File.Exists(path))
            {
                try
                {
                    string json = File.ReadAllText(path, Encoding.UTF8);
                    VanillaVersionCache versionCache = JsonSerializer.Deserialize <VanillaVersionCache>(json);
                    if (DateTime.Now.Subtract(versionCache.CacheCreation).TotalHours < 12)
                    {
                        return(versionCache.Versions);
                    }
                    //TODO update visual list after updating
                    UpdateVanillaVersionsAsync(versionType);
                    return(versionCache.Versions);
                }
                catch (Exception e)
                {
                    ErrorLogger.Append(e);
                    Console.WriteLine("Error while reading Vanilla version cache. Skipping...");
                }
            }
            UpdateVanillaVersions(versionType);
            return(GetVanillaVersionsFromCache(versionType));
        }
Ejemplo n.º 2
0
        private void CacheVanillaVersions(Manifest.VersionType versionType, List <ServerVersion> versions)
        {
            DateTime cacheAge = DateTime.Now;

            //RAM cache
            vanillaDict[versionType]     = versions;
            vanillaCacheAge[versionType] = cacheAge;
            VanillaVersionCache versionCache = new VanillaVersionCache(cacheAge, versionType, versions);

            //File cache
            string json = JsonSerializer.Serialize(versionCache);

            try
            {
                string path = Path.Combine(App.ApplicationPath, "persistence");
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }
                path = Path.Combine(path, "vanilla-" + versionType + ".json");
                File.WriteAllText(path, json, Encoding.UTF8);
            }
            catch (Exception e)
            {
                ErrorLogger.Append(e);
                Console.WriteLine("Error while saving Vanilla version cache. Skipping...");
            }
        }