Skip to content

Commit 262c30c

Browse files
committed
CLI 打包
1 parent 2b7b7a4 commit 262c30c

File tree

4 files changed

+84
-49
lines changed

4 files changed

+84
-49
lines changed

MaiChartManager.CLI/MaiChartManager.CLI.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
<PublishTrimmed>False</PublishTrimmed>
1414
<PublishAot>False</PublishAot>
1515
<PublishReadyToRun>true</PublishReadyToRun>
16+
<PublishDir>..\Packaging\Pack</PublishDir>
1617
</PropertyGroup>
1718

1819
<ItemGroup>

MaiChartManager.CLI/Program.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,26 @@
11
using System.Text;
2+
using MaiChartManager;
23
using MaiChartManager.CLI.Commands;
34
using MaiChartManager.CLI.Utils;
45
using Spectre.Console.Cli;
56

67
Console.OutputEncoding = Encoding.UTF8;
78
Console.CancelKeyPress += (_, _) => TerminalProgress.Clear();
89

10+
AppMain.InitConfiguration(true);
11+
await IapManager.Init();
12+
13+
if (IapManager.License != IapManager.LicenseStatus.Active)
14+
{
15+
Console.WriteLine("命令行工具目前为赞助版功能,请先使用桌面版应用程序解锁");
16+
return 1;
17+
}
18+
919
var app = new CommandApp();
1020

1121
app.Configure(config =>
1222
{
13-
config.SetApplicationName("MaiChartManager CLI");
23+
config.SetApplicationName("mcm");
1424

1525
config.AddCommand<MakeUsmCommand>("makeusm")
1626
.WithDescription("将视频文件转换为 USM 格式")

MaiChartManager/AppMain.cs

Lines changed: 38 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace MaiChartManager;
1111

1212
public class AppMain : ISingleInstance
1313
{
14-
public const string Version = "1.6.1";
14+
public const string Version = "1.7.0";
1515
public static Browser? BrowserWin { get; set; }
1616

1717
private Launcher _launcher;
@@ -24,49 +24,55 @@ public class AppMain : ISingleInstance
2424

2525
public static ILogger GetLogger<T>() => _loggerFactory.CreateLogger<T>();
2626

27-
public void Run()
27+
public static void InitConfiguration(bool noPopup = false)
2828
{
29-
try
30-
{
31-
SentrySdk.Init(o =>
32-
{
33-
// Tells which project in Sentry to send events to:
34-
o.Dsn = "https://[email protected]/3";
35-
// Set TracesSampleRate to 1.0 to capture 100% of transactions for tracing.
36-
// We recommend adjusting this value in production.
37-
o.TracesSampleRate = 0.5;
29+
SentrySdk.Init(o =>
30+
{
31+
// Tells which project in Sentry to send events to:
32+
o.Dsn = "https://[email protected]/3";
33+
// Set TracesSampleRate to 1.0 to capture 100% of transactions for tracing.
34+
// We recommend adjusting this value in production.
35+
o.TracesSampleRate = 0.5;
3836
# if DEBUG
39-
o.Environment = "development";
37+
o.Environment = "development";
4038
# endif
39+
}
40+
);
41+
42+
var cfgFilePath = Path.Combine(StaticSettings.appData, "config.json");
43+
if (File.Exists(cfgFilePath))
44+
{
45+
try
46+
{
47+
var cfg = JsonSerializer.Deserialize<Config>(File.ReadAllText(Path.Combine(StaticSettings.appData, "config.json")));
48+
if (cfg == null)
49+
{
50+
throw new Exception("config.json is null");
4151
}
42-
);
52+
StaticSettings.Config = cfg;
53+
}
54+
catch (Exception e)
55+
{
56+
SentrySdk.CaptureException(e, s => s.TransactionName = "读取配置文件");
57+
if (!noPopup)
58+
MessageBox.Show(Locale.ConfigCorrupted, Locale.ConfigCorruptedTitle, MessageBoxButtons.OK, MessageBoxIcon.Warning);
59+
File.Delete(cfgFilePath);
60+
}
61+
}
62+
}
4363

64+
public void Run()
65+
{
66+
try
67+
{
4468
Application.SetUnhandledExceptionMode(UnhandledExceptionMode.ThrowException);
4569
ApplicationConfiguration.Initialize();
4670
FFmpeg.SetExecutablesPath(StaticSettings.exeDir);
4771
VideoConvert.CheckHardwareAcceleration();
4872

4973
Directory.CreateDirectory(StaticSettings.appData);
5074
Directory.CreateDirectory(StaticSettings.tempPath);
51-
var cfgFilePath = Path.Combine(StaticSettings.appData, "config.json");
52-
if (File.Exists(cfgFilePath))
53-
{
54-
try
55-
{
56-
var cfg = JsonSerializer.Deserialize<Config>(File.ReadAllText(Path.Combine(StaticSettings.appData, "config.json")));
57-
if (cfg == null)
58-
{
59-
throw new Exception("config.json is null");
60-
}
61-
StaticSettings.Config = cfg;
62-
}
63-
catch (Exception e)
64-
{
65-
SentrySdk.CaptureException(e, s => s.TransactionName = "读取配置文件");
66-
MessageBox.Show(Locale.ConfigCorrupted, Locale.ConfigCorruptedTitle, MessageBoxButtons.OK, MessageBoxIcon.Warning);
67-
File.Delete(cfgFilePath);
68-
}
69-
}
75+
InitConfiguration();
7076

7177
// 初始化语言设置
7278
if (StaticSettings.Config.Locale == null)
@@ -91,16 +97,6 @@ public void Run()
9197
}
9298

9399
StaticSettings.Config.Locale = StaticSettings.CurrentLocale;
94-
// 保存配置
95-
try
96-
{
97-
var json = JsonSerializer.Serialize(StaticSettings.Config, new JsonSerializerOptions { WriteIndented = true });
98-
File.WriteAllText(cfgFilePath, json);
99-
}
100-
catch (Exception e)
101-
{
102-
_loggerFactory.CreateLogger<AppMain>().LogError(e, "保存配置文件失败");
103-
}
104100
}
105101
else
106102
{

Packaging/Base/AppxManifest.xml

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@
66
xmlns:build="http://schemas.microsoft.com/developer/appx/2015/build"
77
xmlns:uap4="http://schemas.microsoft.com/appx/manifest/uap/windows10/4"
88
xmlns:desktop="http://schemas.microsoft.com/appx/manifest/desktop/windows10"
9+
xmlns:uap3="http://schemas.microsoft.com/appx/manifest/uap/windows10/3"
910
IgnorableNamespaces="win32dependencies"
1011
>
11-
<Identity Name="22369479C5405.MaiChartManager" Publisher="CN=86A51452-7790-46C3-9A4B-1207C2C97940" Version="1.6.0.0"
12-
ProcessorArchitecture="x64" />
12+
<Identity Name="22369479C5405.MaiChartManager" Publisher="CN=86A51452-7790-46C3-9A4B-1207C2C97940"
13+
Version="1.7.0.0" ProcessorArchitecture="x64" />
1314
<Properties>
1415
<DisplayName>MaiChartManager</DisplayName>
1516
<PublisherDisplayName>凌莞</PublisherDisplayName>
@@ -20,7 +21,7 @@
2021
MaxVersionTested="10.0.22621.0" />
2122
<win32dependencies:ExternalDependency Name="Microsoft.WebView2"
2223
Publisher="CN=Microsoft Windows, O=Microsoft Corporation, L=Redmond, S=Washington, C=US"
23-
MinVersion="100.0.1185.39" Optional="true"/>
24+
MinVersion="100.0.1185.39" Optional="true" />
2425
</Dependencies>
2526
<Resources>
2627
<Resource Language="zh-cn" />
@@ -38,13 +39,40 @@
3839
<uap:SplashScreen Image="SplashScreen.png" />
3940
</uap:VisualElements>
4041
<Extensions>
41-
<desktop:Extension Category="windows.startupTask" Executable="MaiChartManager.exe" EntryPoint="Windows.FullTrustApplication">
42-
<desktop:StartupTask TaskId="MaiChartManagerStartupId" Enabled="false" DisplayName="MaiChartManager" />
42+
<desktop:Extension Category="windows.startupTask" Executable="MaiChartManager.exe"
43+
EntryPoint="Windows.FullTrustApplication">
44+
<desktop:StartupTask TaskId="MaiChartManagerStartupId" Enabled="false"
45+
DisplayName="MaiChartManager" />
4346
</desktop:Extension>
4447
</Extensions>
4548
</Application>
49+
50+
51+
<Application Id="CliTool"
52+
Executable="MaiChartManager.CLI.exe"
53+
EntryPoint="Windows.FullTrustApplication">
54+
<uap:VisualElements
55+
AppListEntry="none"
56+
DisplayName="MaiChartManager CLI"
57+
Description="MaiChartManager Command line tool"
58+
BackgroundColor="transparent"
59+
Square150x150Logo="Square150x150Logo.png"
60+
Square44x44Logo="Square44x44Logo.png">
61+
</uap:VisualElements>
62+
63+
<Extensions>
64+
<uap3:Extension Category="windows.appExecutionAlias">
65+
<uap3:AppExecutionAlias>
66+
<desktop:ExecutionAlias Alias="mcm.exe" />
67+
</uap3:AppExecutionAlias>
68+
</uap3:Extension>
69+
</Extensions>
70+
</Application>
71+
72+
73+
4674
</Applications>
4775
<Capabilities>
4876
<rescap:Capability Name="runFullTrust" />
4977
</Capabilities>
50-
</Package>
78+
</Package>

0 commit comments

Comments
 (0)