2024-08-08 09:29:19 +00:00
|
|
|
|
|
2024-08-19 14:30:11 +00:00
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
using System.IO.Compression;
|
2024-07-19 07:58:15 +00:00
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
2024-07-14 11:24:10 +00:00
|
|
|
|
using Microsoft.Extensions.Hosting;
|
|
|
|
|
using Microsoft.UI.Xaml;
|
2024-08-15 01:40:33 +00:00
|
|
|
|
using Microsoft.Windows.AppLifecycle;
|
2024-08-19 14:30:11 +00:00
|
|
|
|
using Newtonsoft.Json;
|
2024-08-15 01:40:33 +00:00
|
|
|
|
using RustTools.Activation;
|
2024-07-14 11:24:10 +00:00
|
|
|
|
using RustTools.Contracts.Services;
|
2024-08-19 14:30:11 +00:00
|
|
|
|
using RustTools.DataList;
|
|
|
|
|
using RustTools.Helpers;
|
2024-07-14 11:24:10 +00:00
|
|
|
|
using RustTools.Models;
|
2024-08-15 01:40:33 +00:00
|
|
|
|
using RustTools.muqing;
|
2024-07-14 11:24:10 +00:00
|
|
|
|
using RustTools.Services;
|
|
|
|
|
using RustTools.ViewModels;
|
|
|
|
|
using RustTools.Views;
|
2024-08-01 14:28:39 +00:00
|
|
|
|
using RustTools.WindowUI;
|
|
|
|
|
using Windows.ApplicationModel.Activation;
|
2024-08-19 14:30:11 +00:00
|
|
|
|
using Windows.Storage;
|
2024-07-14 11:24:10 +00:00
|
|
|
|
|
|
|
|
|
namespace RustTools;
|
|
|
|
|
|
|
|
|
|
// To learn more about WinUI 3, see https://docs.microsoft.com/windows/apps/winui/winui3/.
|
2024-08-01 14:28:39 +00:00
|
|
|
|
public partial class App : Microsoft.UI.Xaml.Application
|
2024-07-14 11:24:10 +00:00
|
|
|
|
{
|
|
|
|
|
// 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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2024-08-15 01:40:33 +00:00
|
|
|
|
public static UIElement? AppTitlebar
|
|
|
|
|
{
|
|
|
|
|
get; set;
|
|
|
|
|
}
|
2024-08-08 09:29:19 +00:00
|
|
|
|
public static WindowEx? MainWindow;
|
2024-07-14 11:24:10 +00:00
|
|
|
|
|
|
|
|
|
public App()
|
|
|
|
|
{
|
2024-08-04 02:31:05 +00:00
|
|
|
|
InitializeComponent();
|
2024-08-01 14:28:39 +00:00
|
|
|
|
// 注册激活事件处理程序
|
2024-07-14 11:24:10 +00:00
|
|
|
|
Host = Microsoft.Extensions.Hosting.Host.
|
|
|
|
|
CreateDefaultBuilder().
|
|
|
|
|
UseContentRoot(AppContext.BaseDirectory).
|
|
|
|
|
ConfigureServices((context, services) =>
|
|
|
|
|
{
|
|
|
|
|
// Default Activation Handler
|
2024-08-01 14:28:39 +00:00
|
|
|
|
services.AddTransient<ActivationHandler<Microsoft.UI.Xaml.LaunchActivatedEventArgs>, DefaultActivationHandler>();
|
2024-07-14 11:24:10 +00:00
|
|
|
|
|
|
|
|
|
// 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>();
|
2024-08-19 14:30:11 +00:00
|
|
|
|
//services.AddTransient<HomePage>();
|
2024-07-15 05:22:53 +00:00
|
|
|
|
services.AddTransient<ConcernViewModel>();
|
2024-08-19 14:30:11 +00:00
|
|
|
|
//services.AddTransient<ConcernPage>();
|
2024-07-15 05:22:53 +00:00
|
|
|
|
services.AddTransient<RankingViewModel>();
|
2024-08-19 14:30:11 +00:00
|
|
|
|
//services.AddTransient<RankingPage>();
|
2024-07-15 05:22:53 +00:00
|
|
|
|
services.AddTransient<UserViewModel>();
|
2024-08-19 14:30:11 +00:00
|
|
|
|
//services.AddTransient<UserPage>();
|
2024-08-07 02:31:13 +00:00
|
|
|
|
//模组碎片
|
|
|
|
|
services.AddTransient<ModuleViewModel>();
|
2024-08-19 14:30:11 +00:00
|
|
|
|
//services.AddTransient<ModulePage>();
|
|
|
|
|
|
|
|
|
|
services.AddTransient<CodeTableViewModel>();
|
|
|
|
|
//services.AddTransient<CodeTablePage>();
|
2024-07-14 11:24:10 +00:00
|
|
|
|
|
|
|
|
|
services.AddTransient<ShellPage>();
|
|
|
|
|
services.AddTransient<ShellViewModel>();
|
|
|
|
|
|
|
|
|
|
// Configuration
|
|
|
|
|
services.Configure<LocalSettingsOptions>(context.Configuration.GetSection(nameof(LocalSettingsOptions)));
|
|
|
|
|
}).
|
|
|
|
|
Build();
|
|
|
|
|
|
|
|
|
|
UnhandledException += App_UnhandledException;
|
2024-08-19 14:30:11 +00:00
|
|
|
|
var path = ApplicationData.Current.LocalFolder.Path;
|
|
|
|
|
var v = Path.Combine(path, "CodeTable");
|
|
|
|
|
gj.sc(path);
|
|
|
|
|
if (Directory.Exists(v) == false)
|
|
|
|
|
{
|
|
|
|
|
Directory.CreateDirectory(v);
|
|
|
|
|
}
|
|
|
|
|
var RustCode = Path.Combine(v, "RustCode");
|
|
|
|
|
if (Directory.Exists(RustCode) == false)
|
|
|
|
|
{
|
|
|
|
|
new Thread(() =>
|
|
|
|
|
{
|
|
|
|
|
var zipFilePath = Path.Combine(AppContext.BaseDirectory, "Assets\\RustCode.zip");
|
|
|
|
|
gj.sc(zipFilePath);
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
ZipFile.ExtractToDirectory(zipFilePath, RustCode);
|
|
|
|
|
var iniHelper = new IniHelper(IniHelper.FILE.Config);
|
|
|
|
|
iniHelper.SetValue("CodeTable", "Dir", RustCode);
|
|
|
|
|
iniHelper.Save();
|
|
|
|
|
var vr = Path.Combine(RustCode, "DataBaseManifest.json");
|
|
|
|
|
if (File.Exists(vr))
|
|
|
|
|
{
|
|
|
|
|
var json = JsonConvert.DeserializeObject<DataBaseManifest>(File.ReadAllText(vr));
|
|
|
|
|
json.Dir = RustCode;
|
|
|
|
|
CodeDataPage.codetable = json;
|
|
|
|
|
}
|
|
|
|
|
Debug.WriteLine("ZIP文件已成功解压缩并复制到目标目录。");
|
|
|
|
|
}
|
|
|
|
|
catch (FileNotFoundException)
|
|
|
|
|
{
|
|
|
|
|
Debug.WriteLine("源文件未找到。");
|
|
|
|
|
}
|
|
|
|
|
catch (IOException ex)
|
|
|
|
|
{
|
|
|
|
|
Debug.WriteLine("发生IO异常: " + ex.Message);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
Debug.WriteLine("发生未知错误: " + ex.Message);
|
|
|
|
|
}
|
|
|
|
|
}).Start();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
var iniHelper = new IniHelper(IniHelper.FILE.Config);
|
|
|
|
|
var v1 = iniHelper.GetValue("CodeTable", "Dir");
|
|
|
|
|
if (string.IsNullOrEmpty(v1)) { v1 = RustCode; }
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-07-14 11:24:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-01 14:28:39 +00:00
|
|
|
|
|
|
|
|
|
protected async override void OnLaunched(Microsoft.UI.Xaml.LaunchActivatedEventArgs args)
|
2024-07-14 11:24:10 +00:00
|
|
|
|
{
|
2024-08-05 11:38:55 +00:00
|
|
|
|
base.OnLaunched(args);
|
2024-08-01 14:28:39 +00:00
|
|
|
|
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);
|
2024-08-15 01:40:33 +00:00
|
|
|
|
var importModule = new ImportModule(storageFile.Path);
|
2024-08-01 14:28:39 +00:00
|
|
|
|
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
|
|
|
|
|
{
|
2024-08-13 13:59:14 +00:00
|
|
|
|
//new Editor.EditorWin().Activate();
|
|
|
|
|
MainWindow = new MainWindow();
|
|
|
|
|
await App.GetService<IActivationService>().ActivateAsync(args);
|
2024-08-01 14:28:39 +00:00
|
|
|
|
}
|
2024-07-14 11:24:10 +00:00
|
|
|
|
}
|
|
|
|
|
}
|