Skip to content

Commit

Permalink
Fix saving local data
Browse files Browse the repository at this point in the history
  • Loading branch information
xpenatan committed Jun 21, 2024
1 parent 8396621 commit 7e2e954
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ public void run() {
if(delayInitCount == 0) {
initState = AppState.LOAD_ASSETS;
}
break;
case LOAD_ASSETS:
int queue = AssetDownloader.getInstance().getQueue();
if(queue == 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,10 @@ final protected FileData getInternal(String path) {
}

final public void putFileInternal(String path, byte[] bytes) {
putFileInternal(path, bytes, true);
}

final public void putFileInternal(String path, byte[] bytes, boolean callMethod) {
if(debug) {
String pathStr = "\"" + path + "\"";
System.out.println(getClass().getSimpleName() + " PUT FILE: " + pathStr + " Bytes: " + bytes.length);
Expand All @@ -343,10 +347,16 @@ final public void putFileInternal(String path, byte[] bytes) {
}
FileData fileData = new FileData(path, bytes);
fileMap.put(path, fileData);
putFile(path, fileData);
if(callMethod) {
putFile(path, fileData);
}
}

final public void putFolderInternal(String path) {
putFolderInternal(path, true);
}

final public void putFolderInternal(String path, boolean callMethod) {
if(debug) {
String pathStr = "\"" + path + "\"";
System.out.println(getClass().getSimpleName() + " PUT FOLDER: " + pathStr);
Expand All @@ -356,17 +366,23 @@ final public void putFolderInternal(String path) {
}
FileData fileData = new FileData(path);
fileMap.put(path, new FileData(path));
putFile(path, fileData);
if(callMethod) {
putFile(path, fileData);
}
}

final public FileData removeInternal(String path) {
return removeInternal(path, true);
}

final public FileData removeInternal(String path, boolean callMethod) {
FileData fileData = fileMap.remove(path);
if(debug) {
String pathStr = "\"" + path + "\"";
String type = fileData != null && fileData.isDirectory() ? " REMOVE FOLDER: " : " REMOVE FILE: ";
System.out.println(getClass().getSimpleName() + type + (fileData != null) + " Path: " + pathStr);
}
if(fileData != null) {
if(fileData != null && callMethod) {
removeFile(path);
}
return fileData;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,17 +133,17 @@ private void readAllFilesAsync(TeaApplication teaApplication) {
int type = dbFileData.getType();

if(type == FileData.TYPE_DIRECTORY) {
putFolderInternal(key);
putFolderInternal(key, false);
}
else {
Int8ArrayWrapper contents = dbFileData.getContents();
byte[] bytes = TypedArrays.toByteArray(contents);
putFileInternal(key, bytes);
putFileInternal(key, bytes, false);
}

cursor.doContinue();
teaApplication.delayInitCount--;
}
teaApplication.delayInitCount--;
});
cursorRequest.setOnError(() -> {
teaApplication.delayInitCount--;
Expand Down

0 comments on commit 7e2e954

Please sign in to comment.