Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extracting files with their default date & time #6

Open
GIN-X44 opened this issue Jan 6, 2023 · 7 comments
Open

Extracting files with their default date & time #6

GIN-X44 opened this issue Jan 6, 2023 · 7 comments

Comments

@GIN-X44
Copy link

GIN-X44 commented Jan 6, 2023

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
Copy link
Contributor

GWRon commented Jan 6, 2023

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
Copy link
Contributor

GWRon commented Jan 6, 2023

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
Copy link
Contributor

GWRon commented Jan 6, 2023

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
Copy link
Contributor

GWRon commented Jan 6, 2023

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
Copy link
Contributor

GWRon commented Jan 6, 2023

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

  • extract the file
  • store the mtime / modified time in a variable
  • call SetFileTime( pathToThatFile, mtimeYouStored, FILETIME_MODIFIED)

@GIN-X44
Copy link
Author

GIN-X44 commented Jan 7, 2023

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
Copy link
Author

GIN-X44 commented Jan 8, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants