// Decompiled with JetBrains decompiler
// Type: AutoKMS.AutoKMSService
// Assembly: AutoKMS, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: D1CED9E3-1FC7-49B8-B3AC-44976AB7F6E4
// Assembly location: C:\Users\Administrateur\Downloads\Virusshare-00000-msil\HackTool.Win32.KMSAuto.i-f317ba4d4051fad64a0aa45b587fa3dcea795bac30acec2872779abe31a07cbe.exe

using Office_2010_Toolkit;
using Office_2010_Toolkit.Configuration;
using Office_2010_Toolkit.Logic;
using System;
using System.ComponentModel;
using System.ServiceProcess;

namespace AutoKMS
{
  internal class AutoKMSService : ServiceBase
  {
    private IContainer components;
    private BackgroundWorker workerStart;
    public static bool WindowsKMSSet = true;
    public static bool OfficeKMSSet = true;

    protected override void Dispose(bool disposing)
    {
      if (disposing && this.components != null)
        this.components.Dispose();
      base.Dispose(disposing);
    }

    private void InitializeComponent()
    {
      this.workerStart = new BackgroundWorker();
      this.workerStart.DoWork += new DoWorkEventHandler(this.workerStart_DoWork);
      this.workerStart.RunWorkerCompleted += new RunWorkerCompletedEventHandler(this.workerStart_RunWorkerCompleted);
      this.ServiceName = "AutoKMS";
    }

    public AutoKMSService() => this.InitializeComponent();

    protected override void OnStart(string[] args) => this.workerStart.RunWorkerAsync();

    protected override void OnStop()
    {
      if (AutoKMSService.OfficeKMSSet)
        Activation.RemoveKMSHost();
      if (AutoKMSService.WindowsKMSSet)
        Activation.RemoveKMSHostWindows();
      Activation.StopKMSEmulator();
    }

    private void workerStart_DoWork(object sender, DoWorkEventArgs e)
    {
      try
      {
        Activation.SetKMSHost();
      }
      catch (Exception ex)
      {
        AutoKMSService.OfficeKMSSet = false;
      }
      try
      {
        Activation.SetKMSHostWindows();
      }
      catch (Exception ex)
      {
        AutoKMSService.WindowsKMSSet = false;
      }
      Activation.StartKMSEmulator();
      if (!Common.isValidPID(Settings.AutoKMSSettings.KMSPID))
        return;
      KMSEditor.WritePIDToMemory(Settings.AutoKMSSettings.KMSPID);
    }

    private void workerStart_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
    {
    }
  }
}
