Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions Plain Craft Launcher 2/Application.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,14 @@
Lang.Text("Application.EnvironmentWarning.IKnow"),
IsWarn: true);
// 设置初始化
ModBase.Setup.Load("SystemDebugMode");
ModBase.Setup.Load("SystemDebugAnim");
ModBase.Setup.Load("SystemHttpProxy");
ModBase.Setup.Load("SystemHttpProxyCustomUsername");
ModBase.Setup.Load("SystemHttpProxyType");
ModBase.Setup.Load("ToolDownloadThread");
ModBase.Setup.Load("ToolDownloadSpeed");
ModBase.Setup.Load("UiFont");
_ = Config.Debug.Enabled;
_ = Config.Debug.AnimationSpeed;
_ = Config.Network.HttpProxy.CustomAddress;
_ = Config.Network.HttpProxy.CustomUsername;
_ = Config.Network.HttpProxy.Type;
_ = Config.Download.ThreadLimit;
_ = Config.Download.SpeedLimit;
_ = Config.Preference.Font;
var updateBranchCfg = Config.Update.UpdateChannelConfig;
if (updateBranchCfg.IsDefault())
updateBranchCfg.SetValue(ModBase.VersionBaseName.Contains("beta")
Expand Down Expand Up @@ -199,12 +199,12 @@
// 自定义监听器类
public class BindingErrorTraceListener : TraceListener
{
public override void Write(string message)

Check warning on line 202 in Plain Craft Launcher 2/Application.xaml.cs

View workflow job for this annotation

GitHub Actions / build (CI, x64) / Build

Nullability of type of parameter 'message' doesn't match overridden member (possibly because of nullability attributes).

Check warning on line 202 in Plain Craft Launcher 2/Application.xaml.cs

View workflow job for this annotation

GitHub Actions / build (CI, ARM64) / Build

Nullability of type of parameter 'message' doesn't match overridden member (possibly because of nullability attributes).
{
ModBase.Log($"警告,检测到 Binding 失败:{message}");
}

public override void WriteLine(string message)

Check warning on line 207 in Plain Craft Launcher 2/Application.xaml.cs

View workflow job for this annotation

GitHub Actions / build (CI, x64) / Build

Nullability of type of parameter 'message' doesn't match overridden member (possibly because of nullability attributes).

Check warning on line 207 in Plain Craft Launcher 2/Application.xaml.cs

View workflow job for this annotation

GitHub Actions / build (CI, ARM64) / Build

Nullability of type of parameter 'message' doesn't match overridden member (possibly because of nullability attributes).
{
ModBase.Log($"警告,检测到 Binding 失败:{message}");
}
Expand Down
7 changes: 4 additions & 3 deletions Plain Craft Launcher 2/Controls/MyHint.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Markup;

using PCL.Core.App;
using PCL.Core.App.Configuration;
using PCL.Core.UI.Theme;
using System.Windows.Controls;

Expand Down Expand Up @@ -135,13 +135,14 @@ private void UpdateUI()
private void MyHint_Loaded(object sender, RoutedEventArgs e)
{
ThemeService.ColorModeChanged += (v, theme) => _ThemeChanged(v, theme);
if (CanClose && ModBase.Setup.Get(RelativeSetup) != null)
if (CanClose && ConfigService.TryGetConfigItemNoType(RelativeSetup, out var item) && item.GetValueNoType() != null)
Visibility = Visibility.Collapsed;
}

private void BtnClose_Click(object sender, EventArgs e)
{
ModBase.Setup.Set(RelativeSetup, true);
if (ConfigService.TryGetConfigItemNoType(RelativeSetup, out var item))
item.SetValueNoType(true);
ModAnimation.AniDispose(this, false);
}

Expand Down
26 changes: 12 additions & 14 deletions Plain Craft Launcher 2/FormMain.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,26 +86,21 @@
// 触发降级
DowngradeSub(LastVersion);
// 版本隔离设置迁移
if (ModBase.Setup.IsUnset("LaunchArgumentIndieV2"))
if (Config.Launch.IndieSolutionV2Config.IsDefault())
{
if (!ModBase.Setup.IsUnset("LaunchArgumentIndie"))
if (!Config.Launch.IndieSolutionV1Config.IsDefault())
{
ModBase.Log("[Start] 从老 PCL 迁移版本隔离");
Config.Launch.IndieSolutionV2 = Config.Launch.IndieSolutionV1;
}
else if (!ModBase.Setup.IsUnset("WindowHeight"))
{
ModBase.Log("[Start] 从老 PCL 升级,但此前未调整版本隔离,使用老的版本隔离默认值");
Config.Launch.IndieSolutionV2Config.Reset(Config.Launch.IndieSolutionV1Config.DefaultValue);
}
else
{
ModBase.Log("[Start] 全新的 PCL,使用新的版本隔离默认值");
Config.Launch.IndieSolutionV2Config.Reset(Config.Launch.IndieSolutionV2Config.DefaultValue);
}
}

ModBase.Setup.Load("UiLauncherTheme");
_ = Config.Preference.Theme.ThemeSelected;
// 注册拖拽事件(不能直接加 Handles,否则没用;#6340)
AddHandler(DragDrop.DragEnterEvent, new DragEventHandler(HandleDrag), true);
AddHandler(DragDrop.DragOverEvent, new DragEventHandler(HandleDrag), true);
Expand Down Expand Up @@ -169,11 +164,14 @@
ModBase.ApplicationStartTick = TimeUtils.GetTimeTick();
ModBase.FrmHandle = new WindowInteropHelper(this).Handle;
// 读取设置
ModBase.Setup.Load("UiBackgroundOpacity");
ModBase.Setup.Load("UiBackgroundBlur");
ModBase.Setup.Load("UiLogoType");
ModBase.Setup.Load("UiHiddenPageDownload");
ModBase.Setup.Load("UiAutoPauseVideo"); // 智能暂停视频背景
_ = Config.Preference.Background.WallpaperOpacity;
_ = Config.Preference.Background.WallpaperBlurRadius;
_ = Config.Preference.WindowTitleType;
_ = Config.Preference.Hide.PageDownload;
_ = Config.Preference.Background.AutoPauseVideo; // 智能暂停视频背景
ModSetup.UiLogoType((int)Config.Preference.WindowTitleType);
ModSetup.UiLogoText(Config.Preference.WindowTitleCustomText);
ModSetup.UiLogoLeft(Config.Preference.TopBarLeftAlign);
PageSetupUI.HiddenRefresh();
PageSetupUI.BackgroundRefresh(false, true);
ModMusic.MusicRefreshPlay(false, true);
Expand Down Expand Up @@ -375,7 +373,7 @@
// 迁移旧版用户档案
if (LastVersionCode <= 368) ModBase.RunInNewThread(() => ModProfile.MigrateOldProfile());
// Mod 命名设置迁移
if (!ModBase.Setup.IsUnset("ToolDownloadTranslate") && ModBase.Setup.IsUnset("ToolDownloadTranslateV2"))
if (!Config.Download.Comp.NameFormatV1Config.IsDefault() && Config.Download.Comp.NameFormatV2Config.IsDefault())
{
Config.Download.Comp.NameFormatV2 += 1;
ModBase.Log("[Start] 已从老版本迁移 Mod 命名设置");
Expand Down Expand Up @@ -1604,7 +1602,7 @@
/// </summary>
public List<PageStackData> PageStack = new();

public class PageStackData

Check warning on line 1605 in Plain Craft Launcher 2/FormMain.xaml.cs

View workflow job for this annotation

GitHub Actions / build (CI, ARM64) / Build

'FormMain.PageStackData' defines operator == or operator != but does not override Object.GetHashCode()

Check warning on line 1605 in Plain Craft Launcher 2/FormMain.xaml.cs

View workflow job for this annotation

GitHub Actions / build (CI, ARM64) / Build

'FormMain.PageStackData' overrides Object.Equals(object o) but does not override Object.GetHashCode()
{
/// <summary>
/// <list type="bullet">
Expand All @@ -1626,7 +1624,7 @@

public PageType Page;

public override bool Equals(object other)

Check warning on line 1627 in Plain Craft Launcher 2/FormMain.xaml.cs

View workflow job for this annotation

GitHub Actions / build (CI, x64) / Build

Nullability of type of parameter 'other' doesn't match overridden member (possibly because of nullability attributes).

Check warning on line 1627 in Plain Craft Launcher 2/FormMain.xaml.cs

View workflow job for this annotation

GitHub Actions / build (CI, ARM64) / Build

Nullability of type of parameter 'other' doesn't match overridden member (possibly because of nullability attributes).
{
if (other is null)
return false;
Expand Down
2 changes: 1 addition & 1 deletion Plain Craft Launcher 2/Modules/Base/ModBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public static class ModBase
/// <summary>
/// 程序可执行文件所在目录,以“\”结尾。
/// </summary>
public static readonly string ExePath = Conversions.ToString(Basics.ExecutableDirectory.EndsWith(@"\")
public static readonly string ExePath = (Basics.ExecutableDirectory.EndsWith(@"\")
? Basics.ExecutableDirectory
: Basics.ExecutableDirectory + @"\");

Expand Down
84 changes: 6 additions & 78 deletions Plain Craft Launcher 2/Modules/Base/ModSetup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,78 +76,6 @@ private static ConfigItem GetConfigItem(string key)
return result ? item! : throw new KeyNotFoundException($"配置项 '{key}' 不存在");
}

/// <summary>
/// 改变某个设置项的值。
/// </summary>
public void Set(string key, object value, bool forceReload = false, ModMinecraft.McInstance? instance = null)
{
GetConfigItem(key).SetValueNoType(value, instance?.PathInstance);
}

/// <summary>
/// 应用某个设置项的值。
/// </summary>
public object Load(string key, bool forceReload = false, ModMinecraft.McInstance? instance = null)
{
var value = Get(key, instance);
InvokeEventMethod(key, () => value);
return value;
}

/// <summary>
/// 写入某个未经加密的设置项。
/// 若该设置项经过了加密,则会抛出异常。
/// </summary>
public void SetSafe(string key, object value, bool forceReload = false, ModMinecraft.McInstance instance = null)
{
if (!ConfigService.TryGetConfigItemNoType(key, out ConfigItem item)) return;
if (item.Source == ConfigSource.SharedEncrypt) throw new InvalidOperationException("禁止写入加密设置项:" + key);
Set(key, value, forceReload, instance);
}

/// <summary>
/// 获取某个未经加密的设置项的值。
/// 若该设置项经过了加密,则会抛出异常。
/// </summary>
public object GetSafe(string key, ModMinecraft.McInstance instance = null)
{
if (!ConfigService.TryGetConfigItemNoType(key, out ConfigItem item)) return null;
if (item.Source == ConfigSource.SharedEncrypt) throw new InvalidOperationException("禁止读取加密设置项:" + key);
return Get(key, instance);
}

/// <summary>
/// 获取某个设置项的值。
/// </summary>
public object Get(string key, ModMinecraft.McInstance? instance = null)
{
return GetConfigItem(key).GetValueNoType(instance?.PathInstance);
}

/// <summary>
/// 初始化某个设置项的值。
/// </summary>
public void Reset(string key, bool forceReload = false, ModMinecraft.McInstance? instance = null)
{
GetConfigItem(key).Reset(instance?.PathInstance);
}

/// <summary>
/// 获取某个设置项的默认值。
/// </summary>
public object GetDefault(string key)
{
return GetConfigItem(key).DefaultValueNoType;
}

/// <summary>
/// 某个设置项是否从未被设置过。
/// </summary>
public bool IsUnset(string key, ModMinecraft.McInstance? instance = null)
{
return GetConfigItem(key).IsDefault(instance?.PathInstance);
}

#endregion

#region Launch
Expand Down Expand Up @@ -368,7 +296,7 @@ public void UiFont(string value)
}

// 主页
public void UiCustomType(int Value)
public static void UiCustomType(int Value)
{
if (ModMain.FrmSetupUI is null)
return;
Expand Down Expand Up @@ -448,7 +376,7 @@ public void UiBlurType(int Value)
}

// 顶部栏
public void UiLogoType(int Value)
public static void UiLogoType(int Value)
{
if (ThemeService.CurrentTheme == ColorTheme.HmclBlue) Value = 4;
switch (Value)
Expand Down Expand Up @@ -505,7 +433,7 @@ public void UiLogoType(int Value)
ModMain.FrmSetupUI.PanLogoChange.Visibility = Visibility.Collapsed;
}

ModBase.Setup.Load("UiLogoText", true);
_ = Config.Preference.WindowTitleCustomText;
break;
}
case 3: // 图片
Expand Down Expand Up @@ -551,17 +479,17 @@ public void UiLogoType(int Value)
break;
}

ModBase.Setup.Load("UiLogoLeft", true);
_ = Config.Preference.TopBarLeftAlign;
if (ModMain.FrmSetupUI != null)
ModMain.FrmSetupUI.CardLogo.TriggerForceResize();
}

public void UiLogoText(string Value)
public static void UiLogoText(string Value)
{
ModMain.FrmMain.LabTitleLogo.Text = Value;
}

public void UiLogoLeft(bool Value)
public static void UiLogoLeft(bool Value)
{
ModMain.FrmMain.PanTitleMain.ColumnDefinitions[0].Width = new GridLength(
Value && Config.Preference.WindowTitleType == LauncherTitleType.None ? 0 : 1,
Expand Down
Loading
Loading