using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using System.Net.NetworkInformation;
using ICSharpCode.SharpZipLib.Zip;
using System.IO.IsolatedStorage;
using System.IO;
namespace PhoneApp4
{
public partial class MainPage : PhoneApplicationPage
{
// 构造函数
public MainPage()
{
InitializeComponent();
}
private void btnLoad_Click(object sender, RoutedEventArgs e)
{
Button btn = sender as Button;
if (NetworkInterface.GetIsNetworkAvailable())
{
btn.IsEnabled = false;
WebClient client = new WebClient();
progressBarWithText.ShowProgress = true;
client.OpenReadAsync(new Uri("http://files.iyunv.com/youhui/2012-04/20120405.zip", UriKind.Absolute));
client.OpenReadCompleted += (a, b) =>
{
//解压下载的ZIP包
if (null == b.Error && !b.Cancelled)
{
using (ZipInputStream zipInputStream = new ZipInputStream(b.Result))
{
ZipEntry zipEntry;
byte[] data = new byte[2048];
int size = 2048;
while ((zipEntry = zipInputStream.GetNextEntry()) != null)
{
if (zipEntry != null)
{
string fName = zipEntry.Name;
if (fName != String.Empty && fName.Contains(".jpg"))
{
IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication();
string path = "download";
if (!Directory.Exists(path))
{
isf.CreateDirectory(path);
}
using (IsolatedStorageFileStream fileStream = new IsolatedStorageFileStream(System.IO.Path.Combine(path + "\\", fName.Substring(fName.LastIndexOf("/") + 1, fName.Length - fName.LastIndexOf("/") - 1)), FileMode.OpenOrCreate, isf))
{
while (true)
{
size = zipInputStream.Read(data, 0, data.Length);
if (size