// Decompiled with JetBrains decompiler
// Type: FiestaLauncher.Services.WebFrameService
// 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.gClasses;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Windows.Forms;

namespace FiestaLauncher.Services
{
  public static class WebFrameService
  {
    internal static List<WebFrame> CurrentFrames = new List<WebFrame>();

    private static void Browser_DocumentCompleted(
      object sender,
      WebBrowserDocumentCompletedEventArgs e)
    {
      ((Control) sender).Visible = true;
      ((Control) sender).BringToFront();
    }

    private static void Browser_Navigating(object sender, WebBrowserNavigatingEventArgs e)
    {
      Cursor.Current = Cursors.Default;
      e.Cancel = true;
      FeedbackService.OpenBrowser(e.Url.ToString());
    }

    private static void Browser_NewWindow(object sender, CancelEventArgs e)
    {
      WebBrowser webBrowser = sender as WebBrowser;
      e.Cancel = true;
      if (!((!webBrowser.Url.ToString().ToLower().Contains("youtube.com") ? webBrowser.Document.GetElementById("FiestaLauncher_POPURL").GetAttribute("value") : webBrowser.Url.ToString()) != ""))
        return;
      FeedbackService.OpenBrowser(((WebBrowser) sender).Url.ToString());
    }

    public static void PageChange(int page)
    {
      foreach (WebFrame currentFrame in WebFrameService.CurrentFrames)
      {
        currentFrame.browser.Visible = false;
        currentFrame.browser.Parent = (Control) null;
        currentFrame.browser.Dispose();
      }
      if (!gFiestaLauncher.Settings.WebFrames.ContainsKey(page))
        return;
      WebFrameService.CoInternetSetFeatureEnabled(21, 2, true);
      foreach (WebFrame webFrame1 in gFiestaLauncher.Settings.WebFrames[page])
      {
        WebFrame webFrame2 = webFrame1;
        WebBrowser webBrowser = new WebBrowser();
        webBrowser.Visible = false;
        webBrowser.ScrollBarsEnabled = false;
        webBrowser.IsWebBrowserContextMenuEnabled = false;
        webBrowser.ScriptErrorsSuppressed = true;
        webBrowser.Size = new Size(webFrame1.W, webFrame1.H);
        webBrowser.Location = new Point(webFrame1.X, webFrame1.Y);
        webFrame2.browser = webBrowser;
        webFrame1.browser.Navigate(webFrame1.Src);
        webFrame1.browser.Parent = (Control) gFiestaLauncher.GetMain();
        webFrame1.browser.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(WebFrameService.Browser_DocumentCompleted);
        webFrame1.browser.NewWindow += new CancelEventHandler(WebFrameService.Browser_NewWindow);
        webFrame1.browser.Navigating += new WebBrowserNavigatingEventHandler(WebFrameService.Browser_Navigating);
      }
    }

    [DllImport("urlmon.dll")]
    private static extern int CoInternetSetFeatureEnabled(
      int featureEntry,
      int dwFlags,
      bool fEnable);
  }
}
