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
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ namespace PCL.Neo.Core.Models.Configuration;
/// <summary>
/// 全局配置设置,集中管理配置文件路径和默认值
/// </summary>
public static class GlobalSettings
public static class ConfigurationInfo
{
/// <summary>
/// 应用程序配置文件路径
Expand Down
8 changes: 4 additions & 4 deletions PCL.Neo.Core/Models/Configuration/ConfigurationManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,12 @@ private static string GetConfigPath<T>(string attributePath)
return typeof(T).Name switch
{
// 特殊处理已知的配置类型
"AppSettings" => GlobalSettings.GetConfigFilePath(GlobalSettings.AppSettingsFile),
"OAuth2Configurations" => GlobalSettings.GetConfigFilePath(GlobalSettings.OAuth2ConfigurationFile),
"AppSettings" => ConfigurationInfo.GetConfigFilePath(ConfigurationInfo.AppSettingsFile),
"OAuth2Configurations" => ConfigurationInfo.GetConfigFilePath(ConfigurationInfo.OAuth2ConfigurationFile),
_ => attributePath.Contains(Path.DirectorySeparatorChar) ||
attributePath.Contains(Path.AltDirectorySeparatorChar)
? attributePath // 已经是完整路径
: GlobalSettings.GetConfigFilePath(attributePath)
: ConfigurationInfo.GetConfigFilePath(attributePath)
};
}

Expand Down Expand Up @@ -283,7 +283,7 @@ private void ApplyMigrations(object config)
var configPath = GetConfigPath<T>(attribute.FilePath);
var backupPath = $"{configPath}.{DateTime.Now:yyyyMMdd_HHmmss}.bak";

var content = File.ReadAllText(configPath);
var content = await File.ReadAllTextAsync(configPath);
await File.WriteAllTextAsync(backupPath, content);

return true;
Expand Down
91 changes: 87 additions & 4 deletions PCL.Neo.Core/Models/Configuration/Data/AppSettings.cs
Original file line number Diff line number Diff line change
@@ -1,28 +1,111 @@
using Avalonia.Styling;
using Newtonsoft.Json;
using PCL.Neo.Core.Models.Minecraft.Java;
using System.Diagnostics;

namespace PCL.Neo.Core.Models.Configuration.Data;

/// <summary>
/// 应用程序全局设置
/// </summary>
[ConfigurationInfo("appSettings.json")]
public record AppSettings
public record AppSettingsData
{
/// <summary>
/// 应用程序主题
/// </summary>
public string Theme { get; set; } = "Light";
public ThemeVariant Theme { get; set; } = ThemeVariant.Light;

/// <summary>
/// 应用程序语言
/// </summary>
public string Language { get; set; } = "zh-CN";

/// <summary>
/// 下载线程数
/// 全局最大内存
/// </summary>
public int DownloadThreads { get; set; } = 4;
public int MaxMemoryMb { get; set; } = 2048;

/// <summary>
/// 全局最小内存
/// </summary>
public int MinMemoryMb { get; set; } = 512;

/// <summary>
/// 是否启用内存优化
/// </summary>
public bool MemoryOptimize { get; set; } = false;

/// <summary>
/// 当前游戏档案
/// </summary>
public string CurrentGameProfile { get; set; } = "Default";

/// <summary>
/// 当前游戏的名称
/// </summary>
public string CurrentGame { get; set; } = string.Empty;

/// <summary>
/// 版本隔离
/// </summary>
public bool VersionIndie { get; set; } = true;

/// <summary>
/// 游戏窗口标题
/// </summary>
public string GameTitle { get; set; } = string.Empty;

/// <summary>
/// 游戏自定义信息(暂未知作用)
/// </summary>
public string CustomizedInfo { get; set; } = string.Empty;

/// <summary>
/// 启动器可见性
/// </summary>
public LauncherVisibleType LauncherVisible { get; set; } = LauncherVisibleType.None;

/// <summary>
/// 游戏进程优先级
/// </summary>
public ProcessPriorityClass ProcessPriority { get; set; } = ProcessPriorityClass.Normal;

/// <summary>
/// 窗口大小
/// </summary>
public WindowSizeType WindowSize { get; set; } = WindowSizeType.Default; // TODO: 修改游戏启动代码,适配这个

/// <summary>
/// 记住的Java路径
/// </summary>
public List<string> JavaPaths { get; set; } = [];

[JsonIgnore]
public JavaRuntime? GameJava { get; set; }

/// <summary>
/// 默认Java路径
/// </summary>
public string DefaultJava { get; set; } = string.Empty;

/// <summary>
/// 默认下载源
/// </summary>
public DownloadProviderType DownloadProvider { get; set; } = DownloadProviderType.PreferOfficial;

/// <summary>
/// 下载线程数
/// </summary>
public int DownloadThreads { get; set; } = 4;

/// <summary>
/// 下载速度限制,0为无限制
/// </summary>
public ulong DownloadSpeedLimit { get; set; } = 0;

/// <summary>
/// 标题栏内容(空为无;以Ψ开头的合法文件路径为图片标题;否则为文本)
/// </summary>
public string TitleBar { get; set; } = string.Empty;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace PCL.Neo.Core.Models.Configuration.Data;

public enum DownloadProviderType
{
Official,
Mirrored,
PreferMirrored,
PreferOfficial
}
10 changes: 10 additions & 0 deletions PCL.Neo.Core/Models/Configuration/Data/LauncherVisibleType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace PCL.Neo.Core.Models.Configuration.Data;

public enum LauncherVisibleType
{
None, // 无动作
CLose, // 启动后关闭
HideThenClose, // 启动后隐藏,游戏退出后关闭
HideThenOpen, // 启动后隐藏,游戏退出后显示
Hide // 启动后隐藏
}
10 changes: 10 additions & 0 deletions PCL.Neo.Core/Models/Configuration/Data/WindowSizeType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace PCL.Neo.Core.Models.Configuration.Data;

public enum WindowSizeType
{
Default,
FillScreen,
SameAsLauncher,
Customized,
Maximize
}
42 changes: 0 additions & 42 deletions PCL.Neo.Core/Models/Configuration/Examples/ConfigurationExample.cs

This file was deleted.

This file was deleted.

Loading
Loading