igir
Version:
🕹 A zero-setup ROM collection manager that sorts, filters, extracts or archives, patches, and reports on collections of any size on any OS.
165 lines (164 loc) • 4.98 kB
JavaScript
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
import { Expose, Transform } from 'class-transformer';
import ArchiveEntry from '../files/archives/archiveEntry.js';
import File from '../files/file.js';
/**
* @see http://www.logiqx.com/DatFAQs/CMPro.php
*/
export default class ROM {
name;
size;
crc32;
md5;
sha1;
sha256;
status;
merge;
bios;
constructor(props) {
this.name = props?.name ?? '';
this.size = props?.size ?? 0;
this.crc32 = props?.crc32?.toLowerCase().replace(/^0x/, '').padStart(8, '0');
this.md5 = props?.md5?.toLowerCase().replace(/^0x/, '').padStart(32, '0');
this.sha1 = props?.sha1?.toLowerCase().replace(/^0x/, '').padStart(40, '0');
this.sha256 = props?.sha256?.toLowerCase().replace(/^0x/, '').padStart(64, '0');
this.status = props?.status;
this.merge = props?.merge;
this.bios = props?.bios;
}
/**
* Create an XML object, to be used by the owning {@link Game}.
*/
toXmlDatObj() {
return {
$: {
name: this.getName(),
size: this.getSize(),
crc: this.getCrc32(),
md5: this.getMd5(),
sha1: this.getSha1(),
sha256: this.getSha256(),
status: this.getStatus(),
},
};
}
// Property getters
getName() {
return this.name.replaceAll(/[\\/]/g, '/');
}
getSize() {
return this.size;
}
getCrc32() {
return this.crc32;
}
getMd5() {
return this.md5;
}
getSha1() {
return this.sha1;
}
getSha256() {
return this.sha256;
}
getStatus() {
return this.status;
}
getMerge() {
return this.merge;
}
getBios() {
return this.bios;
}
/**
* Return a new copy of this {@link ROM} with a different name.
*/
withName(name) {
if (name === this.name) {
return this;
}
return new ROM({ ...this, name });
}
/**
* Turn this {@link ROM} into a non-existent {@link File}.
*/
async toFile() {
return File.fileOf({
...this,
filePath: this.getName(),
size: this.getSize(),
});
}
/**
* Turn this {@link ROM} into a non-existent {@link ArchiveEntry}, given a {@link Archive}.
*/
async toArchiveEntry(archive) {
return ArchiveEntry.entryOf({
...this,
archive,
entryPath: this.getName(),
size: this.getSize(),
});
}
/**
****************************
*
* Pseudo Built-Ins *
*
****************************
*/
/**
* A string hash code to uniquely identify this {@link ROM}.
*/
hashCode() {
return (this.getSha256() ?? this.getSha1() ?? this.getMd5() ?? `${this.getCrc32()}|${this.getSize()}`);
}
}
__decorate([
Expose(),
__metadata("design:type", String)
], ROM.prototype, "name", void 0);
__decorate([
Expose(),
__metadata("design:type", Number)
], ROM.prototype, "size", void 0);
__decorate([
Expose({ name: 'crc' }),
Transform(({ value }) => value?.toLowerCase().replace(/^0x/, '').padStart(8, '0')),
__metadata("design:type", String)
], ROM.prototype, "crc32", void 0);
__decorate([
Expose(),
Transform(({ value }) => value?.toLowerCase().replace(/^0x/, '').padStart(32, '0')),
__metadata("design:type", String)
], ROM.prototype, "md5", void 0);
__decorate([
Expose(),
Transform(({ value }) => value?.toLowerCase().replace(/^0x/, '').padStart(40, '0')),
__metadata("design:type", String)
], ROM.prototype, "sha1", void 0);
__decorate([
Expose(),
Transform(({ value }) => value?.toLowerCase().replace(/^0x/, '').padStart(64, '0')),
__metadata("design:type", String)
], ROM.prototype, "sha256", void 0);
__decorate([
Expose(),
__metadata("design:type", String)
], ROM.prototype, "status", void 0);
__decorate([
Expose(),
__metadata("design:type", String)
], ROM.prototype, "merge", void 0);
__decorate([
Expose(),
__metadata("design:type", String)
], ROM.prototype, "bios", void 0);