mirror of
https://github.com/kwsch/pkNX.git
synced 2026-03-31 22:54:44 -05:00
File scoped namespaces NET6 for GUI handle nullable references add editorconfig (mostly for newline at end of file)
50 lines
1.2 KiB
C#
50 lines
1.2 KiB
C#
using System.IO;
|
|
using pkNX.Containers;
|
|
using pkNX.Structures;
|
|
|
|
namespace pkNX.WinForms;
|
|
|
|
public class TextContainer
|
|
{
|
|
public readonly IFileContainer Container;
|
|
public readonly TextConfig? Config;
|
|
public bool Remap { get; set; }
|
|
|
|
private readonly string[]?[] Cache;
|
|
|
|
public TextContainer(IFileContainer c, TextConfig? t = null, bool remap = false)
|
|
{
|
|
Remap = remap;
|
|
Config = t;
|
|
Container = c;
|
|
Cache = new string[Container.Count][];
|
|
}
|
|
|
|
public int Length => Cache.Length;
|
|
|
|
public string[] this[int index]
|
|
{
|
|
get => Cache[index] ??= GetLines(index);
|
|
set => Cache[index] = value;
|
|
}
|
|
|
|
private string[] GetLines(int index) => new TextFile(Container[index], Config, remapChars: Remap).Lines;
|
|
|
|
public string GetFileName(int i)
|
|
{
|
|
if (Container is FolderContainer f)
|
|
return Path.GetFileNameWithoutExtension(f.GetFileName(i));
|
|
return i.ToString();
|
|
}
|
|
|
|
public void Save()
|
|
{
|
|
for (int i = 0; i < Length; i++)
|
|
{
|
|
if (Cache[i] == null)
|
|
continue;
|
|
Container[i] = TextFile.GetBytes(Cache[i], Config, Remap);
|
|
}
|
|
}
|
|
}
|