PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

Encrypted package file system integrated into PPL.

What if you want to distribute a game or some other program but don't want users to see the content of the files used by this program?

PPL now has a set of functions to implement encrypted file packaging very easily into your projects. The file is encrypted with the key you have specified. There is a limit of 16000 files per package file.

Here is a simple demo on how to use package files:

Code:
// PPL integrate Package file system demo written by Alain Deschenes (c) 2004 ArianeSoft

// Delete the package file first
DeleteFile("c:\\ppl\\pc\\run\\test\\data.pkg");
// Open the package data.pkg
p$ = OpenPackage("c:\\ppl\\pc\\run\\test\\data.pkg", "MyPrivateKey");
// Add the file editor.ppl to the package file.
AddFileToPackage(p$, "c:\\ppl\\editor.ppl");
// Add the file main.ppl to the package file.
AddFileToPackage(p$, "c:\\ppl\\main.ppl");
// Verify if file main.ppl is really part of the package file.
if (PackageFileExists(p$, "main.ppl"))
// Extract the file into a temporary unencrypted file.
fn$ = ExtractFileFromPackage(p$, "main.ppl");
// Load file content to a variable.
s$ = LoadStr(fn$, sz$);
// Delete the temporary file immediately.
DeleteFile(fn$);
// Show file information.
ShowMessage(fn$ + " = " + s$);
end;
// Close package file and write all changes to disk if needed.
ClosePackage(p$);


Hope you guys like it.
PointOfLight · 08 Oct 2004, 15:03 UTC
What? Only 160000 files? How useful will that be :roll: I assume this is available for both versions of PPL.
Oups, 16000 files and not 160000. :wink: Now it really not useful, I will take the feature out! :lol:

Yes it will be in both versions.
PointOfLight · 08 Oct 2004, 15:22 UTC
Man, you did say 16000, didn't you? I seem to be having a lot of trouble reading this morning. Anyway, I feel much better about that number anyway. 160000 would have given me too many options... no focus...
It originally said 160000, I modified it. You have no problems reading, I have problems writing! :lol:
kornalius: Probably a good idea to d isable smilies when posting code - I did that on your orig post.
Yeah, the source formatter, I guess, only process '' and not "". But it's normal, it is a C source formatter after all and not a PPL one.

Here is the latest code demo. I have added two new functions:

- PackageFiles -> returns a list of all files inside the package.

- LoadPackageFile -> Load the specified file in a unencrypted form and return the content.

Code:
// PPL integrate Package file system demo written by Alain Deschenes (c) 2004 ArianeSoft

// Delete the package file first
DeleteFile("c:\\ppl\\pc\\run\\test\\data.pkg");

// Open the package data.pkg
p$ = OpenPackage("c:\\ppl\\pc\\run\\test\\data.pkg", "MyPrivateKey");

// Add the file editor.ppl to the package file.
AddFileToPackage(p$, "c:\\ppl\\editor.ppl");

// Add the file main.ppl to the package file.
AddFileToPackage(p$, "c:\\ppl\\main.ppl");

// Verify if file main.ppl is really part of the package file.
if (PackageFileExists(p$, "main.ppl"))
// Extract the file into a temporary unencrypted file.
fn$ = ExtractFileFromPackage(p$, "main.ppl");
// Load file content to a variable.
s$ = LoadStr(fn$, sz$);
// Delete the temporary file immediately.
DeleteFile(fn$);
// Show file information.
ShowMessage(fn$ + " = " + s$);
end;

// Here is an alternative way for extracting a file from a package.
if (PackageFileExists(p$, "main.ppl"))
// Extract the file into a temporary unencrypted file.
s$ = LoadPackageFile(p$, "main.ppl");
// Show file content.
ShowMessage(s$);
end;

// Get all file names from the package file.
PackageFiles(l$, p$);
// Show each file name one by one.
ForEach(l$)
ShowMessage(l$);
end;
// Close package file and write all changes to disk if needed.
ClosePackage(p$);
By the way, files in package are only encrypted, or archived too?

Archiving package content can be really useful, I think
What do you mean by archiving? Do you mean compressed? If so then I will be adding zlib features real soon to PPL, then I will allow compression on package files.
kornalius wrote:I will be adding zlib features real soon to PPL, then I will allow compression on package files.


Yes, that's what I asked for. Thanks for your work!