HealthHelper/ConfigJson.cs

(开头部分) 2KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace HealthHelper
{

    public class ConfigJsonFactory
    {
        public static readonly string fileName = "app.json";
        public static ConfigJson LoadConfig()
        {
            ConfigJson configJson = new ConfigJson()
            {
                WorkMinutes = 45,
                RestMinutes = 3,
                RestRemindSecond = 15,
                MinWorkMinutes = 1,
                MaxWorkMinutes = 180
            };
            if (!File.Exists(fileName))
            {
                return configJson;
            }
            try
            {
                string json = File.ReadAllText(fileName);
                configJson = JsonConvert.DeserializeObject<ConfigJson>(json);
            }
            catch (Exception ex)
            {
                MessageBox.Show("配置文件加载异常:" + ex.Message);
            }
            return configJson;
        }


        public static void WriteConfig(ConfigJson configJson)
        {
            JsonSerializer serializer = new JsonSerializer();
            try
            {
                using (StringWriter textWriter = new StringWriter())
                {
                    using (JsonTextWriter jsonWriter = new JsonTextWriter(textWriter)
                    {
                        Formatting = Formatting.Indented,
                        Indentation = 4,
                        IndentChar = ' '
                    })
                    {
                        serializer.Serialize(jsonWriter, configJson);
                        string json = textWriter.ToString();
                        File.WriteAllText(fileName, json);
                    }
后面还有 34 行代码,解锁后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明

AI 解读 AI

登录后可用,每次 10 算力,解读结果公开显示在下面。

还没有人解读过这个文件。