JD2022-TU1/main/tools/legacy/CrashDumpSender/Program.cs

102 lines
3.3 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.Diagnostics;
using System.Net.NetworkInformation;
namespace CrashDumpSender
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
try
{
//Debugger.Break();
if (!IsOnUbiNetwork())
Application.Exit();
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
CrashDumpSenderForm crashdump = new CrashDumpSenderForm();
DialogResult res = DialogResult.Yes;
while (res == DialogResult.Yes)
{
if (!crashdump.checkProcessRunning())
{
res = MessageBox.Show("An other CrashdumpSender application is running,please close the previous one,retry:yes", "Fatal Error", MessageBoxButtons.YesNo);
}
else
{
break;
}
}
if (crashdump.checkProcessRunning())
{
if (crashdump.init(args))
{
Application.Run(crashdump);
}
else
{
Application.Exit();
}
}
else
{
//exit the application
MessageBox.Show("An other CrashdumpSender application is running", "Fatal Error");
Application.Exit();
}
}
catch (System.Exception ex)
{
string message = String.Format("Crashdumpsender encountered an issue\nError : {0}\nDetails : {1}", ex.Message, ex.StackTrace);
MessageBox.Show(message, "CrashDumpSender error");
DateTime dt = DateTime.Now;
System.IO.File.WriteAllText(
string.Format("CrashdumpsenderError_{0}_{1}_{2}__{3}_{4}_{5}.txt",
dt.Year,
dt.Month,
dt.Day,
dt.Hour,
dt.Minute,
dt.Second
),
message);
}
}
static private bool IsOnUbiNetwork()
{
NetworkInterface[] NetInfo =
NetworkInterface.GetAllNetworkInterfaces();
foreach (NetworkInterface info in NetInfo)
{
if (info.OperationalStatus == OperationalStatus.Up)
{
IPInterfaceProperties prop = info.GetIPProperties();
if (!string.IsNullOrEmpty(prop.DnsSuffix))
{
if (prop.DnsSuffix.ToLower().Contains("ubisoft.org"))
{
return true;
}
}
}
}
return false;
}
}
}