Beispiel #1
0
    public List<string> UnzipFile(string zippPath,string outputPath)
    {
        List<string> listFile = new List<string>();
        if (!System.IO.File.Exists(zippPath)){

            WriteMesage("ERROR :  FILE NOT FOUND :"+ zippPath );
            return listFile;

        }

        //ProgressDialog progD = new ProgressDialog("Unpacking",ProgressDialog.CancelButtonType.None, 2048,null);
        Reset(1,"Unpacking");

        using (ZipInputStream s = new ZipInputStream(File.OpenRead(zippPath))) {

            ZipEntry theEntry;
            while ((theEntry = s.GetNextEntry()) != null) {

                string directoryName = System.IO.Path.GetDirectoryName(theEntry.Name);
                string fileName = System.IO.Path.GetFileName(theEntry.Name);
                    WriteMesage("directoryName: "+ directoryName);
                    WriteMesage("fileName: "+ fileName );

                if (!String.IsNullOrEmpty(fileName)) {

                    string newDirectoryPath = System.IO.Path.Combine(outputPath, directoryName);
                    string newFilePath = System.IO.Path.Combine(newDirectoryPath, fileName);
                    WriteMesage("File: "+ fileName);

                    try{
                        int count = (int)(s.Length/2048)+2;

                        WriteMesage("Length: "+ s.Length );
                        WriteMesage("Count: "+ count );

                        //WriteMesage("File: " +newDirectoryPath);
                        WriteMesage("New Path: " +newFilePath);

                        if (!Directory.Exists(newDirectoryPath)){
                            Directory.CreateDirectory(newDirectoryPath);
                        }

                        //if ( (s.Length == null) || (s.Length <1)) continue;

                        //progD.Reset(count,theEntry.Name);
                        Reset(count,theEntry.Name);

                        //progD.SetLabel(fileName);
                        SetLabel(fileName);

                        using (FileStream streamWriter = File.Create(newFilePath)){//theEntry.Name)) {

                            int size = 1048576;//2048;
                            byte[] data = new byte[1048576];//[2048];
                            while (true) {
                                //progD.Update(fileName);
                                Update(fileName);

                                size = s.Read(data, 0, data.Length);
                                if (size > 0) {
                                    streamWriter.Write(data, 0, size);
                                } else {
                                    break;
                                }
                            }
                        }
                    }catch(Exception ex){
                        MessageDialogs md =
                            new MessageDialogs(MessageDialogs.DialogButtonType.YesNo, "I can not unpack file. " +fileName ," Continue ?", Gtk.MessageType.Error,null);
                        int res = md.ShowDialog();
                        WriteMesage(String.Format("ERROR IN FILE {0}: {1}",fileName,ex.Message) );
                        if (res == (int)Gtk.ResponseType.No){
                            cancelUnpack = true;
                            return listFile;
                        }
                    }
                    listFile.Add(newFilePath);
                }
            }
        }
        //progD.Destroy();
        //Reset(1,"Update finish.");
        return listFile;
    }
Beispiel #2
0
    public List <string> UnzipFile(string zippPath, string outputPath)
    {
        List <string> listFile = new List <string>();

        if (!System.IO.File.Exists(zippPath))
        {
            WriteMesage("ERROR :  FILE NOT FOUND :" + zippPath);
            return(listFile);
        }

        //ProgressDialog progD = new ProgressDialog("Unpacking",ProgressDialog.CancelButtonType.None, 2048,null);
        Reset(1, "Unpacking");

        using (ZipInputStream s = new ZipInputStream(File.OpenRead(zippPath))) {
            ZipEntry theEntry;
            while ((theEntry = s.GetNextEntry()) != null)
            {
                string directoryName = System.IO.Path.GetDirectoryName(theEntry.Name);
                string fileName      = System.IO.Path.GetFileName(theEntry.Name);
                WriteMesage("directoryName: " + directoryName);
                WriteMesage("fileName: " + fileName);


                if (!String.IsNullOrEmpty(fileName))
                {
                    string newDirectoryPath = System.IO.Path.Combine(outputPath, directoryName);
                    string newFilePath      = System.IO.Path.Combine(newDirectoryPath, fileName);
                    WriteMesage("File: " + fileName);

                    try{
                        int count = (int)(s.Length / 2048) + 2;

                        WriteMesage("Length: " + s.Length);
                        WriteMesage("Count: " + count);

                        //WriteMesage("File: " +newDirectoryPath);
                        WriteMesage("New Path: " + newFilePath);

                        if (!Directory.Exists(newDirectoryPath))
                        {
                            Directory.CreateDirectory(newDirectoryPath);
                        }

                        //if ( (s.Length == null) || (s.Length <1)) continue;

                        //progD.Reset(count,theEntry.Name);
                        Reset(count, theEntry.Name);

                        //progD.SetLabel(fileName);
                        SetLabel(fileName);

                        using (FileStream streamWriter = File.Create(newFilePath)){ //theEntry.Name)) {
                            int    size = 1048576;                                  //2048;
                            byte[] data = new byte[1048576];                        //[2048];
                            while (true)
                            {
                                //progD.Update(fileName);
                                Update(fileName);

                                size = s.Read(data, 0, data.Length);
                                if (size > 0)
                                {
                                    streamWriter.Write(data, 0, size);
                                }
                                else
                                {
                                    break;
                                }
                            }
                        }
                    }catch (Exception ex) {
                        MessageDialogs md =
                            new MessageDialogs(MessageDialogs.DialogButtonType.YesNo, "I can not unpack file. " + fileName, " Continue ?", Gtk.MessageType.Error, null);
                        int res = md.ShowDialog();
                        WriteMesage(String.Format("ERROR IN FILE {0}: {1}", fileName, ex.Message));
                        if (res == (int)Gtk.ResponseType.No)
                        {
                            cancelUnpack = true;
                            return(listFile);
                        }
                    }
                    listFile.Add(newFilePath);
                }
            }
        }
        //progD.Destroy();
        //Reset(1,"Update finish.");
        return(listFile);
    }