code optimization
This commit is contained in:
@@ -1,102 +1,98 @@
|
||||
using OfficeOpenXml;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SM64Lib.Text.Exporters
|
||||
namespace SM64Lib.Text.Exporters;
|
||||
|
||||
public class ExcelExporter
|
||||
{
|
||||
public class ExcelExporter
|
||||
public ExcelExporter()
|
||||
{
|
||||
public ExcelExporter()
|
||||
ExcelPackage.LicenseContext = LicenseContext.NonCommercial;
|
||||
}
|
||||
|
||||
public async Task Export(string destFilePath, TextGroup[] groups)
|
||||
{
|
||||
var pkg = new ExcelPackage();
|
||||
|
||||
foreach (var tg in groups)
|
||||
{
|
||||
ExcelPackage.LicenseContext = LicenseContext.NonCommercial;
|
||||
var ws = pkg.Workbook.Worksheets.Add(tg.TextGroupInfo.Name);
|
||||
var hasDialogCells = false;
|
||||
|
||||
ws.Cells.Style.VerticalAlignment = OfficeOpenXml.Style.ExcelVerticalAlignment.Top;
|
||||
ws.Cells.Style.HorizontalAlignment = OfficeOpenXml.Style.ExcelHorizontalAlignment.Left;
|
||||
ws.Row(1).Style.Font.Bold = true;
|
||||
ws.Cells[1, 1].Value = "#";
|
||||
ws.Cells[1, 2].Value = "Text";
|
||||
|
||||
for (int i = 0; i < tg.Count; i++)
|
||||
{
|
||||
var ti = tg[i];
|
||||
var ri = i + 2;
|
||||
|
||||
ws.Cells[ri, 1].Value = i;
|
||||
ws.Cells[ri, 2].Value = ti.Text;
|
||||
|
||||
if (ti is TextTableDialogItem)
|
||||
hasDialogCells = true;
|
||||
}
|
||||
|
||||
|
||||
for (int ri = 1; ri <= ws.Cells.Rows; ri++)
|
||||
{
|
||||
var r = ws.Row(ri);
|
||||
r.CustomHeight = false;
|
||||
}
|
||||
|
||||
if (hasDialogCells)
|
||||
{
|
||||
var c = ws.Column(2);
|
||||
c.Style.WrapText = true;
|
||||
c.Width = 30;
|
||||
}
|
||||
|
||||
for (int ci = 1; ci <= 2; ci++)
|
||||
{
|
||||
var c = ws.Column(ci);
|
||||
if (!c.Style.WrapText)
|
||||
c.AutoFit();
|
||||
}
|
||||
}
|
||||
|
||||
public async Task Export(string destFilePath, TextGroup[] groups)
|
||||
await pkg.SaveAsAsync(new FileInfo(destFilePath));
|
||||
pkg.Dispose();
|
||||
}
|
||||
|
||||
public async Task Import(string filePath, TextGroup[] groups)
|
||||
{
|
||||
try
|
||||
{
|
||||
var pkg = new ExcelPackage();
|
||||
await pkg.LoadAsync(new FileInfo(filePath));
|
||||
|
||||
foreach (var tg in groups)
|
||||
{
|
||||
var ws = pkg.Workbook.Worksheets.Add(tg.TextGroupInfo.Name);
|
||||
var hasDialogCells = false;
|
||||
|
||||
ws.Cells.Style.VerticalAlignment = OfficeOpenXml.Style.ExcelVerticalAlignment.Top;
|
||||
ws.Cells.Style.HorizontalAlignment = OfficeOpenXml.Style.ExcelHorizontalAlignment.Left;
|
||||
ws.Row(1).Style.Font.Bold = true;
|
||||
ws.Cells[1, 1].Value = "#";
|
||||
ws.Cells[1, 2].Value = "Text";
|
||||
|
||||
for (int i = 0; i < tg.Count; i++)
|
||||
var ws = pkg.Workbook.Worksheets[tg.TextGroupInfo.Name];
|
||||
if (ws is not null)
|
||||
{
|
||||
var ti = tg[i];
|
||||
var ri = i + 2;
|
||||
|
||||
ws.Cells[ri, 1].Value = i;
|
||||
ws.Cells[ri, 2].Value = ti.Text;
|
||||
|
||||
if (ti is TextTableDialogItem)
|
||||
hasDialogCells = true;
|
||||
}
|
||||
|
||||
|
||||
for (int ri = 1; ri <= ws.Cells.Rows; ri++)
|
||||
{
|
||||
var r = ws.Row(ri);
|
||||
r.CustomHeight = false;
|
||||
}
|
||||
|
||||
if (hasDialogCells)
|
||||
{
|
||||
var c = ws.Column(2);
|
||||
c.Style.WrapText = true;
|
||||
c.Width = 30;
|
||||
}
|
||||
|
||||
for (int ci = 1; ci <= 2; ci++)
|
||||
{
|
||||
var c = ws.Column(ci);
|
||||
if (!c.Style.WrapText)
|
||||
c.AutoFit();
|
||||
}
|
||||
}
|
||||
|
||||
await pkg.SaveAsAsync(new FileInfo(destFilePath));
|
||||
pkg.Dispose();
|
||||
}
|
||||
|
||||
public async Task Import(string filePath, TextGroup[] groups)
|
||||
{
|
||||
try
|
||||
{
|
||||
var pkg = new ExcelPackage();
|
||||
await pkg.LoadAsync(new FileInfo(filePath));
|
||||
|
||||
foreach (var tg in groups)
|
||||
{
|
||||
var ws = pkg.Workbook.Worksheets[tg.TextGroupInfo.Name];
|
||||
if (ws is not null)
|
||||
for (int iti = 0; iti < tg.Count; iti++)
|
||||
{
|
||||
for (int iti = 0; iti < tg.Count; iti++)
|
||||
{
|
||||
var ti = tg[iti];
|
||||
var ri = iti + 2;
|
||||
var c = ws.Cells[ri, 2];
|
||||
var ti = tg[iti];
|
||||
var ri = iti + 2;
|
||||
var c = ws.Cells[ri, 2];
|
||||
|
||||
ti.Text = ((string)c.Value).Replace("\r\n", "\n").Replace("\n", "\r\n");
|
||||
tg.NeedToSave = true;
|
||||
}
|
||||
ti.Text = ((string)c.Value).Replace("\r\n", "\n").Replace("\n", "\r\n");
|
||||
tg.NeedToSave = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pkg.Dispose();
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
}
|
||||
pkg.Dispose();
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// Durch Festlegen von ComVisible auf FALSE werden die Typen in dieser Assembly
|
||||
// für COM-Komponenten unsichtbar. Wenn Sie auf einen Typ in dieser Assembly von
|
||||
|
||||
@@ -1,48 +1,43 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SM64Lib.Text.Exporters
|
||||
namespace SM64Lib.Text.Exporters;
|
||||
|
||||
public class TxtExporter
|
||||
{
|
||||
public class TxtExporter
|
||||
public async Task Export(string destFilePath, TextGroup[] groups)
|
||||
{
|
||||
public async Task Export(string destFilePath, TextGroup[] groups)
|
||||
var sw = new StreamWriter(destFilePath);
|
||||
|
||||
for (int itg = 0; itg < groups.Length; itg++)
|
||||
{
|
||||
var sw = new StreamWriter(destFilePath);
|
||||
var tg = groups[itg];
|
||||
|
||||
for (int itg = 0; itg < groups.Length; itg++)
|
||||
{
|
||||
var tg = groups[itg];
|
||||
|
||||
if (itg != 0)
|
||||
await sw.WriteLineAsync("------------------------------\n");
|
||||
await sw.WriteLineAsync($"Text Group - {tg.TextGroupInfo.Name}\n");
|
||||
if (itg != 0)
|
||||
await sw.WriteLineAsync("------------------------------\n");
|
||||
await sw.WriteLineAsync($"Text Group - {tg.TextGroupInfo.Name}\n");
|
||||
await sw.WriteLineAsync("------------------------------\n");
|
||||
|
||||
for (int iti = 0; iti < tg.Count; iti++)
|
||||
for (int iti = 0; iti < tg.Count; iti++)
|
||||
{
|
||||
var ti = tg[iti];
|
||||
|
||||
if (ti is TextTableDialogItem)
|
||||
{
|
||||
var ti = tg[iti];
|
||||
|
||||
if (ti is TextTableDialogItem)
|
||||
{
|
||||
await sw.WriteLineAsync($"Dialog #{iti}\n");
|
||||
await sw.WriteLineAsync(ti.Text);
|
||||
await sw.WriteLineAsync("\n\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
await sw.WriteLineAsync($"Text Item #{iti}");
|
||||
await sw.WriteLineAsync(ti.Text);
|
||||
await sw.WriteLineAsync();
|
||||
}
|
||||
await sw.WriteLineAsync($"Dialog #{iti}\n");
|
||||
await sw.WriteLineAsync(ti.Text);
|
||||
await sw.WriteLineAsync("\n\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
await sw.WriteLineAsync($"Text Item #{iti}");
|
||||
await sw.WriteLineAsync(ti.Text);
|
||||
await sw.WriteLineAsync();
|
||||
}
|
||||
}
|
||||
|
||||
await sw.FlushAsync();
|
||||
sw.Close();
|
||||
}
|
||||
|
||||
await sw.FlushAsync();
|
||||
sw.Close();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user