Page 1 of 1

Stumped again...Easy file packager process?

Posted: Thu May 31, 2007 6:47 am
by DARKGirl
Hello everyone

So I am at the point in my application where I have to implement the save/load feature. The creating a file and writing it to the disc is easy. Its just the way my application handles projects. You see, because only one level or world can be loaded and worked at a time in my project, each level and world have to be saved individually. I chose to do it this way because it would be the easiest way. The problem is that I need a way to combine all of these files into a project file that allows the file names to be maintained. I would use the packer functions, but they remove the file name and they just put the data one after another. I looked at the purezip feature, etc and that doesnt seem to be what I need either. Maybe I am thinking about this too hard, but I think what I want is a way to write directly to a zip or binary file and access the data by file name instead of memory address.

I hope that makes sense.

Re: Stumped again...Easy file packager process?

Posted: Thu May 31, 2007 9:33 am
by CherokeeStalker
Simple . . . create a list of the files to be added as a text file, and add that file to the pack first. When you want to extract the files, extract the file list first and read each file name from it.

Posted: Thu May 31, 2007 10:11 am
by DARKGirl
huh you see thats what I thought to do initially, but AlphaSND told me that when you add files to the pack list, the filenames are lost.

Posted: Thu May 31, 2007 10:25 am
by Num3
What i do when i need to store filenames using the Packer routines is this:

[Start PackFile]
[odd entry] packed string of filename (use @filename_variable.s)
[even entry] packed file
[odd entry] packed string of filename 1
[even entry] packed file 1
[odd entry] packed string of filename 2
[even entry] packed file 2
[End PackFile]

I'll post a small snipet tonight once i get home...

When i need to unpack files, i know that the odd entries are the filename and odd entry + 1 is the corresponding file.

Posted: Thu May 31, 2007 10:48 am
by Inf0Byt3
Hi... Just posted a similar solution yesterday in this thread :).

http://www.purebasic.fr/english/viewtopic.php?t=27312

Posted: Thu May 31, 2007 10:51 am
by DARKGirl
well you see that kind of defeats the purpose because I was hoping to access the flies by file name instead of memory address...

Posted: Thu May 31, 2007 10:56 am
by Num3
Well you can always create several extensions for each type...

myworld.aaa
myworld.bbb
myworld.ccc
mysecondworld.aaa
mysecondworld.ccc
mysecondworld.ddd

Posted: Thu May 31, 2007 11:13 am
by DARKGirl
lol what are you talking about? How would that resolve my issue? Do you remember that oooolllld application called packager? Do you think that would work?

Posted: Thu May 31, 2007 11:58 am
by Dare
Strikes me that gnozal's zip lib is exactly what you want.

Why not use that?

There are also on these boards some various indexed packed and cab file handling (sources) by various peeps.

I have an old one somewhere I could try to find and make PB4 compliant if you want, but a search here might be faster for you.


Edit:

Also, I am not 100% sure what you mean by not wanting to access by memory. Do you mean:

A: You want to do something like mem = getMyFile(name)
or
B: You don't want to use memory allocations at all?

Posted: Thu May 31, 2007 12:14 pm
by CherokeeStalker
[quote="DARKGirl"]huh you see thats what I thought to do initially, but AlphaSND told me that when you add files to the pack list, the filenames are lost.[/quote]
Example:

NewList file.s()
FileCount.l = 0
ED = ExamineDirectory(#PB_Any,"C:\Program Files\WinZip","*.*")
Repeat
NDE = NextDirectoryEntry(ED)
DET = DirectoryEntryType(ED)
DEN.s = DirectoryEntryName(ED)
If DET = #PB_DirectoryEntry_File
x.s = "C:\Program Files\WinZip" + DEN.s
AddElement(file())
file() = x.s
EndIf
Until NDE = 0
FinishDirectory(ED)
FileCount.l = CountList(file())-1
SortList(file(),2,0,FileCount.l)

CreateFile(0,"C:\___")
WriteStringN(0,Str(FileCount))
c.s = RSet(Str(FileCount.l),5,"0")
For i = 0 To FileCount.l - 1
SelectElement(file(),i)
x.s = file()
WriteStringN(0,file())
Next
CloseFile(0)
Delay(250)
CreatePack("C:\WinZip.pack")
AddPackFile("C:\___",9)
Delay(250)
ReadFile(1,"C:\___")
x.s = ReadString(1)
n = Val(x)
For i = 1 To n
x.s = ReadString(1)
AddPackFile(x.s,9)
Next
ClosePack()
Delay(250)
MessageRequester("Status","Done",64)

You should be able to work out how to unpack with filenames from above code !

Posted: Thu May 31, 2007 9:17 pm
by DARKGirl
Yes I know I sound totally confusing, maybe I can give you an example of how I envision what sort of pack file I am looking for:

[Beginning of Pack File]
Pack File Header.pref
World1.pref
World2.pref
World3.pref
1-1.pref
1-2.pref
1-3.pref
1-4.pref
1-5.pref
2-1.pref
2-2.pref
2-3.pref
2-4.pref
2-5.pref
3-1.pref
3-2.pref
3-3.pref
3-4.pref
3-5.pref
3-6.pref
World1.dat
World2.dat
World3.dat
1-1.dat
1-2.dat
1-3.dat
1-4.dat
1-5.dat
2-1.dat
2-2.dat
2-3.dat
2-4.dat
2-5.dat
3-1.dat
3-2.dat
3-3.dat
3-4.dat
3-5.dat
3-6.dat
[End of Pack File]

Lets see, all the pref files are the headers of the specific levels. They contain all the stuff that makes the worlds and levels work. The dat files contain only sprite positions. I want to be able to create/delete files directly from the pack file. I want to be able to access them by their file name instead of their position in the file! I want to be able to read the files using regular file opening and read commands such as read word, read byte, read long and read string.

Does that make more sense?

Posted: Thu May 31, 2007 9:24 pm
by byo
Why not extract them to some temp folder (far from the user's sight) and then acting on them?

Posted: Thu May 31, 2007 10:09 pm
by DARKGirl
using a temp folder is exactly what I am trying to avoid doing. Do cab files offer what I am looking for?