mirror of
https://github.com/LorisYounger/VPet.ModMaker.git
synced 2024-08-30 18:22:21 +00:00
优化保存速度
测试模组: Code 30s -> 10s
This commit is contained in:
parent
1be307cc93
commit
ca1dc6d9dc
@ -84,23 +84,39 @@ public static class Extensions
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="image">图片资源</param>
|
/// <param name="image">图片资源</param>
|
||||||
/// <param name="path">路径</param>
|
/// <param name="path">路径</param>
|
||||||
|
//public static void SaveToPng(this BitmapImage image, string path)
|
||||||
|
//{
|
||||||
|
// if (image is null)
|
||||||
|
// return;
|
||||||
|
// if (path.EndsWith(".png") is false)
|
||||||
|
// path += ".png";
|
||||||
|
// var encoder = new PngBitmapEncoder();
|
||||||
|
// var stream = image.StreamSource;
|
||||||
|
// // 保存位置
|
||||||
|
// var position = stream.Position;
|
||||||
|
// // 必须要重置位置, 否则EndInit将出错
|
||||||
|
// stream.Seek(0, SeekOrigin.Begin);
|
||||||
|
// encoder.Frames.Add(BitmapFrame.Create(image.StreamSource));
|
||||||
|
// // 恢复位置
|
||||||
|
// stream.Seek(position, SeekOrigin.Begin);
|
||||||
|
// using var fs = new FileStream(path, FileMode.Create);
|
||||||
|
// encoder.Save(fs);
|
||||||
|
//}
|
||||||
public static void SaveToPng(this BitmapImage image, string path)
|
public static void SaveToPng(this BitmapImage image, string path)
|
||||||
{
|
{
|
||||||
if (image is null)
|
if (image is null)
|
||||||
return;
|
return;
|
||||||
if (path.EndsWith(".png") is false)
|
if (path.EndsWith(".png") is false)
|
||||||
path += ".png";
|
path += ".png";
|
||||||
var encoder = new PngBitmapEncoder();
|
|
||||||
var stream = image.StreamSource;
|
var stream = image.StreamSource;
|
||||||
// 保存位置
|
// 保存位置
|
||||||
var position = stream.Position;
|
var position = stream.Position;
|
||||||
// 必须要重置位置, 否则EndInit将出错
|
// 必须要重置位置, 否则EndInit将出错
|
||||||
stream.Seek(0, SeekOrigin.Begin);
|
stream.Seek(0, SeekOrigin.Begin);
|
||||||
encoder.Frames.Add(BitmapFrame.Create(image.StreamSource));
|
using var fs = new FileStream(path, FileMode.Create);
|
||||||
|
stream.CopyTo(fs);
|
||||||
// 恢复位置
|
// 恢复位置
|
||||||
stream.Seek(position, SeekOrigin.Begin);
|
stream.Seek(position, SeekOrigin.Begin);
|
||||||
using var fs = new FileStream(path, FileMode.Create);
|
|
||||||
encoder.Save(fs);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -221,11 +221,11 @@ public class PetModel : I18nModel<I18nPetInfoModel>
|
|||||||
/// <param name="path">路径</param>
|
/// <param name="path">路径</param>
|
||||||
public void Save(string path)
|
public void Save(string path)
|
||||||
{
|
{
|
||||||
if (SourceId is not null)
|
|
||||||
Id.Value = SourceId;
|
|
||||||
if (IsSimplePetModel)
|
if (IsSimplePetModel)
|
||||||
{
|
{
|
||||||
|
Id.Value = SourceId;
|
||||||
SaveSimplePetInfo(path);
|
SaveSimplePetInfo(path);
|
||||||
|
Id.Value = SourceId + " (来自本体)".Translate();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
foreach (var cultureName in I18nHelper.Current.CultureNames)
|
foreach (var cultureName in I18nHelper.Current.CultureNames)
|
||||||
@ -252,13 +252,8 @@ public class PetModel : I18nModel<I18nPetInfoModel>
|
|||||||
SaveMoveInfo(lps);
|
SaveMoveInfo(lps);
|
||||||
File.WriteAllText(petFile, lps.ToString());
|
File.WriteAllText(petFile, lps.ToString());
|
||||||
|
|
||||||
var petAnimePath = Path.Combine(path, Id.Value);
|
// 保存图片
|
||||||
foreach (var anime in Animes)
|
SaveAnime(path);
|
||||||
anime.Save(petAnimePath);
|
|
||||||
foreach (var anime in FoodAnimes)
|
|
||||||
anime.Save(petAnimePath);
|
|
||||||
if (SourceId is not null)
|
|
||||||
Id.Value = SourceId + " (来自本体)".Translate();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SaveSimplePetInfo(string path)
|
private void SaveSimplePetInfo(string path)
|
||||||
@ -270,9 +265,16 @@ public class PetModel : I18nModel<I18nPetInfoModel>
|
|||||||
SaveWorksInfo(lps);
|
SaveWorksInfo(lps);
|
||||||
SaveMoveInfo(lps);
|
SaveMoveInfo(lps);
|
||||||
File.WriteAllText(petFile, lps.ToString());
|
File.WriteAllText(petFile, lps.ToString());
|
||||||
|
SaveAnime(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SaveAnime(string path)
|
||||||
|
{
|
||||||
var petAnimePath = Path.Combine(path, Id.Value);
|
var petAnimePath = Path.Combine(path, Id.Value);
|
||||||
foreach (var animeType in Animes)
|
foreach (var anime in Animes)
|
||||||
animeType.Save(petAnimePath);
|
anime.Save(petAnimePath);
|
||||||
|
foreach (var anime in FoodAnimes)
|
||||||
|
anime.Save(petAnimePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -26,6 +26,7 @@
|
|||||||
<RowDefinition Height="Auto" />
|
<RowDefinition Height="Auto" />
|
||||||
<RowDefinition Height="Auto" />
|
<RowDefinition Height="Auto" />
|
||||||
<RowDefinition />
|
<RowDefinition />
|
||||||
|
<RowDefinition Height="Auto" />
|
||||||
</Grid.RowDefinitions>
|
</Grid.RowDefinitions>
|
||||||
<Label Background="{x:Null}" Content="{ll:Str 打开最近的内容}" />
|
<Label Background="{x:Null}" Content="{ll:Str 打开最近的内容}" />
|
||||||
<Grid Grid.Row="1">
|
<Grid Grid.Row="1">
|
||||||
@ -90,7 +91,7 @@
|
|||||||
<TextBlock
|
<TextBlock
|
||||||
Grid.Row="1"
|
Grid.Row="1"
|
||||||
VerticalAlignment="Bottom"
|
VerticalAlignment="Bottom"
|
||||||
d:Text="{ll:Str Mod描述}"
|
d:Text="{ll:Str 路径}"
|
||||||
Text="{Binding SourcePath}"
|
Text="{Binding SourcePath}"
|
||||||
TextWrapping="Wrap" />
|
TextWrapping="Wrap" />
|
||||||
</Grid>
|
</Grid>
|
||||||
@ -101,6 +102,11 @@
|
|||||||
</Style>
|
</Style>
|
||||||
</ListBox.ItemContainerStyle>
|
</ListBox.ItemContainerStyle>
|
||||||
</ListBox>
|
</ListBox>
|
||||||
|
<TextBlock Grid.Row="3" HorizontalAlignment="Center">
|
||||||
|
<Hyperlink Click="Hyperlink_Click">
|
||||||
|
<TextBlock Text="{ll:Str 模组制作教程}" />
|
||||||
|
</Hyperlink>
|
||||||
|
</TextBlock>
|
||||||
</Grid>
|
</Grid>
|
||||||
<Grid Grid.Column="1">
|
<Grid Grid.Column="1">
|
||||||
<Grid.RowDefinitions>
|
<Grid.RowDefinitions>
|
||||||
|
@ -3,6 +3,7 @@ using LinePutScript.Localization.WPF;
|
|||||||
using Panuon.WPF.UI;
|
using Panuon.WPF.UI;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
@ -69,4 +70,9 @@ public partial class ModMakerWindow : WindowX
|
|||||||
}
|
}
|
||||||
ViewModel.LoadMod(history.SourcePath);
|
ViewModel.LoadMod(history.SourcePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void Hyperlink_Click(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
Process.Start(new ProcessStartInfo("https://github.com/LorisYounger/VPet.ModMaker/wiki"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user