2014-04-06 5 views
4

내 응용 프로그램 내에서 한 번에 약 180 개의 작은 오디오 파일을 다운로드하려고합니다. BackgroundTransferService를 시도했지만 너무 많은 작은 파일이 안정적으로 보이지 않습니다. 이제는 모든 오디오의 ZIP을 다운로드하고 "오디오"폴더에서 압축을 풀고 싶습니다. 나는이 글의 방법을 시도 :Windows Phone 8 앱에서 IsolatedStorage의 파일을 압축 해제하는 방법은 무엇입니까?

How to unzip files in Windows Phone 8

을하지만 난이 오류 : 'System.IO.IOException' occurred in mscorlib.ni.dll...를 다음 코드. 이 문제를 어떻게 극복 할 수 있습니까?

while (reader.ReadInt32() != 101010256) 
{ 
    reader.BaseStream.Seek(-5, SeekOrigin.Current); // this line causes error 
}... 

또한이 코드를 어디에 배치해야합니까? 대상 디렉토리는 어디에서 지정해야합니까?

IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication(); 
using (IsolatedStorageFileStream fileStream = myIsolatedStorage.OpenFile(@"audio.rar", FileMode.Open, FileAccess.ReadWrite)) 
{ 
    UnZipper unzip = new UnZipper(fileStream);        
    foreach (string filename in unzip.FileNamesInZip()) 
    { 
     string FileName = filename; 
    } 
} 
+0

항상 사용중인 또는 귀하의 질문에 대부분의 주제 전문가가 볼 수 없습니다 언어에 대한 태그를 포함한다. –

+0

죄송합니다. 새로운 질문을 여기에. 앞으로도 계속 명심하겠습니다 :-) 감사합니다. – hnabbasi

+0

왜 "마법의 가치"를 찾을 때까지 뒤로 물러나려고합니까? 오류를 일으키는 네거티브 검색 위치를 누르는 중입니다. –

답변

0

Silverlight SharpZipLib을 사용하십시오. SharpZipLib.WindowsPhone7.dll을 프로젝트에 추가하십시오 (WP8 실버 라이트에서도 작동).

private void Unzip() 
    { 
     using (var store = IsolatedStorageFile.GetUserStoreForApplication()) 
     { 
      ZipEntry entry; 
      int size; 
      byte[] data = new byte[2048]; 

      using (ZipInputStream zip = new ZipInputStream(store.OpenFile("YourZipFile.zip", FileMode.Open))) 
      { 
       // retrieve each file/folder 
       while ((entry = zip.GetNextEntry()) != null) 
       { 
        if (!entry.IsFile) 
         continue; 

        // if file name is music/rock/new.mp3, we need only new.mp3 
        // also you must make sure file name doesn't have unsupported chars like /,\,etc. 
        int index = entry.Name.LastIndexOf('/'); 

        string name = entry.Name.Substring(index + 1); 

        // create file in isolated storage 
        using (var writer = store.OpenFile(name, FileMode.Create)) 
        { 
         while (true) 
         { 
          size = zip.Read(data, 0, data.Length); 
          if (size > 0) 
           writer.Write(data, 0, size); 
          else 
           break; 
         } 
        } 
       } 
      } 
     } 

    } 
0

http://slsharpziplib.codeplex.com/ @ 그러나 DotNetZip 부모 ZipLib 훨씬 더 안정에서 다운로드 할 수있는 ZipLib처럼 WP8에 ZIP 파일의 압축을 풉니 다하기 위해 여러 제 3의 라이브러리가 있습니다. 다음은 샘플 코드입니다. 작동하는지는 확인되지 않지만이 방법을 사용하면됩니다.

 ZipFile zip = ZipFile.Read(ZipFileToUnzip); 

foreach (ZipEntry ent in zip) 
{ 
    ent.Extract(DirectoryWhereToUnizp, ExtractExistingFileAction.OverwriteSilently); 
} 
0

방금 ​​문제를 해결했습니다. 당신이 할 수있는 일은이 방법을 사용하는 것이고 파일은 zip 파일에있는 적절한 폴더 구조로 고립 된 저장소에 저장됩니다. 데이터를 저장할 위치에 따라 필요에 따라 변경할 수 있습니다.

방금 ​​sample.zip 파일을 읽었습니다. 앱 폴더에서.

private async Task UnZipFile() 
    { 
     var myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication(); 
     using (var fileStream = Application.GetResourceStream(new Uri("sample.zip", UriKind.Relative)).Stream) 
     { 
      var unzip = new UnZipper(fileStream); 
      foreach (string filename in unzip.FileNamesInZip) 
      { 
       if (!string.IsNullOrEmpty(filename)) 
       { 
        if (filename.Any(m => m.Equals('/'))) 
        { 
         myIsolatedStorage.CreateDirectory(filename.Substring(0, filename.LastIndexOfAny(new char[] { '/' }))); 
        } 

        //save file entry to storage 
        using (var streamWriter = 
         new StreamWriter(new IsolatedStorageFileStream(filename, 
          FileMode.Create, 
          FileAccess.ReadWrite, 
          myIsolatedStorage))) 
        { 
         streamWriter.Write(unzip.GetFileStream(filename)); 
        } 
       } 
      } 
     } 
    } 

환호 :