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

	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;
}
