Comment read and exist fs functions

This commit is contained in:
OleSTEEP 2023-12-29 23:12:56 +03:00
parent ec5c71b3ac
commit ee433772f2

View file

@ -247,50 +247,50 @@ document.addEventListener("deviceready", () => {
return true; return true;
}; };
NativeFunctions.saveFileExists = function(path) { // NativeFunctions.saveFileExists = function(path) {
var split_path = require.libs.path._solve_dots(path).split("/"); // var split_path = require.libs.path._solve_dots(path).split("/");
save_exists = null; // save_exists = null;
window.resolveLocalFileSystemURL(cordova.file.externalDataDirectory, function (dirEntry) { // window.resolveLocalFileSystemURL(cordova.file.externalDataDirectory, function (dirEntry) {
console.log(`Using externalStorage while checking save file ${path} existence`); // console.log(`Using externalStorage while checking save file ${path} existence`);
dirEntry.getDirectory(split_path[0], { create: true }, function (subDirEntry) { // dirEntry.getDirectory(split_path[0], { create: true }, function (subDirEntry) {
subDirEntry.getFile(split_path[1], {create: false, exclusive: false}, function(fileEntry) { // subDirEntry.getFile(split_path[1], {create: false, exclusive: false}, function(fileEntry) {
save_exists = true; // save_exists = true;
console.log(`After "save_exists = true" - ${save_exists}`); // console.log(`After "save_exists = true" - ${save_exists}`);
}, () => { // }, () => {
save_exists = false; // save_exists = false;
console.log(`After "save_exists = false" - ${save_exists}`); // console.log(`After "save_exists = false" - ${save_exists}`);
}); // });
}); // });
}); // });
console.log(`Before return - ${save_exists}`); // console.log(`Before return - ${save_exists}`);
return save_exists; // return save_exists;
} // }
NativeFunctions.readSaveFileUTF8 = function(path, fnCallback) { // NativeFunctions.readSaveFileUTF8 = function(path, fnCallback) {
var split_path = require.libs.path._solve_dots(path).split("/"); // var split_path = require.libs.path._solve_dots(path).split("/");
save_data = null; // save_data = null;
window.resolveLocalFileSystemURL(cordova.file.externalDataDirectory, function (dirEntry) { // window.resolveLocalFileSystemURL(cordova.file.externalDataDirectory, function (dirEntry) {
console.log(`Using externalStorage to read save at ${path}`); // console.log(`Using externalStorage to read save at ${path}`);
dirEntry.getDirectory(split_path[0], { create: true }, function (subDirEntry) { // dirEntry.getDirectory(split_path[0], { create: true }, function (subDirEntry) {
subDirEntry.getFile(split_path[1], {create: false, exclusive: false}, function(fileEntry) { // subDirEntry.getFile(split_path[1], {create: false, exclusive: false}, function(fileEntry) {
fileEntry.file(function (file) { // fileEntry.file(function (file) {
var reader = new FileReader(); // var reader = new FileReader();
reader.onloadend = function() { // reader.onloadend = function() {
save_data = this.result; // save_data = this.result;
}; // };
reader.readAsText(file); // reader.readAsText(file);
}, () => { // }, () => {
console.log("Error to read external save file: " + e.toString()); // console.log("Error to read external save file: " + e.toString());
}); // });
}, (e) => { // }, (e) => {
console.log("Error to find external save file: " + e.toString()); // console.log("Error to find external save file: " + e.toString());
}); // });
}); // });
}); // });
return save_data; // return save_data;
} // }
NativeFunctions.writeSaveFileUTF8 = function(path, data) { NativeFunctions.writeSaveFileUTF8 = function(path, data) {
var split_path = require.libs.path._solve_dots(path).split("/"); var split_path = require.libs.path._solve_dots(path).split("/");