mirror of
https://github.com/OpenFusionProject/Client.git
synced 2024-11-21 13:20:04 +00:00
Add browse button to cache path input and refine validation logic
This commit is contained in:
parent
d8363b61a6
commit
1eee35b230
@ -11,7 +11,7 @@ var configPath = path.join(userData, "config.json");
|
||||
var serversPath = path.join(userData, "servers.json");
|
||||
var versionsPath = path.join(userData, "versions.json");
|
||||
var cacheRoot = path.join(userData, "/../../LocalLow/Unity/Web Player/Cache");
|
||||
var offlineRootDefault = path.join(cacheRoot, "Offline");
|
||||
var offlineRootDefault = path.join(cacheRoot, "../OfflineCache");
|
||||
var offlineRoot = offlineRootDefault;
|
||||
|
||||
var cdnString = "http://cdn.dexlabs.systems/ff/big";
|
||||
@ -328,13 +328,22 @@ function editConfig() {
|
||||
function validateCacheLocation() {
|
||||
var input = document.getElementById("editconfig-offlinecachelocation");
|
||||
var button = document.getElementById("editconfig-savebutton");
|
||||
var parent = path.join(input.value, "/..");
|
||||
|
||||
input.classList.remove("invalidinput");
|
||||
button.removeAttribute("disabled");
|
||||
|
||||
// Parent MUST exist and be a directory
|
||||
// If the target exists, check that is also a directory
|
||||
// Also, prevent putting the offline cache inside of
|
||||
// the normal cache folder to prevent shenanigans
|
||||
if (
|
||||
!remotefs.existsSync(input.value) ||
|
||||
!remotefs.statSync(input.value).isDirectory()
|
||||
!remotefs.existsSync(parent) ||
|
||||
!remotefs.statSync(parent).isDirectory() ||
|
||||
(remotefs.existsSync(input.value) &&
|
||||
!remotefs.statSync(input.value).isDirectory()) ||
|
||||
path.join(input.value, ".") === path.join(cacheRoot, "/..") ||
|
||||
path.join(input.value, ".").startsWith(path.join(cacheRoot))
|
||||
) {
|
||||
input.classList.add("invalidinput");
|
||||
button.setAttribute("disabled", "");
|
||||
@ -948,6 +957,17 @@ function prepConnection(address, port) {
|
||||
launchGame();
|
||||
}
|
||||
|
||||
function browseOfflineCache() {
|
||||
var browsePath = dialog.showOpenDialog({ properties: ["openDirectory"] });
|
||||
var offlineCacheInput = document.getElementById(
|
||||
"editconfig-offlinecachelocation"
|
||||
);
|
||||
if (browsePath && offlineCacheInput) {
|
||||
offlineCacheInput.value = browsePath;
|
||||
validateCacheLocation();
|
||||
}
|
||||
}
|
||||
|
||||
// Returns the UUID of the server with the selected background color.
|
||||
// Yes, there are probably better ways to go about this, but it works well enough.
|
||||
function getSelectedServer() {
|
||||
|
22
index.html
22
index.html
@ -524,12 +524,22 @@
|
||||
/>
|
||||
<label for="editconfig-offlinecachelocation"
|
||||
>Select Offline Cache Location:</label
|
||||
><input
|
||||
class="form-control form-row w-75"
|
||||
id="editconfig-offlinecachelocation"
|
||||
type="text"
|
||||
oninput="validateCacheLocation()"
|
||||
/>
|
||||
>
|
||||
<div class="form-row">
|
||||
<input
|
||||
class="form-control w-75"
|
||||
id="editconfig-offlinecachelocation"
|
||||
type="text"
|
||||
oninput="validateCacheLocation()"
|
||||
/>
|
||||
<button
|
||||
type="button"
|
||||
class="btn btn-primary mb-2 ml-1"
|
||||
onclick="browseOfflineCache()"
|
||||
>
|
||||
<i class="fas fa-folder"></i>
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
|
Loading…
Reference in New Issue
Block a user