Merge branch 'feat/casono-browser-file-search' into 'main'
Feat: Casono Browser file search See merge request cs108-fs26/Gruppe-13!188
This commit is contained in:
+3
-2
@@ -670,7 +670,8 @@ public class CasinoBrowserController {
|
|||||||
securityLabel.setText("LOCAL OK");
|
securityLabel.setText("LOCAL OK");
|
||||||
engine.load(uri.toString());
|
engine.load(uri.toString());
|
||||||
} else {
|
} else {
|
||||||
securityLabel.setText("BLOCKED");
|
securityLabel.setText("UNKNOWN");
|
||||||
|
engine.load(uri.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
@@ -696,7 +697,7 @@ public class CasinoBrowserController {
|
|||||||
securityLabel.setText("BLOCKED");
|
securityLabel.setText("BLOCKED");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
securityLabel.setText("UNBEKANNT");
|
securityLabel.setText("UNKNOWN");
|
||||||
} else {
|
} else {
|
||||||
securityLabel.setText("SAFE");
|
securityLabel.setText("SAFE");
|
||||||
}
|
}
|
||||||
|
|||||||
+99
-12
@@ -9,11 +9,14 @@ import ch.unibas.dmi.dbis.cs108.casono.client.game.PlayerState;
|
|||||||
import ch.unibas.dmi.dbis.cs108.casono.client.network.LobbyClient;
|
import ch.unibas.dmi.dbis.cs108.casono.client.network.LobbyClient;
|
||||||
import ch.unibas.dmi.dbis.cs108.casono.client.ui.lobbyui.Casinomainui;
|
import ch.unibas.dmi.dbis.cs108.casono.client.ui.lobbyui.Casinomainui;
|
||||||
import ch.unibas.dmi.dbis.cs108.casono.ui.sound.SoundManager;
|
import ch.unibas.dmi.dbis.cs108.casono.ui.sound.SoundManager;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
import java.util.function.UnaryOperator;
|
import java.util.function.UnaryOperator;
|
||||||
|
import java.util.stream.Stream;
|
||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
import javafx.scene.control.Alert;
|
import javafx.scene.control.Alert;
|
||||||
import javafx.scene.control.Button;
|
import javafx.scene.control.Button;
|
||||||
@@ -92,6 +95,8 @@ public class TaskbarController {
|
|||||||
private int lastObservedIncrease = 0;
|
private int lastObservedIncrease = 0;
|
||||||
private int lastRaiseIncrement = 0;
|
private int lastRaiseIncrement = 0;
|
||||||
private static final long REFRESH_DELAY_MS = 500;
|
private static final long REFRESH_DELAY_MS = 500;
|
||||||
|
private static final int MAX_SEARCH_DEPTH = 8;
|
||||||
|
private static final int DOWNLOAD_SEARCH_DEPTH = 5;
|
||||||
|
|
||||||
/** Standard constructor. Used by FXML. */
|
/** Standard constructor. Used by FXML. */
|
||||||
public TaskbarController() {
|
public TaskbarController() {
|
||||||
@@ -1838,6 +1843,70 @@ public class TaskbarController {
|
|||||||
return lastState;
|
return lastState;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Searches for a file by traversing parent directories up to a stop folder and recursively
|
||||||
|
* scanning each level. Falls back to the user's Downloads folder.
|
||||||
|
*/
|
||||||
|
private Path findFileUpAndDown(Path startDir, String fileName, String stopFolderName) {
|
||||||
|
Path current = startDir.toAbsolutePath();
|
||||||
|
|
||||||
|
while (current != null) {
|
||||||
|
|
||||||
|
Path found = searchDown(current, fileName, MAX_SEARCH_DEPTH);
|
||||||
|
if (found != null) {
|
||||||
|
return found;
|
||||||
|
}
|
||||||
|
|
||||||
|
Path currentName = current.getFileName();
|
||||||
|
if (currentName != null && currentName.toString().equalsIgnoreCase(stopFolderName)) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
current = current.getParent();
|
||||||
|
}
|
||||||
|
|
||||||
|
Path downloads = Paths.get(System.getProperty("user.home"), "Downloads");
|
||||||
|
|
||||||
|
if (Files.exists(downloads)) {
|
||||||
|
return searchDown(downloads, fileName, DOWNLOAD_SEARCH_DEPTH);
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Recursively searches for a file in subdirectories with a limited depth. Prevents deep or
|
||||||
|
* uncontrolled filesystem traversal using maxDepth.
|
||||||
|
*/
|
||||||
|
private Path searchDown(Path dir, String fileName, int maxDepth) {
|
||||||
|
if (dir == null || maxDepth < 0 || !Files.isDirectory(dir)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
try (Stream<Path> stream = Files.list(dir)) {
|
||||||
|
|
||||||
|
for (Path path : (Iterable<Path>) stream::iterator) {
|
||||||
|
|
||||||
|
if (Files.isRegularFile(path)
|
||||||
|
&& path.getFileName().toString().equalsIgnoreCase(fileName)) {
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Files.isDirectory(path)) {
|
||||||
|
Path found = searchDown(path, fileName, maxDepth - 1);
|
||||||
|
|
||||||
|
if (found != null) {
|
||||||
|
return found;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (IOException ignored) {
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Opens the integrated Casono web browser.
|
* Opens the integrated Casono web browser.
|
||||||
*
|
*
|
||||||
@@ -1846,16 +1915,17 @@ public class TaskbarController {
|
|||||||
@FXML
|
@FXML
|
||||||
private void onBrowserButtonClick() {
|
private void onBrowserButtonClick() {
|
||||||
SoundManager.getInstance().playButtonClick();
|
SoundManager.getInstance().playButtonClick();
|
||||||
try {
|
|
||||||
Path path =
|
|
||||||
Paths.get(
|
|
||||||
System.getProperty("user.dir"),
|
|
||||||
"documents",
|
|
||||||
"docs",
|
|
||||||
"game-engine",
|
|
||||||
"manual.html");
|
|
||||||
|
|
||||||
CasinoBrowserController.open(path.toUri().toString());
|
try {
|
||||||
|
Path start = Paths.get(System.getProperty("user.dir"));
|
||||||
|
|
||||||
|
Path file = findFileUpAndDown(start, "manual.html", "Gruppe-13");
|
||||||
|
|
||||||
|
if (file == null) {
|
||||||
|
throw new IllegalStateException("manual.html not found");
|
||||||
|
}
|
||||||
|
|
||||||
|
CasinoBrowserController.open(file.toUri().toString());
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@@ -1870,10 +1940,27 @@ public class TaskbarController {
|
|||||||
@FXML
|
@FXML
|
||||||
private void onBrowserButtonClickCasono() {
|
private void onBrowserButtonClickCasono() {
|
||||||
SoundManager.getInstance().playButtonClick();
|
SoundManager.getInstance().playButtonClick();
|
||||||
try {
|
|
||||||
Path path = Paths.get(System.getProperty("user.dir"), "outreach", "index.html");
|
|
||||||
|
|
||||||
CasinoBrowserController.open(path.toUri().toString());
|
try {
|
||||||
|
Path start = Paths.get(System.getProperty("user.dir"));
|
||||||
|
|
||||||
|
Path file = start;
|
||||||
|
|
||||||
|
while (file != null && !file.getFileName().toString().equals("Gruppe-13")) {
|
||||||
|
file = file.getParent();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (file == null) {
|
||||||
|
throw new IllegalStateException("Gruppe-13 not found");
|
||||||
|
}
|
||||||
|
|
||||||
|
Path target = file.resolve("outreach").resolve("index.html");
|
||||||
|
|
||||||
|
if (!Files.isRegularFile(target)) {
|
||||||
|
throw new IllegalStateException("outreach/index.html not found");
|
||||||
|
}
|
||||||
|
|
||||||
|
CasinoBrowserController.open(target.toUri().toString());
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
|||||||
Reference in New Issue
Block a user