/
SilentForm.cs
89 lines (74 loc) · 2.38 KB
/
SilentForm.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
88
89
using System;
using System.IO;
using System.Text;
using System.Threading;
using System.Windows.Forms;
namespace CueToOgg
{
public partial class SilentForm : LoggerForm
{
private FileStream logfile;
public SilentForm():base()
{
InitializeComponent();
Alert = new AlertDelegate(AlertMethod);
Exit = new ExitDelegate(ExitMethod);
FatalExit = new FatalExitDelegate(FatalExitMethod);
Log = new LogDelegate(LogMethod);
ReportProgress = new ReportProgressDelegate(ReportProgressMethod);
Info = new InfoDelegate(InfoMethod);
logfile=File.OpenWrite(Path.GetDirectoryName(Application.ExecutablePath)+"\\cuetoogg.log.txt");
}
public new void AlertMethod(string message)
{
}
public new void ExitMethod()
{
if (converterThread != null && converterThread.ThreadState==ThreadState.Running)
{
converterThread.Abort();
}
Application.Exit();
}
public new void FatalExitMethod(string reason)
{
LogMethod(reason);
AlertMethod(reason);
ExitMethod();
}
public new void ReportProgressMethod(int arg)
{
this.progressBar1.Value = arg;
}
public new void LogMethod(string message)
{
InfoMethod(message);
}
public new void InfoMethod(string message)
{
var msg = Encoding.UTF8.GetBytes(message + "\n");
logfile.Write(msg, 0, msg.Length);
}
private Thread converterThread=null;
private void AfterFormLoad(object sender, EventArgs e)
{
CenterToScreen();
var thread = new Thread(new ThreadStart(StartProcessing));
thread.SetApartmentState(ApartmentState.STA);
thread.Start();
}
private void StartProcessing()
{
var c = new CueDirectoryConverter(this);
c.StartProcessing();
}
private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
{
if (converterThread != null && converterThread.ThreadState == ThreadState.Running)
{
converterThread.Abort();
}
logfile.Close();
}
}
}