forked from jim60105/YoutubeSegmentDownloader
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
78 lines (68 loc) · 2.78 KB
/
Copy pathProgram.cs
File metadata and controls
78 lines (68 loc) · 2.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
using Microsoft.Win32;
using Serilog;
using Serilog.Core;
using Serilog.Formatting.Display;
using Serilog.Sinks.WinForms.Base;
namespace YTSDownloader;
internal static class Program
{
public static readonly LoggingLevelSwitch LevelSwitch = new();
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
private static void Main()
{
Log.Logger = new LoggerConfiguration()
.MinimumLevel.ControlledBy(LevelSwitch)
.WriteTo.File(path: Path.Combine(Path.GetTempPath(), $"{Application.ProductName?.Replace(" ", "")}.log"),
rollingInterval: RollingInterval.Day,
outputTemplate: "{Timestamp:HH:mm:ss} [{Level:u3}] {Message:lj} {NewLine}{Exception}")
.WriteToSimpleAndRichTextBox(new MessageTemplateTextFormatter("{Message} {Exception}\n"))
.CreateLogger();
Task.Run(SetAddRemoveProgramsIcon);
try
{
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
Application.Run(new Form1());
}
catch (Exception ex)
{
Log.Fatal(ex, "Program terminated unexpectedly");
}
finally
{
Log.CloseAndFlush();
}
}
#pragma warning disable CS8602 // 可能 null 參考的取值 (dereference)。
private static void SetAddRemoveProgramsIcon()
{
//if (ApplicationDeployment.IsNetworkDeployed && ApplicationDeployment.CurrentDeployment.IsFirstRun)
{
try
{
string iconSourcePath = Path.Combine(Application.StartupPath, @"YTSDownloader.ico");
if (!File.Exists(iconSourcePath)) return;
RegistryKey? uninstallKey = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Uninstall");
if (uninstallKey == null) return;
string[] subKeyNames = uninstallKey.GetSubKeyNames();
foreach (string subKeyName in subKeyNames)
{
RegistryKey? myKey = uninstallKey.OpenSubKey(subKeyName, true);
object? myValue = myKey.GetValue("DisplayName");
if (myValue == null || myValue.ToString() != "YTS Downloader") continue;
myKey.SetValue("DisplayIcon", iconSourcePath);
break;
}
}
catch (Exception e)
{
Log.Logger.Error(e.Message);
}
}
}
#pragma warning restore CS8602 // 可能 null 參考的取值 (dereference)。
}