mirror of
https://github.com/felixrieseberg/macintosh.js.git
synced 2025-02-06 03:30:17 +00:00
fix: User user data disk image
This commit is contained in:
parent
3b23ad828d
commit
9e3e9623d0
@ -8,8 +8,8 @@ This is Mac OS 8, running in an [Electron](https://electronjs.org/) app pretendi
|
||||
|
||||
| | Windows | macOS | Linux |
|
||||
|---------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||
| Standalone Download | 📦[Standalone, 32-bit](https://github.com/felixrieseberg/macintosh.js/releases/download/v1.0.0/macintosh.js-1.0.0-win32-standalone-ia32.zip) <br /> 📦[Standalone, 64-bit](https://github.com/felixrieseberg/macintosh.js/releases/download/v1.0.0/macintosh.js-1.0.0-win32-standalone-x64.zip) | 📦[Standalone](https://github.com/felixrieseberg/macintosh.js/releases/download/v1.0.0/macintosh.js-macos-1.0.0.zip) | |
|
||||
| Installer | 💽[Setup, 64-bit](https://github.com/felixrieseberg/macintosh.js/releases/download/v1.0.0/macintosh.js-1.0.0-setup-win32-x64.exe) <br /> 💽[Setup, 32-bit](https://github.com/felixrieseberg/macintosh.js/releases/download/v1.0.0/macintosh.js-1.0.0-setup-win32-ia32.exe) | | 💽[deb, 64-bit](https://github.com/felixrieseberg/macintosh.js/releases/download/v1.0.0/macintosh.js-linux-1.0.0_amd64.deb) <br /> 💽[rpm, 64-bit](https://github.com/felixrieseberg/macintosh.js/releases/download/v1.0.0/macintosh.js-linux-1.0.0.x86_64.rpm) |
|
||||
| Standalone Download | 📦[Standalone, 32-bit](https://github.com/felixrieseberg/macintosh.js/releases/download/v1.0.0/macintosh.js-win32-x64-1.0.0.zip) <br /> 📦[Standalone, 64-bit](https://github.com/felixrieseberg/macintosh.js/releases/download/v1.0.0/macintosh.js-win32-ia32-1.0.0.zip) | 📦[Standalone](https://github.com/felixrieseberg/macintosh.js/releases/download/v1.0.0/macintosh.js-darwin-x64-1.0.0.zip) | |
|
||||
| Installer | 💽[Setup, 64-bit](https://github.com/felixrieseberg/macintosh.js/releases/download/v1.0.0/macintoshjs-1.0.0-setup-x64.exe) <br /> 💽[Setup, 32-bit](https://github.com/felixrieseberg/macintosh.js/releases/download/v1.0.0/macintoshjs-1.0.0-setup-ia32.exe) | | 💽[deb, 64-bit](https://github.com/felixrieseberg/macintosh.js/releases/download/v1.0.0/macintosh.js_1.0.0_amd64.deb) <br /> 💽[rpm, 64-bit](https://github.com/felixrieseberg/macintosh.js/releases/download/v1.0.0/macintosh.js-1.0.0-1.x86_64.rpm) |
|
||||
|
||||
## Does it work?
|
||||
Yes! Quite well, actually - on macOS, Windows, and Linux. Bear in mind that this is written entirely in JavaScript, so please adjust your expectations. The virtual machine is emulating a 1991 Macintosh Quadra 900 with a Motorola CPU, which Apple used before switching to IBM's PowerPC architecture in the late 1990s.
|
||||
|
@ -1,10 +1,18 @@
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
const { error } = require("console");
|
||||
|
||||
const homeDir = require("os").homedir();
|
||||
const macDir = path.join(homeDir, "macintosh.js");
|
||||
const macintoshCopyPath = path.join(__dirname, "user_files");
|
||||
|
||||
// Set by config
|
||||
let userDataPath;
|
||||
|
||||
function getUserDataDiskPath() {
|
||||
return path.join(userDataPath, 'disk');
|
||||
}
|
||||
|
||||
function cleanupCopyPath() {
|
||||
try {
|
||||
if (fs.existsSync(macintoshCopyPath)) {
|
||||
@ -17,6 +25,29 @@ function cleanupCopyPath() {
|
||||
}
|
||||
}
|
||||
|
||||
function getUserDataDiskImage() {
|
||||
if (!userDataPath) {
|
||||
console.error(`getUserDataDiskImage: userDataPath not set`);
|
||||
return;
|
||||
}
|
||||
|
||||
const diskImageUserPath = getUserDataDiskPath();
|
||||
const diskImagePath = path.join(__dirname, 'disk');
|
||||
|
||||
// If there's a disk image, move it over
|
||||
if (fs.existsSync(diskImageUserPath)) {
|
||||
// Delete a possible basilisk disk image
|
||||
if (fs.existsSync(diskImagePath)) {
|
||||
console.log(`Disk image ${diskImageUserPath} exists, deleting ${diskImagePath}`);
|
||||
fs.unlinkSync(diskImagePath);
|
||||
}
|
||||
|
||||
fs.renameSync(diskImageUserPath, diskImagePath);
|
||||
} else {
|
||||
console.log(`getUserDataDiskImage: No image in user data dir, not doing anything`);
|
||||
}
|
||||
}
|
||||
|
||||
function addAutoloader(module) {
|
||||
const copyFilesAtPath = function (sourcePath) {
|
||||
try {
|
||||
@ -326,7 +357,8 @@ self.onmessage = async function (msg) {
|
||||
|
||||
if (msg && msg.data === "disk_save") {
|
||||
const diskData = Module.FS.readFile("/disk");
|
||||
const diskPath = path.join(__dirname, "disk");
|
||||
const diskPath = getUserDataDiskPath();
|
||||
const basiliskDiskPath = path.join(__dirname, 'disk');
|
||||
|
||||
// I wish we could do this with promises, but OOM crashes kill that idea
|
||||
try {
|
||||
@ -337,6 +369,14 @@ self.onmessage = async function (msg) {
|
||||
console.error(`Failed to write disk`, error);
|
||||
}
|
||||
|
||||
try {
|
||||
if (fs.existsSync(basiliskDiskPath) && !(Module && Module.isDevMode)) {
|
||||
fs.unlinkSync(basiliskDiskPath);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(`Failed to delete ${basiliskDiskPath}`);
|
||||
}
|
||||
|
||||
// Now, user files
|
||||
console.log(`Saving user files`);
|
||||
await saveFilesInPath("/macintosh.js");
|
||||
@ -349,6 +389,10 @@ self.onmessage = async function (msg) {
|
||||
};
|
||||
|
||||
function startEmulator(parentConfig) {
|
||||
userDataPath = parentConfig.userDataPath;
|
||||
|
||||
getUserDataDiskImage();
|
||||
|
||||
let screenBufferView = new Uint8Array(
|
||||
parentConfig.screenBuffer,
|
||||
0,
|
||||
|
@ -30,6 +30,10 @@ function registerIpcHandlers() {
|
||||
ipcMain.handle("getAppVersion", () => {
|
||||
return app.getVersion();
|
||||
});
|
||||
|
||||
ipcMain.handle("getUserDataPath", () => {
|
||||
return app.getPath('userData');
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
|
@ -11,7 +11,7 @@ function asyncLoop() {
|
||||
}
|
||||
|
||||
async function start() {
|
||||
registerWorker();
|
||||
await registerWorker();
|
||||
setupDialogs();
|
||||
openAudio();
|
||||
asyncLoop();
|
||||
|
@ -20,4 +20,8 @@ module.exports = {
|
||||
getAppVersion() {
|
||||
return ipcRenderer.invoke("getAppVersion");
|
||||
},
|
||||
|
||||
getUserDataPath() {
|
||||
return ipcRenderer.invoke("getUserDataPath");
|
||||
}
|
||||
};
|
||||
|
@ -13,7 +13,7 @@ const {
|
||||
audioBlockChunkSize,
|
||||
AUDIO_DATA_BUFFER_SIZE,
|
||||
} = require("./audio");
|
||||
const { quit, getIsDevMode } = require("./ipc");
|
||||
const { quit, getIsDevMode, getUserDataPath } = require("./ipc");
|
||||
|
||||
let isWorkerRunning = false;
|
||||
let isWorkerSaving = false;
|
||||
@ -57,7 +57,7 @@ async function handleWorkerShutdown() {
|
||||
saveDisk();
|
||||
}
|
||||
|
||||
function registerWorker() {
|
||||
async function registerWorker() {
|
||||
const workerConfig = {
|
||||
inputBuffer: inputBuffer,
|
||||
inputBufferSize: INPUT_BUFFER_SIZE,
|
||||
@ -71,6 +71,8 @@ function registerWorker() {
|
||||
audioBlockChunkSize: audioBlockChunkSize,
|
||||
SCREEN_WIDTH: SCREEN_WIDTH,
|
||||
SCREEN_HEIGHT: SCREEN_HEIGHT,
|
||||
userDataPath: await getUserDataPath(),
|
||||
isDevMode: await getIsDevMode()
|
||||
};
|
||||
|
||||
worker = window.emulatorWorker = new Worker(
|
||||
|
Loading…
x
Reference in New Issue
Block a user