private void PathSettingForm_Load(object sender, EventArgs e)
        {
            AppSettings settings = new AppSettings();

            pathTextBox.Text = settings.PathSettings.Path;
            createFolderBox.Checked = settings.PathSettings.CreateFolder;
        }
Esempio n. 2
0
        private void ProxyForm_Load(object sender, EventArgs e)
        {
            AppSettings settings = new AppSettings();

            useProxyBox.Checked = settings.ProxySettings.UseProxy;
            serverBox.Text = settings.ProxySettings.Server;
            portBox.Text = settings.ProxySettings.Port;
            loginBox.Text = settings.ProxySettings.User;
            passwordBox.Text = settings.ProxySettings.Password;

            SetComponentsEnabled(useProxyBox.Checked);
        }
Esempio n. 3
0
        private void button2_Click(object sender, EventArgs e)
        {
            var settings = new AppSettings();

            if (!Directory.Exists(settings.PathSettings.Path))
            {
                MessageBox.Show("Укажите корректный путь сохранения файлов", "Внимание", MessageBoxButtons.OK,
                    MessageBoxIcon.Warning);
                return;
            }

            if (audioListBox.CheckedItems.Count == 0)
            {
                return;
            }

            EnableComponents(false);

            myBackgroundWorker.RunWorkerAsync();
        }
Esempio n. 4
0
        private void myBackgroundWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            using (var client = new WebClient())
            {
                CheckForIllegalCrossThreadCalls = false;

                var settings = new AppSettings();

                if (settings.ProxySettings.UseProxy)
                {
                    client.Proxy = settings.ProxySettings.GetWebProxy();
                }

                var manualReset = new ManualResetEvent(false);
                var task = new CurrentTask();

                client.DownloadProgressChanged += delegate(object send, DownloadProgressChangedEventArgs ea)
                {
                    songPersentStatus.Text = ea.ProgressPercentage + "% ";
                    songProgress.Value = ea.ProgressPercentage;
                };

                client.DownloadFileCompleted += delegate(object sende, System.ComponentModel.AsyncCompletedEventArgs ea)
                {
                    manualReset.Set();
                };

                int progress = 0;
                string path = settings.PathSettings.Path;

                for (int audioIindex = 0; audioIindex < audioListBox.Items.Count; audioIindex++)
                {
                    if (!audioListBox.GetItemChecked(audioIindex))
                        continue;

                    if (settings.PathSettings.CreateFolder)
                    {
                        path = settings.PathSettings.Path + @"\" + list[audioIindex].Artist;

                        if (!Directory.Exists(path))
                        {
                            Directory.CreateDirectory(path);
                        }
                    }

                    progress = 100 * audioIindex / audioListBox.Items.Count;

                    task.Name = list[audioIindex].Artist + " - " + list[audioIindex].Title;
                    task.Index = audioIindex;

                    string fileName = path + @"\" + task.Name + ".mp3";

                    if (File.Exists(fileName))
                        continue;

                    myBackgroundWorker.ReportProgress(progress, task);

                    try
                    {
                        manualReset.Reset();
                        client.DownloadFileAsync(new Uri(list[audioIindex].Path), path + @"\" + task.Name + ".mp3");
                        manualReset.WaitOne();

                    }
                    catch (Exception)
                    {
                        StatusLabel.Text = "Ошибка при загрузке композиций";
                        EnableComponents(true);
                        return;
                    }

                    Thread.Sleep(200);
                }

                task.Name = "Готово";

                SetCheckedAudioList(false);
                EnableComponents(true);

                myBackgroundWorker.ReportProgress(100, task);
            }
        }
Esempio n. 5
0
        private List<AudioInfo> GetAudioList(string postID)
        {
            var audioList = new List<AudioInfo>();

            string url = @"https://api.vk.com/method/wall.getById.xml?posts=" +
                         postID +
                         "&extended=1&copy_history_depth=1&v=5.14";
            try
            {

                HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(url);

                var settings = new AppSettings();

                if (settings.ProxySettings.UseProxy)
                {
                    req.Proxy = settings.ProxySettings.GetWebProxy();
                }

                HttpWebResponse resp = (HttpWebResponse)req.GetResponse();

                string result = "";

                using (StreamReader stream = new StreamReader(resp.GetResponseStream()))
                {
                    result = stream.ReadToEnd();
                }

                XElement root = XElement.Parse(result);

                var audio = (from e
                    in root.Descendants("audio")
                             select e).ToList();

                foreach (XElement element in audio)
                {
                    var info = new AudioInfo();

                    info.Artist = ReplaceBadChars(element.Element("artist").Value);
                    info.Title = ReplaceBadChars(element.Element("title").Value);
                    info.Path = element.Element("url").Value;

                    audioList.Add(info);
                }
            }
            catch (Exception e)
            {
                StatusLabel.Text = "Ошибка при получении композиций";
            }

            return audioList;
        }