コード例 #1
0
ファイル: AudioHelper.cs プロジェクト: LigangSun/AppCenter
        private static bool downloadMusicFile(BackgroundMusicItem item)
        {
            string localMusicFile = Path.Combine(backgroundMusicFolder, item.FileName);
            string tempFile       = Path.Combine(localMusicFile, ".tmp");

            DownloadHelper helper = new DownloadHelper();

            helper.DownloadFileCompleted += (sender, e) =>
            {
                //    if (e.Error == null)
                {
                    try
                    {
                        File.Move(tempFile, localMusicFile);
                    }
                    catch
                    {
                    }

                    lock (backgroundMusicListLocker)
                    {
                        backgroundMusicList.Add(localMusicFile);
                    }

                    downloadingIndex++;
                    if (downloadingIndex >= onlineBackgroundMusicCollection.Count)
                    {
                        return;
                    }

                    downloadMusicFile(onlineBackgroundMusicCollection[downloadingIndex]);
                }
            };
            helper.DownloadProgressChanged += (sender, e) =>
            {
            };

            if (File.Exists(localMusicFile))
            {
                downloadingIndex++;
                if (downloadingIndex >= onlineBackgroundMusicCollection.Count)
                {
                    return(false);
                }

                downloadMusicFile(onlineBackgroundMusicCollection[downloadingIndex]);
                return(true);
            }

            helper.DownloadFile(item.Url, tempFile);

            return(true);
        }
コード例 #2
0
        public static void UpdateBackgroundMusic(string configFileUrl)
        {
            string localConfigFile = Path.GetTempFileName();

            DownloadHelper helper = new DownloadHelper();

            helper.DownloadFileCompleted += (sender, e) =>
            {
                if (e.Error == null)
                {
                    startSyncBackgroundMusicFile(localConfigFile);
                }
            };
            helper.DownloadProgressChanged += (sender, e) =>
            {
            };

            helper.DownloadFile(configFileUrl, localConfigFile);
        }