2using System.Collections.Generic;
5using NPOI.SS.UserModel;
6using NPOI.XSSF.UserModel;
20 List<FileInfo> list =
new List<FileInfo>();
21 FileInfo[] files = dir.GetFiles(
"*.xlsx", SearchOption.TopDirectoryOnly);
22 foreach (FileInfo fileInfo
in files)
26 talkTexts.Add(excelData);
31 Debug.Log(
$"TalkText: {talkTexts.Count}");
36 public IReadOnlyList<FileInfo>
ParseMap(DirectoryInfo dir,
bool addToList =
true)
38 List<FileInfo> list =
new List<FileInfo>();
39 FileInfo[] files = dir.GetFiles(
"*.z", SearchOption.TopDirectoryOnly);
40 foreach (FileInfo fileInfo
in files)
42 string key = Path.ChangeExtension(fileInfo.Name,
null);
52 Debug.Log(
$"Map: {maps.Count}");
57 public IReadOnlyList<FileInfo>
ParseMapPiece(DirectoryInfo dir,
bool addToList =
true)
59 List<FileInfo> list =
new List<FileInfo>();
60 FileInfo[] files = dir.GetFiles(
"*.mp", SearchOption.TopDirectoryOnly);
61 foreach (FileInfo fileInfo
in files)
63 string key = Path.ChangeExtension(fileInfo.Name,
null);
68 partialMaps[key] = fileInfo;
73 Debug.Log(
$"PartialMap: {partialMaps.Count}");
80 List<FileInfo> list =
new List<FileInfo>();
81 FileInfo[] files = dir.GetFiles(
"*.png", SearchOption.TopDirectoryOnly);
82 foreach (FileInfo fileInfo
in files)
84 string key = Path.ChangeExtension(fileInfo.Name,
null);
85 textureReplaces[key] = fileInfo;
90 Debug.Log(
$"Texture Replace: {textureReplaces.Count}");
97 List<FileInfo> list =
new List<FileInfo>();
98 FileInfo[] files = dir.GetFiles(
"*.png", SearchOption.AllDirectories);
99 foreach (FileInfo fileInfo
in files)
101 string key = Path.ChangeExtension(Path.GetRelativePath(dir.FullName, fileInfo.FullName).NormalizePath(),
null);
102 string text = Path.ChangeExtension(fileInfo.FullName,
null);
104 string value = (textures[key] = text);
105 dictModItems[key] = value;
110 Debug.Log(
$"Texture: {textures.Count}");
117 List<FileInfo> list =
new List<FileInfo>();
118 FileInfo[] files = dir.GetFiles(
"*.png", SearchOption.TopDirectoryOnly);
119 foreach (FileInfo fileInfo
in files)
121 string name = fileInfo.Name;
122 if (name.StartsWith(
"BG_", StringComparison.Ordinal))
126 else if (name.StartsWith(
"BGF_", StringComparison.Ordinal))
130 else if (name.EndsWith(
"-full.png", StringComparison.Ordinal))
134 else if (name.EndsWith(
"-overlay.png", StringComparison.Ordinal))
143 portraits[name] = fileInfo;
148 Debug.Log(
$"Portrait: {portraits.Count}");
157 Mapping =
new FileMapping(dir.Parent);
160 Lang.excelDialog =
null;
161 Debug.Log(
"LangMod: " +
string.Join(
", ", Mapping.OrderedLangMods));
162 if (Mapping.SourceSheets.Count > 0)
164 Debug.Log(
$"Source Sheets: {Mapping.SourceSheets.Count}, {Mapping.SourceLangMod}");
170 List<FileInfo> list =
new List<FileInfo>();
171 FileInfo[] files = dir.GetFiles(
"*.*", SearchOption.AllDirectories);
172 foreach (FileInfo fileInfo
in files)
176 string key = Path.ChangeExtension(Path.GetRelativePath(dir.FullName, fileInfo.FullName).NormalizePath(),
null);
177 Dictionary<string, FileInfo> dictionary =
MOD.
sounds;
178 FileInfo value = (sounds[key] = fileInfo);
179 dictionary[key] = value;
185 Debug.Log(
$"Sound: {sounds.Count}");
187 int num = sounds.Keys.Count((
string k) => k.StartsWith(
"BGM/"));
197 SortedDictionary<string, string> sortedDictionary =
new SortedDictionary<string, string>();
202 foreach (KeyValuePair<string, string>
item in sourceRow.ExportTexts(sourceRow.UseAlias ?
"alias" :
"id"))
204 item.Deconstruct(out var key, out var value);
206 string value2 = value;
207 sortedDictionary[key2] = value2;
211 catch (Exception arg)
213 Debug.LogError(
$"#source failed to export localization for {title}/{id}\n{arg}");
215 return sortedDictionary;
222 sourceRow.ImportTexts(texts, sourceRow.UseAlias ?
"alias" :
"id");
228 Mapping.RebuildLangModMapping(lang);
229 for (FileInfo fileInfo = Mapping.RelocateFile(
"SourceLocalization.json"); fileInfo !=
null; fileInfo = Mapping.RelocateFile(
"SourceLocalization.json"))
232 Debug.Log(
"#source localization deleted " + fileInfo.ShortPath());
241 DirectoryInfo[] directories = dir.GetDirectories();
242 foreach (DirectoryInfo directoryInfo
in directories)
244 if (!directoryInfo.Name.StartsWith(
"_") && !TryAddLang(directoryInfo, isNew:
false))
246 Debug.Log(
"Generating Language Mod Contents:" + directoryInfo.FullName);
248 Directory.CreateDirectory(directoryInfo.FullName +
"/Dialog");
250 sources.ExportSourceTexts(directoryInfo.FullName +
"/Game");
252 TryAddLang(directoryInfo, isNew:
true);
255 bool TryAddLang(DirectoryInfo dirLang,
bool isNew)
257 string name = dirLang.Name;
258 FileInfo[] files = dirLang.GetFiles();
259 foreach (FileInfo fileInfo
in files)
261 if (fileInfo.Name ==
"lang.ini")
266 dir = dirLang.FullName +
"/"
275 Log.system =
"Updated Language Files:" + Environment.NewLine + Environment.NewLine;
276 Debug.Log(
"Updating Language:" + langSetting.
name +
"/" + langSetting.
GetVersion() +
"/" + core.version.GetInt());
277 string text = dirLang.FullName +
"/Game";
278 Directory.Move(text, text +
"_temp");
279 sources.ExportSourceTexts(text);
280 sources.UpdateSourceTexts(text);
281 IO.DeleteDirectory(text +
"_temp");
282 text = dirLang.FullName +
"/Dialog";
283 Directory.Move(text, text +
"_temp");
286 IO.DeleteDirectory(text +
"_temp");
287 text = dirLang.FullName +
"/Data";
288 IO.CopyDir(text, text +
"_temp");
291 UpdateTalks(
new DirectoryInfo(text), text +
"_temp");
292 IO.DeleteDirectory(text +
"_temp");
294 IO.SaveText(dirLang.FullName +
"/update.txt",
Log.
system);
306 DirectoryInfo[] directories = dir.GetDirectories();
307 foreach (DirectoryInfo directoryInfo
in directories)
309 UpdateDialogs(directoryInfo, dirTemp +
"/" + directoryInfo.Name);
311 FileInfo[] files = dir.GetFiles();
312 foreach (FileInfo fileInfo
in files)
314 if (fileInfo.Name.EndsWith(
"xlsx"))
323 FileInfo[] files = dir.GetFiles();
324 foreach (FileInfo fileInfo
in files)
326 if (fileInfo.Name ==
"god_talk.xlsx" || fileInfo.Name ==
"chara_talk.xlsx")
335 string path = dirTemp +
"/" + f.Name;
336 if (!File.Exists(path))
340 XSSFWorkbook xSSFWorkbook;
341 using (FileStream @is = File.Open(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
343 xSSFWorkbook =
new XSSFWorkbook((Stream)@is);
345 XSSFWorkbook xSSFWorkbook2;
346 using (FileStream is2 = File.Open(f.FullName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
348 xSSFWorkbook2 =
new XSSFWorkbook((Stream)is2);
350 for (
int i = 0; i < xSSFWorkbook2.NumberOfSheets; i++)
352 ISheet sheetAt = xSSFWorkbook2.GetSheetAt(i);
353 ISheet sheet = xSSFWorkbook.GetSheet(sheetAt.SheetName);
356 Log.system = Log.system +
"Old sheet not found:" + sheetAt.SheetName + Environment.NewLine;
360 Log.system = Log.system + ((num == 0) ?
"(No Changes) " :
"(Updated) ") + f.FullName +
"(" + sheetAt.SheetName +
")" + Environment.NewLine;
363 Log.system = Log.system + num + Environment.NewLine;
365 Log.system += Environment.NewLine;
367 using FileStream stream =
new FileStream(f.FullName, FileMode.Create, FileAccess.Write, FileShare.ReadWrite);
368 xSSFWorkbook2.Write(stream);
373 Dictionary<string, string[]> dictionary =
new Dictionary<string, string[]>();
377 IRow row2 = destSheet.GetRow(0);
378 IRow row3 = oldSheet.GetRow(0);
379 List<SheetIndex> list =
new List<SheetIndex>();
380 int cellnum = FindField(row2,
"id");
381 int cellnum2 = FindField(row3,
"id");
382 for (
int i = 0; i < row2.LastCellNum; i++)
384 ICell cell = row2.GetCell(i);
389 string stringCellValue = cell.StringCellValue;
390 if (stringCellValue ==
"id" || (updateOnlytext && stringCellValue !=
"text"))
394 for (
int j = 0; j < row3.LastCellNum; j++)
396 cell = row3.GetCell(j);
401 if (cell.StringCellValue == stringCellValue)
408 Debug.Log(destSheet.SheetName +
"/" + stringCellValue +
"/" + i +
"/" + j);
413 for (
int k = 2; k <= oldSheet.LastRowNum; k++)
415 IRow row4 = oldSheet.GetRow(k);
426 ICell cell2 = row4.GetCell(cellnum2);
431 string text = ((cell2.CellType == CellType.Numeric) ? cell2.NumericCellValue.ToString() : cell2.StringCellValue);
436 string[] array =
new string[list.Count];
437 for (
int l = 0; l < list.Count; l++)
439 ICell cell3 = row4.GetCell(list[l].old);
442 string stringCellValue2 = cell3.StringCellValue;
443 if (!stringCellValue2.IsEmpty())
445 array[l] = stringCellValue2;
449 dictionary.Add(text, array);
452 for (
int m = 2; m <= destSheet.LastRowNum; m++)
454 IRow row5 = destSheet.GetRow(m);
465 ICell cell4 = row5.GetCell(cellnum);
470 string text2 = ((cell4.CellType == CellType.Numeric) ? cell4.NumericCellValue.ToString() : cell4.StringCellValue);
471 if (text2.IsEmpty() || !dictionary.ContainsKey(text2))
475 string[] array2 = dictionary[text2];
476 for (
int n = 0; n < list.Count; n++)
478 ICell cell5 = row5.GetCell(list[n].dest) ?? row5.CreateCell(list[n].dest, CellType.String);
481 cell5.SetCellValue(array2[n]);
482 cell5.SetCellType(CellType.String);
483 cell5.SetAsActiveCell();
489 static int FindField(IRow row,
string id)
491 for (
int num4 = 0; num4 < row.LastCellNum; num4++)
493 ICell cell6 = row.GetCell(num4);
498 if (cell6.StringCellValue ==
id)
static string packageCore
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="")
IReadOnlyList< FileInfo > ParseTalkText(DirectoryInfo dir)
void UpdateDialogs(DirectoryInfo dir, string dirTemp)
void ClearSourceLocalizations(string lang)
SortedDictionary< string, string > ExportSourceLocalizations()
void ParseLangMod(DirectoryInfo dir)
void UpdateExcelBook(FileInfo f, string dirTemp, bool updateOnlyText)
IReadOnlyList< FileInfo > ParseTexture(DirectoryInfo dir)
void AddOrUpdateLang(DirectoryInfo dir)
IReadOnlyList< FileInfo > ParseMapPiece(DirectoryInfo dir, bool addToList=true)
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)
void ImportSourceLocalizations(IReadOnlyDictionary< string, string > texts)
static AudioType GetAudioType(string extension)
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