Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import org.gradle.api.tasks.JavaExec
import org.gradle.api.tasks.SourceSetContainer
import org.gradle.api.tasks.bundling.AbstractArchiveTask
import org.gradle.api.tasks.bundling.Jar
import org.gradle.api.tasks.testing.Test
import org.gradle.process.CommandLineArgumentProvider
import org.gradle.api.tasks.compile.JavaCompile
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
Expand Down Expand Up @@ -482,6 +484,22 @@ if (stoneNodes.contains(project.name)) {
from(rootProject.layout.projectDirectory.file("LICENSE")) { into("META-INF/dlc-manager") }
}
}
val mixinTestJar = tasks.named<Jar>("jar").flatMap { it.archiveFile }
tasks.withType<Test>().configureEach {
dependsOn(mixinTestJar)
inputs.file(mixinTestJar)
systemProperty("dlc_manager.test.loader", loaderName)
jvmArgumentProviders.add(CommandLineArgumentProvider {
listOf("-Ddlc_manager.test.jar=${mixinTestJar.get().asFile.absolutePath}")
})
if (loaderName == "forge") {
dependsOn("generateDLIConfig")
val launchConfig = rootProject.layout.projectDirectory.file(".gradle/loom-cache/projects/$nodeName/launch.cfg")
inputs.file(launchConfig)
systemProperty("dlc_manager.test.launchConfig", launchConfig.asFile.absolutePath)
}
}

tasks.withType<ProcessResources>().configureEach {
notCompatibleWithConfigurationCache("StoneCraft processResources actions capture Project.")
if (name == "processResources") {
Expand Down Expand Up @@ -612,6 +630,9 @@ if (stoneNodes.contains(project.name)) {
}

extensions.configure<LoomGradleExtensionAPI> {
if (loaderName == "forge") {
forge.mixinConfig("dlc_manager.mixins.json")
}
runs.named("server") {
runDirectory.set(rootProject.layout.projectDirectory.dir("run/$loaderName/$minecraftVersion/server"))
}
Expand Down Expand Up @@ -829,6 +850,9 @@ if (stoneNodes.contains(project.name)) {
}?.forEach(File::delete)
}
}
if (remappedJar.name == "jar") {
tasks.withType<Test>().configureEach { dependsOn(packageDistribution) }
}
remappedJar.configure { finalizedBy(packageDistribution) }
}
tasks.named("publishMods") {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.cozooo.dlc_manager.client.config;

import com.cozooo.dlc_manager.core.DlcFileSize;
import com.cozooo.dlc_manager.core.DlcConfig;
import java.util.List;

Expand Down Expand Up @@ -238,7 +239,7 @@ public static void applyToConfig() {

DlcConfig.setMaxConcurrentDownloads(MAX_CONCURRENT_DOWNLOADS.getIntegerValue());
DlcConfig.setMaxSegmentsPerFile(MAX_SEGMENTS_PER_FILE.getIntegerValue());
DlcConfig.setMinSegmentBytes((long) Math.max(1, MIN_SEGMENT_MB.getIntegerValue()) * 1024L * 1024L);
DlcConfig.setMinSegmentBytes((long) Math.max(1, MIN_SEGMENT_MB.getIntegerValue()) * DlcFileSize.MIB);
DlcConfig.setMaxRetryCount(MAX_RETRY.getIntegerValue());
DlcConfig.setConnectTimeoutMs(CONNECT_TIMEOUT_SECONDS.getIntegerValue() * 1000);
DlcConfig.setTaskTimeoutMs(TASK_TIMEOUT_SECONDS.getIntegerValue() * 1000);
Expand All @@ -248,7 +249,7 @@ public static void applyToConfig() {
}

private static int toMb(long bytes) {
long mb = (bytes + 1024L * 1024L - 1) / (1024L * 1024L);
long mb = DlcFileSize.ceilMiB(bytes);
if (mb < 1) {
return 1;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.cozooo.dlc_manager.client.download;

import com.cozooo.dlc_manager.core.DlcFileSize;
import com.cozooo.dlc_manager.core.DlcConfig;
import java.io.BufferedInputStream;
import java.io.IOException;
Expand Down Expand Up @@ -30,7 +31,7 @@ public final class DlcDownloadService {
private static final long MIRROR_COMPARE_WINDOW_MS = 3000L;
private static final int MIRROR_DISABLE_FAILURES = 2;
private static final long SPEED_WINDOW_MS = 1000L;
private static final long BYTES_PER_MIB = 1024L * 1024L;
private static final long BYTES_PER_MIB = DlcFileSize.MIB;
private static final long MIN_MIRROR_SPEED_CHECK_BYTES = BYTES_PER_MIB;
private static final double SEGMENT_SPEED_DROP_RETRY_RATIO = 0.25;
private static final String CURSEFORGE_PROBE_PROJECT_ID = "678295";
Expand Down Expand Up @@ -92,6 +93,8 @@ public static Path download(String url, Path outputDir, String desiredFileName,
}
Path target = outputDir.resolve(fileName);
Path temp = outputDir.resolve(fileName + ".part");
com.cozooo.dlc_manager.client.update.DlcUpdateJournal.beforeSyncWrite(target);
com.cozooo.dlc_manager.client.update.DlcUpdateJournal.beforeSyncWrite(temp);

if (listener != null) {
listener.onProgress(0L, probe.totalBytes);
Expand Down Expand Up @@ -142,6 +145,8 @@ public static Path downloadKnown(String url, Path outputDir, String desiredFileN
}
Path target = outputDir.resolve(fileName);
Path temp = outputDir.resolve(fileName + ".part");
com.cozooo.dlc_manager.client.update.DlcUpdateJournal.beforeSyncWrite(target);
com.cozooo.dlc_manager.client.update.DlcUpdateJournal.beforeSyncWrite(temp);
long total = expectedSize > 0 ? expectedSize : -1L;
DownloadMirrorMode mode = DownloadMirrorMode.fromConfig(DlcConfig.getDownloadMirrorMode());
MirrorPlan mirrorPlan = mirrorPlan(url, fileName, total);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ public static List<DlcPresetEntry> loadAll() {
return loadAll(DlcConfig.getDlcRoots());
}

public static List<DlcPresetEntry> loadAll(List<Path> roots) {
public static List<DlcPresetEntry> loadAll(List<Path> roots) { return loadAll(roots, true); }

public static List<DlcPresetEntry> loadAll(List<Path> roots, boolean migrate) {
List<DlcPresetEntry> entries = new ArrayList<>();
if (roots == null || roots.isEmpty()) {
return entries;
Expand All @@ -44,7 +46,7 @@ public static List<DlcPresetEntry> loadAll(List<Path> roots) {
try (var stream = Files.walk(presetRoot)) {
stream.filter(path -> path.getFileName() != null && DlcDcFormatUtil.isDcName(path.getFileName().toString()))
.forEach(path -> {
DlcPresetEntry entry = readEntry(path);
DlcPresetEntry entry = readEntry(path, migrate);
if (entry != null) {
entries.add(entry);
}
Expand All @@ -70,7 +72,7 @@ public static Path ensurePresetRoot(Path dlcRoot) {
return presetRoot;
}

private static DlcPresetEntry readEntry(Path path) {
private static DlcPresetEntry readEntry(Path path, boolean migrate) {
JsonObject obj = DlcDcConfigIO.read(path, DlcDcConfigIO.Layout.GENERIC);
if (obj == null) {
return null;
Expand All @@ -87,7 +89,7 @@ private static DlcPresetEntry readEntry(Path path) {

String fileName = stripExtension(path.getFileName().toString());
String id = readIdentifier(basic, obj, fileName);
migrateIfNeeded(path, obj, id, alarm, enable, conflicts);
if (migrate) migrateIfNeeded(path, obj, id, alarm, enable, conflicts);
return new DlcPresetEntry(id, fileName, path, displayName, tip, alarmTip, enable, conflicts, alarm, DlcPresetStatus.OFF);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@ public final class DlcPresetRuntimeState {
private DlcPresetRuntimeState() {
}

public static void reload() {
public static void reload() { reload(true); }

public static void reload(boolean migrate) {
Set<String> previousEnabled = presetDirty ? new LinkedHashSet<>(ENABLED_PRESETS) : null;
List<DlcPresetEntry> entries = DlcPresetLoader.loadAll();
List<DlcPresetEntry> entries = DlcPresetLoader.loadAll(com.cozooo.dlc_manager.core.DlcConfig.getDlcRoots(), migrate);
PRESETS_BY_ID.clear();
for (DlcPresetEntry entry : entries) {
if (entry != null && entry.getId() != null && !entry.getId().isBlank()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,21 @@ protected final Element fileList(String title) {

protected final void fileRow(Element list, String name, String description, Supplier<String> checked,
BooleanSupplier enabled, Runnable select, Runnable open) {
Element line = node(list, "div", "page-row file-row");
fileRowLine(list, name, description, checked, enabled, select, open);
}

protected final Element fileRowLine(Element list, String name, String description, Supplier<String> checked,
BooleanSupplier enabled, Runnable select, Runnable open) {
return fileRowLine(list, name, description, checked, enabled, select, open, false);
}

protected final Element managerRowLine(Element list, String name, Supplier<String> checked, BooleanSupplier enabled, Runnable select) {
return fileRowLine(list, name, null, checked, enabled, select, null, true);
}

private Element fileRowLine(Element list, String name, String description, Supplier<String> checked,
BooleanSupplier enabled, Runnable select, Runnable open, boolean managerStyle) {
Element line = managerStyle ? list.appendChild(pageDocument.createElement("div")) : node(list, "div", "page-row file-row");
var button = action(line, "", () -> {
if (enabled.getAsBoolean()) { select.run(); syncSelections(); }
});
Expand All @@ -32,9 +46,13 @@ protected final void fileRow(Element list, String name, String description, Supp
box.setAttribute("role", "checkbox");
box.setAttribute("aria-label", tr("dlc_manager.ui.select") + " " + name);
box.setInnerHTML("<svg class=\"file-checkmark\" viewBox=\"0 0 16 16\"><path d=\"M3 8 L6.5 11.5 L13 4.5\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\"></path></svg><span class=\"file-mixed\"></span>");
Element copy = node(line, "div", "row-copy");
text(copy, name, "row-title");
if (description != null && !description.isBlank()) text(copy, description, "row-description");
if (managerStyle) {
DlcUiRows.managerRow(pageDocument, line, name, false, false);
} else {
Element copy = node(line, "div", "row-copy");
text(copy, name, "row-title");
if (description != null && !description.isBlank()) text(copy, description, "row-description");
}
if (open != null) {
Document document = pageDocument;
long generation = document.getRefreshGeneration();
Expand All @@ -59,8 +77,9 @@ protected final void fileRow(Element list, String name, String description, Supp
};
selections.add(sync);
sync.run();
return line;
}

private void syncSelections() { selections.forEach(Runnable::run); }
protected final void syncSelections() { selections.forEach(Runnable::run); }
@Override protected void updatePage() { syncSelections(); }
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.util.Map;

public abstract class DlcManagerPageScreen extends DlcApricityScreen {
protected DlcUiButton headerBackButton;
protected DlcManagerPageScreen() { this(DlcUiPage.MANAGER); }
protected DlcManagerPageScreen(DlcUiPage page) { super(page); }
protected DlcUiButton searchClearButton;
Expand All @@ -31,7 +32,7 @@ public abstract class DlcManagerPageScreen extends DlcApricityScreen {
private Document layoutDocument;
private long layoutGeneration = -1;
private boolean sidebarCollapsed;
private double sidebarWidth = 172;
private double sidebarWidth = 240;
private double rowHeight = 40;
private final DlcUiMotion sidebarMotion = new DlcUiMotion(1);
private double lastSidebarProgress = Double.NaN;
Expand All @@ -55,11 +56,19 @@ private static final class GroupView {

protected void bindManagerLayout(Document document, String title) {
Element manager = document.getElementById("manager");
sidebarWidth = layoutMetric(manager, "data-sidebar-width", 172);
sidebarWidth = layoutMetric(manager, "data-sidebar-width", 240);
rowHeight = layoutMetric(manager, "data-row-height", 40);
document.getElementById("manager-header").setAttribute("class", "workspace-header");
restoreUiClasses(document.getElementById("manager-header"));
DlcUiText.set(document.getElementById("manager-title"), title);
Element back = document.getElementById("manager-back");
headerBackButton = null;
if (back != null) {
clearUiContent(back);
headerBackButton = button(document, back, "‹", this::onClose);
headerBackButton.getElement().setAttribute("class", "button manager-back");
headerBackButton.getElement().setAttribute("aria-label", layoutTranslate("gui.back"));
}
document.getElementById("category-label").setTextContent(layoutTranslate("dlc_manager.ui.categories"));
document.getElementById("tools-label").setTextContent(layoutTranslate("dlc_manager.ui.tools"));
if (layoutDocument != document || layoutGeneration != document.getRefreshGeneration()) {
Expand Down Expand Up @@ -94,9 +103,7 @@ protected Element addManagerGroup(Document document, Element list, Element headi
}

protected Element styleManagerRow(Document document, Element entry, String name, boolean enabled, boolean pending) {
entry.setAttribute("class", "dlc-row" + (enabled ? " enabled" : "") + (pending ? " pending" : ""));
if (pending || enabled) managerText(document, entry, "span", "", "item-status-dot " + (pending ? "pending" : "enabled")).setAttribute("aria-hidden", "true");
return managerText(document, entry, "span", name, "item-name");
return DlcUiRows.managerRow(document, entry, name, enabled, pending);
}

protected DlcUiButton managerToggle(Document document, Element entry, boolean enabled, Runnable action) {
Expand Down Expand Up @@ -187,10 +194,7 @@ protected void updateAnimations(Document document, long now) {
}

protected static Element managerText(Document document, Element parent, String tag, String value, String className) {
Element element = document.createElement(tag);
element.setAttribute("class", className);
DlcUiText.set(element, value);
return parent.appendChild(element);
return DlcUiRows.text(document, parent, tag, value, className);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ public DlcNoticeScreen(Screen parent, DlcNoticeConfig config) {
}
var body = node(content, "article", "page-prose");
markdown(body, resolvedContents);
if (config.getShowFrequency() != DlcNoticeConfig.ShowFrequency.ONCE)
toggle(footer, tr("dlc_manager.notice.never_show"), neverShow, value -> { neverShow = value; refreshPage(); });
if (config.getShowFrequency() != DlcNoticeConfig.ShowFrequency.ONCE) {
footerLeading.setAttribute("style", "display:flex");
toggle(footerLeading, tr("dlc_manager.notice.never_show"), neverShow, value -> { neverShow = value; refreshPage(); });
}
primary(tr("dlc_manager.notice.read"), this::onClose);
status(future == null ? "" : tr("dlc_manager.notice.loading"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ protected DlcPageScreen(DlcUiPage page, Screen parent, Component title) {
clearUiContent(back);
backAction = null;
back.setAttribute("style", showHeaderBackButton() ? "" : "display:none");
back.parentElement.setAttribute("data-has-back", Boolean.toString(showHeaderBackButton()));
if (showHeaderBackButton()) {
backAction = action(back, "‹", this::onClose);
backAction.getElement().setAttribute("aria-label", tr("gui.back"));
Expand Down Expand Up @@ -242,18 +243,7 @@ protected Element progress(Element parent, java.util.function.DoubleSupplier val
Element track = node(parent, "div", "progress-track");
track.setAttribute("role", "progressbar"); track.setAttribute("aria-valuemin", "0"); track.setAttribute("aria-valuemax", "100");
Element fill = node(track, "div", "progress-fill");
int[] previous = {-1};
Runnable binding = () -> {
double fraction = value.getAsDouble();
if (fraction < 0) {
double phase = (System.nanoTime() % 1200000000L) / 1200000000.0;
fill.setAttribute("style", "width:25%;transform:translateX(" + (track.getOffsetWidth() * 0.75 * phase) + "px)");
track.removeAttribute("aria-valuenow"); track.setAttribute("aria-busy", "true"); previous[0] = -1; return;
}
track.removeAttribute("aria-busy");
int percent = (int) Math.round(Math.max(0, Math.min(1, fraction)) * 100);
if (percent != previous[0]) { previous[0] = percent; fill.setAttribute("style", "width:" + percent + "%"); track.setAttribute("aria-valuenow", String.valueOf(percent)); }
};
Runnable binding = DlcUiProgress.binding(track, fill, value);
bindings.add(binding); binding.run(); return track;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -320,18 +320,7 @@ private DlcServerFileEntry getSelectedEntry() {
return null;
}

private String formatSize(long size) {
if (size <= 0) {
return "";
}
if (size > 1024 * 1024) {
return String.format("%.1f MB", size / 1024.0 / 1024.0);
}
if (size > 1024) {
return String.format("%.1f KB", size / 1024.0);
}
return size + " B";
}
private String formatSize(long size) { return com.cozooo.dlc_manager.core.DlcFileSize.format(size); }

private boolean controlsReady;
private int pageRevision;
Expand Down
Loading
Loading