Files
PepApi.Core/PepLib.Core/NestIndex.cs
AJ 7c5b4ded5f chore(PepLib.Core): remove unused using directives and clean up formatting
Remove unnecessary System, System.Collections.Generic, System.IO, and
System.Linq using directives that were flagged by IDE analyzers. Also
includes minor whitespace and code style normalization.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-14 07:52:17 -05:00

67 lines
1.8 KiB
C#

using PepLib.IO;
using System.Text;
namespace PepLib
{
public class NestIndex
{
public string Directory { get; set; }
public List<NestInfo> Entries;
public NestIndex()
{
Entries = new List<NestInfo>();
}
public string GetPath(NestInfo entry)
{
return Path.Combine(Directory, entry.Name + ".zip");
}
public static NestIndex LoadFromDir(string directory)
{
var file = Path.Combine(directory, "pepfiles.lfn");
return Load(file);
}
public static NestIndex Load(string file)
{
if (!File.Exists(file))
return null;
var index = new NestIndex() { Directory = Path.GetDirectoryName(file) };
var stream = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
var reader = new StreamReader(stream);
var buffer = new char[4000];
while (reader.Read(buffer, 0, buffer.Length) > 0)
{
var memstream = new MemoryStream(Encoding.ASCII.GetBytes(buffer));
var inforeader = new NestInfoReader();
inforeader.Read(memstream);
index.Entries.Add(inforeader.Info);
}
reader.Close();
return index;
}
public static NestIndex Build(string directory)
{
var index = new NestIndex() { Directory = directory };
foreach (var file in System.IO.Directory.GetFiles(directory, "*.zip"))
{
var reader = new NestInfoReader();
reader.Read(file);
index.Entries.Add(reader.Info);
}
return index;
}
}
}