Skip to content

Commit

Permalink
Merge pull request CinemaMod#71 from DerSimeon/feature/cef-cachepath
Browse files Browse the repository at this point in the history
Added CachePath to CefUtil
  • Loading branch information
ds58 authored Dec 9, 2023
2 parents 3b18394 + 2414e31 commit 0617546
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
8 changes: 8 additions & 0 deletions common/src/main/java/com/cinemamod/mcef/CefUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@

package com.cinemamod.mcef;

import net.minecraft.client.Minecraft;
import org.cef.CefApp;
import org.cef.CefClient;
import org.cef.CefSettings;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.attribute.PosixFilePermission;
import java.util.HashSet;
import java.util.Objects;
Expand All @@ -43,6 +45,11 @@ private CefUtil() {
private static CefApp cefAppInstance;
private static CefClient cefClientInstance;

private static final Path CACHE_PATH = Minecraft.getInstance().gameDirectory
.toPath()
.resolve("mods")
.resolve("mcef-cache");

private static void setUnixExecutable(File file) {
Set<PosixFilePermission> perms = new HashSet<>();
perms.add(PosixFilePermission.OWNER_READ);
Expand Down Expand Up @@ -93,6 +100,7 @@ static boolean init() {

CefSettings cefSettings = new CefSettings();
cefSettings.windowless_rendering_enabled = true;
if (settings.isUsingCache()) cefSettings.cache_path = CACHE_PATH.toString();
cefSettings.background_color = cefSettings.new ColorType(0, 255, 255, 255);
// Set the user agent if there's one defined in MCEFSettings
if (!Objects.equals(settings.getUserAgent(), "null")) {
Expand Down
8 changes: 8 additions & 0 deletions common/src/main/java/com/cinemamod/mcef/MCEFSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,13 @@ public class MCEFSettings {
private boolean skipDownload;
private String downloadMirror;
private String userAgent;
private boolean useCache;

public MCEFSettings() {
skipDownload = false;
downloadMirror = "https://mcef-download.cinemamod.com";
userAgent = null;
useCache = true;
}

public boolean isSkipDownload() {
Expand Down Expand Up @@ -75,6 +77,10 @@ public void setUserAgent(String userAgent) {
saveAsync();
}

public boolean isUsingCache() {
return useCache;
}

public void saveAsync() {
CompletableFuture.runAsync(() -> {
try {
Expand All @@ -98,6 +104,7 @@ public void save() throws IOException {
properties.setProperty("skip-download", String.valueOf(skipDownload));
properties.setProperty("download-mirror", String.valueOf(downloadMirror));
properties.setProperty("user-agent", String.valueOf(userAgent));
properties.setProperty("use-cache", String.valueOf(useCache));

try (FileOutputStream output = new FileOutputStream(file)) {
properties.store(output, null);
Expand All @@ -121,6 +128,7 @@ public void load() throws IOException {
skipDownload = Boolean.parseBoolean(properties.getProperty("skip-download"));
downloadMirror = properties.getProperty("download-mirror");
userAgent = properties.getProperty("user-agent");
useCache = Boolean.parseBoolean(properties.getProperty("use-cache"));
} catch (Exception e) {
// Delete and re-create the file if there was a parsing error
if (deleteRetries++ > 20)
Expand Down

0 comments on commit 0617546

Please sign in to comment.