Files
flowframes/Code/Program.cs

98 lines
3.5 KiB
C#
Raw Normal View History

2020-11-23 16:51:05 +01:00
using Flowframes.Data;
using Flowframes.IO;
using System;
using System.Collections.Generic;
2021-05-03 12:41:11 +02:00
using System.Threading;
2020-11-23 16:51:05 +01:00
using System.Threading.Tasks;
using System.Windows.Forms;
[assembly: System.Windows.Media.DisableDpiAwareness] // Disable Dpi awareness in the application assembly.
2020-11-23 16:51:05 +01:00
namespace Flowframes
{
static class Program
{
public static Form1 mainForm;
public static bool busy = false;
public static string lastInputPath;
public static bool lastInputPathIsSsd;
2020-12-17 11:32:45 +01:00
public static Queue<InterpSettings> batchQueue = new Queue<InterpSettings>();
2020-11-23 16:51:05 +01:00
[STAThread]
static void Main()
{
Config.Init();
2020-11-27 09:45:06 +01:00
if (Config.GetBool("delLogsOnStartup"))
IOUtils.DeleteContentsOfDir(Paths.GetLogPath()); // Clear out older logs from previous session
2020-11-23 16:51:05 +01:00
Networks.Init();
Task.Run(() => Logger.Run());
2021-03-09 19:20:47 +01:00
Task.Run(() => DiskSpaceCheckLoop());
2020-11-23 16:51:05 +01:00
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
2021-05-03 12:41:11 +02:00
Application.ThreadException += new ThreadExceptionEventHandler(Application_ThreadException);
Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
2020-11-23 16:51:05 +01:00
mainForm = new Form1();
Application.Run(mainForm);
2021-03-09 19:20:47 +01:00
}
2021-05-03 12:41:11 +02:00
static void Application_ThreadException(object sender, ThreadExceptionEventArgs e)
{
string text = $"Unhandled Thread Exception!\n\n{e.Exception.Message}\n\nStack Trace:\n{e.Exception.StackTrace}\n\n" +
$"The error has been copied to the clipboard. Please inform the developer about this.";
ShowUnhandledError(text);
}
static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
Exception ex = e.ExceptionObject as Exception;
string text = $"Unhandled UI Exception!\n\n{ex.Message}\n\nStack Trace:\n{ex.StackTrace}\n\n" +
$"The error has been copied to the clipboard. Please inform the developer about this.";
ShowUnhandledError(text);
}
static void ShowUnhandledError (string text)
{
MessageBox.Show(text, "Unhandled Error");
Clipboard.SetText(text);
}
2021-03-09 19:20:47 +01:00
static async Task DiskSpaceCheckLoop ()
{
while (true)
{
if (busy)
{
try
{
if (Interpolate.current.tempFolder.Length < 3)
return;
string drivePath = Interpolate.current.tempFolder.Substring(0, 2);
long mb = IOUtils.GetDiskSpace(Interpolate.current.tempFolder);
2021-03-09 19:20:47 +01:00
Logger.Log($"Disk space check for '{drivePath}/': {(mb / 1024f).ToString("0.0")} GB free.", true);
2021-03-09 19:20:47 +01:00
if (!Interpolate.canceled && mb < (Config.GetInt("minDiskSpaceGb", 5) * 1024))
Interpolate.Cancel("Running out of disk space!");
}
catch
{
// Disk space check failed, this is not critical and might just be caused by a null ref
}
2021-03-09 19:20:47 +01:00
}
2020-11-23 16:51:05 +01:00
2021-03-09 19:20:47 +01:00
await Task.Delay(15000);
}
2020-11-23 16:51:05 +01:00
}
}
}