-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathProgram.cs
More file actions
173 lines (148 loc) · 6.01 KB
/
Program.cs
File metadata and controls
173 lines (148 loc) · 6.01 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
using FlyleafLib;
using System;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using Serilog;
using Serilog.Core;
using Serilog.Events;
namespace opentuner
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
public static LoggingLevelSwitch levelSwitch;
[DllImport("user32.dll")]
private static extern bool ShowWindow([In] IntPtr hWnd, [In] int nCmdShow);
[DllImport("kernel32.dll")]
static extern IntPtr GetConsoleWindow();
[STAThread]
static void Main(string[] args)
{
int i = 0;
int debugLevel = 3; // Warning
levelSwitch = new LoggingLevelSwitch();
while (i < args.Length)
{
switch (args[i])
{
case "--debuglevel":
int new_debug_level = -1;
if (int.TryParse(args[i + 1], out new_debug_level))
{
if (new_debug_level < 6 && new_debug_level >= 0)
{
debugLevel = new_debug_level;
}
i += 1;
}
break;
case "--hideconsolewindow":
// minimize console window
IntPtr handle = GetConsoleWindow();
if (handle != IntPtr.Zero)
{
ShowWindow(handle, 0);
}
break;
default:
break;
}
// grab next param
i += 1;
}
switch (debugLevel)
{
case 0: // Verbose
levelSwitch.MinimumLevel = LogEventLevel.Verbose;
break;
case 1: // Debug
levelSwitch.MinimumLevel = LogEventLevel.Debug;
break;
case 2: // Information
levelSwitch.MinimumLevel = LogEventLevel.Information;
break;
case 3: // Warning
levelSwitch.MinimumLevel = LogEventLevel.Warning;
break;
case 4: // Error
levelSwitch.MinimumLevel = LogEventLevel.Error;
break;
case 5: // Fatal
levelSwitch.MinimumLevel = LogEventLevel.Fatal;
break;
default:
levelSwitch.MinimumLevel = LogEventLevel.Warning;
break;
}
Log.Logger = new LoggerConfiguration()
.MinimumLevel.ControlledBy(levelSwitch)
.WriteTo.Console()
.WriteTo.File("logs\\ot_log_" + DateTime.Now.ToString("yyyy-dd-M--HH-mm-ss") + ".txt")
.CreateLogger();
// Always log the starting information
// swith logging level to Information
LogEventLevel lastMinimumLevel = levelSwitch.MinimumLevel;
levelSwitch.MinimumLevel = LogEventLevel.Information;
Log.Information("Starting OpenTuner");
// swith logging level back
levelSwitch.MinimumLevel = lastMinimumLevel;
string logDirectory = AppDomain.CurrentDomain.BaseDirectory + "logs\\";
if (Directory.Exists(logDirectory))
{
var logFiles = Directory.GetFiles(logDirectory, "*.txt").Select(f => new FileInfo(f)).OrderByDescending(f => f.CreationTime);
int fileCount = logFiles.Count();
if (fileCount > 10)
{
i = 0;
foreach (var file in logFiles)
{
if (i > 9)
{
try
{
File.Delete(file.FullName);
Log.Debug("Log file deleted: " + file.Name);
}
catch
{
Log.Warning("Log file for deletion not found: " + file.Name);
}
}
i++;
}
}
}
try
{
Engine.Start(new EngineConfig()
{
FFmpegPath = @"ffmpeg\",
FFmpegDevices = false, // Prevents loading avdevice/avfilter dll files. Enable it only if you plan to use dshow/gdigrab etc.
//LogLevel = LogLevel.Debug,
//LogOutput = ":console",
//LogOutput = @"C:\temp2\ffmpeg.log",
/*
UIRefresh = true, // Required for Activity, BufferedDuration, Stats in combination with Config.Player.Stats = true
UIRefreshInterval = 250, // How often (in ms) to notify the UI
UICurTimePerSecond = false, // Whether to notify UI for CurTime only when it's second changed or by UIRefreshInterval
*/
});
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new MainForm(args));
}
catch (Exception ex)
{
Log.Fatal(ex, "Program.Main: Uncaught Exception");
}
finally
{
Log.CloseAndFlush();
}
}
}
}