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

@ -97,8 +97,8 @@ namespace ScrapModLoader
if (!mod.IsEnabled(gamePath)) if (!mod.IsEnabled(gamePath))
mod.Enable(gamePath, SelectedGameVersion); mod.Enable(gamePath, SelectedGameVersion);
else else
if (mod.IsEnabled(gamePath)) if (mod.IsEnabled(gamePath))
mod.Disable(gamePath); mod.Disable(gamePath);
} }
} }
} }

View File

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

View File

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