using System;
using System.IO;
using System.Net;
using System.Collections.Generic;

namespace Fiesta_Client.API
{
    class Web
    {
        public static Dictionary<String, String> Settings()
        {
            Dictionary<String, String> SettingDictionary = new Dictionary<String, String>();

            WebClient SettingClient = new WebClient();

            StreamReader SettingReader = new StreamReader(SettingClient.OpenRead(Properties.Settings.Default.Config_URL));

            String CurrentSetting;

            while ((CurrentSetting = SettingReader.ReadLine()) != null)
            {
                String[] SettingSplit = CurrentSetting.Split(' ');

                SettingDictionary.Add(SettingSplit[0], SettingSplit[1]);
            }

            return SettingDictionary;
        }

        public static Int32 ServerVersion()
        {
            WebClient Client = new WebClient();

            return Convert.ToInt32(Client.DownloadString(Settings()["Patches-Version"]));
        }

        public static String[] ClientFiles()
        {
            WebClient Client = new WebClient();

            List<String> ClientList = new List<String>();

            StreamReader FileReader = new StreamReader(Client.OpenRead(Settings()["Client-Files"]));

            String CurrentFile;

            while ((CurrentFile = FileReader.ReadLine()) != null) { ClientList.Add(CurrentFile); }

            if (FileReader != null) { FileReader.Close(); }

            return ClientList.ToArray();
        }

        public static Int32 LauncherVersion()
        {
            WebClient Client = new WebClient();

            return Convert.ToInt32(Client.DownloadString(Settings()["Launcher-Version"]));
        }
    }
}
