mirror of
https://github.com/LorisYounger/VPet.git
synced 2024-08-30 18:42:36 +00:00
# VPet.Solution
## 修复 - `Settings.lps`不存在时启动失败的问题 - 读取模组信息时失败的问题
This commit is contained in:
parent
a46194b353
commit
61e9b9e5af
@ -47,6 +47,6 @@ public class AllIsBoolConverter : MultiValueToBoolConverter<AllIsBoolConverter>
|
||||
{
|
||||
var boolValue = TargetBoolValue;
|
||||
var nullValue = BoolOnNull;
|
||||
return values.All(o => Utils.GetBool(o, boolValue, nullValue));
|
||||
return values.All(o => HKWUtils.HKWUtils.GetBool(o, boolValue, nullValue));
|
||||
}
|
||||
}
|
||||
|
@ -90,7 +90,7 @@ public class AllIsBoolToVisibilityConverter
|
||||
{
|
||||
var boolValue = TargetBoolValue;
|
||||
var nullValue = BoolOnNull;
|
||||
return values.All(o => Utils.GetBool(o, boolValue, nullValue))
|
||||
return values.All(o => HKWUtils.HKWUtils.GetBool(o, boolValue, nullValue))
|
||||
? VisibilityOnTrue
|
||||
: VisibilityOnFalse;
|
||||
}
|
||||
|
@ -56,7 +56,7 @@ public class BoolToVisibilityConverter : BoolToValueConverterBase<BoolToVisibili
|
||||
CultureInfo culture
|
||||
)
|
||||
{
|
||||
return Utils.GetBool(value, BoolValue, NullValue)
|
||||
return HKWUtils.HKWUtils.GetBool(value, BoolValue, NullValue)
|
||||
? TrueVisibilityValue
|
||||
: FalseVisibilityValue;
|
||||
}
|
||||
|
@ -57,6 +57,6 @@ public class IsBoolConverter : ValueConverterBase
|
||||
CultureInfo culture
|
||||
)
|
||||
{
|
||||
return Utils.GetBool(value, BoolValue, NullValue);
|
||||
return HKWUtils.HKWUtils.GetBool(value, BoolValue, NullValue);
|
||||
}
|
||||
}
|
||||
|
@ -91,7 +91,7 @@ public class ModLoader
|
||||
IsSuccesses = false;
|
||||
return;
|
||||
}
|
||||
var modlps = new LpsDocument(File.ReadAllText(infoFile));
|
||||
var modlps = new LPS(File.ReadAllText(infoFile));
|
||||
Name = modlps.FindLine("vupmod").Info;
|
||||
Intro = modlps.FindLine("intro").Info;
|
||||
GameVer = modlps.FindSub("gamever").InfoToInt;
|
||||
@ -119,7 +119,7 @@ public class ModLoader
|
||||
{
|
||||
try
|
||||
{
|
||||
Image = Utils.LoadImageToStream(imagePath);
|
||||
Image = HKWUtils.LoadImageToStream(imagePath);
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
|
@ -8,8 +8,10 @@ using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using VPet.Solution.Views.SettingEditor;
|
||||
using VPet_Simulator.Windows.Interface;
|
||||
|
||||
namespace VPet.Solution.Models.SettingEditor;
|
||||
@ -21,16 +23,8 @@ public class ModSettingModel : ObservableClass<ModSettingModel>
|
||||
public const string MsgModLineName = "msgmod";
|
||||
public const string WorkShopLineName = "workshop";
|
||||
public static string ModDirectory = Path.Combine(Environment.CurrentDirectory, "mod");
|
||||
public static Dictionary<string, ModLoader> LocalMods = Directory.Exists(ModDirectory) is false
|
||||
? new(StringComparer.OrdinalIgnoreCase)
|
||||
: new(
|
||||
Directory
|
||||
.EnumerateDirectories(ModDirectory)
|
||||
.Select(d => new ModLoader(d))
|
||||
.Distinct(CompareUtils<ModLoader>.Create(m => m.Name))
|
||||
.ToDictionary(m => m.Name, m => m),
|
||||
StringComparer.OrdinalIgnoreCase
|
||||
);
|
||||
public static Dictionary<string, ModLoader> LocalMods { get; private set; } = null;
|
||||
|
||||
#region Mods
|
||||
private ObservableCollection<ModModel> _mods = new();
|
||||
public ObservableCollection<ModModel> Mods
|
||||
@ -41,6 +35,7 @@ public class ModSettingModel : ObservableClass<ModSettingModel>
|
||||
|
||||
public ModSettingModel(Setting setting)
|
||||
{
|
||||
LocalMods ??= GetLocalMods();
|
||||
foreach (var item in setting[ModLineName])
|
||||
{
|
||||
var modName = item.Name;
|
||||
@ -77,6 +72,24 @@ public class ModSettingModel : ObservableClass<ModSettingModel>
|
||||
}
|
||||
}
|
||||
|
||||
private static Dictionary<string, ModLoader> GetLocalMods()
|
||||
{
|
||||
var dic = new Dictionary<string, ModLoader>(StringComparer.OrdinalIgnoreCase);
|
||||
foreach (var dir in Directory.EnumerateDirectories(ModDirectory))
|
||||
{
|
||||
try
|
||||
{
|
||||
var loader = new ModLoader(dir);
|
||||
dic.TryAdd(loader.Name, loader);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show("模组载入错误\n路径:{0}\n异常:{1}".Translate(dir, ex));
|
||||
}
|
||||
}
|
||||
return dic;
|
||||
}
|
||||
|
||||
public void Close()
|
||||
{
|
||||
foreach (var modLoader in LocalMods)
|
||||
|
@ -1,11 +1,12 @@
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Text;
|
||||
using System.Windows.Media.Imaging;
|
||||
|
||||
namespace HKW.HKWUtils;
|
||||
|
||||
/// <summary>
|
||||
/// 工具
|
||||
/// </summary>
|
||||
public static class Utils
|
||||
public static class HKWUtils
|
||||
{
|
||||
/// <summary>
|
||||
/// 解码像素宽度
|
||||
@ -123,4 +124,17 @@ public static class Utils
|
||||
.Start("Explorer", $"/select,{Path.GetFullPath(filePath)}")
|
||||
?.Close();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 从文件获取只读流 (用于目标文件被其它进程访问的情况)
|
||||
/// </summary>
|
||||
/// <param name="path">文件</param>
|
||||
/// <param name="encoding">编码</param>
|
||||
/// <returns>流读取器</returns>
|
||||
public static StreamReader StreamReaderOnReadOnly(string path, Encoding? encoding = null)
|
||||
{
|
||||
encoding ??= Encoding.UTF8;
|
||||
var fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
|
||||
return new StreamReader(fs, encoding);
|
||||
}
|
||||
}
|
@ -227,7 +227,7 @@
|
||||
<Compile Include="Utils\ObservableRange.cs" />
|
||||
<Compile Include="Utils\ObservablePoint.cs" />
|
||||
<Compile Include="Utils\ObservableRect.cs" />
|
||||
<Compile Include="Utils\Utils.cs" />
|
||||
<Compile Include="Utils\HKWUtils.cs" />
|
||||
<Compile Include="Resources\NativeResources.cs" />
|
||||
<Compile Include="Usings.cs" />
|
||||
<Page Include="NativeStyles.xaml">
|
||||
|
@ -23,7 +23,7 @@ public class MainWindowVM : ObservableClass<MainWindowVM>
|
||||
_mainSetting = SettingWindowVM.Current.ShowSettings.FirstOrDefault(
|
||||
m => m.Name == nameof(Setting)
|
||||
);
|
||||
if (string.IsNullOrWhiteSpace(_mainSetting.GraphicsSetting.Language))
|
||||
if (string.IsNullOrWhiteSpace(_mainSetting?.GraphicsSetting?.Language))
|
||||
CurrentCulture = LocalizeCore.CurrentCulture;
|
||||
else
|
||||
CurrentCulture = _mainSetting.GraphicsSetting.Language;
|
||||
@ -43,9 +43,11 @@ public class MainWindowVM : ObservableClass<MainWindowVM>
|
||||
private void FirstStartFailedCommand_ExecuteCommand()
|
||||
{
|
||||
if (LocalizeCore.CurrentCulture == "zh-Hans")
|
||||
Utils.OpenLink("https://www.bilibili.com/read/cv26510496/");
|
||||
HKWUtils.OpenLink("https://www.bilibili.com/read/cv26510496/");
|
||||
else
|
||||
Utils.OpenLink("https://steamcommunity.com/games/1920960/announcements/detail/3681184905256253203");
|
||||
HKWUtils.OpenLink(
|
||||
"https://steamcommunity.com/games/1920960/announcements/detail/3681184905256253203"
|
||||
);
|
||||
}
|
||||
|
||||
#region Property
|
||||
|
@ -72,12 +72,12 @@ public class SaveWindowVM : ObservableClass<SaveWindowVM>
|
||||
|
||||
private void OpenFileInExplorerCommand_ExecuteCommand(SaveModel parameter)
|
||||
{
|
||||
Utils.OpenFileInExplorer(parameter.FilePath);
|
||||
HKWUtils.OpenFileInExplorer(parameter.FilePath);
|
||||
}
|
||||
|
||||
private void OpenFileCommand_ExecuteCommand(SaveModel parameter)
|
||||
{
|
||||
Utils.OpenLink(parameter.FilePath);
|
||||
HKWUtils.OpenLink(parameter.FilePath);
|
||||
}
|
||||
|
||||
public void RefreshShowSaves(string name)
|
||||
|
@ -130,7 +130,7 @@ public class ModSettingPageVM : ObservableClass<ModSettingPageVM>
|
||||
|
||||
private void OpenSteamCommunityCommand_ExecuteCommand(ModModel parameter)
|
||||
{
|
||||
Utils.OpenLink(
|
||||
HKWUtils.OpenLink(
|
||||
"https://steamcommunity.com/sharedfiles/filedetails/?id=" + parameter.ItemId
|
||||
);
|
||||
}
|
||||
@ -139,7 +139,7 @@ public class ModSettingPageVM : ObservableClass<ModSettingPageVM>
|
||||
{
|
||||
try
|
||||
{
|
||||
Utils.OpenLink(parameter.ModPath);
|
||||
HKWUtils.OpenLink(parameter.ModPath);
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
@ -111,12 +111,12 @@ public class SettingWindowVM : ObservableClass<SettingWindowVM>
|
||||
|
||||
private void OpenFileInExplorerCommand_ExecuteCommand(SettingModel parameter)
|
||||
{
|
||||
Utils.OpenFileInExplorer(parameter.FilePath);
|
||||
HKWUtils.OpenFileInExplorer(parameter.FilePath);
|
||||
}
|
||||
|
||||
private void OpenFileCommand_ExecuteCommand(SettingModel parameter)
|
||||
{
|
||||
Utils.OpenLink(parameter.FilePath);
|
||||
HKWUtils.OpenLink(parameter.FilePath);
|
||||
}
|
||||
|
||||
private void SaveAllSettingCommand_ExecuteCommand()
|
||||
|
Loading…
Reference in New Issue
Block a user