forked from JMS-1/DVB.NET---VCR.NET
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathProgram.cs
More file actions
226 lines (200 loc) · 9.04 KB
/
Program.cs
File metadata and controls
226 lines (200 loc) · 9.04 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
using System;
using System.IO;
using System.Text;
using Microsoft.Win32;
using System.Diagnostics;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using JMS.DVB;
using JMS.DVB.Viewer;
using JMS.DVB.DirectShow.UI;
using JMS.DVB.DirectShow.RawDevices;
using System.Reflection;
namespace DVBNETViewer
{
/// <summary>
/// Die Startroutine für den DVB.NET / VCR.NET Viewer.
/// </summary>
public static class Program
{
/// <summary>
/// Wird hier zum Abmelden des Anwenders verwendet.
/// </summary>
/// <param name="flags">Die Art der Abmeldung.</param>
/// <param name="reason">Optional ein Grund, falls der Rechner heruntergefahren wird.</param>
/// <returns>Gesetzt, wenn die Operation erfolgreich war.</returns>
[DllImport( "user32.dll" )]
private static extern bool ExitWindowsEx( UInt32 flags, UInt32 reason );
/// <summary>
/// Installiert die Laufzeitumgebung.
/// </summary>
static Program()
{
// Activate dynamic loading
RunTimeLoader.Startup();
}
[STAThread]
static void Main( string[] args )
{
// Be safe
try
{
// Check settings
var version = Assembly.GetExecutingAssembly().GetName().Version.ToString();
if (!version.Equals( Properties.Settings.Default.Version ))
{
// Upgrade
Properties.Settings.Default.Upgrade();
Properties.Settings.Default.Version = version;
Properties.Settings.Default.Save();
}
// Prepare
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault( false );
// Force priority
Process.GetCurrentProcess().PriorityClass = Properties.Settings.Default.Priority;
// Check start mode
string startMode = ((null == args) || (args.Length < 1)) ? null : args[0];
// Apply language
UserProfile.ApplyLanguage();
// See how we should work
if (Equals( startMode, "/Reset" ))
{
// Ask user
if (DialogResult.Yes != MessageBox.Show( Properties.Resources.ResetSettings, Properties.Resources.Confirmation, MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2 )) return;
// Process
Properties.Settings.Default.Reset();
Properties.Settings.Default.Save();
}
if (Equals( startMode, "/LearnRC" ))
{
// Run RC configuration
RCSettings.Edit( RCSettings.ConfigurationFile ).Dispose();
}
else
{
// Check OSD mode
if (Properties.Settings.Default.ManualOSDLegacyMode)
OverlayWindow.UseLegacyOverlay = Properties.Settings.Default.OSDLegacyMode;
// Form to start
ViewerMain form = null;
// Test parameter
if (!string.IsNullOrEmpty( startMode ))
if (Equals( startMode, "/VCR" ))
{
// Create in VCR LIVE / CURRENT mode
form = new ViewerMain( StartupModes.RemoteVCR );
}
else if (startMode.ToLower().StartsWith( "dvbnet://" ))
{
// Start with the server part
startMode = startMode.Substring( 9 );
// See if this is a regular start using the URL protocol
bool startedByProtocol = !startMode.StartsWith( "*" );
// Must be the control center
if (startedByProtocol)
{
// Prepare for special decoding
byte[] tmp = new byte[startMode.Length];
// Copy by byte
for (int i = tmp.Length; i-- > 0; )
tmp[i] = (byte) startMode[i];
// Retrieve
startMode = Encoding.UTF8.GetString( tmp );
}
else
{
// Just cut off the control character
startMode = startMode.Substring( 1 );
}
// Just correct for URL stuff
startMode = Uri.UnescapeDataString( startMode.Replace( '+', ' ' ) );
// See if this is a file replay
int file = startMode.ToLower().IndexOf( "/play=" );
if (file < 0)
{
// Create in VCR CURRENT mode
form = new ViewerMain( StartupModes.WatchOrTimeshift, startMode );
}
else
{
// Get server and file name
string server = startMode.Substring( 0, file );
string path = startMode.Substring( file + 6 );
// Replay
form = new ViewerMain( StartupModes.PlayRemoteFile, path, server );
}
}
else if (startMode.StartsWith( "/VCR=" ))
{
// Create in VCR REPLY mode
form = new ViewerMain( StartupModes.PlayRemoteFile, startMode.Substring( 5 ), null );
}
else if (startMode.StartsWith( "/TCP=" ))
{
// Create in STREAMING SLAVE mode
form = new ViewerMain( StartupModes.ConnectTCP, startMode.Substring( 5 ) );
}
else if (startMode.StartsWith( "/FILE=" ))
{
// Create in LOCAL REPLAY mode
form = new ViewerMain( StartupModes.PlayLocalFile, startMode.Substring( 6 ) );
}
// Local mode
if (form != null)
{
// Run the application
Application.Run( form );
}
else
{
// Ask for the profile
var profile = UserProfile.Profile;
if (profile != null)
using (HardwareManager.Open())
Application.Run( new ViewerMain( profile ) );
}
}
}
catch (Exception e)
{
// Report as is
MessageBox.Show( e.ToString() );
// Terminate
Environment.Exit( 1 );
}
// If we are running as the users shell log off
using (var key = Registry.CurrentUser.OpenSubKey( @"Software\Microsoft\Windows NT\CurrentVersion\Winlogon" ))
if (key != null)
try
{
// Load shell
var shell = key.GetValue( "Shell" ) as string;
if (shell != null)
{
// Remove quotes
if (shell.Length >= 2)
if (shell.StartsWith( "\"" ))
if (shell.EndsWith( "\"" ))
shell = shell.Substring( 1, shell.Length - 2 ).Replace( "\"\"", "\"" );
// Clip
shell = shell.Trim();
// See what's left
if (!string.IsNullOrEmpty( shell ))
{
// Attach to file
var file1 = new FileInfo( shell );
var file2 = new FileInfo( Application.ExecutablePath );
// Check
if (string.Equals( file1.FullName, file2.FullName, StringComparison.InvariantCultureIgnoreCase ))
ExitWindowsEx( 0x10, 0 );
}
}
}
catch
{
// Ignore any error
}
}
}
}