Open GIN-X44 opened 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).
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)
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:
So ... numbers for "Modifiedtime" work.
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).
Once Brucey added the modified-time getter it should be breeze:
SetFileTime( pathToThatFile, mtimeYouStored, FILETIME_MODIFIED)
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?
Hello Bruce, can you please add more bmx examples in ’archive.mod/zip.mod/examples/’ Thanks.
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()??