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

@@ -71,6 +71,25 @@ exports.load_config = function () {
}
// Check for local file
// Updated 2022-03-10
exports.check_local_file = async function ({local_file_path, filename}) {
console.log('*** Electron framework export: check_local_file() ***');
console.log('Check for local file');
console.log(`Local File Path: ${local_file_path}; Filename: ${filename}`);
let 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}`);
return true;
} else {
return false;
}
}
// Check local hash file cache
// Updated 2022-03-09
exports.check_hash_file_cache = async function ({host_file_cache_path, hash}) {
@@ -84,13 +103,15 @@ exports.check_hash_file_cache = async function ({host_file_cache_path, hash}) {
// console.log(hash_file_cache_path);
if (fs.existsSync(hash_file_cache_path)) {
console.log(`Hashed file cache already exists: ${hash_file_cache_path}`);
console.log(`Hashed file exists in cache: ${hash_file_cache_path}`);
return true;
} else {
console.log(`Hashed file not found in cache: ${hash_file_cache_path}`);
return false;
}
}
// Download hash file to cache
// Updated 2022-03-09
exports.download_hash_file_to_cache = async function ({host_file_cache_path, event_file_id=null, hash=null}) {
@@ -121,8 +142,9 @@ exports.download_hash_file_to_cache = async function ({host_file_cache_path, eve
}
}
// Open cached hash file after copying to temp directory
// Updated 2022-03-07
// Updated 2022-03-09
exports.open_hash_file_to_temp = async function ({host_file_cache_path, hash, host_file_temp_path, filename}) {
console.log('*** Electron framework export: open_hash_file_to_temp() ***');
console.log('Open cached hash file after copying to temp directory');
@@ -149,6 +171,40 @@ exports.open_hash_file_to_temp = async function ({host_file_cache_path, hash, ho
}
// Open local file
// Updated 2022-03-10
exports.open_local_file = async function ({local_file_path, filename}) {
console.log('*** Electron framework export: open_local_file() ***');
console.log('Open local file');
console.log(`Local File Path: ${local_file_path}; Filename: ${filename}`);
// let 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}`);
// // return true;
// } else {
// return false;
// }
let open_local_file_result = await ipcRenderer.invoke('open_local_file', local_file_path, filename).then((result) => {
console.log('IPC open local file finished');
console.log(result);
return true;
})
console.log(open_local_file_result);
console.log('End: open_local_file()');
if (open_local_file_result) {
console.log('File opened successfully');
return true;
} else {
console.log('File was not opened successfully');
return false;
}
}