login about faq

Hello, I'm using chilkatsoft version 9.5.0.69 with .net 4.0. I'm renaming a zip file, adding a new file, renaming that new file and saving again that zip file.

I can extract the file compressed and the renamed, but if i open that zip file with 7-zip and looking for the info for one entry (right button and properties option) it says: warnings: headers error All the entries says the same looking at properties, shows the same warning. Another simpton is that created time and last access time of the entry modified name and the new entry are with no value. All the other entries have value in last access time and created time. The code used is:

private static bool RenombraEntradayAñadeAZip(string pnombreorigen, string pnombredestino, string pFichAñadirAZip, string pNombreEnZipFicheroAñadido, string prutazip) {

    bool lValorRetorno;
    Chilkat.Zip lzip=null;
    string lTempString;
    Chilkat.ZipEntry lentradazip;
    int i;
    string lNombreSinPath,lNombreConPath;
    string lDirDeNombre;
    string lold;
    bool lrenombrado;

    lValorRetorno = false;
    lNombreSinPath = string.Empty;
    try
    {
        do
        {
            lzip = new Chilkat.Zip();
            lTempString = clsChilkatSoft.PonLicencia(lzip);
            if (lTempString.Length > 0)
            {
                Console.WriteLine("Error al poner licencia de Chilkat.Zip : " + lTempString);
                break;
            }
            if (!lzip.OpenZip(prutazip))
            {
                Console.WriteLine("Error al abrir fichero zip, error : " + lzip.LastErrorText);
                break;
            }
            Console.WriteLine("Abierto fichero zip '" + prutazip + "'");
            lrenombrado = false;
            lDirDeNombre = string.Empty;
            for (i=0;i<lzip.NumEntries;++i)
            {
                lentradazip = lzip.GetEntryByIndex(i);
                if (!lentradazip.IsDirectory)
                {
                    lNombreConPath = lentradazip.FileName;
                    lNombreSinPath = System.IO.Path.GetFileName(lNombreConPath);
                    lDirDeNombre = System.IO.Path.GetDirectoryName(lNombreConPath);
                    if (System.String.Compare(lNombreSinPath, pnombreorigen, true) == 0)
                    {
                        //encontrada entrada a renombrar
                        lold = lentradazip.FileName;
                        if (lDirDeNombre.Length > 0)
                            lTempString = lDirDeNombre + System.IO.Path.DirectorySeparatorChar;
                        else
                            lTempString = string.Empty;
                        lentradazip.FileName = lTempString + pnombredestino;
                        if (!lentradazip.LastMethodSuccess)
                        {
                            Console.WriteLine("Error al renombrar entrada de zip : " + lentradazip.LastErrorText);
                        }
                        Console.WriteLine("Renombrada entrada de zip de '" + lold + "' a '" +
                            lentradazip.FileName + "'");
                        lrenombrado = true;
                        break;
                    }
                }
            }
            if (lrenombrado)
            {
                if (!lzip.WriteZip())
                {
                    Console.WriteLine("Error al guardar cambios en fichero zip : " + lzip.LastErrorText);
                    break;
                }
            }
            //ahora añadimos fichero especificado al fichero zip
            if (!lzip.AppendOneFileOrDir(pFichAñadirAZip,false))
            {
                //error
                Console.WriteLine("Error al añadir fichero '" + pFichAñadirAZip + "' al fichero zip :" +
                    lzip.LastErrorText);
                break;
            }
            Console.WriteLine("Añadido a zip fichero '" + pFichAñadirAZip + "'");
            if (!lzip.WriteZip())
            {
                Console.WriteLine("Error al guardar cambios en fichero zip : " + lzip.LastErrorText);
                break;
            }
            lTempString = System.IO.Path.GetFileName(pFichAñadirAZip);
            lentradazip = lzip.GetEntryByName(lTempString);
            if (!lzip.LastMethodSuccess)
            {
                Console.WriteLine("Error interno, no encontrado fichero '" + lTempString + 
                    "' en fichero zip '" +
                    prutazip + "', error :" + lzip.LastErrorText);
                break;
            }
            lold = lentradazip.FileName;
            if (lDirDeNombre.Length > 0)
                lTempString = lDirDeNombre + 
                     System.IO.Path.DirectorySeparatorChar;
            else
                lTempString = string.Empty;
            lentradazip.FileName = lTempString + 
                   pNombreEnZipFicheroAñadido;
            if (!lentradazip.LastMethodSuccess)
            {
                Console.WriteLine("Error al renombrar entrada de zip : " +                                 lentradazip.LastErrorText);
                break;
            }
            Console.WriteLine("Renombrada entrada de zip de '" + lold + "' a '" +
                lentradazip.FileName + "'");
            Console.WriteLine("Guardando y cerrando fichero zip...");
            if (!lzip.WriteZipAndClose())
            {
                Console.WriteLine("Error al guardar fichero zip : " + lzip.LastErrorText);
                break;
            }
            Console.WriteLine("Guardado y cerrado");
            lzip.Dispose();
            lzip = null;
            lValorRetorno = true;
        } while (false);
    }
    catch (Exception e)
    {
        System.Reflection.MethodBase lMethodBase;

        lMethodBase = System.Reflection.MethodBase.GetCurrentMethod();
        Console.WriteLine("En " + lMethodBase.DeclaringType.Name + " , " + lMethodBase.Name +
            " : " + e.ToString());
        lValorRetorno = false;
    }
    finally
    {
        if (lzip!=null)
        {
            lzip.CloseZip();
            lzip.Dispose();
            lzip= null;
        }
    }
    return lValorRetorno;
}

I can extract correctly with no error the new entry and the renamed entry. If I open that zip file with winrar it doesn't say anything, it works with no problem. Another extrange thing is that if i open the zip file, rename one entry, add a new file, rename that new entry and then save the zip file it needs a minute or more to save the zip file. If i save the zip file after rename the entry, after adding new file and after the last renaming, it needs only one or two seconds to save the file. In that code I save the zip file after a change (rename entry, add new file, and rename new entry).

asked Oct 05 at 06:01

david's gravatar image

david
1

Be the first one to answer this question!
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or __italic__
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×98
×51
×34
×4

Asked: Oct 05 at 06:01

Seen: 67 times

Last updated: Oct 05 at 06:01

powered by OSQA