using System;
using System.Collections.Generic;
using System.Configuration;
using System.IO;
using System.Net;
using System.Windows.Forms;
using Gsome.Properties;

internal static class program
{
	public static WebProxy proxy = null;

	public static List<Account> Accounts = null;

	public static List<byte[]> VideoData;

	public static List<string> VideoNames;

	public static List<byte[]> AudioData;

	public static List<byte[]> PhotoData;

	public static string lib_path;

	public static bool Changed = false;

	[STAThread]
	private static void Main()
	{
		Application.EnableVisualStyles();
		StreamReader streamReader = null;
		try
		{
			Accounts = new List<Account>();
			streamReader = new StreamReader("accounts.txt");
			do
			{
				string text = streamReader.ReadLine().Trim();
				string[] array = text.Split(new char[1] { ':' }, StringSplitOptions.RemoveEmptyEntries);
				Accounts.Add(new Account
				{
					EMail = array[0].Trim(),
					Pass = array[1].Trim()
				});
			}
			while (!streamReader.EndOfStream);
		}
		catch
		{
			MessageBox.Show("Ошибка чтения списка аккаунтов!", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Hand);
			return;
		}
		finally
		{
			if (streamReader != null)
			{
				streamReader.Close();
				streamReader.Dispose();
			}
		}
		AppSettingsReader appSettingsReader = new AppSettingsReader();
		try
		{
			string text2 = appSettingsReader.GetValue("proxy", typeof(string)) as string;
			if (text2.Length > 0)
			{
				proxy = new WebProxy(text2);
			}
		}
		catch
		{
			MessageBox.Show("Неверный прокси сервер!", "Ошибка конфигурации", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
		}
		bool flag = false;
		try
		{
			lib_path = appSettingsReader.GetValue("library", typeof(string)) as string;
		}
		catch
		{
		}
		if (!File.Exists(lib_path))
		{
			MessageBox.Show("Ошибка загрузки словаря!", "Ошибка конфигурации", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
			return;
		}
		bool flag2 = false;
		PhotoData = new List<byte[]>();
		string[] array2 = new string[4] { "jpg", "jpeg", "png", "gif" };
		if (Directory.Exists("photo"))
		{
			string[] files = Directory.GetFiles("photo");
			for (int i = 0; i < files.Length; i++)
			{
				string path2 = files[i].ToLower();
				if (Array.Find(array2, (string s) => path2.EndsWith(s)) != null)
				{
					PhotoData.Add(File.ReadAllBytes(path2));
				}
			}
			flag2 = PhotoData.Count != 0;
		}
		else
		{
			Directory.CreateDirectory("photo");
			flag2 = false;
		}
		if (!flag2)
		{
			MessageBox.Show("Папка 'photo' не содеожит фотографий!", "Ошибка фото", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
		}
		bool flag3 = false;
		AudioData = new List<byte[]>();
		if (Directory.Exists("audio"))
		{
			string[] files2 = Directory.GetFiles("audio");
			for (int j = 0; j < files2.Length; j++)
			{
				string text3 = files2[j].ToLower();
				if (text3.EndsWith("mp3"))
				{
					AudioData.Add(File.ReadAllBytes(text3));
				}
			}
			flag3 = AudioData.Count != 0;
		}
		else
		{
			Directory.CreateDirectory("audio");
			flag3 = false;
		}
		if (!flag3)
		{
			MessageBox.Show("Папка 'audio' не содеожит mp3 файлов!", "Ошибка аудио", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
		}
		bool flag4 = false;
		VideoData = new List<byte[]>();
		VideoNames = new List<string>();
		string[] array3 = new string[8] { "wmv", "flv", "mp4", "avi", "mpeg", "mpg", "mov", "3gp" };
		if (Directory.Exists("video"))
		{
			string[] files3 = Directory.GetFiles("video");
			for (int k = 0; k < files3.Length; k++)
			{
				string path = files3[k].ToLower();
				if (Array.Find(array3, (string s) => path.EndsWith(s)) != null)
				{
					VideoData.Add(File.ReadAllBytes(path));
					VideoNames.Add(new FileInfo(path).Name);
				}
			}
			flag4 = VideoData.Count != 0;
		}
		else
		{
			Directory.CreateDirectory("video");
			flag4 = false;
		}
		if (!flag4)
		{
			MessageBox.Show("Папка 'video' не содеожит видеофайлов!", "Ошибка видео", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
		}
		Application.Run(new MainForm());
		if (Changed)
		{
			StreamWriter streamWriter = new StreamWriter("accounts.txt");
			foreach (Account account in Accounts)
			{
				streamWriter.WriteLine(account.ToString());
			}
			streamWriter.Close();
			streamWriter.Dispose();
		}
		Settings.Default.Save();
	}
}
