refactor(PepLib.Core): reorganize files into logical folder structure
Move 38 files from root directory into organized subfolders: - Enums/ (7 files): StatusType, ApplicationType, DrawingType, etc. - Geometry/ (5 files): Vector, Box, Size, Spacing, Node - Models/ (15 files): Nest, Plate, Part, Program, Report, etc. - Utilities/ (7 files): MathHelper, Tolerance, ZipHelper, etc. - Extensions/ (2 files): PartListExtensions, PlateListExtensions - Interfaces/ (1 file): IMovable Update namespaces to follow folder hierarchy (e.g., PepLib.Models). Add GlobalUsings.cs for internal backward compatibility. Update Codes/ and IO/ files with new using statements. Update PepApi.Core consumers to reference new namespaces. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
81
PepLib.Core/Utilities/ZipHelper.cs
Normal file
81
PepLib.Core/Utilities/ZipHelper.cs
Normal file
@@ -0,0 +1,81 @@
|
||||
using System.IO.Compression;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace PepLib.Utilities
|
||||
{
|
||||
public static class ZipHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// Returns the files that match the specified pattern.
|
||||
/// </summary>
|
||||
/// <param name="file">Input zip file.</param>
|
||||
/// <param name="pattern">Pattern to match.</param>
|
||||
/// <param name="names">Names of the files that match the pattern.</param>
|
||||
/// <param name="streams">Data of the files that match the pattern.</param>
|
||||
/// <returns></returns>
|
||||
public static int ExtractByPattern(string file, string pattern, out string[] names, out Stream[] streams)
|
||||
{
|
||||
var nameList = new List<string>();
|
||||
var streamList = new List<Stream>();
|
||||
|
||||
using (var fileStream = new FileStream(file, FileMode.Open, FileAccess.Read))
|
||||
using (var zip = new ZipArchive(fileStream, ZipArchiveMode.Read))
|
||||
{
|
||||
foreach (var entry in zip.Entries)
|
||||
{
|
||||
if (!Regex.IsMatch(entry.FullName, pattern))
|
||||
continue;
|
||||
|
||||
nameList.Add(entry.FullName);
|
||||
|
||||
var memstream = new MemoryStream();
|
||||
using var entryStream = entry.Open();
|
||||
entryStream.CopyTo(memstream);
|
||||
memstream.Seek(0, SeekOrigin.Begin);
|
||||
streamList.Add(memstream);
|
||||
}
|
||||
}
|
||||
|
||||
names = nameList.ToArray();
|
||||
streams = streamList.ToArray();
|
||||
|
||||
return streams.Length;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the first file found that matches the specified file extension.
|
||||
/// </summary>
|
||||
/// <param name="file">Input zip file.</param>
|
||||
/// <param name="extension">Extension to match.</param>
|
||||
/// <param name="name">The name of the file that matches the file extension.</param>
|
||||
/// <param name="stream">The data of the file that matches the file extension.</param>
|
||||
/// <returns></returns>
|
||||
public static bool ExtractByExtension(string file, string extension, out string name, out Stream stream)
|
||||
{
|
||||
using (var fileStream = new FileStream(file, FileMode.Open, FileAccess.Read))
|
||||
using (var zip = new ZipArchive(fileStream, ZipArchiveMode.Read))
|
||||
{
|
||||
foreach (var entry in zip.Entries)
|
||||
{
|
||||
if (Path.GetExtension(entry.FullName) != extension)
|
||||
continue;
|
||||
|
||||
var memstream = new MemoryStream();
|
||||
using var entryStream = entry.Open();
|
||||
entryStream.CopyTo(memstream);
|
||||
memstream.Seek(0, SeekOrigin.Begin);
|
||||
|
||||
stream = memstream;
|
||||
name = entry.FullName;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
stream = null;
|
||||
name = null;
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user