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