mirror of
https://github.com/LorisYounger/VPet.git
synced 2024-08-30 18:42:36 +00:00
更加安全的图片URI加载
This commit is contained in:
parent
504efba24b
commit
3e673083b6
@ -133,7 +133,7 @@ namespace VPet_Simulator.Windows.Interface
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="imagename">图片名称</param>
|
/// <param name="imagename">图片名称</param>
|
||||||
/// <returns>图片资源,如果未找到则退回错误提示图片</returns>
|
/// <returns>图片资源,如果未找到则退回错误提示图片</returns>
|
||||||
public BitmapImage FindImage(string imagename) => new BitmapImage(FindImageUri(imagename));
|
public BitmapImage FindImage(string imagename) => NewSafeBitmapImage(FindImageUri(imagename));
|
||||||
|
|
||||||
public Uri FindImageUri(string imagename)
|
public Uri FindImageUri(string imagename)
|
||||||
{
|
{
|
||||||
@ -158,13 +158,33 @@ namespace VPet_Simulator.Windows.Interface
|
|||||||
string source = FindSource(imagename);
|
string source = FindSource(imagename);
|
||||||
if (source == null)
|
if (source == null)
|
||||||
{
|
{
|
||||||
return new BitmapImage(FindImageUri(superior));
|
return NewSafeBitmapImage(source);
|
||||||
}
|
}
|
||||||
return new BitmapImage(new Uri(source));
|
return NewSafeBitmapImage(source);
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 图片设置 (eg:定位锚点等)
|
/// 图片设置 (eg:定位锚点等)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public LpsDocument ImageSetting = new LpsDocument();
|
public LpsDocument ImageSetting = new LpsDocument();
|
||||||
|
/// <summary>
|
||||||
|
/// 更加安全的图片URI加载
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="source">图片源</param>
|
||||||
|
/// <returns>BitmapImage</returns>
|
||||||
|
public static BitmapImage NewSafeBitmapImage(string source) => NewSafeBitmapImage(new Uri(source));
|
||||||
|
/// <summary>
|
||||||
|
/// 更加安全的图片URI加载
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="source">图片源</param>
|
||||||
|
/// <returns>BitmapImage</returns>
|
||||||
|
public static BitmapImage NewSafeBitmapImage(Uri source)
|
||||||
|
{
|
||||||
|
BitmapImage bi = new BitmapImage();
|
||||||
|
bi.BeginInit();
|
||||||
|
bi.CreateOptions = BitmapCreateOptions.IgnoreColorProfile;
|
||||||
|
bi.UriSource = source;
|
||||||
|
bi.EndInit();
|
||||||
|
return bi;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -61,7 +61,7 @@ namespace VPet_Simulator.Windows
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 版本号
|
/// 版本号
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int version { get; } = 108;
|
public int version { get; } = 109;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 版本号
|
/// 版本号
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -144,7 +144,7 @@ namespace VPet_Simulator.Windows
|
|||||||
if (hashcheckimg == null)
|
if (hashcheckimg == null)
|
||||||
{
|
{
|
||||||
hashcheckimg = new Image();
|
hashcheckimg = new Image();
|
||||||
hashcheckimg.Source = new BitmapImage(new Uri("pack://application:,,,/Res/hash.png"));
|
hashcheckimg.Source = ImageResources.NewSafeBitmapImage("pack://application:,,,/Res/hash.png");
|
||||||
hashcheckimg.HorizontalAlignment = System.Windows.HorizontalAlignment.Right;
|
hashcheckimg.HorizontalAlignment = System.Windows.HorizontalAlignment.Right;
|
||||||
hashcheckimg.ToolTip = "是没有修改过存档/使用超模MOD的玩家专属标志".Translate();
|
hashcheckimg.ToolTip = "是没有修改过存档/使用超模MOD的玩家专属标志".Translate();
|
||||||
Grid.SetColumn(hashcheckimg, 4);
|
Grid.SetColumn(hashcheckimg, 4);
|
||||||
|
@ -27,6 +27,7 @@ using static VPet_Simulator.Core.GraphInfo;
|
|||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using static VPet_Simulator.Windows.Interface.ExtensionFunction;
|
using static VPet_Simulator.Windows.Interface.ExtensionFunction;
|
||||||
using LinePutScript.Dictionary;
|
using LinePutScript.Dictionary;
|
||||||
|
using System.Windows.Media.Imaging;
|
||||||
|
|
||||||
namespace VPet_Simulator.Windows
|
namespace VPet_Simulator.Windows
|
||||||
{
|
{
|
||||||
@ -65,7 +66,6 @@ namespace VPet_Simulator.Windows
|
|||||||
CultureInfo.CurrentCulture = new CultureInfo(CultureInfo.CurrentCulture.Name);
|
CultureInfo.CurrentCulture = new CultureInfo(CultureInfo.CurrentCulture.Name);
|
||||||
CultureInfo.CurrentCulture.NumberFormat = new CultureInfo("en-US").NumberFormat;
|
CultureInfo.CurrentCulture.NumberFormat = new CultureInfo("en-US").NumberFormat;
|
||||||
|
|
||||||
|
|
||||||
//判断是不是Steam用户,因为本软件会发布到Steam
|
//判断是不是Steam用户,因为本软件会发布到Steam
|
||||||
//在 https://store.steampowered.com/app/1920960/VPet
|
//在 https://store.steampowered.com/app/1920960/VPet
|
||||||
try
|
try
|
||||||
@ -205,7 +205,7 @@ namespace VPet_Simulator.Windows
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public new void Close()
|
public new void Close()
|
||||||
{
|
{
|
||||||
if (Main == null)
|
if (Main == null)
|
||||||
|
@ -331,7 +331,7 @@ namespace VPet_Simulator.Windows
|
|||||||
runMODAuthor.Text = mod.Author;
|
runMODAuthor.Text = mod.Author;
|
||||||
runMODGameVer.Text = CoreMOD.INTtoVER(mod.GameVer);
|
runMODGameVer.Text = CoreMOD.INTtoVER(mod.GameVer);
|
||||||
runMODGameVer.Foreground = Function.ResourcesBrush(Function.BrushType.PrimaryText);
|
runMODGameVer.Foreground = Function.ResourcesBrush(Function.BrushType.PrimaryText);
|
||||||
ImageMOD.Source = new BitmapImage(new Uri(mod.Path.FullName + @"\icon.png"));
|
ImageMOD.Source = ImageResources.NewSafeBitmapImage(mod.Path.FullName + @"\icon.png");
|
||||||
if (mod.GameVer < mw.version)
|
if (mod.GameVer < mw.version)
|
||||||
{
|
{
|
||||||
if (mod.GameVer / 10 == mw.version / 10)
|
if (mod.GameVer / 10 == mw.version / 10)
|
||||||
|
Loading…
Reference in New Issue
Block a user