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

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="net.rptools.maptool.client.ui.addresource.AddRessourcesDialogView">
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="net.rptools.maptool.client.ui.addresource.AddResourceDialogView">
<grid id="2bcf8" binding="mainPanel" layout-manager="GridLayoutManager" row-count="1" column-count="4" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="5" left="5" bottom="5" right="5"/>
<constraints>
<xy x="10" y="10" width="386" height="229"/>
<xy x="10" y="10" width="326" height="211"/>
</constraints>
<properties/>
<border type="none"/>
Expand Down Expand Up @@ -167,7 +167,7 @@
</vspacer>
</children>
</grid>
<grid id="39781" layout-manager="GridLayoutManager" row-count="2" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<grid id="39781" layout-manager="GridLayoutManager" row-count="3" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<tabbedpane title=""/>
Expand All @@ -188,26 +188,36 @@
</component>
<scrollpane id="19cce">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<horizontalScrollBarPolicy value="31"/>
<name value="rptoolsListPane"/>
</properties>
<border type="none"/>
<children>
<component id="bdf01" class="javax.swing.JList">
<component id="aaa0" class="javax.swing.JTable" default-binding="true">
<constraints/>
<properties>
<name value="@rptoolsList"/>
<autoCreateRowSorter value="true"/>
<name value="libraryTable"/>
</properties>
</component>
</children>
</scrollpane>
<vspacer id="676ac">
<constraints>
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
<component id="c9398" class="javax.swing.JLabel">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<name value="downloadingLabel"/>
</properties>
</component>
</children>
</grid>
</children>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@
*/
package net.rptools.maptool.client.ui.addresource;

import java.awt.*;
import javax.swing.*;

public class AddRessourcesDialogView {
public class AddResourceDialogView {
private JPanel mainPanel;

public JComponent getRootComponent() {
Expand Down
20 changes: 20 additions & 0 deletions src/main/java/net/rptools/maptool/util/library/Library.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* This software Copyright by the RPTools.net development team, and
* licensed under the Affero GPL Version 3 or, at your option, any later
* version.
*
* MapTool Source Code is distributed in the hope that it will be
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public
* License * along with this source Code. If not, please visit
* <http://www.gnu.org/licenses/> and specifically the Affero license
* text at <http://www.gnu.org/licenses/agpl.html>.
*/
package net.rptools.maptool.util.library;

import java.net.URL;
import javax.annotation.Nullable;

public record Library(String name, URL location, long size, @Nullable String author) {}
185 changes: 185 additions & 0 deletions src/main/java/net/rptools/maptool/util/library/LibraryUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
/*
* This software Copyright by the RPTools.net development team, and
* licensed under the Affero GPL Version 3 or, at your option, any later
* version.
*
* MapTool Source Code is distributed in the hope that it will be
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public
* License * along with this source Code. If not, please visit
* <http://www.gnu.org/licenses/> and specifically the Affero license
* text at <http://www.gnu.org/licenses/agpl.html>.
*/
package net.rptools.maptool.util.library;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;
import java.net.URLConnection;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;
import java.util.regex.Pattern;
import javax.annotation.Nullable;
import net.rptools.maptool.client.AppSetup;
import net.rptools.maptool.client.AppStatePersisted;
import net.rptools.maptool.client.RemoteFileDownloader;
import org.apache.commons.io.IOUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

public final class LibraryUtils {
private static final Logger log = LogManager.getLogger(LibraryUtils.class);

private LibraryUtils() {}

private static final URI LIBRARY_BASE_URI = URI.create("https://library.rptools.net/1.3/");
private static final URI LIBRARY_LIST_URI = LIBRARY_BASE_URI.resolve("listArtPacks");

public static CompletionStage<String> downloadLibraryList() {
CompletionStage<URL> urlStage;
try {
urlStage = CompletableFuture.completedStage(LIBRARY_LIST_URI.toURL());
} catch (MalformedURLException e) {
log.error("Library list URL is not valid: {}", LIBRARY_LIST_URI, e);
urlStage = CompletableFuture.failedStage(e);
}
return urlStage
.thenComposeAsync(
url -> {
URLConnection conn;
try {
conn = url.openConnection();
conn.setConnectTimeout(5000);
conn.setReadTimeout(5000);
// Send the request.
conn.connect();
return CompletableFuture.completedStage(conn);
} catch (IOException e) {
log.error("Unable to connect to {}", url, e);
return CompletableFuture.failedStage(e);
}
})
.thenComposeAsync(
conn -> {
try (InputStream in = conn.getInputStream()) {
var list = IOUtils.toString(in, StandardCharsets.UTF_8);
return CompletableFuture.completedStage(list);
} catch (IOException e) {
log.error("Unable to download data from {}", conn.getURL(), e);
return CompletableFuture.failedStage(e);
}
});
}

public static List<Library> parseLibraryList(String listAsString) {
var libraries = new ArrayList<Library>();

var scanner = new Scanner(listAsString);
while (scanner.hasNextLine()) {
var line = scanner.nextLine().trim();
if (line.isEmpty()) {
// Nothing of value.
continue;
}

// Negative limit to get trailing blank strings if present.
String[] data = line.split(Pattern.quote("|"), -1);
final var requiredParts = 3;
if (data.length < requiredParts) {
log.warn(
"Skipping library with too few components. Expected {} parts, but only found {}",
requiredParts,
data.length);
continue;
}

var name = data[0].trim();
if (name.isEmpty()) {
log.warn("Skipping library that is missing a name");
continue;
}

URL url;
var path = data[1].trim();
if (path.isEmpty()) {
log.warn("Skipping library with empty path");
continue;
}
try {
url = LIBRARY_BASE_URI.resolve(data[1].trim()).toURL();
} catch (IllegalArgumentException | MalformedURLException e) {
log.warn("Skipping library with invalid URL", e);
continue;
}

long size;
try {
size = Long.parseLong(data[2]);
} catch (NumberFormatException e) {
log.warn("Skipping library with invalid size", e);
continue;
}

// The author is optional for backwards compatibility.
@Nullable String author;
if (data.length < 4) {
author = null;
} else {
author = data[3].trim();
if (author.isEmpty()) {
author = null;
}
}

libraries.add(new Library(name, url, size, author));
}

return libraries;
}

public static CompletionStage<DownloadResult> downloadAndInstall(List<Library> libraries) {
return CompletableFuture.completedStage(libraries)
.thenComposeAsync(
libraries2 -> {
var failures = new ArrayList<Library>();
var successes = new ArrayList<Library>();

var assetRoots =
AppStatePersisted.getAssetRoots().stream().map(File::getName).toList();

var failed = false;
for (var library : libraries2) {
if (assetRoots.contains(library.name())) {
// Library already exists. Skip it to avoid duplicates.
log.info("Skipping already-installed library: {}", library.name());
continue;
}

try {
RemoteFileDownloader downloader = new RemoteFileDownloader(library.location());
File tmpFile = downloader.read();
AppSetup.installLibrary(library.name(), tmpFile.toURI().toURL());
tmpFile.delete();
} catch (IOException e) {
log.error("Error downloading library: {}", e, e);
failed = true;
}

(failed ? failures : successes).add(library);
}

return CompletableFuture.completedStage(new DownloadResult(successes, failures));
});
}

public record DownloadResult(List<Library> successes, List<Library> failures) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1798,15 +1798,17 @@ defaultTool.visionMenu = Vision

dialog.addresource.downloading = Downloading List ...
dialog.addresource.errorDownloading = Error downloading list.
dialog.addresource.warn.badpath = Invalid path
dialog.addresource.warn.couldnotload = Error while downloading library
dialog.addresource.error.couldNotInstallLibraries = Error while installing these libraries:
dialog.addresource.warn.directoryrequired = Must be a directory
dialog.addresource.warn.filenotfound = Could not find resource "{0}"
dialog.addresource.warn.invalidurl = Invalid URL: {0}
dialog.addresource.warn.musthavename = Must supply a name for the library
dialog.addresource.warn.mustselectone = Must select at least one library to download
dialog.addresource.error.malformedurl = Artpack URL {0} is malformed. Please check your installation.
dialog.addresource.warn.badresourceid = Bad resource identifier: {0}. Report error to MapTool team.
dialog.addresource.column.libraryName = Library Name
dialog.addresource.column.librarySize = Size
dialog.addresource.column.libraryAuthor = Author
dialog.addresource.unknownAuthor = unknown
dialog.campaignExport.notes.version.1.4.0.0 = Exporting to this version will strip out any drawables and any campaign settings for <b>Lumens</b>.<br>Tokens with <b>VBL</b> will loose this functionality as well as any <i>Always Visible</i> values.<br><b>Merged Drawings</b> will still be present but their label in Draw Explorer will not show as normal.<br><br><i>Note: Macros will remain unchanged, so any reference to newer functionality not available in this version will cause normal errors when ran.</i>
dialog.campaignExport.notes.version.1.4.0.1 = Exporting to this version will strip out any campaign settings for <b>Lumens</b>.<br>Tokens with <b>VBL</b> will loose this functionality as well as any <i>Always Visible</i> values.<br><b>Merged Drawings</b> will still be present but their label in Draw Explorer will not show as normal.<br><br><i>Note: Macros will remain unchanged, so any reference to newer functionality not available in this version will cause normal errors when ran.</i>
dialog.campaignExport.notes.version.1.4.1..1.5.0 = Exporting to this version will make sure the former format of the content.xml inside the campaign file is kept and the unitsPerCell value for zones/maps is an integer (vs. double in the newer versions).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1570,14 +1570,11 @@ defaultTool.visionMenu = Vision

dialog.addresource.downloading = Downloading List ...
dialog.addresource.errorDownloading = Error downloading list.
dialog.addresource.warn.badpath = Invalid path
dialog.addresource.warn.couldnotload = Error while downloading library
dialog.addresource.warn.directoryrequired = Must be a directory
dialog.addresource.warn.filenotfound = Could not find resource "{0}"
dialog.addresource.warn.invalidurl = Invalid URL\: {0}
dialog.addresource.warn.musthavename = Must supply a name for the library
dialog.addresource.warn.mustselectone = Must select at least one library to download
dialog.addresource.error.malformedurl = Artpack URL {0} is malformed. Please check your installation.
dialog.addresource.warn.badresourceid = Bad resource identifier\: {0}. Report error to MapTool team.
dialog.campaignExport.notes.version.1.4.0.0 = Exporting to this version will strip out any drawables and any campaign settings for <b>Lumens</b>.<br>Tokens with <b>VBL</b> will loose this functionality as well as any <i>Always Visible</i> values.<br><b>Merged Drawings</b> will still be present but their label in Draw Explorer will not show as normal.<br><br><i>Note\: Macros will remain unchanged, so any reference to newer functionality not available in this version will cause normal errors when ran.</i>
dialog.campaignExport.notes.version.1.4.0.1 = Exporting to this version will strip out any campaign settings for <b>Lumens</b>.<br>Tokens with <b>VBL</b> will loose this functionality as well as any <i>Always Visible</i> values.<br><b>Merged Drawings</b> will still be present but their label in Draw Explorer will not show as normal.<br><br><i>Note\: Macros will remain unchanged, so any reference to newer functionality not available in this version will cause normal errors when ran.</i>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1570,14 +1570,11 @@ defaultTool.visionMenu = Vision

dialog.addresource.downloading = Henter liste...
dialog.addresource.errorDownloading = Fejl under download af liste.
dialog.addresource.warn.badpath = Ugyldig sti
dialog.addresource.warn.couldnotload = Fejl ved download af bibliotek
dialog.addresource.warn.directoryrequired = Skal være en mappe
dialog.addresource.warn.filenotfound = Kunne ikke finde ressource "{0}"
dialog.addresource.warn.invalidurl = Ugyldig URL\: {0}
dialog.addresource.warn.musthavename = Must supply a name for the library
dialog.addresource.warn.mustselectone = Vælge mindst ét bibliotek til download
dialog.addresource.error.malformedurl = Artpack URL {0} is malformed. Please check your installation.
dialog.addresource.warn.badresourceid = Bad resource identifier\: {0}. Report error to MapTool team.
dialog.campaignExport.notes.version.1.4.0.0 = Exporting to this version will strip out any drawables and any campaign settings for <b>Lumens</b>.<br>Tokens with <b>VBL</b> will loose this functionality as well as any <i>Always Visible</i> values.<br><b>Merged Drawings</b> will still be present but their label in Draw Explorer will not show as normal.<br><br><i>Note\: Macros will remain unchanged, so any reference to newer functionality not available in this version will cause normal errors when ran.</i>
dialog.campaignExport.notes.version.1.4.0.1 = Exporting to this version will strip out any campaign settings for <b>Lumens</b>.<br>Tokens with <b>VBL</b> will loose this functionality as well as any <i>Always Visible</i> values.<br><b>Merged Drawings</b> will still be present but their label in Draw Explorer will not show as normal.<br><br><i>Note\: Macros will remain unchanged, so any reference to newer functionality not available in this version will cause normal errors when ran.</i>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1570,14 +1570,11 @@ defaultTool.visionMenu = Sicht

dialog.addresource.downloading = Lade Liste herunter ...
dialog.addresource.errorDownloading = Fehler beim Herunterladen der Liste.
dialog.addresource.warn.badpath = Ungültiger Pfad
dialog.addresource.warn.couldnotload = Fehler beim Herunterladen der Bibliothek
dialog.addresource.warn.directoryrequired = Es muss ein Verzeichnis sein
dialog.addresource.warn.filenotfound = Kann die Ressource "{0}" nicht finden
dialog.addresource.warn.invalidurl = Ungültige URL\: {0}
dialog.addresource.warn.musthavename = Es muss ein Name für die Bibliothek angegeben werden
dialog.addresource.warn.mustselectone = Es muss mindestens eine Bibliothek zum Herunterladen ausgewählt werden
dialog.addresource.error.malformedurl = Artpack-URL {0} ist fehlerhaft. Bitte Installation überprüfen.
dialog.addresource.warn.badresourceid = Ungültige Ressourcenkennung\: {0}. Melden Sie den Fehler an das MapTool-Team.
dialog.campaignExport.notes.version.1.4.0.0 = Beim Export in diese Version werden alle Zeichnungen und Kampagneneinstellungen für <b>Lumens</b> entfernt.<br><b>VBL</b> und <i>Immer sichtbar</i> bei Tokens geht verloren.<br><b>Verbundene Zeichnungen</b> bleiben bestehen, aber ihre Beschriftung im Draw Explorer wird nicht normal dargestellt.<br><br><i>Hinweis\: Makros bleiben unverändert. Die Verwendung von Funktionen, die in jener Version noch nicht zur Verfügung standen, werden daher entsprechende Fehler verursachen.</i>
dialog.campaignExport.notes.version.1.4.0.1 = Beim Export in diese Version werden alle Kampagneneinstellungen für <b>Lumens</b> entfernt.<br><b>VBL</b> und <i>Immer sichtbar</i> bei Tokens geht verloren.<br><b>Verbundene Zeichnungen</b> bleiben bestehen, aber ihre Beschriftung im Draw Explorer wird nicht normal dargestellt.<br><br><i>Hinweis\: Makros bleiben unverändert. Die Verwendung von Funktionen, die in jener Version noch nicht zur Verfügung standen, werden daher entsprechende Fehler verursachen.</i>
Expand Down
Loading