Skip to content
Snippets Groups Projects
Commit 275e7f33 authored by Rob Swindell's avatar Rob Swindell :speech_balloon:
Browse files

Replace the guts of OldFileBase to make it v3.19 compatible

This appears to be enough to make hatchit.js work again and file
listings in webv4 (not sure beyond that).

This file is now just an unnecessary shim and should go away when
the consumers (hatchit and webv4) no longer need it.

I did not "port" support for the file properties:
- base
- ext
- datoffset
- opencount
- misc
- altpath

They don't appear to be needed.
parent e0870d89
No related branches found
No related tags found
No related merge requests found
/* /*
* Pass a directory code and get back an array of objects for the files * Pass a directory code and get back an array of objects for the files
* in the specified directory. * in the specified directory.
*
* This is file is now just an unnecessary shim for the new FileBase class
* and should be deprecated.
* *
* Similar to filedir.js. * Similar to filedir.js.
* *
...@@ -8,122 +11,46 @@ ...@@ -8,122 +11,46 @@
* *
* base: Base filename. * base: Base filename.
* ext: Filename extension. * ext: Filename extension.
* datoffset: Offset in .dat file of file data. * datoffset: Offset in .dat file of file data. - N/A
* uldate: Date uploaded * uldate: Date uploaded
* dldate: Date downloaded(?) * dldate: Date downloaded(?)
* credits: Number of credits(?) * credits: Number of credits(?)
* desc: Short description (58 chars max) * desc: Short description (58 chars max)
* uploader: Name of user that uploaded the file. * uploader: Name of user that uploaded the file.
* downloaded: Number of times the file has been downloaded. * downloaded: Number of times the file has been downloaded.
* opencount: I have no idea what this is. * opencount: I have no idea what this is. - N/A
* misc: Misc flags... see FM_* below. * misc: Misc flags... see FM_* below. - N/A
* anonymous: Anonymous upload * anonymous: Anonymous upload
* altpath: Index into the internal array of alt paths (not visible to JavaScript) * altpath: Index into the internal array of alt paths (not visible to JavaScript) - N/A
* extdesc: May be undefined... extended description. * extdesc: May be undefined... extended description.
* path: Full path to file. Undefined if the file doesn't exist or * path: Full path to file. Undefined if the file doesn't exist or
* is in an alt path (since they're not visible to JS). * is in an alt path (since they're not visible to JS).
*/ */
var FM_EXTDESC = 1;
var FM_ANON = (1<<1);
function OldFileBase(dir) { function OldFileBase(dir) {
var f = new File(format("%s%s.ixb", file_area.dir[dir].data_dir, dir));
var dat = new File(format("%s%s.dat", file_area.dir[dir].data_dir, dir));
var exb = new File(format("%s%s.exb", file_area.dir[dir].data_dir, dir));
var record = null;
var ret = []; var ret = [];
var filebase = new FileBase(dir);
function FileEntry() { if(!filebase.open())
var byte;
function getrec(file, len) {
var ret=file.read(len);
ret = ret.replace(/[\x03\r\n].*$/,'');
return ret;
}
// Read from the IXB file
this.base = f.read(8).replace(/ +$/,'');
this.ext = f.read(3).replace(/ +$/, '');
this.datoffset = f.readBin(2);
byte = f.readBin(1);
this.datoffset |= (byte<<16);
this.uldate = f.readBin(4);
this.dldate = f.readBin(4);
// Read from the DAT file
dat.position = this.datoffset;
this.credits = parseInt(getrec(dat, 9), 10);
this.desc = getrec(dat, 58);
dat.readBin(2); // Should be \r\n
this.uploader = getrec(dat, 25);
dat.read(5); // Padding?
dat.readBin(2); // Should be \r\n
this.downloaded = parseInt(getrec(dat, 5), 10);
dat.readBin(2); // Should be \r\n
this.opencount = parseInt(getrec(dat, 3), 10);
dat.readBin(2); // Should be \r\n
this.misc = getrec(dat, 1);
if (this.misc.length > 0)
this.misc = ascii(this.misc)-32;
else
this.misc = 0;
if (this.misc & FM_ANON)
this.anonymous = true;
else
this.anonymous = false;
this.altpath = parseInt(getrec(dat, 2), 16);
// Read from the EXB file
var exbpos = (this.datoffset / 118) * 512;
if (exb.is_open && (this.misc & FM_EXTDESC)) {
if (exb.length > exbpos) {
exb.position = exbpos;
this.extdesc = exb.read(512).replace(/\x00.*$/, '');
}
}
if (this.altpath > 0 && file_area.alt_paths !== undefined) {
if (file_exists(file_area.alt_paths[this.altpath-1]+this.name))
this.path = fullpath(file_area.alt_paths[this.altpath-1]+this.name);
}
else {
if (file_exists(file_area.dir[dir].path+this.name))
this.path = fullpath(file_area.dir[dir].path+this.name);
}
}
Object.defineProperty(FileEntry.prototype, "name", {
enumerable: true,
get: function() {
return this.ext ? this.base+'.'+this.ext : this.base;
}
});
if(!f.exists)
return ret;
if (!f.open("rb"))
return ret; return ret;
if(!dat.exists) { var file_list = filebase.get_list(FileBase.DETAIL.EXTENDED);
f.close(); for(var i = 0; i < file_list.length; i++) {
log(LOG_DEBUG, "readIxb: Invalid code or "+dat.name+" does not exist."); var file = file_list[i];
return ret; ret.push({
name: file.name,
uldate: file.added,
dldate: file.last_downloaded,
credits: file.cost,
desc: file.desc,
uploader: file.from,
downloaded: file.times_downloaded,
extdesc: file.extdesc,
anonymous: file.anon,
path: filebase.get_path(file.name)
});
} }
if (!dat.open("rb")) {
log(LOG_DEBUG, "readIxb: Unable to open "+dat.name+".");
return ret;
}
exb.open("rb");
for(var i = 0; f.position+1<f.length ; i++)
ret.push(new FileEntry(i));
f.close(); filebase.close();
dat.close();
if (exb.is_open)
exb.close();
return ret; return ret;
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment