public static async ValueTask <bool> Initialize() { var enLocalResPath = Constants.EnLocalizationPath(Globals.Settings.ResourceDirectory); var ResEn = new GameResource(); await ResEn.Load(enLocalResPath); var WorkFileKoPath = Path.Combine(Globals.Settings.WorkingDirectory, Constants.JsonKoName); await Task.Run(() => { var jsonEnFilePath = Path.Combine(Globals.Settings.WorkingDirectory, Constants.JsonEnName); if (!File.Exists(jsonEnFilePath)) { File.WriteAllText(jsonEnFilePath, JsonConvert.SerializeObject(ResEn.TextMap, Formatting.Indented)); } if (!File.Exists(WorkFileKoPath)) { var Translated = ResEn.TextMap.ToDictionary(x => x.Key, x => { if (string.Compare(x.Key, "Manifest") == 0) { return(new(x.Value)); } else { return(x.Value.ToDictionary(x => x.Key, x => x.Value.EndsWith(".png") ? x.Value : "")); } }); File.WriteAllTextAsync(WorkFileKoPath, JsonConvert.SerializeObject(Translated, Formatting.Indented)); } var htmlEnFilePath = Path.Combine(Globals.Settings.WorkingDirectory, Constants.HtmlEnName); if (!File.Exists(htmlEnFilePath)) { File.WriteAllText(htmlEnFilePath, HtmlSerializer.Serialize(ResEn.TextMap)); } var txtZipEnFilePath = Path.Combine(Globals.Settings.WorkingDirectory, Constants.TxtZipEnName); if (!File.Exists(txtZipEnFilePath)) { File.WriteAllBytes(txtZipEnFilePath, TxtZipSerialier.Serialize(ResEn.TextMap)); } }); await Globals.UpdateAppSettings(); return(true); }
public static async ValueTask <bool> PatchTextTxtZip() { var enLocalResPath = Constants.EnLocalizationPath(Globals.Settings.ResourceDirectory); var WorkFileKoPath = Path.Combine(Globals.Settings.WorkingDirectory, Constants.TxtZipKoName); if (!File.Exists(WorkFileKoPath)) { throw new Exception($"Not Found Translated File.({Constants.TxtZipKoName})"); } var GRes = new GameResource(); await GRes.Load(enLocalResPath); var translateMap = TxtZipSerialier.Deserialize(File.ReadAllBytes(WorkFileKoPath)); foreach (var kvFile in translateMap) { var fileName = kvFile.Key; var resource = GRes.Resources.Where(r => Path.GetFileNameWithoutExtension(r.FilePath) == fileName).FirstOrDefault(); if (resource == null) { continue; } foreach (var kvLine in kvFile.Value) { resource.UpdateText(kvLine.Key, kvLine.Value); } } var krResDirPath = Path.Combine(Globals.Settings.WorkingDirectory, "PatchedText"); if (!Directory.Exists(krResDirPath)) { Directory.CreateDirectory(krResDirPath); } foreach (var pair in GRes.Resources) { await pair.Export(Path.Combine(krResDirPath, Path.GetFileName(pair.FilePath))); } await Globals.UpdateAppSettings(); return(true); }