91 lines
2.7 KiB
C#
91 lines
2.7 KiB
C#
using System;
|
|
using System.Configuration;
|
|
using System.IO;
|
|
using System.Reflection;
|
|
using System.Text;
|
|
using System.Threading;
|
|
using System.Windows.Forms;
|
|
using VideoReader.Properties;
|
|
|
|
namespace VideoReader;
|
|
|
|
internal static class Program
|
|
{
|
|
public static int FrameRate = 30;
|
|
|
|
public static string log_file = "";
|
|
|
|
public static string[] Arg;
|
|
|
|
[STAThread]
|
|
private static void Main(string[] arg)
|
|
{
|
|
Arg = arg;
|
|
Settings.Default.Chenal = 56;
|
|
((SettingsBase)Settings.Default).Save();
|
|
bool createdNew;
|
|
Mutex mutex = new Mutex(initiallyOwned: false, $"Start_current_video_Reader_{Settings.Default.Chenal}", out createdNew);
|
|
if (createdNew)
|
|
{
|
|
switch (Environment.OSVersion.Platform)
|
|
{
|
|
case PlatformID.Win32S:
|
|
case PlatformID.Win32Windows:
|
|
case PlatformID.Win32NT:
|
|
{
|
|
string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
|
|
string path = string.Format("{0}/FFmpeg/bin/{1}", directoryName, Environment.Is64BitProcess ? "x64" : "x86");
|
|
InteropHelper.RegisterLibrariesSearchPath(path);
|
|
break;
|
|
}
|
|
case PlatformID.Unix:
|
|
case PlatformID.MacOSX:
|
|
{
|
|
string environmentVariable = Environment.GetEnvironmentVariable("LD_LIBRARY_PATH");
|
|
InteropHelper.RegisterLibrariesSearchPath(environmentVariable);
|
|
break;
|
|
}
|
|
}
|
|
Application.EnableVisualStyles();
|
|
Application.SetCompatibleTextRenderingDefault(false);
|
|
Application.ThreadException += Application_ThreadException;
|
|
Application.Run((Form)(object)new Form1());
|
|
}
|
|
}
|
|
|
|
private static void Application_ThreadException(object sender, ThreadExceptionEventArgs e)
|
|
{
|
|
Console.WriteLine(e.Exception.Message);
|
|
Console.WriteLine(e.Exception.StackTrace);
|
|
using StreamWriter streamWriter = new StreamWriter($"{Directory.GetCurrentDirectory()}\\{DateTime.Now:yyMMdd}_fatal.err", append: true, Encoding.Default);
|
|
streamWriter.Write($"{DateTime.Now:HH:mm:ss:fff} : ");
|
|
streamWriter.Write(e);
|
|
streamWriter.WriteLine();
|
|
streamWriter.Close();
|
|
}
|
|
|
|
public static void ErrWrite(Exception e)
|
|
{
|
|
string text = e.ToString();
|
|
string path = $"{log_file}.err";
|
|
File.AppendAllText(path, $"{DateTime.Now:HH:mm:ss.fffffff}:{text}/n");
|
|
Console.WriteLine(text);
|
|
}
|
|
|
|
public static void ErrPrim(string pref, string suff)
|
|
{
|
|
string path = $"{log_file}.err";
|
|
StreamWriter streamWriter = new StreamWriter(path, append: true);
|
|
streamWriter.WriteLine($"{DateTime.Now:HH:mm:ss.fffffff}: +++ {pref}:{suff}");
|
|
streamWriter.Close();
|
|
}
|
|
|
|
public static void LogWrite(string prim, string str)
|
|
{
|
|
string path = $"{log_file}.log";
|
|
StreamWriter streamWriter = new StreamWriter(path, append: true);
|
|
streamWriter.WriteLine($"{DateTime.Now:HH:mm:ss.fffffff}:{prim}:{str}");
|
|
streamWriter.Close();
|
|
}
|
|
}
|