forked from marc365/Windows-DesktopRecorder
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathForm1.cs
More file actions
1539 lines (1379 loc) · 51.7 KB
/
Form1.cs
File metadata and controls
1539 lines (1379 loc) · 51.7 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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#region MIT license
//
// MIT license
//
// Copyright (c) 2017-2025 Marc Williams
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
#endregion
using Microsoft.Win32;
using NAudio;
using NAudio.Lame;
using System;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.IO.Pipes;
using System.Net;
using System.Net.Security;
using System.Net.Sockets;
using System.Reflection;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading;
using System.Windows.Forms;
namespace DesktopRecorder
{
public partial class Form1 : Form
{
#region Constructor
private RegistryKey registry;
private WasapiLoopbackCapture mx;
private WaveBuffer source;
private WaveBuffer dest;
private LameMP3FileWriter mp3writer;
private IntPtr mp3lib;
private Stream stdout;
private TcpClient tcp;
private Stopwatch Timer;
private SaveFileDialog dialog;
private MethodInvoker updateTimer;
private MethodInvoker resetView;
private MethodInvoker button1Click;
private MethodInvoker outputSwap;
private MethodInvoker modeSwap;
private MethodInvoker loadRegistry;
private MethodInvoker closeForm;
private Thread pipe;
private int _rate;
private int _bits;
private int _bitrate;
private int _channels;
private int _mode = 1;
private readonly string[] _modes = { Title.Mode0, Title.Mode1, Title.Mode2, Title.Mode3, Title.Mode4, Title.Mode5, Title.Mode6 };
private int _output = 0;
private readonly string[] _outputs = { Title.File, Title.Stream };
private string _verb;
private string _filename;
private int _width;
private int _height;
private int _left;
private int _top;
private int _deltax;
private int _deltay;
private int _update;
private string _time;
private string _button_start;
private string _button_stop;
private bool _transparent;
private FileMode _filemode = FileMode.Create;
private bool recording;
private bool restart;
private bool recover;
private bool exit;
private bool remote;
private bool minimized;
private bool small;
private bool drag;
private bool cancel;
private bool tiny;
private bool userRequestStop;
/// <summary>
/// Initializer
/// </summary>
internal Form1()
{
//remote control
InitIPC();
//load the settings
LoadRegistry();
//set before open
Left = _left;
Top = _top;
InitializeComponent();
//method invokers
updateTimer = UpdateTimer;
resetView = ResetView;
button1Click = button1_Invoke;
outputSwap = OutputSwap;
modeSwap = ModeSwap;
loadRegistry = LoadRegistry;
closeForm = FormClosing_Invoke;
//set timer
Timer = new Stopwatch();
}
#endregion
#region UI
/// <summary>
/// Called when starting
/// </summary>
private void Form1_Load(object sender, EventArgs e)
{
//load the UI settings
LoadRegistryUI();
//set when starting
Width = _width;
Height = _height;
//view modes
OutputSwap(); //close registry
ModeSwap();
ResetView();
if (_height >= Def.ToggleHeight) small = false;
ButtonSwap();
//output modes
comboBox1.DisplayMember = Def.Name;
comboBox1.ValueMember = Def.Id;
int m = 0;
for (; m < _outputs.Length; m++)
{
comboBox1.Items.Add(new Item(_outputs[m], m));
}
//recording modes
comboBox2.DisplayMember = Def.Name;
comboBox2.ValueMember = Def.Id;
for (m = 0; m < _modes.Length; m++)
{
comboBox2.Items.Add(new Item(_modes[m], m));
}
#region libmp3lame.dll
//extract embedded resource to the Temp folder and load
string libdir = Path.GetTempPath();
try
{
if (!Directory.Exists(libdir))
{
Directory.CreateDirectory(libdir);
}
}
catch (Exception exc)
{
MessageBox.Show(exc.Message, Error.Directory, MessageBoxButtons.OK);
Environment.Exit(exc.HResult);
}
libdir = Path.Combine(libdir, Def.LameDll);
if (!File.Exists(libdir)) using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(Def.LameResource))
{
try
{
using (Stream outFile = File.Create(libdir))
{
const int bufs = 4096;
byte[] buf = new byte[bufs];
while (true)
{
int read = stream.Read(buf, 0, bufs);
if (read < 1)
break;
outFile.Write(buf, 0, read);
}
}
}
catch (Exception exc)
{
MessageBox.Show(exc.Message, Error.FileSystem, MessageBoxButtons.OK);
Environment.Exit(exc.HResult);
}
}
mp3lib = NativeMethods.LoadLibrary(libdir);
#endregion
}
/// <summary>
/// Called after starting
/// </summary>
private void Form1_Shown(object sender, EventArgs e)
{
if (Form.ActiveForm != null)
{
ButtonSwap();
}
if (pipe != null) pipe.Start();
ResetTimer();
BorderSwap();
if (!_transparent)
{
tableLayoutPanel2.Visible = true;
SetTransparencyColour(Color.WhiteSmoke);
TransparencyKey = default(Color);
}
else
{
FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
if (Width == Def.MinWidth) tableLayoutPanel2.Visible = false;
SetTransparencyColour(Color.Black);
TransparencyKey = BackColor;
}
if (Program.AutoStart) Invoke(button1Click);
}
/// <summary>
/// Called after resizing or moving window (not called when using drag button)
/// </summary>
private void Form1_Resized(object sender, EventArgs e)
{
_width = Width;
_height = Height;
_left = Left;
_top = Top;
ButtonSwap();
SaveRegistry();
UpdateTimer();
BorderSwap();
if (tableLayoutPanel2.Visible == false) tableLayoutPanel2.Visible = true;
}
/// <summary>
/// Called when quiting
/// </summary>
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
SaveRegistry();
if (recording)
{
recording = false;
exit = true;
mx.StopRecording();
}
else
{
NativeMethods.FreeLibrary(mp3lib);
}
if (pipe != null && remote)
{
remote = false;
using (NamedPipeClientStream instance = new NamedPipeClientStream(Def.PipeName)) //connecting to close
{
instance.Connect(0);
if (instance.IsConnected) instance.ReadByte();
}
}
}
/// <summary>
/// STAThread invoke
/// </summary>
private void FormClosing_Invoke()
{
Form1_FormClosing(null, null);
}
/// <summary>
/// Change output
/// </summary>
private void OutputSwap()
{
registry = Registry.CurrentUser.OpenSubKey(Reg.KEY);
switch (_output)
{
case 0:
textBox1.Text = (string)registry.GetValue(Reg.File, Def.EmptyString);
toolTip1.SetToolTip(textBox1, Title.FileName);
if (!tiny) button2.Show();
checkBox1.Show();
checkBox2.Show();
checkBox3.Show();
radioButton1.Hide();
radioButton2.Hide();
radioButton3.Hide();
break;
case 1:
textBox1.Text = (string)registry.GetValue(Reg.Stream, Def.Https);
toolTip1.SetToolTip(textBox1, Title.StreamLocation);
button2.Hide();
checkBox1.Hide();
checkBox2.Hide();
checkBox3.Hide();
radioButton1.Show();
radioButton2.Show();
radioButton3.Show();
break;
}
registry.Close();
comboBox1.SelectedItem = _output;
comboBox1.Text = _outputs[_output];
}
/// <summary>
/// Change audio mode
/// </summary>
private void ModeSwap()
{
switch (_mode)
{
case 0:
_bits = 16;
break;
case 1:
_bits = 32;
break;
case 2:
_bits = 16;
_bitrate = 32;
break;
case 3:
_bits = 16;
_bitrate = 64;
break;
case 4:
_bits = 16;
_bitrate = 128;
break;
case 5:
_bits = 16;
_bitrate = 256;
break;
case 6:
_bits = 16;
_bitrate = 320;
break;
default:
break;
}
if (_mode < 2)
{
textBox1.Text = SwapFileExtension(textBox1.Text, Def.Wav);
}
else
{
textBox1.Text = SwapFileExtension(textBox1.Text, Def.Mp3);
}
comboBox2.SelectedItem = _mode;
comboBox2.Text = _modes[_mode];
}
/// <summary>
/// Resize the button
/// </summary>
private void ButtonSwap()
{
if (_height < Def.ToggleHeight && !small)
{
small = true;
button1.Image = Properties.Resources.rec_but;
tableLayoutPanel1.ColumnStyles.Clear();
tableLayoutPanel1.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, 70F));
button1.Font = new System.Drawing.Font(Def.Font, 8F, FontStyle.Regular, GraphicsUnit.Point, 0);
checkBox4.Hide();
checkBox5.Hide();
hScrollBar1.Hide();
}
else if (_height >= Def.ToggleHeight)
{
if (small || button1.Image == null)
{
button1.Image = Properties.Resources.rec_large;
tableLayoutPanel1.ColumnStyles.Clear();
tableLayoutPanel1.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, 124F));
button1.Font = new System.Drawing.Font(Def.Font, 11.25F, FontStyle.Regular, GraphicsUnit.Point, 0);
}
small = false;
checkBox4.Show();
checkBox5.Show();
hScrollBar1.Show();
}
tableLayoutPanel3.Show();
tableLayoutPanel1.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 100F));
if (_height >= Def.ToggleHeight && _width < Def.ShortWidth)
{
comboBox1.Hide();
textBox1.Hide();
hScrollBar1.Hide();
checkBox1.Hide();
checkBox2.Hide();
checkBox3.Hide();
checkBox4.Hide();
checkBox5.Hide();
tableLayoutPanel3.Hide();
tiny = true;
}
else if (_height >= Def.ToggleHeight && _width < Def.ToolWidth)
{
comboBox1.Hide();
textBox1.Hide();
hScrollBar1.Hide();
checkBox1.Hide();
checkBox2.Hide();
checkBox3.Hide();
checkBox4.Hide();
checkBox5.Hide();
}
else if (_width < Def.TinyWidth)
{
comboBox1.Hide();
textBox1.Hide();
hScrollBar1.Hide();
checkBox1.Hide();
checkBox2.Hide();
checkBox3.Hide();
tableLayoutPanel3.Hide();
tiny = true;
}
else if (_width < Def.ShortWidth)
{
comboBox1.Hide();
textBox1.Hide();
hScrollBar1.Hide();
checkBox1.Hide();
checkBox2.Hide();
checkBox3.Hide();
}
else
{
comboBox1.Show();
textBox1.Show();
checkBox1.Show();
checkBox2.Show();
checkBox3.Show();
tiny = false;
}
}
/// <summary>
/// Change the Window Style
/// </summary>
private void BorderSwap()
{
int nudge = 0;
if (_height < Def.ToggleHeight) nudge = 54;
if (_width < Def.ToolWidth - nudge) FormBorderStyle = FormBorderStyle.SizableToolWindow;
else FormBorderStyle = FormBorderStyle.Sizable;
}
/// <summary>
/// Change the background colour when toggled
/// </summary>
private void SetTransparencyColour(Color bg)
{
BackColor = bg;
button1.BackColor = bg;
button1.FlatAppearance.BorderColor = bg;
button1.FlatAppearance.MouseDownBackColor = bg;
button1.FlatAppearance.MouseOverBackColor = bg;
button1.FlatAppearance.BorderSize = 0;
}
/// <summary>
/// Start drag the window by the record button
/// </summary>
private void button1_MouseDown(object sender, MouseEventArgs e)
{
drag = true;
_deltax = MousePosition.X - Left;
_deltay = MousePosition.Y - Top;
}
/// <summary>
/// Drag the window by the record button
/// </summary>
private void button1_MouseMove(object sender, MouseEventArgs e)
{
if (drag)
{
if (Left != MousePosition.X - _deltax || Top != MousePosition.Y - _deltay)
{
cancel = true;
Left = MousePosition.X - _deltax;
Top = MousePosition.Y - _deltay;
_left = Left;
_top = Top;
}
}
}
/// <summary>
/// Stop drag the window by the record button
/// </summary>
private void button1_MouseUp(object sender, MouseEventArgs e)
{
if (drag) SaveRegistry();
drag = false;
cancel = false;
}
/// <summary>
/// Format the recording time and
/// change the form border style
/// based on the width of the window
/// </summary>
private void UpdateTimer()
{
_time = Timer.Elapsed.ToString(Def.TimeStamp);
if (_time != label1.Text) label1.Text = _time;
}
/// <summary>
/// Run the timer update from a background thread
/// </summary>
private void BackgroundTimer()
{
while (recording)
{
if ( _width > Def.MinWidth)
{
try
{
Invoke(updateTimer);
}
catch (InvalidOperationException)
{
//Object disposed exception
}
}
Thread.Sleep(_update);
}
}
/// <summary>
/// Reset the recording time
/// </summary>
private void ResetTimer()
{
Timer.Reset();
Invoke(updateTimer);
}
/// <summary>
/// Called after Stopped Recording
/// </summary>
private void ResetView()
{
Timer.Stop();
if (_transparent)
{
SetTransparencyColour(Color.Black);
TransparencyKey = BackColor;
}
else
{
SetTransparencyColour(Color.WhiteSmoke);
TransparencyKey = Color.Green;
}
comboBox1.Enabled = true;
textBox1.Enabled = true;
comboBox2.Enabled = true;
button1.Text = _button_start;
}
#endregion
#region Actions
/// <summary>
/// Record
/// </summary>
private void button1_Click(object sender, EventArgs e)
{
if (cancel)
{
cancel = false;
drag = false;
return;
}
//toggle stop
if (recording)
{
try
{
userRequestStop = true;
mx.StopRecording();
}
catch (Exception exc)
{
MessageBox.Show(exc.Message, _button_stop, MessageBoxButtons.OK);
}
return;
}
InitWasapi();
#region File
if (_output == 0)
{
if (string.IsNullOrEmpty(textBox1.Text))
{
button2_Click(sender, e);
if (string.IsNullOrEmpty(textBox1.Text)) return;
SaveRegistry();
}
_filename = textBox1.Text;
if (checkBox1.Checked)
{
_filename = _filename.Substring(0, _filename.Length - 4) + DateTime.Now.ToString(Def.DateStamp) + _filename.Substring(_filename.Length - 4, 4);
}
if (File.Exists(_filename))
{
if (checkBox3.Checked || recover)
{
_filemode = FileMode.Append;
}
else
{
_filemode = FileMode.Create;
if (!checkBox2.Checked && !recover)
{
FileInfo file = new FileInfo(_filename);
_filename = file.Name.Substring(0, file.Name.Length - file.Extension.Length);
_filename = Path.Combine(file.DirectoryName, string.Concat(_filename, Def.Dot, Directory.GetFiles(file.DirectoryName, _filename + Def.DotStar).Length, file.Extension));
}
}
}
if (!recover)
{
try
{
stdout = File.Open(_filename, _filemode);
}
catch (Exception exc)
{
MessageBox.Show(exc.Message, Error.File, MessageBoxButtons.OK);
return;
}
}
}
#endregion
#region Stream
else if (_output == 1)
{
try
{
Uri uri = new Uri(textBox1.Text);
tcp = new TcpClient();
IPAddress[] a = Dns.GetHostAddresses(uri.DnsSafeHost);
tcp.Connect(a[0], uri.Port);
if (uri.Scheme == Def.https)
{
SslStream ssl = new SslStream(tcp.GetStream(), true, new RemoteCertificateValidationCallback(ValidateServerCertificate), null);
ssl.AuthenticateAsClient(uri.DnsSafeHost, null, System.Security.Authentication.SslProtocols.Tls12, false);
stdout = ssl;
}
else
{
stdout = tcp.GetStream();
}
#region send header
byte[] header = Encoding.ASCII.GetBytes(new StringBuilder()
.Append(_verb).Append(Def.Space).Append(uri.PathAndQuery).Append(Def.Space).Append(Def.Proto).Append(Def.NewLine)
.Append((uri.UserInfo == null) ? Def.EmptyString : string.Concat(Def.Authorization, Def.Basic, Def.Space, Convert.ToBase64String(Encoding.ASCII.GetBytes(uri.UserInfo)), Def.NewLine))
.Append(Def.Host).Append(uri.DnsSafeHost).Append(Def.NewLine)
.Append(Def.UserAgent).Append(Def.AppName).Append(Def.Slash).Append(Application.ProductVersion).Append(Def.NewLine).Append(Def.NewLine).ToString());
stdout.Write(header, 0, header.Length);
#endregion
#region parse response
Thread.Sleep(500); //pause for network (single thread)
//the server will return an header if there is an error
if (tcp.Available > 0)
{
byte[] buf = new byte[65535];
int l = stdout.Read(buf, 0, buf.Length);
string Header = Encoding.ASCII.GetString(buf, 0, l);
switch (buf[9] - 0x30) //error class 100, 200, 300, 400, 500 from the first ASCII character
{
case 1: //Continue
case 2: //OK
goto end;
case 3: //Redirect
uri = new Uri(DeSerializeHeader(Header, Def.Location));
textBox1.Text = uri.AbsoluteUri;
break;
case 4: //Authentication
case 5: //Error
break;
}
MessageBox.Show(Header, Title.ServerResponse, MessageBoxButtons.OK);
return;
end:
;
}
#endregion
}
catch (Exception exc)
{
MessageBox.Show(exc.Message, Error.Stream, MessageBoxButtons.OK);
return;
}
}
#endregion
#region Mp3
//encode with libmp3lame.dll
if (_mode > 1)
{
try
{
mp3writer = new LameMP3FileWriter(stdout, new WaveFormat(_rate, _bits, _channels), _bitrate);
}
catch (ArgumentException exc)
{
MessageBox.Show(exc.Message, Error.Mp3, MessageBoxButtons.OK);
stdout.Close();
return;
}
}
#endregion
#region Wav
else if (_filemode == FileMode.Create && _output == 0)
{
try
{
WriteWavHeader(stdout, (_bits == 32) ? true : false, (ushort)_channels, (ushort)_bits, _rate, 0);
}
catch (Exception exc)
{
MessageBox.Show(exc.Message, Error.Header, MessageBoxButtons.OK);
stdout.Close();
return;
}
}
#endregion
if (!checkBox3.Checked && !recover) ResetTimer(); //don't reset timer if write mode is Append
int count = 0;
retry:
try
{
mx.StartRecording();
}
catch (Exception exc)
{
if (string.IsNullOrWhiteSpace(exc.Message))
{
if (count < Int16.MaxValue && recover)
{
count++;
Thread.Sleep(1);
InitWasapi();
goto retry;
}
else
{
mx.Dispose();
}
}
Timer.Stop();
MessageBox.Show(exc.Message, Error.Startup, MessageBoxButtons.OK);
stdout.Close();
return;
}
comboBox1.Enabled = false;
textBox1.Enabled = false;
comboBox2.Enabled = false;
if (!_transparent)
{
SetTransparencyColour(Color.DarkRed);
TransparencyKey = default(Color);
}
button1.Text = _button_stop;
recover = false;
recording = true;
new Thread(BackgroundTimer).Start();
}
/// <summary>
/// STAThread invoke
/// </summary>
private void button1_Invoke()
{
button1_Click(null, null);
}
/// <summary>
/// File selector
/// </summary>
private void button2_Click(object sender, EventArgs e)
{
dialog = new SaveFileDialog()
{
Title = Title.SaveAs,
OverwritePrompt = false,
Filter = string.Format(Title.FileSelector, (_mode < 2) ? Def.wav : Def.mp3 )
};
if (dialog.ShowDialog() == DialogResult.OK)
{
textBox1.Text = dialog.FileName;
if (recording)
{
HotSwap();
}
else
{
SaveRegistry();
}
}
}
/// <summary>
/// Change output
/// </summary>
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
if ((sender as ComboBox).SelectedIndex == _output) return;
_output = (sender as ComboBox).SelectedIndex;
OutputSwap();
SaveRegistry();
}
/// <summary>
/// Change audio mode
/// </summary>
private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
{
if ((sender as ComboBox).SelectedIndex == _mode) return;
_mode = (sender as ComboBox).SelectedIndex;
ModeSwap();
SaveRegistry();
}
/// <summary>
/// Click the timer to reset it
/// </summary>
private void label1_Click(object sender, EventArgs e)
{
ResetTimer();
}
/// <summary>
/// Set the verb to GET
/// </summary>
private void radioButton1_CheckedChanged(object sender, EventArgs e)
{
_verb = Def.GET;
}
/// <summary>
/// Set the verb to POST
/// </summary>
private void radioButton2_CheckedChanged(object sender, EventArgs e)
{
_verb = Def.POST;
}
/// <summary>
/// Set the verb to PUT
/// </summary>
private void radioButton3_CheckedChanged(object sender, EventArgs e)
{
_verb = Def.PUT;
}
/// <summary>
/// Uncheck overwrite if append was toggled
/// </summary>
private void checkBox3_CheckedChanged(object sender, EventArgs e)
{
if (checkBox2.Checked == true) checkBox2.Checked = false;
}
/// <summary>
/// Window always on top
/// </summary>
private void checkBox4_CheckedChanged(object sender, EventArgs e)
{
TopMost = checkBox4.Checked;
}
/// <summary>
/// Right click button menu, toggle transparency
/// </summary>
private void item1ToolStripMenuItem_Click(object sender, EventArgs e)
{
if (_transparent)
{
_transparent = false;
if (Width > Def.MinWidth) tableLayoutPanel2.Visible = true;
if (recording) SetTransparencyColour(Color.DarkRed);
else SetTransparencyColour(Color.WhiteSmoke);
TransparencyKey = default(Color);
BorderSwap();
}
else
{
_transparent = true;
FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
if (Width == Def.MinWidth) tableLayoutPanel2.Visible = false;
if (_height == Def.ToggleHeight) Height = Def.ToggleHeight;
SetTransparencyColour(Color.Black);
TransparencyKey = BackColor;
}
}
/// <summary>
/// Right click button menu, toggle shrink window size
/// </summary>
private void item2ToolStripMenuItem_Click(object sender, EventArgs e)
{
if (tableLayoutPanel2.Visible == true)
{
tableLayoutPanel2.Visible = false;
Width = Def.MinWidth;
if (Height > Def.ToggleHeight) Height = Def.ToggleHeight;
if (!_transparent) FormBorderStyle = FormBorderStyle.SizableToolWindow;
}
else
{
tableLayoutPanel2.Visible = true;
Width = _width;
Height = _height;
if (!_transparent) BorderSwap();
}