|
|
@@ -10,15 +10,15 @@ let memoryCache = {};
|
|
|
|
|
|
// Function to decrypt a file and store its content in memory
|
|
|
function decryptFile(filePath) {
|
|
|
- console.log(`Decrypting: ${filePath}`);
|
|
|
+ // console.log(`Decrypting: ${filePath}`);
|
|
|
const fileContent = fs.readFileSync(filePath);
|
|
|
const iv = fileContent.slice(0, 16); // Extract IV
|
|
|
const encrypted = fileContent.slice(16); // Extract encrypted data
|
|
|
const decipher = crypto.createDecipheriv(algorithm, key, iv);
|
|
|
const decrypted = Buffer.concat([decipher.update(encrypted), decipher.final()]);
|
|
|
- const relativePath = path.relative(process.resourcesPath, filePath);
|
|
|
+ const relativePath = path.relative(process.resourcesPath, filePath).replace(/\\/g, '/');
|
|
|
memoryCache[relativePath] = decrypted;
|
|
|
- console.log(`Decrypted: ${filePath}, content: ${decrypted.slice(0, 100)}`);
|
|
|
+ // console.log(`Decrypted: ${filePath}, content: ${decrypted.slice(0, 100)}`);
|
|
|
}
|
|
|
|
|
|
// Recursively decrypt files in a directory and store their content in memory
|
|
|
@@ -26,7 +26,7 @@ function decryptDirectory(directoryPath) {
|
|
|
const files = fs.readdirSync(directoryPath);
|
|
|
files.forEach(file => {
|
|
|
const fullPath = path.join(directoryPath, file);
|
|
|
- console.log(`Processing: ${fullPath}`);
|
|
|
+ // console.log(`Processing: ${fullPath}`);
|
|
|
if (fs.lstatSync(fullPath).isDirectory()) {
|
|
|
decryptDirectory(fullPath);
|
|
|
} else {
|
|
|
@@ -37,19 +37,21 @@ function decryptDirectory(directoryPath) {
|
|
|
|
|
|
function createWindow() {
|
|
|
const directoryToDecrypt = path.join(process.resourcesPath, 'app.asar', 'static');
|
|
|
- console.log(`Decrypting directory: ${directoryToDecrypt}`);
|
|
|
+ // console.log(`Decrypting directory: ${directoryToDecrypt}`);
|
|
|
decryptDirectory(directoryToDecrypt);
|
|
|
|
|
|
// Load index.html into memory
|
|
|
const indexPath = path.join(process.resourcesPath, 'app.asar', 'index.html');
|
|
|
- const indexRelativePath = path.relative(process.resourcesPath, indexPath);
|
|
|
+ const indexRelativePath = path.relative(process.resourcesPath, indexPath).replace(/\\/g, '/');
|
|
|
memoryCache[indexRelativePath] = fs.readFileSync(indexPath);
|
|
|
- console.log(`index: ${indexRelativePath}, content: ${memoryCache[indexRelativePath].slice(0, 100)}`);
|
|
|
+ // console.log(`index: ${indexRelativePath}, content: ${memoryCache[indexRelativePath].slice(0, 100)}`);
|
|
|
|
|
|
// Register a custom protocol to serve content from memory
|
|
|
protocol.interceptBufferProtocol('file', (request, callback) => {
|
|
|
const url = request.url.substr(7); // Remove 'file://' prefix
|
|
|
- const relativePath = path.relative(process.resourcesPath, url);
|
|
|
+ const relativePath = path.relative(process.resourcesPath, url).replace(/\\/g, '/');
|
|
|
+ console.log(`Intercepting request for: ${relativePath}`);
|
|
|
+
|
|
|
if (memoryCache[relativePath]) {
|
|
|
let mimeType = 'text/plain';
|
|
|
if (relativePath.endsWith('.js')) {
|
|
|
@@ -59,14 +61,12 @@ function createWindow() {
|
|
|
} else if (relativePath.endsWith('.html')) {
|
|
|
mimeType = 'text/html';
|
|
|
}
|
|
|
+ console.log(`Serving from memory: ${relativePath} as ${mimeType}`);
|
|
|
callback({ mimeType: mimeType, data: memoryCache[relativePath] });
|
|
|
} else {
|
|
|
+ console.error(`File not found in memory: ${relativePath}`);
|
|
|
callback({ error: -6 }); // FILE_NOT_FOUND
|
|
|
}
|
|
|
- }, (error) => {
|
|
|
- if (error) {
|
|
|
- console.error('Failed to register protocol');
|
|
|
- }
|
|
|
});
|
|
|
|
|
|
const win = new BrowserWindow({
|