bmx-ng / archive.mod

Archives!
BSD 2-Clause "Simplified" License
3 stars 1 forks source link

Extracting files with their default date & time #6

Open GIN-X44 opened 1 year ago

GIN-X44 commented 1 year ago

Hello, how can i extract the files with their default time and date from the zip file?

For example, i want to extract the mymovie.mp4 that made in Dec 12, 2019 at 5:15 am from the zip file... how could i do extract the mp4 file without using a write new stream like ra.DataStream()??

GWRon commented 1 year ago

As it is up to you on "how" you store the unarchived data, it will be also up to you to modify the file time of the created file (the file you just unpacked).

GWRon commented 1 year ago

brl.filesystem offers what you want:

Function SetFileTime( path:String, time:Long, timeType:Int=FILETIME_MODIFIED)
    FixPath path
    If MaxIO.ioInitialized Then
        ' Not available
    Else
        Select timetype
            Case FILETIME_MODIFIED
                utime_(path, timeType, time)
            Case FILETIME_ACCESSED
                utime_(path, timeType, time)
        End Select
    End If
End Function

The examples for each archive-format contain this:

Local entry:TArchiveEntry = New TArchiveEntry

Local ra:TReadArchive = New TReadArchive
ra.SetFormat(EArchiveFormat.ZIP)
ra.Open("data.zip")

While ra.ReadNextHeader(entry) = ARCHIVE_OK
    Print "File : " + entry.Pathname()
    Print "Size : " + entry.Size()
    Print "Type : " + entry.FileType().ToString()
    Local s:String = LoadText(ra.DataStream())
    Print "String size   : " + s.Length
    Print "First n chars : " + s[0..17]
    Print
Wend

This TArchiveEntry is defined in archive.mod/core.mod/core.bmx. It has methods like:

    Rem
    bbdoc: Returns the entry birth time, if set.
    End Rem
    Method BirthTime:Long()

    Rem
    bbdoc: 
    End Rem
    Method BirthTimeIsSet:Int()

    Rem
    bbdoc: Returns the entry creation time, if set.
    End Rem
    Method CreationTime:Long()

    Rem
    bbdoc: Returns #True if the creation time is set.
    End Rem
    Method CreationTimeIsSet:Int()

dunno if one of these is useful for you. For "modifiedtime" I only saw a setter (for now)

GWRon commented 1 year ago

I added a Getter for "ModifiedTime" but it says "0" as it does for all other values in "zip.mod/example_01.bmx"

glue.c:

BBInt64 bmx_libarchive_archive_entry_mtime(struct archive_entry * entry) {
    return archive_entry_mtime(entry);
}

core.bmx: TType TArchiveEntry

    Rem
    bbdoc: Returns the entries modified time, if set.
    End Rem
    Method ModifiedTime:Long()
        return bmx_libarchive_archive_entry_mtime(entryPtr)
    End Method
[ 88%] Processing:example_01.bmx
[ 94%] Compiling:example_01.bmx.gui.release.linux.x64.c
[100%] Linking:example_01
Executing:example_01
File : files/testdata.txt
Size : 67
Type : File
ModifiedTime : 1643357849
AccessTime : 0
Birthtime : 0
CreationTime : 0
String size   : 67
First n chars : This is some data

Archiver thinks it is from january 2022: image

So ... numbers for "Modifiedtime" work.

GWRon commented 1 year ago

Seems there is some confusion in the archive.mod-assumptions:

    Rem
    bbdoc: Returns the entry creation time, if set.
    End Rem
    Method CreationTime:Long()
        return bmx_libarchive_archive_entry_ctime(entryPtr)
    End Method

"ctime" is not the creation time - creation time is "birthtime".

These functions create and manipulate the time fields in an archive_entry. Supported time fields are atime (access time), birthtime (creation time), ctime (last time an inode property was changed) and mtime (modification time).

source: https://nxmnpg.lemoda.net/3/archive_entry_mtime

GWRon commented 1 year ago

Once Brucey added the modified-time getter it should be breeze:

GIN-X44 commented 1 year ago

Thank you so much GWRon for giving time to answer my questions. 🙏 And can you give me a proper example of how to extract a file with their original date&time... with those methods?

GIN-X44 commented 1 year ago

Hello Bruce, can you please add more bmx examples in ’archive.mod/zip.mod/examples/’ Thanks.