Exemple #1
0
 private void ButtonLogin_Click(object sender, EventArgs e)
 {
     if (!ParametersClass.autch)
     {
         VkApiClass.Auth(LoginBox.Text, PasswordBox.Text, ButtonLogin);
     }
     else
     {
         MessageBox.Show("Вы уже авторизованны.");
     }
 }
Exemple #2
0
        private void Form1_Load(object sender, EventArgs e)
        {
            ParametersClass.timertoautopost = timertoautopost;

            if (!Directory.Exists(System.Windows.Forms.Application.StartupPath + "\\Json"))
            {
                Directory.CreateDirectory(System.Windows.Forms.Application.StartupPath + "\\Json");
            }

            if (!Directory.Exists(System.Windows.Forms.Application.StartupPath + "\\Json" + "\\groups"))
            {
                Directory.CreateDirectory(System.Windows.Forms.Application.StartupPath + "\\Json" + "\\groups");
            }

            if (File.Exists(ParametersClass.GlobalJson))
            {
                GlobalParametersJson globalParametersJson = IOClass.ReadGlobalJson();
                LoginBox.Text    = globalParametersJson.LoginT;
                PasswordBox.Text = globalParametersJson.PassT;

                ParametersClass.ip             = globalParametersJson.Ip;
                ParametersClass.token          = globalParametersJson.Token;
                ParametersClass.AutostartValue = globalParametersJson.AutoStart;
            }
            else
            {
                using (FileStream fs = File.Create(ParametersClass.GlobalJson))
                {
                    fs.Close();
                    fs.Dispose();
                }

                IOClass.SaveGlobalJson(LoginBox.Text, PasswordBox.Text);
            }

            string[] groups = Directory.GetFiles(System.Windows.Forms.Application.StartupPath + "\\Json" + "\\groups");
            for (int i = 0; i < groups.Length; i++)
            {
                GroupItem groupItem = IOClass.ReadGroupJson(groups[i]);
                TimeClass time      = new TimeClass(groupItem.Hour, groupItem.Minute, groupItem.Yer, groupItem.Mounth, groupItem.Day, groupItem.PostSpace);

                Classes.Group group = new Classes.Group(Path.GetFileNameWithoutExtension(groups[i]), time);
                group.groupItem = groupItem;

                ParametersClass.groups.Add(group);
            }
            if (groups.Length == 0)
            {
                ParametersClass.groups.Add(GroupManager.CreateGroup("Default", true));
                GroupManager.SaveAllGroup();
                LastIndex = 0;
            }

            if (File.Exists(ParametersClass.logsPath))
            {
                ParametersClass.logs = IOClass.ReadLogsJson();
            }
            if (ParametersClass.logs == null)
            {
                ParametersClass.logs = new List <Logs>();
            }

            AutoPostStop.Enabled = false;
            if (ParametersClass.AutostartValue)
            {
                this.ShowInTaskbar   = false;
                this.WindowState     = FormWindowState.Minimized;
                this.FormBorderStyle = FormBorderStyle.SizableToolWindow;

                notifyIcon1.Icon            = this.Icon;
                notifyIcon1.BalloonTipIcon  = ToolTipIcon.Info;
                notifyIcon1.BalloonTipText  = "DesuBot работает в автоматическом режиме. Работа начнётся через 10 минут.";
                notifyIcon1.BalloonTipTitle = "DesuBot";
                notifyIcon1.ShowBalloonTip(12);

                AutoPostStop.Enabled = true;
            }
            else
            {
                this.WindowState     = FormWindowState.Normal;
                this.FormBorderStyle = FormBorderStyle.Sizable;
            }
            try
            {
                label11.Text = "Количество вайлов в папке: " + Directory.GetFiles(patchToPublic.Text).Length;
            }
            catch { }

            string nowIP = new WebClient().DownloadString("http://bot.whatismyipaddress.com");

            if (ParametersClass.ip != nowIP)
            {
                ParametersClass.ip = nowIP;
                if (ParametersClass.AutostartValue)
                {
                    VkApiClass.Auth(LoginBox.Text, PasswordBox.Text, ButtonLogin);
                }
            }
            else if (ParametersClass.AutostartValue == true && ParametersClass.ip == nowIP)
            {
                VkApiClass.Auth(LoginBox.Text, PasswordBox.Text, ButtonLogin);
            }
            else
            {
                try
                {
                    ParametersClass.vkapi.Authorize(new ApiAuthParams
                    {
                        AccessToken = ParametersClass.token
                    });
                    if (ParametersClass.AutostartValue)
                    {
                        timertoautopost.Enabled = true;
                    }
                    else
                    {
                        MessageBox.Show("Успешная авторизация через токен.");
                    }
                    ParametersClass.autch = true;
                    ButtonLogin.BackColor = Color.Lime;
                }
                catch
                {
                    ParametersClass.autch = false;
                    ButtonLogin.BackColor = Color.Red;
                    if (ParametersClass.AutostartValue)
                    {
                        VkApiClass.Auth(LoginBox.Text, PasswordBox.Text, ButtonLogin);
                    }
                    else
                    {
                        MessageBox.Show("Авторизация через токен не удалась.");
                    }
                }
            }

            UpdateGroupList();
            groupList.SelectedIndex = LastIndex;
            UpdateGUI();
        }