Archived Forum Post

Index of archived forum posts

Question:

chilkat.zip .net 4.0, renaming an entry and adding new file to zip . 7-zip says warnings : headers error

Oct 05 '17 at 06:01

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).