Working on opening local files

This commit is contained in:
Scott Idem
2022-03-10 18:19:35 -05:00
parent f0bf184a4a
commit 437b9af482
5 changed files with 136 additions and 10 deletions

View File

@@ -203,8 +203,8 @@ ipcMain.handle('open_hash_file_to_temp', async (event, host_file_cache_path, has
}
if (fs.existsSync(full_cache_file_path)) {
console.log('Hashed file cache exists: '+full_cache_file_path);
console.log('Copying file to temp: '+open_temp_file_path);
console.log(`Hashed file exists in cache: ${full_cache_file_path}`);
console.log(`Copying file to temp: ${open_temp_file_path}`);
try {
await fs.copyFileSync(full_cache_file_path, open_temp_file_path);
} catch (error) {
@@ -215,6 +215,7 @@ ipcMain.handle('open_hash_file_to_temp', async (event, host_file_cache_path, has
// console.log('Creating file link: '+open_temp_file_path);
// fs.linkSync(full_cache_file_path, open_temp_file_path);
} else {
console.log(`Hashed file not found in cache: ${full_cache_file_path}`);
return false;
}
@@ -230,3 +231,37 @@ ipcMain.handle('open_hash_file_to_temp', async (event, host_file_cache_path, has
// return 'Return from Electron IPC Main open_hash_file_to_temp()';
return true;
});
ipcMain.handle('open_local_file', async (event, local_file_path, filename, use_cwd=true) => {
console.log('*** Electron IPC Main: open_local_file() ***');
console.log('ipcMain on open_local_file');
console.log(`ipcMain open local file from directory: ${local_file_path}/${filename}`);
let full_local_file_path = null;
if (use_cwd) {
full_local_file_path = path.join(process.cwd(), local_file_path, filename);
console.log(full_local_file_path);
} else {
full_local_file_path = path.join(local_file_path, filename);
console.log(full_local_file_path);
}
if (fs.existsSync(full_local_file_path)) {
console.log(`Local file exists: ${full_local_file_path}`);
} else {
console.log(`Local file not found: ${full_local_file_path}`);
return false;
}
try {
await shell.openPath(full_local_file_path);
} catch (error) {
console.error(error);
return false;
}
console.log('End: Electron IPC Main: open_local_file()');
return true;
});