Example #1
0
 public void DownloadAllMusic()
 {
     AudioList = GetAllAudio();
     if (AudioList != null || AudioList.Count != 0)
     {
         using (WebClient client = new WebClient())
         {
             foreach (var audio in AudioList)
             {
                 string   path = $@"{Properties.Resources.MusicFolderPath}{Account.Name}\{audio.Title} - {audio.Artist}.mp3";
                 FileInfo file = new FileInfo(path);
                 if (Directory.Exists(Properties.Resources.MusicFolderPath + Account.Name))
                 {
                     if (!file.Exists)
                     {
                         client.DownloadFile(audio.Url, path);
                     }
                 }
                 else
                 {
                     Directory.CreateDirectory(Properties.Resources.MusicFolderPath + Account.Name);
                 }
             }
         }
     }
     else
     {
         MusicMessageBox box = new MusicMessageBox();
         box.Show();
         box.ShowWindow(null, Properties.Resources.NoMusicToDownloadText + "\n\rThanks form using our product.");
     }
 }
Example #2
0
 //Authentificate from json file and returns VKAccaunt instance
 public VKAccount AuthentificateFromFile(string UserDataJSON, string SecretUserJSON)
 {
     Account = new VKAccount();
     UserVk  = new VkApi(service);
     try
     {
         Account = JsonConvert.DeserializeObject <VKAccount>(UserDataJSON);
         var obj = JsonConvert.DeserializeObject <VKAccount>(SecretUserJSON);
         Account.Password = obj.Password;
         Account.Login    = obj.Login;
         Settings set = Settings.Audio;
         UserVk.Authorize(new ApiAuthParams
         {
             AccessToken   = Account.Token,
             ApplicationId = appID,
             Settings      = set
         });
         GiveAllInfoToAccountObject();
     }
     catch (VkNet.Exception.VkApiException ex)
     {
         MusicMessageBox box = new MusicMessageBox();
         box.Show();
         box.ShowWindow(null, ex.Message);
     }
     return(Account);
 }
Example #3
0
 //Authentificate and returns VKAccaunt instance
 public VKAccount Authentificate(bool saveProfileToJson = false)
 {
     Account = new VKAccount(Password, Login);
     UserVk  = new VkApi(service);
     try
     {
         Settings set = Settings.Audio;
         UserVk.Authorize(new ApiAuthParams
         {
             Password      = this.Password,
             Login         = this.Login,
             ApplicationId = appID,
             Settings      = set
         });
         if (UserVk.IsAuthorized)
         {
             GiveAllInfoToAccountObject();
             if (saveProfileToJson)
             {
                 SaveAs(UserDataFile.Name, JsonConvert.SerializeObject(UserVk));
                 using (JsonTextWriter writer = new JsonTextWriter(new StreamWriter(SecretDataFile.Name, true)))
                 {
                     //string json = JsonConvert.SerializeObject(Account);
                     writer.WriteStartObject();
                     writer.WritePropertyName("Name");
                     writer.WriteValue(Account.Name);
                     writer.WritePropertyName("SurName");
                     writer.WriteValue(Account.SurName);
                     writer.WritePropertyName("Password");
                     writer.WriteValue(Account.Password);
                     writer.WritePropertyName("Login");
                     writer.WriteValue(Account.Login);
                     writer.WriteEndObject();
                 }
                 SaveAs(UserAccauntDataFile.Name, JsonConvert.SerializeObject(UserVk.Account.GetInfo()));
             }
         }
         else
         {
             MusicMessageBox box = new MusicMessageBox();
             box.Show();
             box.ShowWindow(null, MessageFlags.WrongAuth);
         }
     }
     catch (Exception ex)
     {
         MusicMessageBox box = new MusicMessageBox();
         box.Show();
         box.ShowWindow(null, ex.Message);
     }
     return(Account);
 }
Example #4
0
        public VkCollection <Audio> GetAllAudio()
        {
            VkCollection <Audio> list = null;

            try
            {
                list = UserVk.Audio.Get(new AudioGetParams {
                    OwnerId = UserVk.UserId.Value
                });
            }
            catch (Exception ex)
            {
                MusicMessageBox box = new MusicMessageBox();
                box.ShowWindow(null, ex.Message);
            }
            return(list);
        }
Example #5
0
        private async void Signin_btn_Click(object sender, EventArgs e)
        {
            LoadBar loadbar = new LoadBar();

            loadbar.Show();
            this.Hide();
            loadbar.Refresh();
            var client = new VKManager(login_box.Text, password_box.Text);

            if (remember_me.CheckState == CheckState.Checked)
            {
                Task t = new Task(() =>
                {
                    account = client.Authentificate(true);
                });
                t.Start();
                await t;
            }
            else if (remember_me.CheckState == CheckState.Unchecked)
            {
                Task t = new Task(() =>
                {
                    account = client.Authentificate(false);
                });
                t.Start();
                await t;
            }
            loadbar.Close();
            if (account.IsAuthorized)
            {
                player        = new Player(account);
                player.Client = client;
                player.Show();
                player.Refresh();
            }
            else
            {
                MusicMessageBox box = new MusicMessageBox();
                box.Show();
                box.ShowWindow(this, MessageFlags.WrongAuth);
            }
            this.Close();
        }