View Single Post
  #1  
Old 04-09-2008, 04:27 AM
xXziroXx xXziroXx is offline
Malorian
xXziroXx's Avatar
Join Date: May 2004
Posts: 5,289
xXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant future
Updage Package (.gupd) updater

Here's a nifty tool that I made that scans all files of a folder, and creates subpackages and sub-subpackages with all the files in.


First thing you want to do, is to give the (npcserver) rights to .gupd files.

PHP Code:
rw levels/ *.gupd 
(remove the space between / and *)

Also add it as a file in folder options.

PHP Code:
file    *.gupd 
Then, create a class named functions_updatepackages and join it to your Control-NPC as well as add a onRCChat function.

functions_updatepackages
PHP Code:
function updateGUPD(typesub)
{
  echo(
"Updating update packages...");
  
// Checks if subpackages exists, if not, creates them and
  // adds them to other packages.
  
temp.file.loadLines("levels/package_" type ".gupd");
  if (!
checkSubPackage("basepackage"type)) addSubPackage("basepackage"type);
  else if (
temp.file.size() == NULLcreateSubPackage(typetype);
  
temp.file.loadLines("levels/" type "_" sub ".gupd");
  if (!
checkSubPackage("package_" typetypesub) || temp.file.size() == NULLcreateSubPackage(typesub);

  
// Loading files in folder
  
temp.folder = (sub == NULL "levels/" type "/*" "levels/" type "/" sub "/*");
  
temp.data.loadFolder(temp.folder0);
  if (
sub == NULLsub type;
  
  
// Clearing old file entries
  
temp.package.loadLines("levels/" type "_" sub ".gupd");
  for (
temp.0temp.<= 6temp.++) temp.newpackage.add(temp.package[temp.i]);
  
temp.newpackage.saveLines("levels/" type "_" sub ".gupd"0);
  
  
// Saving file list
  
temp.package.loadLines("levels/" type "_" sub ".gupd");
  
temp.package[2] = getNewVersion(temp.package[2]);
  for (
temp.filetemp.datatemp.package.add("FILE" SPC (sub == NULL "levels/" type "/" "levels/" type "/" sub "/") @ temp.file);
  
temp.package.saveLines("levels/" type "_" sub ".gupd"0);

  echo(
"Done!");
  
sendToRC("/refreshfilelist");
}

function 
checkSubPackage(packagetypesub)
{
  if (
package == "basepackage"temp.checksum "package_" type;
  else if (
package.starts("package_")) temp.checksum type "_" sub;

  
temp.data.loadLines("levels/" package ".gupd");
  for (
temp.var: temp.data) {
    if (
temp.var == "SUBPACKAGE" SPC temp.checksum ".gupd") return true;
  }
}

function 
addSubPackage(packagetypesub)
{
  if (
package == "basepackage"temp.checksum "package_" type;
  else if (
package.starts("package_")) temp.checksum type "_" sub;

  
temp.data.loadLines("levels/" package ".gupd");
  
temp.data[2] = getNewVersion(temp.data[2]);
  
temp.data.insert((package == "basepackage" 7), "SUBPACKAGE" SPC temp.checksum ".gupd");
  
temp.data.saveLines("levels/" package ".gupd"0);
  
  if (
package == "basepackage"createSubPackage(typetype);
  echo(
"Added sub package \"" type "\" to \"" package "\"");
}

function 
createSubPackage(typesub)
{
  
temp.layout = {
    
"GRPKG001",
    
"NAME" SPC sub.substring(01).upper() @ sub.substring(1),
    
"VERSION 1.00",
    
"PLATFORM any",
    
"DESCRIPTION",
    
sub.substring(01).upper() @ sub.substring(1),
    
"DESCRIPTIONEND"
  
};
  if (
type == sub) {
    
temp.layout.add("USECHECKSUM false");
    
temp.layout.add("PROTECTOVERWRITE false");
    
temp.layout.add("FLAG popupforoptionalpackages=false");
    
temp.layout.saveLines("levels/package_" type ".gupd"0);
    
    echo(
"New sub package created \"package_" type "\"!");
  } else {
    if (
sub == NULLsub type;
    
temp.layout[1] = "NAME" SPC sub.substring(01).upper() @ sub.substring(1);
    
temp.layout[5] = sub.substring(01).upper() @ sub.substring(1);
    
temp.layout.saveLines("levels/" type "_" sub ".gupd"0);
    if (!
checkSubPackage("package_" typetypesub)) addSubPackage("package_" typetypesub);
    
    echo(
"New sub-sub package created \"" type "_" sub "\"!");
  }
}

function 
getNewVersion(arg)
{
  
temp.var = arg.tokenize()[1] + 0.01;
  return 
arg.tokenize()[0SPC temp.var;

Control-NPC
PHP Code:
function onCreated()
{
  
join("functions_updatepackages");
}

function 
onRCChat()
{
  if (
params[0] == "updategupd"updateGUPD(params[1], params[2]);

Then, upload this as a file named basepackage.gupd into your servers levels/ folder:

PHP Code:
GRPKG001
NAME Base Package
VERSION 1.00
PLATFORM any
USECHECKSUM false
PROTECTOVERWRITE false
FLAG popupforoptionalpackages
=false 

To use the tool, I will demonstrate an example. Say that I have 18 images in my levels/images/ folder, then I would say on RC:

/npcupdatepackages images

If I want to update a subfolder such as levels/images/gui/ instead, I'd do:

/npcupdatepackages images gui

Note that only one subfolder is supported at the moment. I haven't tried and use it on a sub-subfolder, but I doubt it would work. Whenever you update a package, it's version gets increased by 0.01, making it download automatically for players that logon (if you use the script provided below).


If you want the packages to be forced upon the client instead of optional, a script such as this could be added into a Weapon NPC:

PHP Code:
//#CLIENTSIDE
function onCreated() printPackage(getBasePackage());

function 
printPackage(package) {
  if (
package.localversion package.versionpackage.update();

  for (
temp.subpackagepackage.packagesprintPackage(temp.subpackage);


As always, please, use the forums reputation system. If you like this script, hey why not give me good rep? If not, pleaaaase give me bad rep. Crits and suggestions welcomed too, of course!
__________________
Follow my work on social media post-Graal:Updated august 2025.

Last edited by xXziroXx; 04-09-2008 at 05:29 PM..
Reply With Quote