|
2 | 2 | using System.Linq; |
3 | 3 | using System.Threading; |
4 | 4 | using System.Threading.Tasks; |
| 5 | +using ICSharpCode.SharpZipLib.BZip2; |
| 6 | +using ICSharpCode.SharpZipLib.GZip; |
| 7 | +using ICSharpCode.SharpZipLib.Tar; |
5 | 8 | using Microsoft.Extensions.Hosting; |
6 | 9 | using Microsoft.Extensions.Logging; |
7 | 10 | using NosCore.ParserInputGenerator.Downloader; |
@@ -60,16 +63,30 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken) |
60 | 63 | // ignored as header is not important |
61 | 64 | } |
62 | 65 | var manifest = await _client.DownloadManifest(); |
63 | | - var fileslist = _parserInputFiles.Select(o => $"NostaleData\\{o}").ToList(); |
| 66 | + var fileslist = _parserInputFiles.Select(o => $"NostaleData{Path.DirectorySeparatorChar}{o}").ToList(); |
64 | 67 | manifest.Entries = manifest.Entries.Where(s => fileslist.Contains(s.File)).ToArray(); |
65 | 68 | await _client.DownloadClientAsync(manifest); |
66 | 69 | foreach (var file in fileslist) |
67 | 70 | { |
68 | 71 | var rename = file.Contains("NScliData"); |
69 | | - var dest = file.Contains("NStcData") ? ".\\output\\parser\\maps\\" : ".\\output\\parser\\"; |
70 | | - var fileInfo = new FileInfo($".\\output\\{file}"); |
| 72 | + var dest = file.Contains("NStcData") ? $".{Path.DirectorySeparatorChar}output{Path.DirectorySeparatorChar}parser{Path.DirectorySeparatorChar}maps{Path.DirectorySeparatorChar}" : $".{Path.DirectorySeparatorChar}output{Path.DirectorySeparatorChar}parser{Path.DirectorySeparatorChar}"; |
| 73 | + var fileInfo = new FileInfo($".{Path.DirectorySeparatorChar}output{Path.DirectorySeparatorChar}{file}"); |
71 | 74 | await _extractor.ExtractAsync(fileInfo, dest, rename); |
72 | 75 | } |
| 76 | + var directoryOfFilesToBeTarred = new DirectoryInfo(".{Path.DirectorySeparatorChar}output{Path.DirectorySeparatorChar}parser"); |
| 77 | + var filesInDirectory = directoryOfFilesToBeTarred.GetFiles("*.*", SearchOption.AllDirectories); |
| 78 | + var tarArchiveName = $".{Path.DirectorySeparatorChar}output{Path.DirectorySeparatorChar}parser-input-files.tar.bz2"; |
| 79 | + if (File.Exists(tarArchiveName)) |
| 80 | + { |
| 81 | + File.Delete(tarArchiveName); |
| 82 | + } |
| 83 | + await using Stream targetStream = new BZip2OutputStream(File.Create(tarArchiveName)); |
| 84 | + using var tarArchive = TarArchive.CreateOutputTarArchive(targetStream, TarBuffer.DefaultBlockFactor); |
| 85 | + foreach (var fileToBeTarred in filesInDirectory) |
| 86 | + { |
| 87 | + var entry = TarEntry.CreateEntryFromFile(fileToBeTarred.FullName); |
| 88 | + tarArchive.WriteEntry(entry, true); |
| 89 | + } |
73 | 90 | _logger.LogInformation(LogLanguage.Instance.GetMessageFromKey(LogLanguageKey.PARSER_INPUT_GENERATED)); |
74 | 91 | } |
75 | 92 | } |
|
0 commit comments