Semi-Unique id for folder/zip and zipping folder.

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
BorhilIan
Prole
Posts: 38
Joined: Wed Mar 15, 2017 6:46 am

Semi-Unique id for folder/zip and zipping folder.

Post by BorhilIan »

Firstly I am looking for a way to generate a unique identifier from a folder and zip file separately. If the contents of the folder and the zip file match the same identifier should be returned. This will be used to ensure the server and clients have matching content and as such can play together.

Secondly I am looking for a way to zip a folders contents from within lua. If for example the servers 'content' folder is different from its 'content.zip' I would like to automatically generate a new one from the folder.
User avatar
raidho36
Party member
Posts: 2063
Joined: Mon Jun 17, 2013 12:00 pm

Re: Semi-Unique id for folder/zip and zipping folder.

Post by raidho36 »

Simply have the config file carry a version variable, and download and optionally unpack the archive from the server if it's different. Actual install validation is not necessary, it usually just won't work and worst case scenario it'll glitch, either way that is solved by doing new install.

ID-wise, what you're looking for is some sort of hash function, that you run over all of your files' contents. Naturally I don't recommend using cryptographic hashes because it'll take forever to hash all of your files. A simple checksum often would suffice, collisions should be rare if any, plus you can always produce a different hash by adding a dumbbell file with arbitrary contents.
BorhilIan
Prole
Posts: 38
Joined: Wed Mar 15, 2017 6:46 am

Re: Semi-Unique id for folder/zip and zipping folder.

Post by BorhilIan »

The config file method would not be the ideal solution since server to server content will vary greatly. Not only that but clients could just falsify there local data easily creating a method for cheating. The zip files which will be sent/received will ideally also be encrypted to decrease the average script kiddy from cheating.

Also I don't need something as complex as a hash, a crc or the like would suffice I'm just not familiar with performing such a thing from lua.
User avatar
raidho36
Party member
Posts: 2063
Joined: Mon Jun 17, 2013 12:00 pm

Re: Semi-Unique id for folder/zip and zipping folder.

Post by raidho36 »

You read a file, run a hash function over its contents, close a file. Rinse and repeat. Checksum would take byte's value as integer and add it to accumulator variable, which is never reset and therefore keeps byte value sum of all files, which you trivially can check against.
BorhilIan
Prole
Posts: 38
Joined: Wed Mar 15, 2017 6:46 am

Re: Semi-Unique id for folder/zip and zipping folder.

Post by BorhilIan »

Ah so a checksum is just a sort of short number value which presumably iterates within a set range looping back around when it gets to large.
User avatar
raidho36
Party member
Posts: 2063
Joined: Mon Jun 17, 2013 12:00 pm

Re: Semi-Unique id for folder/zip and zipping folder.

Post by raidho36 »

It doesn't matter. It just have to have enough range not to cause collisions between versions.
BorhilIan
Prole
Posts: 38
Joined: Wed Mar 15, 2017 6:46 am

Re: Semi-Unique id for folder/zip and zipping folder.

Post by BorhilIan »

I see how I could implement such a thing and I can simply mount the zip file to a dummy path to check it. That's the more important thing resolves, now a way to automatically zip a folder through lua would certainly improve my project though isn't as important.

EDIT: I'll post a working script for whatever it is I decide on for others to use in the 'Libraries and Tools' forum.
User avatar
raidho36
Party member
Posts: 2063
Joined: Mon Jun 17, 2013 12:00 pm

Re: Semi-Unique id for folder/zip and zipping folder.

Post by raidho36 »

Your best bet is to use a command line zipping tool. Hooking up compression dynamic link library is not easy nor straightforward.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot], Google [Bot] and 51 guests