Exemplo n.º 1
0
 private async void DownloadItem_LoadedAsync(object sender, RoutedEventArgs e)
 {
     tb.Text = MData.MusicName + " - " + MData.SingerText;
     d       = new HttpDownloadHelper(MData.MusicID, path);
     Loadedd();
     d.ProgressChanged += (pro) =>
     {
         Dispatcher.Invoke(() =>
         {
             finished = true;
             Pb.Value = pro;
             zt.Text  = pro + "%";
         });
     };
     d.Finished += () =>
     {
         Dispatcher.Invoke(() =>
         {
             finished = true;
             zt.Text  = "已完成";
         });
     };
     d.GetSize += (s) =>
     {
         Dispatcher.Invoke(() =>
         {
             size.Text = s;
         });
     };
     if (index == 0 || index == 1 || index == 2)
     {
         d.Download();
     }
     await MusicLib.GetLyric(MData.MusicID, path.Replace(".mp3", ".lrc"));
 }
Exemplo n.º 2
0
        public void LoadImage(string imgCachePath, bool icon)
        {
            if (string.IsNullOrEmpty(icon ? IconURI : ImageURI))
            {
                return;
            }
            var downloadHelper = new HttpDownloadHelper();

            downloadHelper.DownloadCompleted += OnDownloadCompleted;
            try
            {
                if (!Directory.Exists(imgCachePath))
                {
                    Directory.CreateDirectory(imgCachePath);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Failed to create directory: " + imgCachePath);
                return;
            }

            var path = Path.Combine(imgCachePath, string.Format("{0}_{1}.png", _label, (icon ? "icon" : "img")));

            if (!icon)
            {
                ImagePath = path;
            }
            else
            {
                IconPath = path;
            }

            if (!File.Exists(icon ? IconPath : ImagePath))
            {
                ThreadPool.QueueUserWorkItem((x) => downloadHelper.DownloadImage(icon ? IconURI : ImageURI, path));
            }
        }
Exemplo n.º 3
0
        private async Task Download(HttpDownloadHelper helper, string url, string remoteFile, bool execute)
        {
            try
            {
                SetListViewReady(helper.Client as ClientData);
                SetListViewSpeed(helper.Client as ClientData, "");
                await helper.StartAsync(url, remoteFile);

                SetListViewSuccess(helper.Client as ClientData);

                if (execute)
                {
                    using (CommandHelper helper2 = new CommandHelper(helper.Client))
                    {
                        await helper2.StartAsync(textBoxRemote.Text, null);
                    }
                }
            }
            catch (Exception ex)
            {
                SetListViewError(helper.Client as ClientData, ex.Message);
            }
        }
Exemplo n.º 4
0
 private void Load()
 {
     tb.Text            = MData.MusicName + " - " + MData.SingerText;
     d                  = new HttpDownloadHelper(MData.MusicID, path);
     d.ProgressChanged += (pro) =>
     {
         Dispatcher.Invoke(() =>
         {
             Pb.Value = pro;
             zt.Text  = pro + "%";
         });
     };
     d.Finished += async() =>
     {
         if (Settings.USettings.DownloadWithLyric)
         {
             await MusicLib.GetLyric(MData.MusicID, path.Replace(".mp3", ".lrc"));
         }
         Dispatcher.Invoke(() =>
         {
             Finished(this);
             finished = true;
             zt.Text  = "已完成";
         });
     };
     d.GetSize += (s) =>
     {
         Dispatcher.Invoke(() =>
         {
             size.Text = s;
         });
     };
     if (index == 0)
     {
         d.Download();
     }
 }