Skip to content

Commit

Permalink
feat: add js script to read settings from indexedDB
Browse files Browse the repository at this point in the history
  • Loading branch information
akorzunin committed Aug 6, 2024
1 parent c175268 commit e18c3d0
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions scripts/get_web_settings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
(function functionToExecute() {
// Open the database connection.
var open = indexedDB.open("/userfs");

open.onupgradeneeded = function () {
// Define the database schema if necessary.
var db = open.result;
var store = db.createObjectStore("/userfs");
console.log("------------> Upgraded userfs?");
};

open.onsuccess = function () {
var db = open.result;
var key = "/userfs/godot/app_userdata/SuperIcosahedron/settings.cfg";

// Write file to DB
// var tx = db.transaction('files', 'readwrite');
// var store = tx.objectStore('files');
// store.put(null, "test");

// Later, read file back out of DB
var tx2 = db.transaction("FILE_DATA");
var store2 = tx2.objectStore("FILE_DATA");
var request = store2.get(key);

request.onsuccess = function (e) {
// Got the file!
var file = request.result;

if (file == null) {
alert("You haven't generated any results yet.");
console.log("File is null");
return;
} else {
console.log("Is int8array: " + (file.contents instanceof Int8Array));
}

var blob = new Blob([file.contents], { type: "text/csv;charset=utf-8;" });
var link = document.createElement("a");
link.href = window.URL.createObjectURL(blob);
link.download = "webSettings.cfg";
link.click();
};
};
})();

0 comments on commit e18c3d0

Please sign in to comment.