Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 29 additions & 4 deletions www/modloader/overlayfs_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,32 @@
const util = require('util');
const asyncRF = util.promisify(fs.readFile);
const zlib = require('zlib');

const path = require('path');

const unlinux_cache = new Map();

window.__fs_unlinuxFile = (f) => {
if (process.platform !== "linux") return f;

let base = path.dirname(f).toLowerCase();
let fname = path.basename(f).toLowerCase();

if (base.split("/").length > 2) {
base = __fs_unlinuxFile(base);
}

const list = (unlinux_cache.has(base) ? unlinux_cache.get(base) : (() => {
const l = fs.readdirSync(base);
unlinux_cache.set(base, l);
return l;
})());

const index = list.map(a => a.toLowerCase()).indexOf(fname);
const resolved = list[index];

return `${base}/${resolved}`;
}

function _overlay_fs_split_path(path) {
let pathComponentRe = /[\/\\]*([^\\\/]+)[\/\\]*/g;
let pathComponents = [];
Expand Down Expand Up @@ -46,7 +71,7 @@
async function _read_file(dataSource) {
$modLoader.$vfsTrace("[READFILE] " + dataSource.type);
if (dataSource.type === "filesystem") {
return await asyncRF(dataSource.path);
return await asyncRF(__fs_unlinuxFile(dataSource.path));
}
if (dataSource.type === "zip") {
return await dataSource.sz.entryData(dataSource.entry);
Expand All @@ -63,7 +88,7 @@
function _read_file_sync(dataSource) {
$modLoader.$vfsTrace("[READFILE] " + dataSource.type);
if (dataSource.type === "filesystem") {
return fs.readFileSync(dataSource.path);
return fs.readFileSync(__fs_unlinuxFile(dataSource.path));
}
if (dataSource.type === "zip") {
return dataSource.sz.resolvedStreamZip.entryDataSync(dataSource.entry);
Expand All @@ -79,4 +104,4 @@

window._read_file = _read_file;
window._read_file_Sync = _read_file_sync;
}
}
4 changes: 2 additions & 2 deletions www/modloader/stage2.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ async function _modloader_stage2(knownMods) {

let base_file = _modloader_encryption.decrypt(
await async_fs.readFile(
path.join(base, k)
__fs_unlinuxFile(path.join(base, k))
)
).toString("utf-8");
let files = deltaFiles.get(k);
Expand Down Expand Up @@ -339,4 +339,4 @@ async function _modloader_stage2(knownMods) {


if (global && global.gc) global.gc();
}
}
9 changes: 4 additions & 5 deletions www/modloader/vfs_common.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
const native_fs = require('fs');
const util = require('util');
const isWindows = (['Win32', 'Win64', 'Windows', 'WinCE'].indexOf(window.navigator.platform) != -1);
const async_fs = { // old node polyfill bruh
readdir: util.promisify(native_fs.readdir),
readFile: util.promisify(native_fs.readFile),
Expand All @@ -12,7 +11,7 @@

async function _vfs_resolve_file(relativePath) {
$modLoader.$vfsTrace("[ResolveSyncStart] " + relativePath);
relativePath = isWindows ? relativePath.toLowerCase() : relativePath;
relativePath = relativePath.toLowerCase();
let dirTree = _overlay_fs_split_path(relativePath);
let currentDir = $modLoader.overlayFS;
let fileName = dirTree.pop();
Expand Down Expand Up @@ -60,7 +59,7 @@
window._logLine(e.stack);
}
}
return await async_fs.readFile(path.join(base, relativePath));
return await async_fs.readFile(__fs_unlinuxFile(path.join(base, relativePath)));
} else {
$modLoader.$vfsTrace("[ResolveSyncVFS] " + relativePath);
let data = await _read_file(entry.dataSource);
Expand All @@ -73,7 +72,7 @@

function _vfs_resolve_file_sync(relativePath) {
$modLoader.$vfsTrace("[ResolveSyncStart] " + relativePath);
relativePath = isWindows ? relativePath.toLowerCase() : relativePath;
relativePath = relativePath.toLowerCase();
let dirTree = _overlay_fs_split_path(relativePath);
let currentDir = $modLoader.overlayFS;
let fileName = dirTree.pop();
Expand Down Expand Up @@ -108,7 +107,7 @@

if (bail) {
$modLoader.$vfsTrace("[ResolveSyncBail] " + relativePath);
return native_fs.readFileSync(path.join(base, relativePath));
return native_fs.readFileSync(__fs_unlinuxFile(path.join(base, relativePath)));
} else {
$modLoader.$vfsTrace("[ResolveSyncVFS] " + relativePath);
let data = _read_file_sync(entry.dataSource);
Expand Down
8 changes: 4 additions & 4 deletions www/modloader/vfs_node.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ async function _modLoader_install_node_vfs(shadowfs, nativefs) {
let _native_fs_location = path.join(base, ...components);
let _native_fs_files = [];
try {
_native_fs_files = nativefs.readdirSync(_native_fs_location);
_native_fs_files = nativefs.readdirSync(__fs_unlinuxFile(_native_fs_location));
} catch(e) {
window._logLine("vfs_node.js: Failed to nativefs.readdirSync: " + _native_fs_location + ", because it doesn't exist!");
}
Expand Down Expand Up @@ -101,7 +101,7 @@ async function _modLoader_install_node_vfs(shadowfs, nativefs) {
throw new Error("What even the fuck happened");
} catch(e) {
let _native_fs_location = path.join(path.join(base, ...components), file);
return nativefs.statSync(_native_fs_location);
return nativefs.statSync(__fs_unlinuxFile(_native_fs_location));
}
}

Expand All @@ -124,7 +124,7 @@ async function _modLoader_install_node_vfs(shadowfs, nativefs) {
throw new Error("What even the fuck happened");
} catch(e) {
let _native_fs_location = path.join(path.join(base, ...components), file);
return await nfsstat(_native_fs_location);
return await nfsstat(__fs_unlinuxFile(_native_fs_location));
}
}
window._exec_vfs_readdir = exec_vfs_readdir;
Expand Down Expand Up @@ -360,4 +360,4 @@ async function _modLoader_install_node_vfs(shadowfs, nativefs) {
window.__unload_node_vfs = function() {
window.require = old_require;
}
}
}