/// <summary> /// 构造函数 /// </summary> /// <param name="rootPath"></param> /// <param name="clientToken"></param> public DefaultLauncherProfileParser(string rootPath, Guid clientToken) { RootPath = rootPath; if (!File.Exists(GamePathHelper.GetLauncherProfilePath(RootPath))) { var launcherProfile = new LauncherProfileModel { AuthenticationDatabase = new Dictionary <string, AuthInfoModel>(), ClientToken = clientToken.ToString("D"), LauncherVersion = new LauncherVersionModel { Format = 1, Name = "" }, Profiles = new Dictionary <string, GameProfileModel>() }; LauncherProfile = launcherProfile; var launcherProfileJson = JsonConvert.SerializeObject(launcherProfile, new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() }); if (!Directory.Exists(RootPath)) { Directory.CreateDirectory(RootPath); } FileHelper.Write(GamePathHelper.GetLauncherProfilePath(RootPath), launcherProfileJson); } else { var launcherProfileJson = File.ReadAllText(GamePathHelper.GetLauncherProfilePath(rootPath), Encoding.UTF8); LauncherProfile = JsonConvert.DeserializeObject <LauncherProfileModel>(launcherProfileJson); } }
/// <summary> /// 构造函数 /// </summary> /// <param name="rootPath"></param> /// <param name="clientToken"></param> public DefaultLauncherProfileParser(string rootPath, Guid clientToken) { RootPath = rootPath; FullLauncherProfilePath = Path.Combine(rootPath, GamePathHelper.GetLauncherProfilePath()); if (!File.Exists(FullLauncherProfilePath)) { var launcherProfile = new LauncherProfileModel { ClientToken = clientToken.ToString("D"), LauncherVersion = new LauncherVersionModel { Format = 1, Name = string.Empty }, Profiles = new Dictionary <string, GameProfileModel>() }; LauncherProfile = launcherProfile; var launcherProfileJson = JsonConvert.SerializeObject(launcherProfile, JsonHelper.CamelCasePropertyNamesSettings); if (!Directory.Exists(RootPath)) { Directory.CreateDirectory(RootPath); } File.WriteAllText(FullLauncherProfilePath, launcherProfileJson); } else { var launcherProfileJson = File.ReadAllText(FullLauncherProfilePath, Encoding.UTF8); LauncherProfile = JsonConvert.DeserializeObject <LauncherProfileModel>(launcherProfileJson); } }