Skip to content

Commit

Permalink
Moved config to properties
Browse files Browse the repository at this point in the history
  • Loading branch information
JrMasterModelBuilder committed Oct 11, 2023
1 parent c3a964a commit 2edba08
Show file tree
Hide file tree
Showing 9 changed files with 162 additions and 137 deletions.
20 changes: 16 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ const projector = new ProjectorWindows('projector-windows/application.exe');
// Required skeleton.
projector.skeleton = 'skeleton.zip';

// File to create config file with.
projector.configFile = 'config.ini';

// Optional custom icon.
projector.iconFile = 'icon.ico';

Expand Down Expand Up @@ -73,7 +76,7 @@ projector.nestXtrasConfiguration = true;
// Optionally fix Shockwave 3D Xtra InstalledDisplayDrivers reading.
projector.patchShockwave3dInstalledDisplayDriversSize = true;

await projector.withFile('config.ini');
await projector.write();
```

### Mac App
Expand All @@ -86,6 +89,9 @@ const projector = new ProjectorMacApp('projector-macapp/application.app');
// Required skeleton.
projector.skeleton = 'skeleton.zip';

// File to create config file with.
projector.configFile = 'config.ini';

// Optional custom icon.
projector.iconFile = 'icon.icns';

Expand Down Expand Up @@ -124,7 +130,7 @@ projector.nestXtrasContents = true;
// Optionally use Intel-only skeleton.
// projector.intel = true;

await projector.withFile('config.ini');
await projector.write();
```

## Bundle
Expand All @@ -139,7 +145,10 @@ const bundle = new BundleWindows('bundle-windows/application.exe');
// Use projector property to set options.
bundle.projector.skeleton = 'skeleton.zip';

await bundle.withFile('config.ini', async b => {
// File to create config file with.
bundle.projector.configFile = 'config.ini';

await bundle.write(async b => {
// Add resources in callback.
await b.copyResource('movie.dir', 'movie.dir');
});
Expand All @@ -155,7 +164,10 @@ const bundle = new BundleMacApp('bundle-macapp/application.app');
// Use projector property to set options.
bundle.projector.skeleton = 'skeleton.zip';

await bundle.withFile('config.ini', async b => {
// File to create config file with.
bundle.projector.configFile = 'config.ini';

await bundle.write(async b => {
// Add resources in callback.
await b.copyResource('movie.dir', 'movie.dir');
});
Expand Down
9 changes: 6 additions & 3 deletions src/bundle.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ void describe('bundle', () => {

const b = new BundleDummy(dest);
b.projector.skeleton = fixtureFile('dummy.zip');
await b.withFile(fixtureFile('config.ini.crlf.bin'));
b.projector.configFile = fixtureFile('config.ini.crlf.bin');
await b.write();
});

void it('resources', async () => {
Expand Down Expand Up @@ -109,7 +110,8 @@ void describe('bundle', () => {

const b = new BundleDummy(dest);
b.projector.skeleton = fixtureFile('dummy.zip');
await b.withFile(fixtureFile('config.ini.crlf.bin'), async p => {
b.projector.configFile = fixtureFile('config.ini.crlf.bin');
await b.write(async p => {
await p.copyResource('resources0', resources);

await p.copyResource('resources1', resources, {
Expand Down Expand Up @@ -252,7 +254,8 @@ void describe('bundle', () => {

const b = new BundleDummy(dest);
b.projector.skeleton = fixtureFile('dummy.zip');
await b.withFile(fixtureFile('config.ini.crlf.bin'), async p => {
b.projector.configFile = fixtureFile('config.ini.crlf.bin');
await b.write(async p => {
await p.createResourceFile('d/b.txt', 'beta');

// Merge contents at root of resources.
Expand Down
53 changes: 9 additions & 44 deletions src/bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {
chmod,
lstat,
mkdir,
readFile,
readlink,
stat,
symlink,
Expand Down Expand Up @@ -133,28 +132,16 @@ export abstract class Bundle {
}

/**
* Open output with file.
*
* @param configFile Config file.
* Open output.
*/
public async openFile(configFile: string | null) {
const configData = configFile ? await readFile(configFile) : null;
await this.openData(configData);
}

/**
* Open output with data.
*
* @param configData Config data.
*/
public async openData(configData: Readonly<Buffer> | null) {
public async open() {
if (this._isOpen) {
throw new Error('Already open');
}
await this._checkOutput();

this._closeQueue.clear();
await this._openData(configData);
await this._open();

this._isOpen = true;
}
Expand All @@ -175,34 +162,14 @@ export abstract class Bundle {
}

/**
* Write out projector with player and file.
* Write out the bundle.
* Has a callback to write out the resources.
*
* @param configFile Config file.
* @param func Async function.
* @returns Return value of the async function.
*/
public async withFile<T>(
configFile: string | null,
func: ((self: this) => Promise<T>) | null = null
) {
const configData = configFile ? await readFile(configFile) : null;
return this.withData(configData, func);
}

/**
* Write out projector with player and data.
* Has a callback to write out the resources.
*
* @param configData Config data.
* @param func Async function.
* @returns Return value of the async function.
*/
public async withData<T>(
configData: Readonly<Buffer> | null,
func: ((self: this) => Promise<T>) | null = null
) {
await this.openData(configData);
public async write<T>(func: ((self: this) => Promise<T>) | null = null) {
await this.open();
try {
return func ? await func.call(this, this) : null;
} finally {
Expand Down Expand Up @@ -580,12 +547,10 @@ export abstract class Bundle {
}

/**
* Open output with data.
*
* @param configData Config data.
* Open output.
*/
protected async _openData(configData: Readonly<Buffer> | null) {
await this.projector.withData(configData);
protected async _open() {
await this.projector.write();
}

/**
Expand Down
32 changes: 14 additions & 18 deletions src/bundle/mac/app.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,13 @@ void describe('bundle/mac/app', () => {

const b = new BundleMacApp(dest);
b.projector.skeleton = await getSkeleton();
await b.withFile(
fixtureFile('config.ini.lf.bin'),
async b => {
await b.copyResource(
'movie.dir',
fixtureFile('dir7.dir')
);
}
);
b.projector.configFile = fixtureFile('config.ini.lf.bin');
await b.write(async b => {
await b.copyResource(
'movie.dir',
fixtureFile('dir7.dir')
);
});
});

void it('complex', async () => {
Expand All @@ -45,6 +43,7 @@ void describe('bundle/mac/app', () => {
const b = new BundleMacApp(dest);
const p = b.projector;
p.skeleton = await getSkeleton();
p.configFile = fixtureFile('config.ini.lf.bin');
p.lingoFile = fixtureFile('lingo.ini.lf.bin');
p.splashImageFile = fixtureFile('splash.pict');
p.iconFile = fixtureFile('icon.icns');
Expand All @@ -57,15 +56,12 @@ void describe('bundle/mac/app', () => {
// eslint-disable-next-line @typescript-eslint/naming-convention
'': null
};
await b.withFile(
fixtureFile('config.ini.lf.bin'),
async b => {
await b.copyResource(
'movie.dir',
fixtureFile('dir7.dir')
);
}
);
await b.write(async b => {
await b.copyResource(
'movie.dir',
fixtureFile('dir7.dir')
);
});
});
});
}
Expand Down
32 changes: 14 additions & 18 deletions src/bundle/windows.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,13 @@ void describe('bundle/windows', () => {

const b = new BundleWindows(dest);
b.projector.skeleton = await getSkeleton();
await b.withFile(
fixtureFile('config.ini.crlf.bin'),
async b => {
await b.copyResource(
'movie.dir',
fixtureFile('dir7.dir')
);
}
);
b.projector.configFile = fixtureFile('config.ini.crlf.bin');
await b.write(async b => {
await b.copyResource(
'movie.dir',
fixtureFile('dir7.dir')
);
});
});

void it('complex', async () => {
Expand All @@ -49,6 +47,7 @@ void describe('bundle/windows', () => {
const b = new BundleWindows(dest);
const p = b.projector;
p.skeleton = await getSkeleton();
b.projector.configFile = fixtureFile('config.ini.crlf.bin');
p.lingoFile = fixtureFile('lingo.ini.crlf.bin');
p.splashImageFile = fixtureFile('splash.bmp');
p.nestXtrasConfiguration = true;
Expand All @@ -60,15 +59,12 @@ void describe('bundle/windows', () => {
patchShockwave3dInstalledDisplayDriversSize;
p.iconFile = fixtureFile('icon.ico');
p.versionStrings = versionStrings;
await b.withFile(
fixtureFile('config.ini.crlf.bin'),
async b => {
await b.copyResource(
'movie.dir',
fixtureFile('dir7.dir')
);
}
);
await b.write(async b => {
await b.copyResource(
'movie.dir',
fixtureFile('dir7.dir')
);
});
});
});
}
Expand Down
12 changes: 8 additions & 4 deletions src/projector.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ void describe('projector', () => {

const p = new ProjectorDummy(dest);
p.skeleton = 'dummy';
await p.withFile(fixtureFile('config.ini.crlf.bin'));
p.configFile = fixtureFile('config.ini.crlf.bin');
await p.write();

await copyFile(fixtureFile('dir7.dir'), pathJoin(dir, 'movie.dir'));
});
Expand All @@ -26,8 +27,9 @@ void describe('projector', () => {

const p = new ProjectorDummy(dest);
p.skeleton = 'dummy';
p.configFile = fixtureFile('config.ini.crlf.bin');
p.lingoFile = fixtureFile('lingo.ini.crlf.bin');
await p.withFile(fixtureFile('config.ini.crlf.bin'));
await p.write();

await copyFile(fixtureFile('dir7.dir'), pathJoin(dir, 'movie.dir'));
});
Expand All @@ -38,8 +40,9 @@ void describe('projector', () => {

const p = new ProjectorDummy(dest);
p.skeleton = 'dummy';
p.configFile = fixtureFile('config.ini.crlf.bin');
p.splashImageFile = fixtureFile('splash.bmp');
await p.withFile(fixtureFile('config.ini.crlf.bin'));
await p.write();

await copyFile(fixtureFile('dir7.dir'), pathJoin(dir, 'movie.dir'));
});
Expand All @@ -50,9 +53,10 @@ void describe('projector', () => {

const p = new ProjectorDummy(dest);
p.skeleton = 'dummy';
p.configFile = fixtureFile('config.ini.crlf.bin');
p.lingoFile = fixtureFile('lingo.ini.crlf.bin');
p.splashImageFile = fixtureFile('splash.bmp');
await p.withFile(fixtureFile('config.ini.crlf.bin'));
await p.write();

await copyFile(fixtureFile('dir7.dir'), pathJoin(dir, 'movie.dir'));
});
Expand Down
Loading

0 comments on commit 2edba08

Please sign in to comment.