mirror of
https://github.com/real-zony/ZonyLrcToolsX.git
synced 2026-11-25 04:17:46 +08:00
修复 KGG/KGM 识别、密钥解码及输出文件保护;改进配置无损保存、登录会话安全和取消处理。统一新增 C# 代码风格,补齐发布许可声明及文档,并增加针对性回归测试。
86 lines
3.4 KiB
C#
86 lines
3.4 KiB
C#
using System.Globalization;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using ZonyLrcTools.Common.Infrastructure.DependencyInject;
|
|
using ZonyLrcTools.Common.Infrastructure.Logging;
|
|
using ZonyLrcTools.Common.Infrastructure.Network;
|
|
using ZonyLrcTools.Desktop.Infrastructure.Configuration;
|
|
using ZonyLrcTools.Desktop.Infrastructure.Localization;
|
|
using ZonyLrcTools.Desktop.ViewModels;
|
|
|
|
namespace ZonyLrcTools.Desktop.Services;
|
|
|
|
public static class ServiceCollectionExtensions
|
|
{
|
|
/// <summary>
|
|
/// Register all services for the desktop application.
|
|
/// </summary>
|
|
public static IServiceCollection AddDesktopServices(this IServiceCollection services)
|
|
{
|
|
// Register Common project's auto dependency injection
|
|
services.BeginAutoDependencyInject<AvaloniaWarpLogger>();
|
|
services.BeginAutoDependencyInject<IWarpHttpClient>();
|
|
|
|
// Configure Common services
|
|
// 桌面端使用可写的配置目录,避免只读安装位置导致保存失败。
|
|
services.ConfigureDesktopConfiguration();
|
|
services.ConfigureLocalization();
|
|
services.ConfigureToolService();
|
|
|
|
// Configure Desktop localization
|
|
// Note: Don't set ResourcesPath here because the embedded resource name is
|
|
// ZonyLrcTools.Desktop.UIStrings (not ZonyLrcTools.Desktop.Resources.UIStrings)
|
|
services.AddLocalization();
|
|
services.AddSingleton<IUILocalizationService, UILocalizationService>();
|
|
|
|
// Register GUI-specific IWarpLogger implementation
|
|
services.AddSingleton<AvaloniaWarpLogger>();
|
|
services.AddSingleton<IWarpLogger>(sp => sp.GetRequiredService<AvaloniaWarpLogger>());
|
|
|
|
// Register navigation and dialog services
|
|
services.AddSingleton<INavigationService, NavigationService>();
|
|
services.AddSingleton<IDialogService, DialogService>();
|
|
services.AddSingleton<IThemeService, ThemeService>();
|
|
|
|
// 保存网易云登录状态。
|
|
services.AddSingleton<NetEaseSessionStore>();
|
|
|
|
// 保存本机酷狗数据库路径。
|
|
services.AddSingleton<KugouDatabaseStore>();
|
|
|
|
// Register ViewModels (Singleton to preserve state across navigation)
|
|
services.AddSingleton<MainWindowViewModel>();
|
|
services.AddSingleton<HomeViewModel>();
|
|
services.AddSingleton<LyricsDownloadViewModel>();
|
|
services.AddSingleton<AlbumDownloadViewModel>();
|
|
services.AddSingleton<DecryptViewModel>();
|
|
services.AddSingleton<SettingsViewModel>();
|
|
|
|
return services;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Initialize language settings based on system culture or user preference.
|
|
/// </summary>
|
|
public static void InitializeLanguage(string? preferredCulture = null)
|
|
{
|
|
CultureInfo culture;
|
|
|
|
if (!string.IsNullOrEmpty(preferredCulture))
|
|
{
|
|
// Use user's preferred culture
|
|
culture = new CultureInfo(preferredCulture);
|
|
}
|
|
else
|
|
{
|
|
// Use system culture, fallback to zh-CN if not supported
|
|
var systemCulture = CultureInfo.CurrentUICulture.Name;
|
|
culture = systemCulture.StartsWith("zh") ? new CultureInfo("zh-CN") :
|
|
systemCulture.StartsWith("en") ? new CultureInfo("en-US") :
|
|
new CultureInfo("zh-CN");
|
|
}
|
|
|
|
CultureInfo.CurrentCulture = culture;
|
|
CultureInfo.CurrentUICulture = culture;
|
|
}
|
|
}
|