This repository has been archived by the owner on Aug 8, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.cs
87 lines (71 loc) · 2.65 KB
/
Main.cs
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
79
80
81
82
83
84
85
86
87
using System;
using System.IO;
using System.Configuration;
using System.Reflection;
using Gtk;
using Microsoft.Extensions.Configuration;
using System.Linq;
using System.Threading.Tasks;
using NLog;
using Xunit;
using NLog.Config;
using NLog.Targets;
namespace TelegramApp
{
class Program
{
public static readonly Client Client;
public static readonly IConfigurationRoot Config;
public static Logger Logger;
static Program()
{
Config = new ConfigurationBuilder()
.AddJsonFile("appconfig.json")
.AddUserSecrets<Program>()
.Build();
int api_id;
var api_hash = Config["API_HASH"];
Assert.True(int.TryParse(Config["API_ID"], out api_id), "Failed to read api_id");
Assert.True(api_hash != null, "Failed to read api_hash");
Client = new Client(api_id, api_hash);
}
private static void SetupLogging()
{
var nlogConfig = new LoggingConfiguration();
var fileTarget = new FileTarget("file")
{
FileName = Path.Combine(DataStorage.UserDataFolder, "nlog.log"),
KeepFileOpen = true,
ConcurrentWrites = false,
DeleteOldFileOnStartup = true,
};
nlogConfig.AddTarget(fileTarget);
nlogConfig.LoggingRules.Add(new LoggingRule("*", NLog.LogLevel.Debug, fileTarget));
var consoleTarget = new ConsoleTarget("console");
nlogConfig.AddTarget(consoleTarget);
nlogConfig.LoggingRules.Add(new LoggingRule("*", NLog.LogLevel.Warn, consoleTarget));
LogManager.Configuration = nlogConfig;
LogManager.EnableLogging();
Logger = LogManager.GetCurrentClassLogger();
}
private static void SetupDllPaths()
{
var dllDirectory = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, Config["GtkDllPath"]);
Environment.SetEnvironmentVariable("PATH", Environment.GetEnvironmentVariable("PATH") + ";" + dllDirectory);
Assert.False(string.IsNullOrEmpty(dllDirectory), "Gtk dll directory not found");
}
[STAThread]
public static void Main(string[] args)
{
SetupLogging();
SetupDllPaths();
Application.Init();
var app = new Application("org.telega_sharp.telega_sharp", GLib.ApplicationFlags.None);
app.Register(GLib.Cancellable.Current);
var win = new MainWindow();
app.AddWindow(win);
win.Show();
Application.Run();
}
}
}