예제 #1
0
        protected void SaveSettings <T>(T cls, string fileName = null)
        {
            Type clsT = cls.GetType();

            string saveName = Path.Combine(SettingsPath, (fileName ?? clsT.Name) + ".json");

            if (!Directory.Exists(SettingsPath))
            {
                Directory.CreateDirectory(SettingsPath);
            }

            ConcurrentFile.WriteAllText(saveName, Newtonsoft.Json.JsonConvert.SerializeObject(cls));
        }
예제 #2
0
파일: Plugin.cs 프로젝트: Gtsz/Daylily
        protected void SaveSettings <T>(T cls, string fileName = null, bool writeLog = false)
        {
            Type clsT = cls.GetType();

            string saveName = Path.Combine(SettingsPath, (fileName ?? clsT.Name) + ".json");

            if (!Directory.Exists(SettingsPath))
            {
                Directory.CreateDirectory(SettingsPath);
            }

            ConcurrentFile.WriteAllText(saveName, Newtonsoft.Json.JsonConvert.SerializeObject(cls));
            if (writeLog)
            {
                var fileInfo = new FileInfo(saveName);
                Logger.Success($"写入了 {Path.Combine("~", fileInfo.Directory?.Name, fileInfo.Name)}。");
            }
        }
예제 #3
0
        public static void LoadSecret()
        {
            var    file = new FileInfo(Path.Combine(Domain.SecretPath, "secret.json"));
            string json;
            Secret secret;

            if (!file.Exists)
            {
                secret = new Secret();
                json   = Newtonsoft.Json.JsonConvert.SerializeObject(secret);
                ConcurrentFile.WriteAllText(file.FullName, json.ToJsonFormat());

                Logger.Error("请完善secret配置。");
                Console.ReadKey();
                Environment.Exit(0);
            }

            json   = ConcurrentFile.ReadAllText(file.FullName);
            secret = Newtonsoft.Json.JsonConvert.DeserializeObject <Secret>(json);

            // 读设置
            DbHelper.ConnectionString.Add("cabbage", secret.ConnectionStrings.DefaultConnection);
            DbHelper.ConnectionString.Add("daylily", secret.ConnectionStrings.MyConnection);

            OsuApiConfig.ApiKey   = secret.OsuSettings.ApiKey;
            OsuApiConfig.UserName = secret.OsuSettings.UserName;
            OsuApiConfig.Password = secret.OsuSettings.Password;

            Signature.AppId      = secret.CosSettings.AppId;
            Signature.SecretId   = secret.CosSettings.SecretId;
            Signature.SecretKey  = secret.CosSettings.SecretKey;
            Signature.BucketName = secret.CosSettings.BucketName;

            CoolQHttpApiClient.ApiUrl       = secret.BotSettings.PostUrl;
            CoolQCode.CqPath                = secret.BotSettings.CqDir;
            DaylilyCore.Current.CommandFlag = secret.BotSettings.CommandFlag;

            TuLingSecret.ApiKeys = secret.TuLingSettings.ApiKey;
        }
예제 #4
0
 private static void Backup()
 {
     ConcurrentFile.WriteAllText("player.db.bak", JsonConvert.SerializeObject(_dbJsonObject));
 }
예제 #5
0
 public static void SaveDefault()
 {
     ConcurrentFile.WriteAllText(Domain.ConfigFile, JsonConvert.SerializeObject(Default, Formatting.Indented));
 }
예제 #6
0
 private static void SaveCache()
 {
     ConcurrentFile.WriteAllText(CachePath, Newtonsoft.Json.JsonConvert.SerializeObject(UserDictionary, Newtonsoft.Json.Formatting.Indented));
 }