Skip to content

Commit

Permalink
更新安装脚本和代码逻辑
Browse files Browse the repository at this point in the history
在 `arm-build.iss` 文件中:
* 添加头部注释和定义。
* 配置应用程序信息和安装设置。
* 添加简体中文语言支持。
* 配置桌面图标任务和文件关联。
* 配置安装完成后运行的程序。

在 `build.iss` 文件中:
* 更新应用程序信息和安装设置。
* 删除英文语言支持,仅保留简体中文。

在 `Program.cs` 文件中:
* 添加 `HostApplication.Builder()` 和 `CrossPlatformCustomProtocolHelper.RegisterCustomProtocol()` 调用。

在 `ChatBoxLogger.cs` 文件中:
* 重构 `ChatBoxLogger` 类,添加日志目录创建逻辑。

在 `App.axaml.cs` 文件中:
* 删除不必要的 `using` 语句。
* 更新 `OnFrameworkInitializationCompleted` 方法,使用 `HostApplication.Services` 获取 `MainWindow` 实例。
  • Loading branch information
239573049 committed Dec 30, 2024
1 parent 8f83f44 commit 79348cd
Show file tree
Hide file tree
Showing 5 changed files with 136 additions and 61 deletions.
70 changes: 70 additions & 0 deletions arm-build.iss
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
; Script generated by the Inno Setup Script Wizard.
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!

#define MyAppName "ChatBox"
#define MyAppVersion "0.1.1"
#define MyAppPublisher "TokenAi"
#define MyAppURL "https://api.token-ai.cn"
#define MyAppExeName "ChatBox.Desktop.exe"
#define MyAppAssocName MyAppName + ""
#define MyAppAssocExt ".exe"
#define MyAppAssocKey StringChange(MyAppAssocName, " ", "") + MyAppAssocExt

[Setup]
; NOTE: The value of AppId uniquely identifies this application. Do not use the same AppId value in installers for other applications.
; (To generate a new GUID, click Tools | Generate GUID inside the IDE.)
AppId={{1E9A7D67-5468-469D-86AB-FFE07136EBD1}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
;AppVerName={#MyAppName} {#MyAppVersion}
AppPublisher={#MyAppPublisher}
AppPublisherURL={#MyAppURL}
AppSupportURL={#MyAppURL}
AppUpdatesURL={#MyAppURL}
DefaultDirName={autopf}\{#MyAppName}
; "ArchitecturesAllowed=x64compatible" specifies that Setup cannot run
; on anything but x64 and Windows 11 on Arm.
ArchitecturesAllowed=x64compatible
; "ArchitecturesInstallIn64BitMode=x64compatible" requests that the
; install be done in "64-bit mode" on x64 or Windows 11 on Arm,
; meaning it should use the native 64-bit Program Files directory and
; the 64-bit view of the registry.
ArchitecturesInstallIn64BitMode=x64compatible
ChangesAssociations=yes
DisableProgramGroupPage=yes
; Uncomment the following line to run in non administrative install mode (install for current user only.)
;PrivilegesRequired=lowest
PrivilegesRequiredOverridesAllowed=dialog
OutputDir=D:\GitHub\ChatBox\outpu
OutputBaseFilename=win-arm64
SetupIconFile=D:\GitHub\ChatBox\favicon.ico
Compression=lzma
SolidCompression=yes
WizardStyle=modern

[Languages]
Name: "chinesesimplified"; MessagesFile: "compiler:Languages\ChineseSimplified.isl"

[Tasks]
Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked

[Files]
Source: "D:\GitHub\ChatBox\src\ChatBox.Desktop\bin\Release\net9.0\publish\win-arm64\{#MyAppExeName}"; DestDir: "{app}"; Flags: ignoreversion
Source: "D:\GitHub\ChatBox\src\ChatBox.Desktop\bin\Release\net9.0\publish\win-arm64\i18n\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs
Source: "D:\GitHub\ChatBox\src\ChatBox.Desktop\bin\Release\net9.0\publish\win-arm64\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs
; NOTE: Don't use "Flags: ignoreversion" on any shared system files

[Registry]
Root: HKA; Subkey: "Software\Classes\{#MyAppAssocExt}\OpenWithProgids"; ValueType: string; ValueName: "{#MyAppAssocKey}"; ValueData: ""; Flags: uninsdeletevalue
Root: HKA; Subkey: "Software\Classes\{#MyAppAssocKey}"; ValueType: string; ValueName: ""; ValueData: "{#MyAppAssocName}"; Flags: uninsdeletekey
Root: HKA; Subkey: "Software\Classes\{#MyAppAssocKey}\DefaultIcon"; ValueType: string; ValueName: ""; ValueData: "{app}\{#MyAppExeName},0"
Root: HKA; Subkey: "Software\Classes\{#MyAppAssocKey}\shell\open\command"; ValueType: string; ValueName: ""; ValueData: """{app}\{#MyAppExeName}"" ""%1"""
Root: HKA; Subkey: "Software\Classes\Applications\{#MyAppExeName}\SupportedTypes"; ValueType: string; ValueName: ".myp"; ValueData: ""

[Icons]
Name: "{autoprograms}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"
Name: "{autodesktop}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; Tasks: desktopicon

[Run]
Filename: "{app}\{#MyAppExeName}"; Description: "{cm:LaunchProgram,{#StringChange(MyAppName, '&', '&&')}}"; Flags: nowait postinstall skipifsilent

24 changes: 12 additions & 12 deletions build.iss
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
; Script generated by the Inno Setup Script Wizard.
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!

#define MyAppName "Chatbox"
#define MyAppVersion "1.0.1"
#define MyAppPublisher "Token"
#define MyAppURL "https://www.token-ai.cn"
#define MyAppName "ChatBox"
#define MyAppVersion "0.1.1"
#define MyAppPublisher "TokenAi"
#define MyAppURL "https://api.token-ai.cn"
#define MyAppExeName "ChatBox.Desktop.exe"
#define MyAppAssocName MyAppName + ".exe"
#define MyAppAssocName MyAppName + ""
#define MyAppAssocExt ".exe"
#define MyAppAssocKey StringChange(MyAppAssocName, " ", "") + MyAppAssocExt

[Setup]
; NOTE: The value of AppId uniquely identifies this application. Do not use the same AppId value in installers for other applications.
; (To generate a new GUID, click Tools | Generate GUID inside the IDE.)
AppId={{F746F9FA-A30F-4762-80EA-24C025030A93}
AppId={{1E9A7D67-5468-469D-86AB-FFE07136EBD1}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
;AppVerName={#MyAppName} {#MyAppVersion}
Expand All @@ -35,23 +35,23 @@ DisableProgramGroupPage=yes
; Uncomment the following line to run in non administrative install mode (install for current user only.)
;PrivilegesRequired=lowest
PrivilegesRequiredOverridesAllowed=dialog
OutputDir=D:\AI\ChatBox\output
OutputBaseFilename=Chatbox
SetupIconFile=D:\AI\Gitea\ChatBox\src\ChatBox.Desktop\logo.ico
OutputDir=D:\GitHub\ChatBox\outpu
OutputBaseFilename=win-64-framework
SetupIconFile=D:\GitHub\ChatBox\favicon.ico
Compression=lzma
SolidCompression=yes
WizardStyle=modern

[Languages]
Name: "english"; MessagesFile: "compiler:Default.isl"
Name: "chinesesimplified"; MessagesFile: "compiler:Languages\ChineseSimplified.isl"

[Tasks]
Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked

[Files]
Source: "D:\AI\ChatBox\src\ChatBox.Desktop\bin\Release\net9.0\publish\win-x64\{#MyAppExeName}"; DestDir: "{app}"; Flags: ignoreversion
Source: "D:\AI\ChatBox\src\ChatBox.Desktop\bin\Release\net9.0\publish\win-x64\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs
Source: "D:\GitHub\ChatBox\src\ChatBox.Desktop\bin\Release\net9.0\publish\win-x64\{#MyAppExeName}"; DestDir: "{app}"; Flags: ignoreversion
Source: "D:\GitHub\ChatBox\src\ChatBox.Desktop\bin\Release\net9.0\publish\win-x64\i18n\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs
Source: "D:\GitHub\ChatBox\src\ChatBox.Desktop\bin\Release\net9.0\publish\win-x64\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs
; NOTE: Don't use "Flags: ignoreversion" on any shared system files

[Registry]
Expand Down
4 changes: 4 additions & 0 deletions src/ChatBox.Desktop/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ public static void Main(string[] args)
{
try
{

HostApplication.Builder();


CrossPlatformCustomProtocolHelper.RegisterCustomProtocol();

var token = CrossPlatformCustomProtocolHelper.ParseCustomProtocolArgs(args);
Expand Down
87 changes: 48 additions & 39 deletions src/ChatBox.Logger/ChatBoxLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,52 @@

namespace ChatBox.Logger
{
public class ChatBoxLogger : ILogger
{
private readonly string _categoryName;

public ChatBoxLogger(string categoryName)
{
_categoryName = categoryName;
}

public IDisposable BeginScope<TState>(TState state) => null;

public bool IsEnabled(LogLevel logLevel) => true;

public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func<TState, Exception, string> formatter)
{
if (!IsEnabled(logLevel))
return;

var message = $"{DateTime.Now:yyyy-MM-dd HH:mm:ss.fff} [{logLevel}] {_categoryName}: {formatter(state, exception)}";
if (exception != null)
{
message += $"\n{exception}";
}

File.AppendAllText(Path.Combine(Path.Combine(Directory.GetCurrentDirectory(), "logs"), $"{DateTime.Now:yyyy-MM-dd}.log"), message + Environment.NewLine);
}
}

public class ChatBoxLoggerProvider : ILoggerProvider
{
public ILogger CreateLogger(string categoryName)
{
return new ChatBoxLogger(categoryName);
}

public void Dispose()
{
}
}
public class ChatBoxLogger : ILogger
{
private readonly string _categoryName;

public ChatBoxLogger(string categoryName)
{
_categoryName = categoryName;
}

public IDisposable BeginScope<TState>(TState state) => null;

public bool IsEnabled(LogLevel logLevel) => true;

public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func<TState, Exception, string> formatter)
{
if (!IsEnabled(logLevel))
return;

var message = $"{DateTime.Now:yyyy-MM-dd HH:mm:ss.fff} [{logLevel}] {_categoryName}: {formatter(state, exception)}";
if (exception != null)
{
message += $"\n{exception}";
}

var info = new FileInfo(Path.Combine(Path.Combine(Directory.GetCurrentDirectory(), "logs"), $"{DateTime.Now:yyyy-MM-dd}.log"));


if (info.Directory?.Exists == false)
{
info.Directory.Create();
}


File.AppendAllText(info.FullName, message + Environment.NewLine);
}
}

public class ChatBoxLoggerProvider : ILoggerProvider
{
public ILogger CreateLogger(string categoryName)
{
return new ChatBoxLogger(categoryName);
}

public void Dispose()
{
}
}
}
12 changes: 2 additions & 10 deletions src/ChatBox/App.axaml.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
using System;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Data.Core.Plugins;
using Avalonia.Markup.Xaml;
using Avalonia.Platform;
using ChatBox.Pages;
using ChatBox.ViewModels;
using ChatBox.Views;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;

namespace ChatBox;

Expand All @@ -22,12 +16,10 @@ public override void Initialize()

public override void OnFrameworkInitializationCompleted()
{
var host = HostApplication.Builder();

if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
{
BindingPlugins.DataValidators.RemoveAt(0);
desktop.MainWindow = host.Services.GetRequiredService<MainWindow>();
desktop.MainWindow = HostApplication.Services.GetRequiredService<MainWindow>();

// 创建托盘
var trayIcon = new TrayIcon();
Expand All @@ -49,7 +41,7 @@ public override void OnFrameworkInitializationCompleted()
}
else if (ApplicationLifetime is ISingleViewApplicationLifetime singleViewPlatform)
{
singleViewPlatform.MainView = host.Services.GetRequiredService<MainWindow>();
singleViewPlatform.MainView = HostApplication.Services.GetRequiredService<MainWindow>();
}

base.OnFrameworkInitializationCompleted();
Expand Down

0 comments on commit 79348cd

Please sign in to comment.