using System;
using System.CodeDom.Compiler;
using System.Diagnostics;
using System.IO;
using System.Windows;

namespace QCLVR;

public class App : Application
{
	private void App_Startup(object sender, StartupEventArgs e)
	{
		main mainApp = new main();
		if (e.Args.Length > 1)
		{
			checkFlags(e.Args);
			Application.Current.Shutdown();
			return;
		}
		if (e.Args.Length == 1)
		{
			RunApp(mainApp, e.Args[0]);
			return;
		}
		string text = main.SelectFile();
		if (text != "")
		{
			RunApp(mainApp, text);
		}
		else
		{
			Application.Current.Shutdown();
		}
	}

	private void RunApp(main MainApp, string FilePath)
	{
		if (!MainApp.ValidateFile(FilePath))
		{
			Application.Current.Shutdown();
			return;
		}
		MainApp.setFilePath(FilePath);
		MainApp.run();
	}

	private void checkFlags(string[] Args)
	{
		bool compress = false;
		string input = string.Empty;
		foreach (string text in Args)
		{
			text.ToLower();
			switch (text)
			{
			case "-c":
				compress = true;
				break;
			case "-d":
				compress = false;
				break;
			}
			if (Directory.Exists(text) || File.Exists(text))
			{
				input = text;
			}
		}
		Compression.transform(input, compress);
	}

	[DebuggerNonUserCode]
	[GeneratedCode("PresentationBuildTasks", "4.0.0.0")]
	public void InitializeComponent()
	{
		base.Startup += App_Startup;
	}

	[STAThread]
	[DebuggerNonUserCode]
	[GeneratedCode("PresentationBuildTasks", "4.0.0.0")]
	public static void Main()
	{
		App app = new App();
		app.InitializeComponent();
		app.Run();
	}
}
