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); }
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); }