do PR note

This commit is contained in:
Никонов Василий 2022-02-14 09:46:59 +11:00
parent 1e25aa210a
commit 90764c8636
3 changed files with 14 additions and 15 deletions

View file

@ -2,7 +2,6 @@
using System.Collections.Generic;
using System.IO;
using System.Windows.Media.Imaging;
using System.Xml;
using Ionic.Zip;
@ -87,7 +86,7 @@ namespace ScrapModLoader
gamePath += @"Mods\" + Name;
Directory.CreateDirectory(gamePath);
using (var zipFile = ZipFile.Read(ModPath))
using (ZipFile zipFile = ZipFile.Read(ModPath))
{
foreach (ZipEntry zipEntry in zipFile)
{
@ -102,28 +101,28 @@ namespace ScrapModLoader
public static ScrapMod LoadFromFile(String path)
{
using var zipFile = ZipFile.Read(path);
using ZipFile zipFile = ZipFile.Read(path);
Byte[] iconBuffer = Utils.ExtractFromZip(zipFile, "icon.png");
Byte[] confBuffer = Utils.ExtractFromZip(zipFile, "config.toml");
var mod = new ScrapMod()
ScrapMod mod = new ScrapMod()
{
ModPath = path,
Icon = Utils.LoadImage(iconBuffer)
};
LoadConfig(ref mod, confBuffer);
LoadConfig(mod, confBuffer);
return mod;
}
private static void LoadConfig(ref ScrapMod mod, Byte[] buffer)
private static void LoadConfig(ScrapMod mod, Byte[] buffer)
{
using var sourceStream = new MemoryStream(buffer);
using var reader = new StreamReader(sourceStream);
using MemoryStream sourceStream = new MemoryStream(buffer);
using StreamReader reader = new StreamReader(sourceStream);
TomlTable config = TOML.Parse(reader);

View file

@ -1,8 +1,8 @@
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Windows.Media.Imaging;
using System.IO;
using System.Windows.Media.Imaging;
using Ionic.Zip;
@ -35,8 +35,8 @@ internal static class Utils
if (entry == null)
throw new FileFormatException($"No '{entry_path}' in {zip.Name} found");
var buffer = new Byte[entry.UncompressedSize];
using (var zipStream = new MemoryStream(buffer))
Byte[] buffer = new Byte[entry.UncompressedSize];
using (MemoryStream zipStream = new MemoryStream(buffer))
entry.Extract(zipStream);
return buffer;
@ -44,9 +44,9 @@ internal static class Utils
public static BitmapImage LoadImage(Byte[] buffer)
{
using var sourceStream = new MemoryStream(buffer);
using MemoryStream sourceStream = new MemoryStream(buffer);
var image = new BitmapImage();
BitmapImage? image = new BitmapImage();
image.BeginInit();
image.CacheOption = BitmapCacheOption.OnLoad;