// Decompiled with JetBrains decompiler
// Type: FiestaLauncher.LauncherUpdater
// 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 System;
using System.Diagnostics;
using System.IO;
using System.Net;
using System.Threading;

namespace FiestaLauncher
{
  public class LauncherUpdater
  {
    private readonly string _downloader;
    private readonly string _launcher;
    private readonly bool _emergency;

    public LauncherUpdater(string downloader, string newlauncher)
    {
      this._downloader = downloader;
      this._launcher = newlauncher;
      this.StartUpdate();
    }

    public LauncherUpdater(bool e, string url)
    {
      this._emergency = true;
      this._downloader = url;
      this.StartUpdate();
    }

    private void StartUpdate()
    {
      if (this._emergency)
        new Thread((ThreadStart) (() => this.StartEmergency(this._downloader))).Start();
      else
        new Thread((ThreadStart) (() => this.StartUpdate(this._downloader, this._launcher))).Start();
    }

    private void StartEmergency(string downloader)
    {
      WebClient webClient = new WebClient();
      string str = Directory.GetCurrentDirectory() + "\\FiestaOnline_LP.exe";
      if (!Directory.Exists(Path.GetDirectoryName(str)))
        Directory.CreateDirectory(Path.GetDirectoryName(str));
      webClient.DownloadFile(downloader, str);
      Process.Start(new ProcessStartInfo()
      {
        FileName = str,
        WorkingDirectory = Directory.GetCurrentDirectory()
      });
      Environment.Exit(0);
    }

    private void StartUpdate(string Downloader, string Launcher)
    {
      WebClient webClient = new WebClient();
      string str = Directory.GetCurrentDirectory() + "\\FiestaOnlineLauncherUpdater.exe";
      if (!Directory.Exists(Path.GetDirectoryName(str)))
        Directory.CreateDirectory(Path.GetDirectoryName(str));
      webClient.DownloadFile(Downloader, str);
      Process.Start(new ProcessStartInfo()
      {
        FileName = str,
        WorkingDirectory = Directory.GetCurrentDirectory(),
        Arguments = "-patchhive " + gFiestaLauncher.Settings["PatchHive"]
      });
      Environment.Exit(0);
    }
  }
}
