focus on intervals, and fix provider

This commit is contained in:
2026-09-08 14:44:34 +02:00
parent 579cd8e4b3
commit acad70aaac
11 changed files with 1163 additions and 286 deletions
+50 -4
View File
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
@@ -298,9 +298,55 @@ namespace AnotherReplayReader
public List<AiProvider> Providers { get; set; } = [];
public AiPromptSettings Prompt { get; set; } = new();
// 以下两个不持久化,由 UI 层维护当前选中项
[System.Text.Json.Serialization.JsonIgnore]
public int CurrentProviderIndex { get; set; }
/// <summary>
/// 上次选中的 Provider 名称(持久化;用于下次打开设置页时恢复)。
/// 按名称识别,Provider 被重命名/删除后自动回退到第一个 Provider。
/// </summary>
public string? CurrentProviderName { get; set; }
/// <summary>
/// 上次选中的模型 ID(持久化;与 <see cref="CurrentProviderName"/> 配合使用)。
/// 模型被删除后自动回退到该 Provider 的第一个模型。
/// </summary>
public string? CurrentModelId { get; set; }
/// <summary>
/// 更新并持久化当前选中的 Provider 与模型。
/// </summary>
public void SetCurrentSelection(AiProvider provider, AiModel model)
{
CurrentProviderName = provider.Name;
CurrentModelId = model.ModelId;
}
/// <summary>
/// 解析持久化的上次选择。任一标识缺失或对应 Provider/Model 已不存在时返回 null。
/// </summary>
public (AiProvider Provider, AiModel Model)? ResolveLastSelection()
{
var providerName = CurrentProviderName?.Trim();
var modelId = CurrentModelId?.Trim();
if (string.IsNullOrEmpty(providerName) || string.IsNullOrEmpty(modelId))
{
return null;
}
var provider = Providers.FirstOrDefault(p =>
string.Equals(p.Name, providerName, StringComparison.OrdinalIgnoreCase));
if (provider is null)
{
return null;
}
var model = provider.Models.FirstOrDefault(m =>
string.Equals(m.ModelId, modelId, StringComparison.OrdinalIgnoreCase));
if (model is null)
{
return null;
}
return (provider, model);
}
private static readonly string ConfigPath = Path.Combine(
AppContext.BaseDirectory,