コード例 #1
0
        public static async Task PersistSpecificationsAsync(PersistenceFile specifications)
        {
            try
            {
                await Utils.InitializeInstall(true);

                var jsonConvert = JsonConvert.SerializeObject(specifications, Formatting.Indented);

                foreach (var item in specifications.mods)
                {
                    Utils.Debug(item.file);
                }

                foreach (var item in specifications.packs)
                {
                    Utils.Debug(item.file);
                }

                Utils.Debug(jsonConvert);
                await Task.Run(() => File.WriteAllText(Globals.skyblockPersistenceLocation, jsonConvert));
            }
            catch (Exception e)
            {
                string message = $"Failed creating or writing {Globals.PERSISTANCE_JSON_NAME}";
                Utils.Error(message);
                Utils.Log(e, "PersistSpecificationsAsync(UpdateSpecification specifications)", message);
            }
        }
コード例 #2
0
        public static async Task <PersistenceFile> CreateSpecificationsAsync(bool readExistingSpecifications)
        {
            bool persistanceLocationExists = await Task.Run(() => File.Exists(Globals.skyblockPersistenceLocation));

            PersistenceFile specification = null;

            if (persistanceLocationExists)
            {
                if (readExistingSpecifications)
                {
                    try
                    {
                        var specificationText = await Task.Run(() => File.ReadAllText(Globals.skyblockPersistenceLocation));

                        specification = await Task.Run(() => JsonConvert.DeserializeObject <PersistenceFile>(specificationText));
                    }
                    catch (JsonReaderException e)
                    {
                        Utils.Error(e.Message, e.StackTrace);
                    }
                    catch (Exception e)
                    {
                        Utils.Error(e.Message, e.StackTrace);
                    }
                }
                if (specification is null)
                {
                    specification = new PersistenceFile();
                }
            }
            else
            {
                specification = new PersistenceFile();
            }
            specification.AddRangeSafe(Globals.neededMods);
            specification.AddRangeSafe(Globals.neededPacks);
            return(specification);
        }
コード例 #3
0
 public static async Task Update(PersistenceFile specification)
 {
     await PersistSpecificationsAsync(specification);
 }