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.
176 lines (175 loc) • 4.25 kB
JavaScript
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __decorateClass = (decorators, target, key, kind) => {
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
for (var i = decorators.length - 1, decorator; i >= 0; i--)
if (decorator = decorators[i])
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
if (kind && result) __defProp(target, key, result);
return result;
};
import { Expose, Transform } from "class-transformer";
import ArchiveEntry from "../files/archives/archiveEntry.js";
import File from "../files/file.js";
const _ROM = 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("\\", "/");
}
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 await 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 await 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()}`;
}
};
__decorateClass([
Expose()
], _ROM.prototype, "name", 2);
__decorateClass([
Expose(),
Transform(({ value }) => {
if (typeof value === "number") {
return value;
}
if (typeof value === "string") {
return Number.parseInt(value);
}
return 0;
})
], _ROM.prototype, "size", 2);
__decorateClass([
Expose({ name: "crc" }),
Transform(
({ value }) => value?.toLowerCase().replace(/^0x/, "").padStart(8, "0")
)
], _ROM.prototype, "crc32", 2);
__decorateClass([
Expose(),
Transform(
({ value }) => value?.toLowerCase().replace(/^0x/, "").padStart(32, "0")
)
], _ROM.prototype, "md5", 2);
__decorateClass([
Expose(),
Transform(
({ value }) => value?.toLowerCase().replace(/^0x/, "").padStart(40, "0")
)
], _ROM.prototype, "sha1", 2);
__decorateClass([
Expose(),
Transform(
({ value }) => value?.toLowerCase().replace(/^0x/, "").padStart(64, "0")
)
], _ROM.prototype, "sha256", 2);
__decorateClass([
Expose()
], _ROM.prototype, "status", 2);
__decorateClass([
Expose()
], _ROM.prototype, "merge", 2);
__decorateClass([
Expose()
], _ROM.prototype, "bios", 2);
let ROM = _ROM;
export {
ROM as default
};
//# sourceMappingURL=rom.js.map