partial autodownload rewrite
* own source file for autodownload * use cleaned up zip functions * use new http get function (no more curl) * enforce strict file naming rules and file size limits * ping all package servers on every game start to determine ping times * support media file update lists (also kept on package servers) * allow users to manually prioritise package servers * automatically select server with newest media file revision new or changed commands: addpckserver hostname [priority] Adds a host name to the list of package servers. If a priority is given, it influences the sorting of servers. Servers with higher priority are queried first. If servers have the same priority, they are sorted by ping. Default priority is zero. getpackageserver Returns a table with four columns of all configured package servers. The columns are: host name, priority, ping and resolved. "resolved" is a flag, indicating, if the server answered the ping during game start. removed cubescript idents: sortpckservers gamestarts DOCREF addpckserver getpckserver
This commit is contained in:
@@ -191,169 +191,6 @@ static bool readlocalfileheader(stream *f, ziplocalfileheader &h, uint offset)
|
||||
return true;
|
||||
}
|
||||
|
||||
#if 0
|
||||
ziparchive *findzip(const char *name)
|
||||
{
|
||||
loopv(archives) if(!strcmp(name, archives[i]->name)) return archives[i];
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static bool checkprefix(vector<zipfile> &files, const char *prefix, int prefixlen)
|
||||
{
|
||||
loopv(files)
|
||||
{
|
||||
if(!strncmp(files[i].name, prefix, prefixlen)) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool extractzipfile(ziparchive *a, zipfile *f, const char *name);
|
||||
|
||||
bool fitspackage(char *filename, int type)
|
||||
{
|
||||
if(strchr(filename, ' ')) return false; // refuse all filenames with spaces
|
||||
char *extension = strrchr(filename, '.');
|
||||
if(!extension) return false;
|
||||
++extension;
|
||||
switch(type)
|
||||
{
|
||||
case PCK_MAPMODEL: return !strcmp(extension, "md2") || !strcmp(extension, "md3")
|
||||
|| !strcmp(extension, "cfg") || !strcmp(extension, "txt")
|
||||
|| !strcmp(extension, "jpg") || !strcmp(extension, "png");
|
||||
case PCK_MAP: return !strcmp(extension, "cgz") || !strcmp(extension, "cfg");
|
||||
case PCK_SKYBOX: return !strcmp(extension, "jpg") || !strcmp(extension, "png");
|
||||
default: return true;
|
||||
}
|
||||
}
|
||||
|
||||
static void mountzip(ziparchive &arch, vector<zipfile> &files, const char *mountdir, const char *stripdir, bool extract)
|
||||
{
|
||||
string packagesdir = "packages/";
|
||||
path(packagesdir);
|
||||
int striplen = stripdir ? (int)strlen(stripdir) : 0;
|
||||
if(arch.type == PCK_MAP) mountdir = "packages/maps/";
|
||||
if(!mountdir && !stripdir) loopv(files)
|
||||
{
|
||||
zipfile &f = files[i];
|
||||
const char *foundpackages = strstr(f.name, packagesdir);
|
||||
if(foundpackages)
|
||||
{
|
||||
if(foundpackages > f.name)
|
||||
{
|
||||
stripdir = f.name;
|
||||
striplen = foundpackages - f.name;
|
||||
}
|
||||
break;
|
||||
}
|
||||
const char *foundcgz = strstr(f.name, ".cgz");
|
||||
if(foundcgz)
|
||||
{
|
||||
const char *cgzdir = foundcgz;
|
||||
while(--cgzdir >= f.name && *cgzdir != PATHDIV);
|
||||
if(cgzdir < f.name || checkprefix(files, f.name, cgzdir + 1 - f.name))
|
||||
{
|
||||
if(cgzdir >= f.name)
|
||||
{
|
||||
stripdir = f.name;
|
||||
striplen = cgzdir + 1 - f.name;
|
||||
}
|
||||
if(!mountdir) mountdir = "packages/maps/";
|
||||
break;
|
||||
}
|
||||
mountdir = "packages/maps/";
|
||||
}
|
||||
}
|
||||
string mdir = "", fname;
|
||||
if(mountdir)
|
||||
{
|
||||
copystring(mdir, mountdir);
|
||||
if(fixpackagedir(mdir) <= 1) mdir[0] = '\0';
|
||||
}
|
||||
loopv(files)
|
||||
{
|
||||
zipfile &f = files[i];
|
||||
formatstring(fname)("%s%s", mdir, striplen && !strncmp(f.name, stripdir, striplen) ? &f.name[striplen] : f.name);
|
||||
if(arch.files.access(fname)) continue;
|
||||
char *mname = newstring(fname);
|
||||
zipfile &mf = arch.files[mname];
|
||||
mf = f;
|
||||
mf.name = mname;
|
||||
|
||||
if(extract)
|
||||
{
|
||||
if(fitspackage(fname, arch.type)) extractzipfile(&arch, &f, fname);
|
||||
else conoutf("\f3could not extract \"%s\" : file extension not supported", fname);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool addzip(const char *name, const char *mount, const char *strip, bool extract, int type)
|
||||
{
|
||||
string pname;
|
||||
copystring(pname, name);
|
||||
path(pname);
|
||||
/*int plen = (int)strlen(pname);
|
||||
if(plen < 4 || !strchr(&pname[plen-4], '.')) concatstring(pname, ".zip");*/
|
||||
|
||||
/*ziparchive *exists = findzip(pname);
|
||||
if(exists)
|
||||
{
|
||||
conoutf("already added zip %s", pname);
|
||||
return true;
|
||||
}*/
|
||||
|
||||
stream *f = openfile(pname, "rb");
|
||||
if(!f)
|
||||
{
|
||||
conoutf("could not open file %s", pname);
|
||||
return false;
|
||||
}
|
||||
zipdirectoryheader h;
|
||||
vector<zipfile> files;
|
||||
if(!findzipdirectory(f, h) || !readzipdirectory(f, h.entries, h.offset, h.size, files))
|
||||
{
|
||||
conoutf("could not read directory in zip %s", pname);
|
||||
delete f;
|
||||
return false;
|
||||
}
|
||||
|
||||
ziparchive *arch = new ziparchive;
|
||||
arch->name = newstring(pname);
|
||||
arch->data = f;
|
||||
arch->type = type;
|
||||
mountzip(*arch, files, mount, strip, extract);
|
||||
if(!extract) archives.add(arch);
|
||||
else delete arch;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool removezip(const char *name)
|
||||
{
|
||||
string pname;
|
||||
copystring(pname, name);
|
||||
path(pname);
|
||||
/*int plen = (int)strlen(pname);
|
||||
if(plen < 4 || !strchr(&pname[plen-4], '.')) concatstring(pname, ".zip");*/
|
||||
ziparchive *exists = findzip(pname);
|
||||
if(!exists)
|
||||
{
|
||||
conoutf("zip %s is not loaded", pname);
|
||||
return false;
|
||||
}
|
||||
if(exists->openfiles)
|
||||
{
|
||||
conoutf("zip %s has open files", pname);
|
||||
return false;
|
||||
}
|
||||
//conoutf("removed zip %s", exists->name);
|
||||
archives.removeobj(exists);
|
||||
delete exists;
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
// stream interface
|
||||
|
||||
struct zipstream : stream
|
||||
|
||||
Reference in New Issue
Block a user