2using System.Collections.Generic;
5using NPOI.SS.UserModel;
6using NPOI.XSSF.UserModel;
21 IO.DeleteDirectory(dir);
22 IO.CopyAll(dirInfo.FullName, dir);
28 List<FileInfo> list =
new List<FileInfo>();
29 FileInfo[] files = dir.GetFiles(
"*.xlsx", SearchOption.TopDirectoryOnly);
30 foreach (FileInfo fileInfo
in files)
34 talkTexts.Add(excelData);
39 Debug.Log(
$"TalkText: {talkTexts.Count}");
44 public IReadOnlyList<FileInfo>
ParseMap(DirectoryInfo dir,
bool addToList =
true)
46 List<FileInfo> list =
new List<FileInfo>();
47 FileInfo[] files = dir.GetFiles(
"*.z", SearchOption.TopDirectoryOnly);
48 foreach (FileInfo fileInfo
in files)
50 string key = Path.ChangeExtension(fileInfo.Name,
null);
60 Debug.Log(
$"Map: {maps.Count}");
65 public IReadOnlyList<FileInfo>
ParseMapPiece(DirectoryInfo dir,
bool addToList =
true)
67 List<FileInfo> list =
new List<FileInfo>();
68 FileInfo[] files = dir.GetFiles(
"*.mp", SearchOption.TopDirectoryOnly);
69 foreach (FileInfo fileInfo
in files)
71 string key = Path.ChangeExtension(fileInfo.Name,
null);
76 partialMaps[key] = fileInfo;
81 Debug.Log(
$"PartialMap: {partialMaps.Count}");
88 List<FileInfo> list =
new List<FileInfo>();
89 FileInfo[] files = dir.GetFiles(
"*.png", SearchOption.TopDirectoryOnly);
90 foreach (FileInfo fileInfo
in files)
92 string key = Path.ChangeExtension(fileInfo.Name,
null);
93 textureReplaces[key] = fileInfo;
98 Debug.Log(
$"Texture Replace: {textureReplaces.Count}");
105 List<FileInfo> list =
new List<FileInfo>();
106 FileInfo[] files = dir.GetFiles(
"*.png", SearchOption.AllDirectories);
107 foreach (FileInfo fileInfo
in files)
109 string key = Path.ChangeExtension(Path.GetRelativePath(dir.FullName, fileInfo.FullName).NormalizePath(),
null);
110 string text = Path.ChangeExtension(fileInfo.FullName,
null);
112 string value = (textures[key] = text);
113 dictModItems[key] = value;
118 Debug.Log(
$"Texture: {textures.Count}");
125 List<FileInfo> list =
new List<FileInfo>();
126 FileInfo[] files = dir.GetFiles(
"*.png", SearchOption.TopDirectoryOnly);
127 foreach (FileInfo fileInfo
in files)
129 string name = fileInfo.Name;
130 if (name.StartsWith(
"BG_", StringComparison.Ordinal))
134 else if (name.StartsWith(
"BGF_", StringComparison.Ordinal))
138 else if (name.EndsWith(
"-full.png", StringComparison.Ordinal))
142 else if (name.EndsWith(
"-overlay.png", StringComparison.Ordinal))
151 portraits[name] = fileInfo;
156 Debug.Log(
$"Portrait: {portraits.Count}");
165 Mapping =
new FileMapping(dir.Parent);
168 Lang.excelDialog =
null;
169 Debug.Log(
"LangMod: " +
string.Join(
", ", Mapping.OrderedLangMods));
170 if (Mapping.SourceSheets.Count > 0)
172 Debug.Log(
$"Source Sheets: {Mapping.SourceSheets.Count}, {Mapping.SourceLangMod}");
178 List<FileInfo> list =
new List<FileInfo>();
179 FileInfo[] files = dir.GetFiles(
"*.*", SearchOption.AllDirectories);
180 foreach (FileInfo fileInfo
in files)
182 if (ModUtil.GetAudioType(fileInfo.Extension) != 0)
184 string key = Path.ChangeExtension(Path.GetRelativePath(dir.FullName, fileInfo.FullName).NormalizePath(),
null);
185 Dictionary<string, FileInfo> dictionary =
MOD.
sounds;
186 FileInfo value = (sounds[key] = fileInfo);
187 dictionary[key] = value;
193 Debug.Log(
$"Sound: {sounds.Count}");
195 int num = sounds.Keys.Count((
string k) => k.StartsWith(
"BGM/"));
205 customContent.Clear();
251 else if (row.id.StartsWith(
"cwl") || row.id.StartsWith(
"custom"))
253 customContent.Add(CustomReligionContent.CreateFromRow(row,
this));
258 ModUtil.FixDefaultCharaRowPref(r);
262 customContent.RemoveAll((ICustomContent p) => p ==
null);
267 SortedDictionary<string, string> sortedDictionary =
new SortedDictionary<string, string>();
272 foreach (KeyValuePair<string, string>
item in sourceRow.ExportTexts(sourceRow.UseAlias ?
"alias" :
"id"))
274 item.Deconstruct(out var key, out var value);
276 string value2 = value;
277 sortedDictionary[key2] = value2;
281 catch (Exception arg)
283 Debug.LogError(
$"#source failed to export localization for {title}/{id}\n{arg}");
285 return sortedDictionary;
292 sourceRow.ImportTexts(texts, sourceRow.UseAlias ?
"alias" :
"id");
298 Mapping.RebuildLangModMapping(lang);
299 for (FileInfo fileInfo = Mapping.RelocateFile(
"SourceLocalization.json"); fileInfo !=
null; fileInfo = Mapping.RelocateFile(
"SourceLocalization.json"))
302 Debug.Log(
"#source-localization deleted " + fileInfo.ShortPath());
309 if (!base.IsSourceLocalizable)
313 IReadOnlyDictionary<string, string> modEntries = SourceLocalization.GetModEntries(
id, lang);
315 SortedDictionary<string, string>
final =
new SortedDictionary<string, string>();
316 foreach (var (key, defaultValue) in sortedDictionary)
318 final[key] = modEntries.GetValueOrDefault(key, defaultValue);
320 string text3 = Path.Combine(dirInfo.FullName,
"LangMod/" + lang +
"/SourceLocalization.json");
321 if (force || modEntries.Count !=
final.Count || modEntries.Any((KeyValuePair<string, string> kv) => !
final.ContainsKey(kv.Key)))
323 JsonSerializerSettings setting =
new JsonSerializerSettings
325 PreserveReferencesHandling = PreserveReferencesHandling.None,
326 NullValueHandling = NullValueHandling.Ignore
328 IO.SaveFile(text3,
final, compress:
false, setting);
329 SourceLocalization.UpdateModEntries(
id, lang,
final);
338 DirectoryInfo[] directories = dir.GetDirectories();
339 foreach (DirectoryInfo directoryInfo
in directories)
341 if (!directoryInfo.Name.StartsWith(
"_") && !TryAddLang(directoryInfo, isNew:
false))
343 Debug.Log(
"Generating Language Mod Contents:" + directoryInfo.FullName);
345 Directory.CreateDirectory(directoryInfo.FullName +
"/Dialog");
347 sources.ExportSourceTexts(directoryInfo.FullName +
"/Game");
349 TryAddLang(directoryInfo, isNew:
true);
352 bool TryAddLang(DirectoryInfo dirLang,
bool isNew)
354 string name = dirLang.Name;
355 FileInfo[] files = dirLang.GetFiles();
356 foreach (FileInfo fileInfo
in files)
358 if (fileInfo.Name ==
"lang.ini")
363 dir = dirLang.FullName +
"/"
372 Log.system =
"Updated Language Files:" + Environment.NewLine + Environment.NewLine;
373 Debug.Log(
"Updating Language:" + langSetting.
name +
"/" + langSetting.
GetVersion() +
"/" + core.version.GetInt());
374 string text = dirLang.FullName +
"/Game";
375 Directory.Move(text, text +
"_temp");
376 sources.ExportSourceTexts(text);
377 sources.UpdateSourceTexts(text);
378 IO.DeleteDirectory(text +
"_temp");
379 text = dirLang.FullName +
"/Dialog";
380 Directory.Move(text, text +
"_temp");
383 IO.DeleteDirectory(text +
"_temp");
384 text = dirLang.FullName +
"/Data";
385 IO.CopyDir(text, text +
"_temp");
388 UpdateTalks(
new DirectoryInfo(text), text +
"_temp");
389 IO.DeleteDirectory(text +
"_temp");
391 IO.SaveText(dirLang.FullName +
"/update.txt",
Log.
system);
403 DirectoryInfo[] directories = dir.GetDirectories();
404 foreach (DirectoryInfo directoryInfo
in directories)
406 UpdateDialogs(directoryInfo, dirTemp +
"/" + directoryInfo.Name);
408 FileInfo[] files = dir.GetFiles();
409 foreach (FileInfo fileInfo
in files)
411 if (fileInfo.Name.EndsWith(
"xlsx"))
420 FileInfo[] files = dir.GetFiles();
421 foreach (FileInfo fileInfo
in files)
423 if (fileInfo.Name ==
"god_talk.xlsx" || fileInfo.Name ==
"chara_talk.xlsx")
432 string path = dirTemp +
"/" + f.Name;
433 if (!File.Exists(path))
437 XSSFWorkbook xSSFWorkbook;
438 using (FileStream @is = File.Open(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
440 xSSFWorkbook =
new XSSFWorkbook((Stream)@is);
442 XSSFWorkbook xSSFWorkbook2;
443 using (FileStream is2 = File.Open(f.FullName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
445 xSSFWorkbook2 =
new XSSFWorkbook((Stream)is2);
447 for (
int i = 0; i < xSSFWorkbook2.NumberOfSheets; i++)
449 ISheet sheetAt = xSSFWorkbook2.GetSheetAt(i);
450 ISheet sheet = xSSFWorkbook.GetSheet(sheetAt.SheetName);
453 Log.system = Log.system +
"Old sheet not found:" + sheetAt.SheetName + Environment.NewLine;
457 Log.system = Log.system + ((num == 0) ?
"(No Changes) " :
"(Updated) ") + f.FullName +
"(" + sheetAt.SheetName +
")" + Environment.NewLine;
460 Log.system = Log.system + num + Environment.NewLine;
462 Log.system += Environment.NewLine;
464 using FileStream stream =
new FileStream(f.FullName, FileMode.Create, FileAccess.Write, FileShare.ReadWrite);
465 xSSFWorkbook2.Write(stream);
470 Dictionary<string, string[]> dictionary =
new Dictionary<string, string[]>();
474 IRow row2 = destSheet.GetRow(0);
475 IRow row3 = oldSheet.GetRow(0);
476 List<SheetIndex> list =
new List<SheetIndex>();
477 int cellnum = FindField(row2,
"id");
478 int cellnum2 = FindField(row3,
"id");
479 for (
int i = 0; i < row2.LastCellNum; i++)
481 ICell cell = row2.GetCell(i);
486 string stringCellValue = cell.StringCellValue;
487 if (stringCellValue ==
"id" || (updateOnlytext && stringCellValue !=
"text"))
491 for (
int j = 0; j < row3.LastCellNum; j++)
493 cell = row3.GetCell(j);
498 if (cell.StringCellValue == stringCellValue)
505 Debug.Log(destSheet.SheetName +
"/" + stringCellValue +
"/" + i +
"/" + j);
510 for (
int k = 2; k <= oldSheet.LastRowNum; k++)
512 IRow row4 = oldSheet.GetRow(k);
523 ICell cell2 = row4.GetCell(cellnum2);
528 string text = ((cell2.CellType == CellType.Numeric) ? cell2.NumericCellValue.ToString() : cell2.StringCellValue);
533 string[] array =
new string[list.Count];
534 for (
int l = 0; l < list.Count; l++)
536 ICell cell3 = row4.GetCell(list[l].old);
539 string stringCellValue2 = cell3.StringCellValue;
540 if (!stringCellValue2.IsEmpty())
542 array[l] = stringCellValue2;
546 dictionary.Add(text, array);
549 for (
int m = 2; m <= destSheet.LastRowNum; m++)
551 IRow row5 = destSheet.GetRow(m);
562 ICell cell4 = row5.GetCell(cellnum);
567 string text2 = ((cell4.CellType == CellType.Numeric) ? cell4.NumericCellValue.ToString() : cell4.StringCellValue);
568 if (text2.IsEmpty() || !dictionary.ContainsKey(text2))
572 string[] array2 = dictionary[text2];
573 for (
int n = 0; n < list.Count; n++)
575 ICell cell5 = row5.GetCell(list[n].dest) ?? row5.CreateCell(list[n].dest, CellType.String);
578 cell5.SetCellValue(array2[n]);
579 cell5.SetCellType(CellType.String);
580 cell5.SetAsActiveCell();
586 static int FindField(IRow row,
string id)
588 for (
int num4 = 0; num4 < row.LastCellNum; num4++)
590 ICell cell6 = row.GetCell(num4);
595 if (cell6.StringCellValue ==
id)
static string packageCore
static CustomCharaContent CreateFromRow(SourceChara.Row r, ModPackage owner=null)
static CustomElementContent CreateFromRow(SourceElement.Row r, ModPackage owner=null)
static CustomMaterialContent CreateFromRow(SourceMaterial.Row r, ModPackage owner=null)
static CustomStatContent CreateFromRow(SourceStat.Row r, ModPackage owner=null)
static CustomThingContent CreateFromRow(SourceThing.Row r, ModPackage mod=null)
static CustomZoneContent CreateFromRow(SourceZone.Row r, ModPackage owner=null)
static bool IsBuiltin(string id)
static Dictionary< string, LangSetting > langs
static Dictionary< string, FileInfo > sounds
static List< FileInfo > listMaps
static List< FileInfo > listPartialMaps
void Add(FileInfo fi, string path=null, string prefix="")
void CopyContentTo(string dir)
IReadOnlyList< FileInfo > ParseTalkText(DirectoryInfo dir)
void UpdateDialogs(DirectoryInfo dir, string dirTemp)
override void ClearSourceLocalizations(string lang)
override string UpdateSourceLocalizationFile(string lang, bool force=false)
void ParseLangMod(DirectoryInfo dir)
void UpdateExcelBook(FileInfo f, string dirTemp, bool updateOnlyText)
IReadOnlyList< FileInfo > ParseTexture(DirectoryInfo dir)
void AddOrUpdateLang(DirectoryInfo dir)
override void GenerateCustomContentProfiles()
IReadOnlyList< FileInfo > ParseMapPiece(DirectoryInfo dir, bool addToList=true)
override void ImportSourceLocalizations(IReadOnlyDictionary< string, string > texts)
override SortedDictionary< string, string > ExportSourceLocalizations()
void UpdateTalks(DirectoryInfo dir, string dirTemp)
IReadOnlyList< FileInfo > ParseTextureReplace(DirectoryInfo dir)
IReadOnlyList< FileInfo > ParsePortrait(DirectoryInfo dir)
IReadOnlyList< FileInfo > ParseMap(DirectoryInfo dir, bool addToList=true)
int UpdateExcelSheet(ISheet destSheet, ISheet oldSheet, bool updateOnlytext)
IReadOnlyList< FileInfo > ParseSound(DirectoryInfo dir)
static ModItemList< Sprite > modPortraitBGFs
static ModItemList< Sprite > modPortraitBGs
static ModItemList< Sprite > modOverlays
static ModItemList< Sprite > modPortraits
static HashSet< string > allIds
static ModItemList< Sprite > modFull
static Dictionary< string, string > dictModItems
static List< ExcelData > modList