Skip to content

Commit

Permalink
Update to WebMinidisc 1.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
asivery committed Aug 18, 2024
1 parent 189bb10 commit f6cf774
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 20 deletions.
2 changes: 1 addition & 1 deletion build-renderer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ rm -rf webminidisc

git clone https://github.com/asivery/webminidisc
cd webminidisc
npm i --legacy-peer-deps
npm i
PUBLIC_URL="sandbox://" npm run build; rm -rf ../renderer; cp -rv dist ../renderer
cd ..

36 changes: 21 additions & 15 deletions src/wmd/original/services/interfaces/himd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,24 @@ export class HiMDSpec implements MinidiscSpec {
constructor(private unrestricted: boolean = false) {
this.specName = unrestricted ? 'HiMD_full' : 'HiMD_restricted';
}
public readonly availableFormats: RecordingCodec[] = this.unrestricted
public availableFormats: RecordingCodec[] = this.unrestricted
? [
{ codec: 'A3+', availableBitrates: [352, 256, 192, 64, 48], defaultBitrate: 256 },
{ codec: 'AT3', availableBitrates: [132, 105, 66], defaultBitrate: 132 },
{ codec: 'MP3', availableBitrates: [320, 256, 192, 128, 96, 64], defaultBitrate: 192 },
{ codec: 'PCM' },
]
: [{ codec: 'MP3', availableBitrates: [320, 256, 192, 128, 96, 64], defaultBitrate: 192 }];
public readonly defaultFormat: Codec = this.unrestricted ? { codec: 'A3+', bitrate: 256 } : { codec: 'MP3', bitrate: 192 };
public readonly specName: string;
public defaultFormat: Codec = this.unrestricted ? { codec: 'A3+', bitrate: 256 } : { codec: 'MP3', bitrate: 192 };
public specName: string;

public static derive(name: string, formats: RecordingCodec[], defaultFormat: Codec) {
const instance = new HiMDSpec(true);
instance.specName = name;
instance.defaultFormat = defaultFormat;
instance.availableFormats = formats;
return instance;
}

getRemainingCharactersForTitles(disc: Disc): { halfWidth: number; fullWidth: number } {
const ALL_CHARACTERS = 0x1000 * 14;
Expand Down Expand Up @@ -299,20 +307,11 @@ export class HiMDRestrictedService extends NetMDService {
}

async deleteTracks(indexes: number[]): Promise<void> {
window.alert('Not yet available in HiMD');
window.alert('Unavailable in restricted mode');
}

async wipeDisc(): Promise<void> {
const space = await this.fsDriver!.getTotalSpace();
// Recreate FS only on the 1GB discs
try{
await this.himd!.wipe(space > 500000000);
this.dropCachedContentList();
}catch(ex){
console.log(ex);
window.alert('Not yet available in HiMD');
return;
}
window.alert('Unavailable in restricted mode');
}

async moveTrack(src: number, dst: number, updateGroups?: boolean) {
Expand Down Expand Up @@ -623,6 +622,13 @@ export class HiMDFullService extends HiMDRestrictedService {
}

isDeviceConnected(device: USBDevice){
return this.fsDriver!.driver.isDeviceConnected(device);
return this.fsDriver?.driver.isDeviceConnected(device) ?? false;
}

async wipeDisc(): Promise<void> {
const space = await this.fsDriver!.getTotalSpace();
// Recreate FS only on the 1GB discs
await this.himd!.wipe(space > 500000000);
this.dropCachedContentList();
}
}
18 changes: 17 additions & 1 deletion src/wmd/original/services/interfaces/netmd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ import {
MonoSPUpload,
} from 'netmd-exploits';
import netmdExploits from 'netmd-exploits';
import netmdTocmanip from 'netmd-tocmanip';
import { HiMDCodecName } from 'himd-js';
const Worker = null as any;

Expand All @@ -69,6 +70,7 @@ export enum Capability {
factoryMode,
himdTitles,
fullWidthSupport,
nativeMonoUpload,

requiresManualFlush,
}
Expand Down Expand Up @@ -427,6 +429,13 @@ export class NetMDUSBService extends NetMDService {
basic.push(Capability.factoryMode);
}

const deviceFlags = this.netmdInterface?.netMd.getDeviceFlags();
if(deviceFlags) {
if(deviceFlags.nativeMonoUpload) {
basic.push(Capability.nativeMonoUpload);
}
}

try {
const flags = (await this.netmdInterface?.getDiscFlags()) ?? 0;
if ((flags & DiscFlag.writeProtected) === 0) {
Expand Down Expand Up @@ -786,7 +795,7 @@ export class NetMDUSBService extends NetMDService {
}

isDeviceConnected(device: USBDevice){
return this.netmdInterface!.netMd.isDeviceConnected(device);
return this.netmdInterface?.netMd.isDeviceConnected(device) ?? false;
}
}

Expand Down Expand Up @@ -819,6 +828,13 @@ class NetMDFactoryUSBService implements NetMDFactoryService {
if ((window as any).interface) {
Object.defineProperty(window, 'exploitStateManager', { value: this.exploitStateManager, configurable: true });
Object.defineProperty(window, 'exploits', { value: netmdExploits, configurable: true });
Object.defineProperty(window, 'tocmanip', { value: netmdTocmanip, configurable: true });
Object.defineProperty(window, 'getToC', { value: async () => {
let sector0 = await this.readUTOCSector(0);
let sector1 = await this.readUTOCSector(1);
let sector2 = await this.readUTOCSector(2);
return netmdTocmanip.parseTOC(sector0, sector1, sector2);
} , configurable: true });
}

return capabilities;
Expand Down
12 changes: 9 additions & 3 deletions src/wmd/translations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import path from 'path';
import { Worker } from 'worker_threads';
import { makeAsyncWorker } from "himd-js/dist/node-crypto-worker";
import { DevicesIds, UMSCHiMDFilesystem } from "himd-js";
import { WebUSBDevice, findByIds } from 'usb';
import { WebUSBDevice, findByIds, usb } from 'usb';
import { unmountAll } from "../unmount-drives";

export class EWMDNetMD extends NetMDUSBService {
Expand All @@ -19,14 +19,19 @@ export class EWMDNetMD extends NetMDUSBService {

export class EWMDHiMD extends HiMDFullService {
public fsDriver?: UMSCHiMDFilesystem;
public deviceConnectedCallback?: (legacy: usb.Device, webusb: WebUSBDevice) => {}

override getWorker(): any[] {
return [new Worker(
path.join(__dirname, '..', '..', 'node_modules', 'himd-js', 'dist', 'node-crypto-worker.js')
), makeAsyncWorker];
}

async pair() {
this.bypassFSCoherencyChecks = process.env.EWMD_HIMD_BYPASS_COHERENCY_CHECK === 'true';
this.bypassFSCoherencyChecks = true; // process.env.EWMD_HIMD_BYPASS_COHERENCY_CHECK === 'true';
if(this.bypassFSCoherencyChecks) {
console.log("Warning: All FAT filesystem coherency checks are bypassed!\nThis might cause data corruption!")
}
let legacyDevice, vendorId, deviceId;
for({ vendorId, deviceId } of DevicesIds){
legacyDevice = findByIds(vendorId, deviceId);
Expand All @@ -48,6 +53,7 @@ export class EWMDHiMD extends HiMDFullService {
}
const webUsbDevice = await WebUSBDevice.createInstance(legacyDevice);
await webUsbDevice.open();
this.deviceConnectedCallback?.(legacyDevice, webUsbDevice);
this.fsDriver = new UMSCHiMDFilesystem(webUsbDevice);
return true;
}
Expand Down

0 comments on commit f6cf774

Please sign in to comment.