此次提交主要对代码进行了简化和优化,具体更改如下: 1. 在 `App.xaml` 中,将 `ConCernItem` 的 `DataTemplate` 从 `StackPanel` 改为 `Grid`,并添加了 `Grid.ColumnDefinitions` 和 `Grid.RowDefinitions`。 2. 在 `App.xaml.cs` 中,删除了创建和解压缩 `RustCode` 目录的代码,改为直接从 `Assets` 目录获取 `DataBaseManifest` 文件,并更新了异常处理逻辑。 3. 在 `RustTools.csproj` 中,添加了新的 `PackageReference`,更新了 `RestSharp` 的版本,并注释掉了 `squirrel.windows` 的引用。 4. 在 `PostRwmod.xaml.cs` 中,删除了 `SharpCompress.Common` 和 `TinyPinyin` 的引用。 5. 在 `CodeDataPage.xaml.cs` 中,更新了 `filePath` 的路径,从 `ApplicationData.Current.LocalFolder.Path` 改为 `AppContext.BaseDirectory`。 6. 在 `ConcernPage.xaml` 中,调整了 `StackPanelA` 的 `MinWidth` 属性,并删除了 `StackPanel` 的 `Background` 属性。 7. 在 `ConcernPage.xaml.cs` 中,更新了 `Getlist` 方法的逻辑,增加了对 `response` 的空值和错误码检查。 8. 在 `ModulePage.xaml.cs` 中,删除了 `SharpCompress.Common` 和 `WinRT.Interop` 的引用。 9. 在 `SettingsPage.xaml` 中,更新了 `PersonPicture` 的 `ToolTipService.ToolTip` 属性。 10. 在 `IniHelper.cs` 中,更新了 `Load` 方法的 `filePath` 路径,并添加了目录不存在时创建目录的逻辑。 11. 在 `wj.cs` 中,更新了 `CD` 的路径为 `AppContext.BaseDirectory`,并注释掉了废弃的路径。 12. 在 `config.ini` 中,添加了 `[Settings]` 节点和 `SystemBackdrop=Mica` 设置。 此外,添加了以下新 JSON 文件: 1. `DataBaseManifest.json`:包含数据集的基本信息和数据表的映射。 2. `game_version.json`:包含游戏版本数据。 3. `section.json`:包含铁锈助手节名数据。 4. `value_type.json`:定义了一个名为 "值类型表" 的数据结构,包含多个值类型及其详细信息。
190 lines
6.7 KiB
C#
190 lines
6.7 KiB
C#
|
|
using System.Diagnostics;
|
|
using System.IO.Compression;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Hosting;
|
|
using Microsoft.UI.Xaml;
|
|
using Microsoft.Windows.AppLifecycle;
|
|
using Newtonsoft.Json;
|
|
using RustTools.Activation;
|
|
using RustTools.Contracts.Services;
|
|
using RustTools.DataList;
|
|
using RustTools.Helpers;
|
|
using RustTools.Models;
|
|
using RustTools.muqing;
|
|
using RustTools.Services;
|
|
using RustTools.ViewModels;
|
|
using RustTools.Views;
|
|
using RustTools.WindowUI;
|
|
using Windows.ApplicationModel.Activation;
|
|
using Windows.Storage;
|
|
|
|
namespace RustTools;
|
|
|
|
// To learn more about WinUI 3, see https://docs.microsoft.com/windows/apps/winui/winui3/.
|
|
public partial class App : Microsoft.UI.Xaml.Application
|
|
{
|
|
// The .NET Generic Host provides dependency injection, configuration, logging, and other services.
|
|
// https://docs.microsoft.com/dotnet/core/extensions/generic-host
|
|
// https://docs.microsoft.com/dotnet/core/extensions/dependency-injection
|
|
// https://docs.microsoft.com/dotnet/core/extensions/configuration
|
|
// https://docs.microsoft.com/dotnet/core/extensions/logging
|
|
public IHost Host
|
|
{
|
|
get;
|
|
}
|
|
|
|
public static T GetService<T>()
|
|
where T : class
|
|
{
|
|
if ((App.Current as App)!.Host.Services.GetService(typeof(T)) is not T service)
|
|
{
|
|
throw new ArgumentException($"{typeof(T)} needs to be registered in ConfigureServices within App.xaml.cs.");
|
|
}
|
|
|
|
return service;
|
|
}
|
|
|
|
|
|
public static UIElement? AppTitlebar
|
|
{
|
|
get; set;
|
|
}
|
|
public static WindowEx? MainWindow;
|
|
|
|
public App()
|
|
{
|
|
InitializeComponent();
|
|
// 注册激活事件处理程序
|
|
Host = Microsoft.Extensions.Hosting.Host.
|
|
CreateDefaultBuilder().
|
|
UseContentRoot(AppContext.BaseDirectory).
|
|
ConfigureServices((context, services) =>
|
|
{
|
|
// Default Activation Handler
|
|
services.AddTransient<ActivationHandler<Microsoft.UI.Xaml.LaunchActivatedEventArgs>, DefaultActivationHandler>();
|
|
|
|
// Other Activation Handlers
|
|
|
|
// Services
|
|
services.AddSingleton<ILocalSettingsService, LocalSettingsService>();
|
|
services.AddSingleton<IThemeSelectorService, ThemeSelectorService>();
|
|
services.AddTransient<INavigationViewService, NavigationViewService>();
|
|
|
|
services.AddSingleton<IActivationService, ActivationService>();
|
|
services.AddSingleton<IPageService, PageService>();
|
|
services.AddSingleton<INavigationService, NavigationService>();
|
|
|
|
// Core Services
|
|
services.AddSingleton<IFileService, FileService>();
|
|
|
|
// Views and ViewModels
|
|
services.AddTransient<SettingsViewModel>();
|
|
services.AddTransient<SettingsPage>();
|
|
|
|
services.AddTransient<HomePageViewModel>();
|
|
//services.AddTransient<HomePage>();
|
|
services.AddTransient<ConcernViewModel>();
|
|
//services.AddTransient<ConcernPage>();
|
|
services.AddTransient<RankingViewModel>();
|
|
//services.AddTransient<RankingPage>();
|
|
services.AddTransient<UserViewModel>();
|
|
//services.AddTransient<UserPage>();
|
|
//模组碎片
|
|
services.AddTransient<ModuleViewModel>();
|
|
//services.AddTransient<ModulePage>();
|
|
|
|
services.AddTransient<CodeTableViewModel>();
|
|
//services.AddTransient<CodeTablePage>();
|
|
|
|
services.AddTransient<ShellPage>();
|
|
services.AddTransient<ShellViewModel>();
|
|
|
|
// Configuration
|
|
services.Configure<LocalSettingsOptions>(context.Configuration.GetSection(nameof(LocalSettingsOptions)));
|
|
}).
|
|
Build();
|
|
|
|
UnhandledException += App_UnhandledException;
|
|
|
|
|
|
//获取当前路径
|
|
|
|
//Debug.WriteLine();
|
|
try
|
|
{
|
|
var DataBaseManifest = Path.Combine(AppContext.BaseDirectory, "Assets\\CodeTable\\RustCode");
|
|
var iniHelper = new IniHelper(IniHelper.FILE.Config);
|
|
var v1 = iniHelper.GetValue("CodeTable", "Dir");
|
|
if (string.IsNullOrEmpty(v1)||!wj.cz(Path.Combine(v1," DataBaseManifest.json")))
|
|
{
|
|
v1 = DataBaseManifest;
|
|
iniHelper.SetValue("CodeTable", "Dir", v1);
|
|
iniHelper.Save();
|
|
}
|
|
var vr = Path.Combine(v1, "DataBaseManifest.json");
|
|
if (File.Exists(vr))
|
|
{
|
|
var json = JsonConvert.DeserializeObject<DataBaseManifest>(File.ReadAllText(vr));
|
|
json.Dir = v1;
|
|
CodeDataPage.codetable = json;
|
|
}
|
|
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Debug.WriteLine(e);
|
|
}
|
|
}
|
|
|
|
private void App_UnhandledException(object sender, Microsoft.UI.Xaml.UnhandledExceptionEventArgs e)
|
|
{
|
|
// TODO: Log and handle exceptions as appropriate.
|
|
// https://docs.microsoft.com/windows/windows-app-sdk/api/winrt/microsoft.ui.xaml.application.unhandledexception.
|
|
}
|
|
|
|
|
|
protected async override void OnLaunched(Microsoft.UI.Xaml.LaunchActivatedEventArgs args)
|
|
{
|
|
base.OnLaunched(args);
|
|
var activatedEventArgs = Microsoft.Windows.AppLifecycle.AppInstance.GetCurrent().GetActivatedEventArgs();
|
|
if (activatedEventArgs.Kind == Microsoft.Windows.AppLifecycle.ExtendedActivationKind.File)
|
|
{
|
|
gj.sc("打开文件");
|
|
if (activatedEventArgs.Kind == ExtendedActivationKind.File)
|
|
{
|
|
if (activatedEventArgs.Data is IFileActivatedEventArgs fileArgs)
|
|
{
|
|
var files = fileArgs.Files;
|
|
// 处理打开的文件
|
|
foreach (var file in files)
|
|
{
|
|
var storageFile = file as Windows.Storage.StorageFile;
|
|
if (storageFile != null)
|
|
{
|
|
gj.sc(storageFile.Path);
|
|
var importModule = new ImportModule(storageFile.Path);
|
|
importModule.Activate();
|
|
// 读取或处理文件内容
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return;
|
|
}
|
|
var mainInstance = Microsoft.Windows.AppLifecycle.AppInstance.FindOrRegisterForKey("main");
|
|
if (!mainInstance.IsCurrent)
|
|
{
|
|
await mainInstance.RedirectActivationToAsync(activatedEventArgs);
|
|
System.Diagnostics.Process.GetCurrentProcess().Kill();
|
|
return;
|
|
}
|
|
else
|
|
{
|
|
//new Editor.EditorWin().Activate();
|
|
MainWindow = new MainWindow();
|
|
await App.GetService<IActivationService>().ActivateAsync(args);
|
|
}
|
|
}
|
|
}
|