locked
extraction of zip not working when we install created app packages RRS feed

  • Question

  • hi,

        I have created windows store apps using winjs,In that I have implemented downloading zip file and its extraction.all working fine for zip files upto 303MB size.I have tested in both debug and release mode all working fine.then I created app packages and installed in my system.

       download and other concepts working fine ,extraction started but not completed it just extracted 2 folders and its sub contents.i don't know whats happening on extraction?..no memory issues stil my app not terminated but extraction not completed.

      its working good in my local why its not working on appx file?I want to know the reason behind it


    I have used below codes,

            public IAsyncOperationWithProgress<int, double> Uncompress(StorageFile File,StorageFolder Destination)
            {
                return AsyncInfo.Run<int, double>((Token, Progress) =>
                {
                    return Task.Run(async () =>
                    {
                        Progress.Report(0);
                        await UnZipFile(File,Destination);
                        Token.ThrowIfCancellationRequested();
                        Progress.Report(100.0);
                        return 0;
                    }, Token
                      );
    
                });
            }
            private async Task<bool> UnZipFile(StorageFile file,StorageFolder destination)
            {
                try
                {
                    var folder = destination;
                    var filename = file.DisplayName;
                    var zipStream = await file.OpenStreamForReadAsync();
    
                    MemoryStream zipMemoryStream = new MemoryStream((int)zipStream.Length);
    
                    await zipStream.CopyToAsync(zipMemoryStream);
                    var storage = await folder.CreateFolderAsync(filename, CreationCollisionOption.OpenIfExists);
    
                    var archive = new ZipArchive(zipMemoryStream, ZipArchiveMode.Read);
    
                    foreach (ZipArchiveEntry entry in archive.Entries)
                    {
                        try
                        {
                            if (entry.Name == "")
                            {
                                // Folder
                                await CreateRecursiveFolder(storage, entry);
                            }
                            else
                            {
                                // File
                                await ExtractFile(storage, entry);
                            }
                        }
    
                        catch (Exception ex)
                        {
                            Debug.WriteLine(ex.Message);
                        }
                    }
    
                    return true;
                }
                catch (Exception)
                {
                    return false;
                }
            }
           
            private async Task CreateRecursiveFolder(StorageFolder folder, ZipArchiveEntry entry)
            {
                var steps = entry.FullName.Split('/').ToList();
    
                steps.RemoveAt(steps.Count() - 1);
    
                foreach (var i in steps)
                {
                    try
                    {
                       var NewFolder= await folder.CreateFolderAsync(i, CreationCollisionOption.OpenIfExists);
    
                        
                    }
                    catch (Exception ex) {
                        var x = ex;
                    }
                }
            }
    
            private async Task ExtractFile(StorageFolder folder, ZipArchiveEntry entry)
            {
                var steps = entry.FullName.Split('/').ToList();
    
                steps.RemoveAt(steps.Count() - 1);
    
                foreach (var i in steps)
                {
                    folder = await folder.CreateFolderAsync(i,CreationCollisionOption.OpenIfExists);
                }
    
                using (Stream fileData = entry.Open())
                {
                    StorageFile outputFile = await folder.CreateFileAsync(entry.Name, CreationCollisionOption.ReplaceExisting);
    
                    using (Stream outputFileStream = await outputFile.OpenStreamForWriteAsync())
                    {
                        await fileData.CopyToAsync(outputFileStream);
                        await outputFileStream.FlushAsync();
                    }
                }
            }

    Any help would be greatly appreciated

    Tuesday, July 1, 2014 10:48 AM

All replies

  • Please post a working project to Onedrive and share it here, and give me exact reproduction steps as well.

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Tuesday, July 1, 2014 7:35 PM
    Moderator
  • extraction of zip file not working in app suspended state?is there any possibility to do extraction in background task?

    how can i achieve this?

    thanks in advance

    Wednesday, July 2, 2014 1:13 PM
  • If the app is suspended, no, you can't do *anything*. Have you tried the background task of unzipping a file? I can't think of any reason it wouldn't work offhand.

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Wednesday, July 2, 2014 2:22 PM
    Moderator
  • hi matt,

         could you explain about how to do long unzipping operations in background task.how to implement background task in my application

    Thursday, July 3, 2014 4:17 AM
  • Here's a walkthrough:
    http://msdn.microsoft.com/en-us/library/windows/apps/Hh977046.aspx

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Wednesday, July 16, 2014 4:07 PM
    Moderator