// Decompiled with JetBrains decompiler
// Type: FiestaLauncher.gFiestaLauncher
// Assembly: FiestaOnline, Version=2019.5.22.0, Culture=neutral, PublicKeyToken=null
// MVID: 2FD5EB61-BC25-469D-997E-88998E849F6A
// Assembly location: C:\Users\marbo\Documents\Gamigo 2020 Client\FiestaOnline.exe

using FiestaLauncher.Services;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Threading;
using System.Windows.Forms;

namespace FiestaLauncher
{
  internal static class gFiestaLauncher
  {
    internal static string VERSION_DATE = Assembly.GetExecutingAssembly().GetName().Version.ToString();
    internal static string XMLURL = "https://fiestalauncher.gamigo.com/" + "us" + "/FiestaLauncher.xml";
    internal static string XMLURLBACKUP = "https://assets.cdn.gamigo.com/folauncher/live/" + "us" + "/FiestaLauncher.xml";
    internal static string LauncherVersion = gFiestaLauncher.VERSION_DATE + "us".ToUpper();
    internal static Dictionary<string, string> Static_FlashOK = new Dictionary<string, string>()
    {
      {
        "us",
        "Please restart the Fiesta Launcher if it does not restart automatically."
      },
      {
        "en",
        "Please restart the Fiesta Launcher if it does not restart automatically."
      },
      {
        "test",
        "Please restart the Fiesta Launcher if it does not restart automatically."
      },
      {
        "de",
        "Bitte starte den Fiesta Launcher neu, wenn dieser sich nicht automatisch neustartet."
      },
      {
        "it",
        "Riavvia il Launcher di Fiesta se non si riavvia automaticamente"
      },
      {
        "es",
        "Por favor reinicia el launcher de Fiesta si no se reinicia automáticamente"
      },
      {
        "fr",
        "Veuillez redémarrer le launcher de Fiesta si ce dernier ne démarre pas automatiquement."
      }
    };
    internal static Dictionary<string, string> Static_CDNError = new Dictionary<string, string>()
    {
      {
        "us",
        "Unable to connect to patch server. Would you like to try and run Fiesta anyway?"
      },
      {
        "en",
        "Unable to connect to patch server. Would you like to try and run Fiesta anyway?"
      },
      {
        "test",
        "Unable to connect to patch server. Would you like to try and run Fiesta anyway?"
      },
      {
        "de",
        "Verbindung zum Patchserver fehlgeschlagen. Möchtest du versuchen, Fiesta trotzdem zu starten?"
      },
      {
        "it",
        "Impossibile collegarsi al Server di Patch. Vuoi far partire Fiesta comunque?"
      },
      {
        "es",
        "No se ha podido conectar al parche del servidor. ¿Quieres intentarlo y ejecutar Fiesta de todas formas?"
      },
      {
        "fr",
        "Impossible de se connecter au serveur de patch. Voulez-vous quand même lancer Fiesta ?"
      }
    };
    internal static Dictionary<string, string> Static_MaintError = new Dictionary<string, string>()
    {
      {
        "us",
        "Server is currently in maintenance."
      },
      {
        "en",
        "Server is currently in maintenance."
      },
      {
        "test",
        "Server is currently in maintenance."
      },
      {
        "de",
        "Die Server werden derzeit gewartet."
      },
      {
        "it",
        "Server in manutenzione."
      },
      {
        "es",
        "Servidor en mantenimiento"
      },
      {
        "fr",
        "Serveur en maintenance"
      }
    };
    internal static Dictionary<string, string> Static_MCError = new Dictionary<string, string>()
    {
      {
        "us",
        "You can only run up to 3 clients at one time."
      },
      {
        "en",
        "You can only run up to 3 clients at one time."
      },
      {
        "test",
        "You can only run up to 3 clients at one time."
      },
      {
        "de",
        "Du kannst höchstens 3 Clients gleichzeitig offen haben."
      },
      {
        "it",
        "Puoi avviare solo tre Client contemporaneamente."
      },
      {
        "es",
        "Puedes ejecutar solo 3 cilentes a la vez."
      },
      {
        "fr",
        "Vous ne pouvez lancer que 3 clients en même temps"
      }
    };
    internal static SettingsService Settings = new SettingsService();
    internal static string CURRENT_PATCH = "";
    internal static string FUTURE_PATCH = "";
    internal static string ADDED_BIN_ARGS = "";
    public static string FirstPatch = "";
    internal const string VERSION_KEY = "us";
    internal static ushort SUBVERSION;
    internal static ushort YEAR;
    internal static ushort PATCHNO;
    internal static ushort VERSION;
    internal static ulong VERSIONHASH;
    internal static string CDNError;
    internal static string MaintError;
    internal static string MCError;
    internal static FiestaLauncher.Main MainWindow;
    internal static Splash SplashWindow;

    [STAThread]
    private static void Main(string[] args)
    {
      AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(gFiestaLauncher.onCrash);
      Application.ThreadException += new ThreadExceptionEventHandler(gFiestaLauncher.OnCrash);
      try
      {
        if (Process.GetProcessesByName("Fiesta.bin").Length <= 2)
        {
          gFiestaLauncher.INIT(args);
        }
        else
        {
          gFiestaLauncher.MCError = gFiestaLauncher.Static_MCError["us"];
          FeedbackService.PopError(gFiestaLauncher.MCError, true);
          Environment.Exit(0);
        }
      }
      catch (Exception ex)
      {
        gFiestaLauncher.onCrash(ex);
      }
    }

    internal static Form GetMain()
    {
      return (Form) gFiestaLauncher.MainWindow;
    }

    private static void INIT(string[] args)
    {
      gFiestaLauncher.CDNError = gFiestaLauncher.Static_CDNError["us"];
      gFiestaLauncher.MaintError = gFiestaLauncher.Static_MaintError["us"];
      try
      {
        string path = "XMLOverride.xml";
        if (File.Exists(path))
          gFiestaLauncher.XMLURL = path;
        if (File.Exists("XMLOverride.txt"))
          gFiestaLauncher.XMLURL = File.ReadAllText("XMLOverride.txt");
        if ((uint) args.Length > 0U)
        {
          gFiestaLauncher.ADDED_BIN_ARGS = " " + string.Join(" ", args);
          if (gFiestaLauncher.ADDED_BIN_ARGS.ToLower().Contains("-steam_login"))
            gFiestaLauncher.ADDED_BIN_ARGS = gFiestaLauncher.ADDED_BIN_ARGS.Replace("-steam_login", "-k -steam_login");
        }
      }
      catch (Exception ex)
      {
        gFiestaLauncher.onCrash(ex);
      }
      VersionService.VersionControl("Fiesta.vdt", (byte) 0);
      Application.EnableVisualStyles();
      Application.SetCompatibleTextRenderingDefault(false);
      gFiestaLauncher.MainWindow = new FiestaLauncher.Main();
      gFiestaLauncher.SplashWindow = new Splash();
      Application.Run((Form) gFiestaLauncher.SplashWindow);
    }

    internal static void onCrash(Exception ee)
    {
      FeedbackService.Exception(ee);
      Environment.Exit(911);
    }

    private static void onCrash(object sender, UnhandledExceptionEventArgs e)
    {
      FeedbackService.Exception((Exception) e.ExceptionObject);
      Environment.Exit(911);
    }

    private static void OnCrash(object sender, ThreadExceptionEventArgs e)
    {
      FeedbackService.Exception(e.Exception);
      Environment.Exit(911);
    }
  }
}
