Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    ZipFile::CopyInFileInZip() file names

    Cinema 4D SDK
    c++ r21
    2
    2
    458
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • A
      AiMiDi
      last edited by AiMiDi

      I use ZipFile::CopyInFileInZip() to compress the file into a zip package. However, when the file name contains non ASCII characters, the file name is replaced with an underscore. Is there a way to use non ASCII file names in zip without using external libraries?
      04ff1a02-b2f7-402a-8330-eae42c1adaf5-image.png

      AutoAlloc<ZipFile> zf;
        if (zf == nullptr)
          return maxon::OutOfMemoryError(MAXON_SOURCE_LOCATION);
       
        if (!zf->Open(fnZip, false, ZIP_APPEND_CREATE))
          return maxon::UnknownError(MAXON_SOURCE_LOCATION);
      
      Filename fnCopy;
        while (fnCopy.FileSelect(FILESELECTTYPE::ANYTHING, FILESELECT::LOAD, "Select file to add to Zip File"_s))
        {
          zf->CopyInFileInZip(fnCopy, "textures/" + fnCopy.GetFileString());
        }
      

      Thank,
      AiMiDi

      1 Reply Last reply Reply Quote 0
      • M
        m_adam
        last edited by

        Hi @AiMiDi you are using the old ZipFile implementation, instead, you should use the new one from the MAXON API as explained in Archives Manual.

        And here an example of how to copy a file.

        #include "maxon/ioarchivehandler.h"
        
        
        Bool res = false;
        Filename importFilename;
        res = importFilename.FileSelect(FILESELECTTYPE::ANYTHING, FILESELECT::LOAD, "Load"_s);
        if (!res)
        	return maxon::UnknownError(MAXON_SOURCE_LOCATION);
        maxon::Url importUrl = MaxonConvert(importFilename, MAXONCONVERTMODE::READ);
        
        
        Filename zipFilename;
        res = zipFilename.FileSelect(FILESELECTTYPE::ANYTHING, FILESELECT::SAVE, "Save"_s, "zip"_s);
        if (!res)
        	return maxon::UnknownError(MAXON_SOURCE_LOCATION);
        
        const maxon::WriteArchiveRef zipArchive = maxon::WriteArchiveClasses::Zip().Create() iferr_return;
        zipArchive.Open(MaxonConvert(zipFilename, MAXONCONVERTMODE::WRITE), false) iferr_return;
        zipArchive.SetCompressionLevel(2) iferr_return;
        zipArchive.CopyFile(importUrl, importUrl.GetName()) iferr_return;
        zipArchive.Close() iferr_return;
        

        This new Maxon API support correctly non ASCII character.
        Cheers,
        Maxime.

        MAXON SDK Specialist

        Development Blog, MAXON Registered Developer

        1 Reply Last reply Reply Quote 1
        • First post
          Last post