using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Text;
using System.Threading;
using System.Windows.Forms;
using Gsome.Properties;
using Pepyaka;
using VKontakte;

internal partial class MainForm : Form
{
	public MainForm()
	{
		this.InitializeComponent();
		this.tray.Icon = base.Icon;
		this.tray.BalloonTipTitle = this.Text;
		this.tlpInitialization.Show();
		this.tlpAttack.Hide();
		MainForm.gen = new Gsom(program.lib_path, Encoding.Default);
		for (int i = 0; i < program.Accounts.Count; i++)
		{
			this.cmbClientAccount.Items.Add(program.Accounts[i]);
		}
		this.cmbClientAccount.SelectedIndex = 0;
		this.RefreshTrayText();
		this.chkDoWall.Checked = Settings.Default.Wall_Enabled;
		this.nudWall_TimeInterval.Value = Settings.Default.Wall_Interval;
		this.nudWall_MsgLen.Value = Settings.Default.Wall_MessLen;
		this.chkWall_AddLineBreaks.Checked = Settings.Default.Wall_LineBreaks;
		this.chkWall_RandomCase.Checked = Settings.Default.Wall_RandomCase;
		this.chkWall_AddASCII_Img.Checked = Settings.Default.Wall_AsciiImg;
		this.chkWall_AddGraffiti.Checked = Settings.Default.Wall_Graffiti;
		this.chkDoTopics.Checked = Settings.Default.Topics_Enabled;
		this.nudTopics_TimeInterval.Value = Settings.Default.Topics_Interval;
		this.nudTopics_SubjLen.Value = Settings.Default.Topics_SubjLen;
		this.nudTopics_TitleLen.Value = Settings.Default.Topics_NameLen;
		this.chkTopics_AddASCII_Img.Checked = Settings.Default.Topics_AsciiImg;
		this.chkTopics_AddLineBreaks.Checked = Settings.Default.Topics_LineBreaks;
		this.chkTopics_RandomCase.Checked = Settings.Default.Topics_RandomCase;
		this.chkDoAlbums.Checked = Settings.Default.Albums_Enabled;
		this.nudAlbums_CreationTimeInterval.Value = Settings.Default.Albums_CreationInterval;
		this.nudAlbums_PhotoTimeInterval.Value = Settings.Default.Albums_PhotoInterval;
		this.chkAlbums_AddASCII_Img.Checked = Settings.Default.Albums_AsciiImg;
		this.chkAlbums_AddLineBreaks.Checked = Settings.Default.Albums_LineBreaks;
		this.chkAlbums_AttackTodayCreated.Checked = Settings.Default.Albums_AttackTodayCreated;
		this.chkAlbums_RandomCase.Checked = Settings.Default.Albums_RandomCase;
		this.chkDoAudio.Checked = Settings.Default.Audio_Enabled;
		this.nudAudio_TimeInterval.Value = Settings.Default.Audio_Interval;
		this.chkDoVideo.Checked = Settings.Default.Video_Enabled;
		this.chkVideo_NotAjax.Checked = Settings.Default.Video_NotAjax;
		this.nudVideo_TimeInterval.Value = Settings.Default.Video_Interval;
		this.nudVideo_NameLen.Value = Settings.Default.Video_NameLen;
		this.nudVideo_DescLen.Value = Settings.Default.Video_DescLen;
	}

	private void rbtnAim_Person_CheckedChanged(object sender, EventArgs e)
	{
		this.txtPersonID.Enabled = this.rbtnAim_Person.Checked;
	}

	private void rbtnAim_Group_CheckedChanged(object sender, EventArgs e)
	{
		this.txtGroupID.Enabled = this.rbtnAim_Group.Checked;
	}

	private void btnAccept_Click(object sender, EventArgs e)
	{
		this.rtxtLog.Clear();
		string text;
		if (this.rbtnAim_Group.Checked)
		{
			text = this.txtGroupID.Text;
		}
		else
		{
			text = this.txtPersonID.Text;
		}
		int num;
		if (!int.TryParse(text, out num))
		{
			MessageBox.Show("ID введен неверно!", "Ошибка ввода", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
			return;
		}
		this.AimID = num * (this.rbtnAim_Group.Checked ? -1 : 1);
		int selectedIndex = this.cmbClientAccount.SelectedIndex;
		Account account = program.Accounts[selectedIndex];
		bool flag = false;
		try
		{
			this.client = new VKClient(account.EMail, account.Pass, program.proxy);
			flag = true;
		}
		catch (AuthorizationFailed)
		{
			flag = false;
		}
		if (!flag)
		{
			if (MessageBox.Show("Авторизация провалена!\nАккаунт " + account.ToString() + " не действителен.\nУдалить из списка?", "Ошибка авторизации", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == DialogResult.Yes)
			{
				program.Accounts.RemoveAt(selectedIndex);
				this.cmbClientAccount.Items.RemoveAt(selectedIndex);
				program.Changed = true;
				if (program.Accounts.Count > 0)
				{
					this.cmbClientAccount.SelectedIndex = 0;
					return;
				}
				MessageBox.Show("Список аккаунтов пуст!\nПриложение будет закрыто.", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
				base.Close();
			}
			return;
		}
		this.LogWrite("Авторизация выполнена", Color.DarkGreen, new object[0]);
		string text2;
		if (this.AimID > 0)
		{
			text2 = this.client.GetPersonName(this.AimID);
		}
		else
		{
			text2 = this.client.GetGroupName(this.AimID);
		}
		this.AimName = text2;
		if (text2 != null)
		{
			this.LogWrite("Цель: {0}", Color.Black, new object[]
			{
				text2
			});
			this.ClientName = this.client.GetPersonName(this.client.MyID);
			this.LogWrite("Воен: {0}", Color.Black, new object[]
			{
				this.ClientName
			});
			if (this.AimID < 0)
			{
				this.in_group = this.client.EnterGroup(this.AimID);
				if (this.in_group)
				{
					this.LogWrite("Вход в группу выполен", Color.DarkGreen, new object[0]);
				}
			}
			this.video_info = new List<VideoInfo>();
			this.audio_curls = null;
			this.albums = null;
			this.wall_m_count = 0;
			this.topics_count = 0;
			this.video_count = 0;
			this.audio_count = 0;
			this.albums_count = 0;
			this.log_lines_count = 0;
			this.tlpInitialization.Hide();
			this.tlpAttack.Show();
			return;
		}
		MessageBox.Show(string.Concat(new object[]
		{
			(this.AimID < 0) ? "Группа" : "Щачло",
			" c ID=",
			Math.Abs(this.AimID),
			" не существует!"
		}), "Ошибка ввода", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
	}

	private void btnInitialize_Click(object sender, EventArgs e)
	{
		this.btnStop_Click(null, null);
		this.lblWallStatus.Text = "    -";
		this.lblVideoStatus.Text = "    -";
		this.lblAlbumsStatus.Text = "    -";
		this.lblAudioStatus.Text = "    -";
		this.lblTopicsStatus.Text = "    -";
		this.AimName = null;
		this.ClientName = null;
		this.RefreshTrayText();
		this.tlpAttack.Hide();
		this.tlpInitialization.Show();
	}

	private void btnGsom_Click(object sender, EventArgs e)
	{
		this.btnGsom.Enabled = false;
		this.nudVideo_NameLen.Enabled = false;
		this.nudVideo_DescLen.Enabled = false;
		this.thr_wall = new Thread(new ThreadStart(this.AttackWall))
		{
			Name = "wall",
			IsBackground = true
		};
		this.thr_wall.Start();
		this.thr_topics = new Thread(new ThreadStart(this.AttackTopics))
		{
			Name = "topics",
			IsBackground = true
		};
		this.thr_topics.Start();
		this.thr_albums = new Thread(new ThreadStart(this.AttackAlbums))
		{
			Name = "albums",
			IsBackground = true
		};
		this.thr_albums.Start();
		this.thr_audio = new Thread(new ThreadStart(this.AttackAudio))
		{
			Name = "audio",
			IsBackground = true
		};
		this.thr_audio.Start();
		this.thr_video = new Thread(new ThreadStart(this.AttackVideo))
		{
			Name = "video",
			IsBackground = true
		};
		this.thr_video.Start();
		this.tmrScan.Start();
		this.btnStop.Enabled = true;
		this.LogWrite("GSOM!", Color.Green, new object[0]);
	}

	private void btnStop_Click(object sender, EventArgs e)
	{
		this.btnStop.Enabled = false;
		Thread[] array = new Thread[]
		{
			this.thr_wall,
			this.thr_topics,
			this.thr_albums,
			this.thr_audio,
			this.thr_video
		};
		foreach (Thread thread in array)
		{
			if (thread != null)
			{
				thread.Abort();
				thread.Join();
			}
		}
		this.tmrScan.Stop();
		this.nudVideo_NameLen.Enabled = true;
		this.nudVideo_DescLen.Enabled = true;
		this.btnGsom.Enabled = true;
		this.LogWrite("Остановлено пользователем", Color.Green, new object[0]);
	}

	private void tmrScan_Tick(object sender, EventArgs e)
	{
		while (this.log.Count > 0)
		{
			MainForm.LogEntity logEntity = this.log.Dequeue();
			this.LogWrite(logEntity.message, logEntity.color, new object[0]);
		}
		if (!this.chkDoWall.Checked || this.thr_wall == null || !this.thr_wall.IsAlive)
		{
			this.lblWallStatus.Text = "    -";
		}
		else
		{
			this.lblWallStatus.Text = this.wall_m_count.ToString().PadLeft(5);
		}
		if (!this.chkDoTopics.Checked || this.thr_topics == null || !this.thr_topics.IsAlive)
		{
			this.lblTopicsStatus.Text = "    -";
		}
		else
		{
			this.lblTopicsStatus.Text = this.topics_count.ToString().PadLeft(5);
		}
		if (!this.chkDoAlbums.Checked || this.thr_albums == null || !this.thr_albums.IsAlive)
		{
			this.lblAlbumsStatus.Text = "    -";
		}
		else
		{
			this.lblAlbumsStatus.Text = this.albums_count.ToString().PadLeft(5);
		}
		if (!this.chkDoAudio.Checked || this.thr_audio == null || !this.thr_audio.IsAlive)
		{
			this.lblAudioStatus.Text = "    -";
		}
		else
		{
			this.lblAudioStatus.Text = this.audio_count.ToString().PadLeft(5);
		}
		if (!this.chkDoVideo.Checked || this.thr_video == null || !this.thr_video.IsAlive)
		{
			this.lblVideoStatus.Text = "    -";
		}
		else
		{
			this.lblVideoStatus.Text = this.video_count.ToString().PadLeft(5);
		}
		this.RefreshTrayText();
	}

	private void AttackWall()
	{
		int num = 0;
		for (;;)
		{
			if (this.chkDoWall.Checked)
			{
				GsomFormats gsomFormats = GsomFormats.Default;
				if (this.chkWall_AddASCII_Img.Checked)
				{
					gsomFormats |= GsomFormats.UseMultiLineMessages;
				}
				if (this.chkWall_AddLineBreaks.Checked)
				{
					gsomFormats |= GsomFormats.InsertExtraLines;
				}
				if (this.chkWall_RandomCase.Checked)
				{
					gsomFormats |= GsomFormats.RandomCase;
				}
				Thread.Sleep((int)this.nudWall_TimeInterval.Value);
				bool flag = false;
				try
				{
					if (this.chkWall_AddGraffiti.Checked && program.PhotoData.Count > 0 && MainForm.rnd.Next(0, 2) == 1)
					{
						flag = this.client.SendGraffitiToWall(this.AimID, program.PhotoData[MainForm.rnd.Next(0, program.PhotoData.Count)]);
					}
					else
					{
						flag = this.client.WriteToWall(this.AimID, MainForm.gen.Generate((int)this.nudWall_MsgLen.Value, gsomFormats));
					}
				}
				catch (NotAvailableException)
				{
					num = 5;
				}
				catch
				{
					flag = false;
				}
				if (flag)
				{
					this.wall_m_count++;
					num = 0;
				}
				else
				{
					num++;
				}
				if (num >= 5)
				{
					num = 0;
					this.log.Enqueue(new MainForm.LogEntity
					{
						message = "Стена: приостановлено на 4 мин",
						color = Color.Maroon
					});
					Thread.Sleep(240000);
				}
			}
			else
			{
				Thread.Sleep(2000);
			}
		}
	}

	private void AttackTopics()
	{
		if (this.AimID > 0)
		{
			return;
		}
		int num = 0;
		for (;;)
		{
			if (this.chkDoTopics.Checked)
			{
				GsomFormats gsomFormats = GsomFormats.Default;
				if (this.chkTopics_AddASCII_Img.Checked)
				{
					gsomFormats |= GsomFormats.UseMultiLineMessages;
				}
				if (this.chkTopics_AddLineBreaks.Checked)
				{
					gsomFormats |= GsomFormats.InsertExtraLines;
				}
				if (this.chkTopics_RandomCase.Checked)
				{
					gsomFormats |= GsomFormats.RandomCase;
				}
				Thread.Sleep((int)this.nudTopics_TimeInterval.Value);
				int num2 = 0;
				try
				{
					num2 = this.client.AddGroupDiscussion(this.AimID, MainForm.gen.Generate((int)this.nudTopics_TitleLen.Value, gsomFormats & GsomFormats.RandomCase), MainForm.gen.Generate((int)this.nudTopics_SubjLen.Value, gsomFormats));
				}
				catch (NotAvailableException)
				{
					num = 5;
				}
				catch
				{
					num2 = 0;
				}
				if (num2 > 0)
				{
					this.topics_count++;
					num = 0;
				}
				else
				{
					num++;
				}
				if (num >= 5)
				{
					num = 0;
					this.log.Enqueue(new MainForm.LogEntity
					{
						message = "Стена: приостановлено на 4 мин",
						color = Color.Maroon
					});
					Thread.Sleep(240000);
				}
			}
			else
			{
				num = 0;
				Thread.Sleep(2000);
			}
		}
	}

	private void AttackAlbums()
	{
		if (this.AimID > 0 || program.PhotoData.Count == 0)
		{
			return;
		}
		int num = 0;
		for (;;)
		{
			if (this.chkDoAlbums.Checked)
			{
				if (this.albums != null)
				{
					break;
				}
				try
				{
					this.albums = this.client.GetGroupAlbums(this.AimID, 300);
					this.log.Enqueue(new MainForm.LogEntity
					{
						message = string.Format("Альбомы: получено {0} альбомов", this.albums.Length),
						color = Color.Black
					});
					break;
				}
				catch
				{
					this.log.Enqueue(new MainForm.LogEntity
					{
						message = "Альбомы: ошибка просмотра",
						color = Color.Maroon
					});
					this.log.Enqueue(new MainForm.LogEntity
					{
						message = "Альбомы: приостановлено на 4 мин",
						color = Color.Maroon
					});
					Thread.Sleep(240000);
					continue;
				}
			}
			Thread.Sleep(2000);
		}
		List<byte[]> list = new List<byte[]>();
		for (int i = 0; i < this.albums.Length; i++)
		{
			if (this.chkDoAlbums.Checked)
			{
				string confirm_url;
				try
				{
					if (this.albums[i].PhotosCount > 500)
					{
						goto IL_44F;
					}
					if (!this.chkAlbums_AttackTodayCreated.Checked && this.albums[i].CreationDate == DateTime.Today)
					{
						goto IL_44F;
					}
					list.Clear();
					for (int j = 0; j < 6; j++)
					{
						list.Add(program.PhotoData[MainForm.rnd.Next(0, program.PhotoData.Count)]);
					}
					confirm_url = this.client.UploadPhotoToAlbum(this.albums[i], list);
					this.log.Enqueue(new MainForm.LogEntity
					{
						message = string.Format("Альбомы: пячим '{0}'", this.albums[i].Name),
						color = Color.Black
					});
				}
				catch (BlankErrorException ex)
				{
					if (ex.Code == 21)
					{
						this.albums[i].PhotosCount = 501;
					}
					else
					{
						this.log.Enqueue(new MainForm.LogEntity
						{
							message = "Альбомы: " + ex.Message,
							color = Color.Maroon
						});
					}
					goto IL_44F;
				}
				catch
				{
					this.log.Enqueue(new MainForm.LogEntity
					{
						message = "Альбомы: ошибка загрузки в '" + this.albums[i].Name + "'",
						color = Color.Maroon
					});
					goto IL_44F;
				}
				for (;;)
				{
					if (this.chkDoAlbums.Checked)
					{
						bool flag = false;
						try
						{
							flag = this.client.AddPhotoToAlbum(confirm_url);
						}
						catch (BlankErrorException ex2)
						{
							if (ex2.Code == 21)
							{
								this.albums[i].PhotosCount = 501;
								break;
							}
							this.log.Enqueue(new MainForm.LogEntity
							{
								message = "Альбомы: " + ex2.Message,
								color = Color.Maroon
							});
						}
						catch
						{
							flag = false;
						}
						if (flag)
						{
							this.albums_count += 6;
							num = 0;
						}
						else
						{
							num++;
							this.log.Enqueue(new MainForm.LogEntity
							{
								message = "Альбомы: ошибка добавления в '" + this.albums[i].Name + "'",
								color = Color.Maroon
							});
						}
						if (num >= 5)
						{
							num = 0;
							this.log.Enqueue(new MainForm.LogEntity
							{
								message = "Альбомы: приостановлено на 4 мин",
								color = Color.Maroon
							});
							Thread.Sleep(240000);
						}
						Thread.Sleep((int)this.nudAlbums_PhotoTimeInterval.Value);
					}
					else
					{
						Thread.Sleep(2000);
					}
				}
			}
			else
			{
				Thread.Sleep(2000);
			}
			IL_44F:;
		}
		bool flag2 = false;
		for (;;)
		{
			if (this.chkDoAlbums.Checked)
			{
				if (!flag2)
				{
					this.log.Enqueue(new MainForm.LogEntity
					{
						message = "Альбомы: добавляем новые",
						color = Color.Black
					});
					flag2 = true;
				}
				Thread.Sleep((int)this.nudAlbums_CreationTimeInterval.Value);
				GsomFormats gsomFormats = GsomFormats.Default;
				if (this.chkAlbums_AddASCII_Img.Checked)
				{
					gsomFormats |= GsomFormats.UseMultiLineMessages;
				}
				if (this.chkAlbums_AddLineBreaks.Checked)
				{
					gsomFormats |= GsomFormats.InsertExtraLines;
				}
				if (this.chkAlbums_RandomCase.Checked)
				{
					gsomFormats |= GsomFormats.RandomCase;
				}
				bool flag3 = false;
				try
				{
					int num2 = this.client.AddGroupPhotoAlbum(this.AimID, MainForm.gen.Phrases[MainForm.rnd.Next(0, MainForm.gen.Phrases.Count)], MainForm.gen.Generate(1000, gsomFormats));
					if (num2 > 0)
					{
						List<byte[]> list2 = new List<byte[]>();
						list2.Add(program.PhotoData[MainForm.rnd.Next(0, program.PhotoData.Count)]);
						Thread.Sleep(2000);
						string confirm_url2 = this.client.UploadPhotoToAlbum(new AlbumInfo
						{
							ID = num2,
							OwnerID = this.AimID
						}, list2);
						flag3 = this.client.AddPhotoToAlbum(confirm_url2);
					}
				}
				catch (BlankErrorException ex3)
				{
					this.log.Enqueue(new MainForm.LogEntity
					{
						message = "Альбомы: " + ex3.Message,
						color = Color.Maroon
					});
					num = 5;
				}
				catch
				{
					this.log.Enqueue(new MainForm.LogEntity
					{
						message = "Альбомы: ошибка создания",
						color = Color.Maroon
					});
					flag3 = false;
				}
				if (flag3)
				{
					this.albums_count++;
					num = 0;
				}
				else
				{
					num++;
				}
				if (num >= 5)
				{
					num = 0;
					this.log.Enqueue(new MainForm.LogEntity
					{
						message = "Альбомы: приостановлено на 4 мин",
						color = Color.Maroon
					});
					Thread.Sleep(240000);
				}
			}
			else
			{
				Thread.Sleep(2000);
			}
		}
	}

	private void AttackAudio()
	{
		if (this.AimID > 0 || program.AudioData.Count == 0)
		{
			return;
		}
		int num = 0;
		if (this.audio_curls == null)
		{
			this.audio_curls = new List<string>();
		}
		while (this.audio_curls.Count < program.AudioData.Count)
		{
			if (this.chkDoAudio.Checked)
			{
				string text = null;
				int num2 = 0;
				try
				{
					text = this.client.UploadAudioToGroup(this.AimID, program.AudioData[this.audio_curls.Count], out num2);
				}
				catch (BlankErrorException ex)
				{
					this.log.Enqueue(new MainForm.LogEntity
					{
						message = "Аудио: " + ex.Message,
						color = Color.Maroon
					});
					num = 5;
				}
				catch
				{
					this.log.Enqueue(new MainForm.LogEntity
					{
						message = "Аудио: ошибка загрузки",
						color = Color.Maroon
					});
				}
				if (text != null)
				{
					this.audio_curls.Add(text);
				}
				else
				{
					num++;
				}
				if (num >= 5)
				{
					num = 0;
					this.log.Enqueue(new MainForm.LogEntity
					{
						message = "Аудио: приостановлено на 4 мин",
						color = Color.Maroon
					});
					Thread.Sleep(240000);
				}
				if (this.audio_curls.Count == program.AudioData.Count)
				{
					this.log.Enqueue(new MainForm.LogEntity
					{
						message = "Аудио: загружено",
						color = Color.Black
					});
				}
				Thread.Sleep(1000);
			}
			else
			{
				Thread.Sleep(2000);
			}
		}
		for (;;)
		{
			if (this.chkDoAudio.Checked)
			{
				bool flag = false;
				try
				{
					flag = this.client.AddAudioToGroup(this.audio_curls[MainForm.rnd.Next(0, this.audio_curls.Count)]);
				}
				catch
				{
					flag = false;
				}
				if (flag)
				{
					this.audio_count++;
					num = 0;
				}
				else
				{
					num++;
				}
				if (num >= 5)
				{
					num = 0;
					this.log.Enqueue(new MainForm.LogEntity
					{
						message = "Аудио: приостановлено на 4 мин",
						color = Color.Maroon
					});
					Thread.Sleep(240000);
				}
				Thread.Sleep((int)this.nudAudio_TimeInterval.Value);
			}
			else
			{
				Thread.Sleep(2000);
			}
		}
	}

	private void AttackVideo()
	{
		if (this.AimID > 0 || program.VideoData.Count == 0)
		{
			return;
		}
		int num = 0;
		for (;;)
		{
			if (this.chkDoVideo.Checked)
			{
				int num2 = this.video_count;
				if (num2 < program.VideoData.Count)
				{
					VideoInfo item = default(VideoInfo);
					try
					{
						item = this.client.UploadVideo(this.AimID, MainForm.GenerateString((int)this.nudVideo_NameLen.Value), MainForm.GenerateString((int)this.nudVideo_DescLen.Value), program.VideoData[num2]);
					}
					catch (NotAvailableException)
					{
						num = 5;
					}
					catch
					{
					}
					if (item.AddHash != null)
					{
						this.video_info.Add(item);
						this.video_count++;
						if (num2 + 1 == program.VideoData.Count)
						{
							this.log.Enqueue(new MainForm.LogEntity
							{
								message = "Видео: загружено",
								color = Color.Black
							});
						}
					}
					else
					{
						this.log.Enqueue(new MainForm.LogEntity
						{
							message = "Видео: ошибка загрузки!",
							color = Color.Maroon
						});
						num++;
					}
					Thread.Sleep(5000);
				}
				else
				{
					bool flag = false;
					int index = MainForm.rnd.Next(0, this.video_info.Count);
					try
					{
						flag = this.client.AddVideoToGroup(this.video_info[index], !this.chkVideo_NotAjax.Checked);
					}
					catch (NotAvailableException)
					{
						num = 5;
					}
					catch
					{
						flag = false;
					}
					if (flag)
					{
						this.video_count++;
						num = 0;
					}
					else
					{
						this.log.Enqueue(new MainForm.LogEntity
						{
							message = "Видео: ошибка добавления!",
							color = Color.Maroon
						});
						num++;
					}
				}
				if (num >= 5)
				{
					num = 0;
					this.log.Enqueue(new MainForm.LogEntity
					{
						message = "Видео: приостановлено на 4 мин",
						color = Color.Maroon
					});
					Thread.Sleep(240000);
				}
				Thread.Sleep((int)this.nudVideo_TimeInterval.Value);
			}
			else
			{
				Thread.Sleep(2000);
			}
		}
	}

	private void LogWrite(string message, Color color, params object[] p)
	{
		this.rtxtLog.SelectionLength = 0;
		this.rtxtLog.SelectionStart = this.rtxtLog.Text.Length;
		this.rtxtLog.SelectionColor = color;
		TextBoxBase textBoxBase = this.rtxtLog;
		int num = ++this.log_lines_count;
		textBoxBase.AppendText(string.Format(num.ToString().PadRight(3) + ": " + message + "\r\n", p));
		this.rtxtLog.ScrollToCaret();
	}

	private static string GenerateString(int capacity)
	{
		StringBuilder stringBuilder = new StringBuilder();
		for (int i = 0; i < capacity; i++)
		{
			stringBuilder.Append((char)MainForm.rnd.Next(97, 122));
		}
		return stringBuilder.ToString();
	}

	private void tray_MouseDoubleClick(object sender, MouseEventArgs e)
	{
		base.WindowState = FormWindowState.Normal;
		this.tray.Visible = false;
		base.ShowInTaskbar = true;
	}

	protected override void OnResize(EventArgs e)
	{
		if (base.WindowState == FormWindowState.Minimized)
		{
			this.RefreshTrayText();
			this.tray.Visible = true;
			base.ShowInTaskbar = false;
			this.tray.ShowBalloonTip(5000);
		}
		base.OnResize(e);
	}

	private void RefreshTrayText()
	{
		this.tray.BalloonTipText = "Двойной щелчок, чтобы восстановить";
		if (this.AimName != null)
		{
			NotifyIcon notifyIcon = this.tray;
			notifyIcon.BalloonTipText += string.Format("\r\n\r\nВоен: {0}\r\nЦель: {1}\r\n\r\nСтена: {2}\r\nОбсуждения: {3}\r\nАльбомы: {4}\r\nАудио: {5}\r\nВидео: {6}", new object[]
			{
				this.ClientName,
				this.AimName,
				this.wall_m_count,
				this.topics_count,
				this.albums_count,
				this.audio_count,
				this.video_count
			});
		}
	}

	private void tray_MouseClick(object sender, MouseEventArgs e)
	{
		this.tray.ShowBalloonTip(20000);
	}

	protected override void OnClosing(CancelEventArgs e)
	{
		Settings.Default.Wall_Enabled = this.chkDoWall.Checked;
		Settings.Default.Wall_Interval = (int)this.nudWall_TimeInterval.Value;
		Settings.Default.Wall_MessLen = (int)this.nudWall_MsgLen.Value;
		Settings.Default.Wall_LineBreaks = this.chkWall_AddLineBreaks.Checked;
		Settings.Default.Wall_RandomCase = this.chkWall_RandomCase.Checked;
		Settings.Default.Wall_AsciiImg = this.chkWall_AddASCII_Img.Checked;
		Settings.Default.Wall_Graffiti = this.chkWall_AddGraffiti.Checked;
		Settings.Default.Topics_Enabled = this.chkDoTopics.Checked;
		Settings.Default.Topics_Interval = (int)this.nudTopics_TimeInterval.Value;
		Settings.Default.Topics_SubjLen = (int)this.nudTopics_SubjLen.Value;
		Settings.Default.Topics_NameLen = (int)this.nudTopics_TitleLen.Value;
		Settings.Default.Topics_AsciiImg = this.chkTopics_AddASCII_Img.Checked;
		Settings.Default.Topics_LineBreaks = this.chkTopics_AddLineBreaks.Checked;
		Settings.Default.Topics_RandomCase = this.chkTopics_RandomCase.Checked;
		Settings.Default.Albums_Enabled = this.chkDoAlbums.Checked;
		Settings.Default.Albums_CreationInterval = (int)this.nudAlbums_CreationTimeInterval.Value;
		Settings.Default.Albums_PhotoInterval = (int)this.nudAlbums_PhotoTimeInterval.Value;
		Settings.Default.Albums_AsciiImg = this.chkAlbums_AddASCII_Img.Checked;
		Settings.Default.Albums_LineBreaks = this.chkAlbums_AddLineBreaks.Checked;
		Settings.Default.Albums_AttackTodayCreated = this.chkAlbums_AttackTodayCreated.Checked;
		Settings.Default.Albums_RandomCase = this.chkAlbums_RandomCase.Checked;
		Settings.Default.Audio_Enabled = this.chkDoAudio.Checked;
		Settings.Default.Audio_Interval = (int)this.nudAudio_TimeInterval.Value;
		Settings.Default.Video_Enabled = this.chkDoVideo.Checked;
		Settings.Default.Video_NotAjax = this.chkVideo_NotAjax.Checked;
		Settings.Default.Video_Interval = (int)this.nudVideo_TimeInterval.Value;
		Settings.Default.Video_NameLen = (int)this.nudVideo_NameLen.Value;
		Settings.Default.Video_DescLen = (int)this.nudVideo_DescLen.Value;
		base.OnClosing(e);
	}

	private void btnCopyReport_Click(object sender, EventArgs e)
	{
		string text = string.Format("Воен: {0}\r\nЦель: {1}\r\n\r\nСтена: {2}\r\nОбсуждения: {3}\r\nАльбомы: {4}\r\nАудио: {5}\r\nВидео: {6}", new object[]
		{
			this.ClientName,
			this.AimName,
			this.wall_m_count,
			this.topics_count,
			this.albums_count,
			this.audio_count,
			this.video_count
		});
		Clipboard.SetText(text, TextDataFormat.UnicodeText);
	}

	private const int ERROR_LIMIT = 5;

	private const int NOT_AVALIBLE_ATTACK_TIME_INTERVAL = 2000;

	private const int ERROR_TIME_DELAY = 240000;

	private const string STOPPED_VALUE = "    -";

	private Queue<MainForm.LogEntity> log = new Queue<MainForm.LogEntity>();

	private VKClient client;

	private static Random rnd = new Random();

	private static Gsom gen;

	private int AimID;

	private bool in_group;

	private string AimName;

	private string ClientName;

	private int wall_m_count;

	private Thread thr_wall;

	private int topics_count;

	private Thread thr_topics;

	private int albums_count;

	private Thread thr_albums;

	private AlbumInfo[] albums;

	private int audio_count;

	private Thread thr_audio;

	private List<string> audio_curls;

	private List<VideoInfo> video_info;

	private int video_count;

	private Thread thr_video;

	private int log_lines_count;

	private struct LogEntity
	{
		public override string ToString()
		{
			return this.message;
		}

		public string message;

		public Color color;
	}
}
