[fixes #825] Rename AssetHandler methods
This commit is contained in:
parent
a6285a64e2
commit
59de3094b2
@ -14,35 +14,35 @@ import java.util.TreeMap;
|
||||
* @author Sibo Van Gool <sibo.vangool@hotmail.com>
|
||||
*/
|
||||
public class AssetHandler {
|
||||
private static final Map<String, Platform> mapExtensionToOS = new HashMap<>(); // Map file extensions to operating system
|
||||
private static final Map<Platform, String> mapOSToName = new HashMap<>(); // Map operating system to a name
|
||||
private static final Map<String, Platform> mapExtensionToPlatform = new HashMap<>(); // Map file extensions to operating platform
|
||||
private static final Map<Platform, String> mapPlatformToName = new HashMap<>(); // Map operating platform to a name
|
||||
static {
|
||||
mapExtensionToOS.put(".dmg", Platform.MAC_OS);
|
||||
mapExtensionToOS.put(".exe", Platform.WINDOWS);
|
||||
mapExtensionToOS.put(".AppImage", Platform.UNIX);
|
||||
mapExtensionToOS.put(".jar", null);
|
||||
mapExtensionToPlatform.put(".dmg", Platform.MAC_OS);
|
||||
mapExtensionToPlatform.put(".exe", Platform.WINDOWS);
|
||||
mapExtensionToPlatform.put(".AppImage", Platform.UNIX);
|
||||
mapExtensionToPlatform.put(".jar", null);
|
||||
|
||||
mapOSToName.put(Platform.MAC_OS, "Mac OS");
|
||||
mapOSToName.put(Platform.WINDOWS, "Windows");
|
||||
mapOSToName.put(Platform.UNIX, "Linux");
|
||||
mapOSToName.put(null, "JAR");
|
||||
mapPlatformToName.put(Platform.MAC_OS, "Mac OS");
|
||||
mapPlatformToName.put(Platform.WINDOWS, "Windows");
|
||||
mapPlatformToName.put(Platform.UNIX, "Linux");
|
||||
mapPlatformToName.put(null, "JAR");
|
||||
}
|
||||
|
||||
/**
|
||||
* Maps a list of asset URLs to their respective operating system.
|
||||
* E.g. "https://github.com/openrocket/openrocket/releases/download/release-15.03/OpenRocket-15.03.dmg" is mapped to
|
||||
* "Mac OS".
|
||||
* Maps a list of asset URLs to their respective operating platform name.
|
||||
* E.g. "https://github.com/openrocket/openrocket/releases/download/release-15.03/OpenRocket-15.03.dmg" is mapped a
|
||||
* map element with "Mac OS" as key and the url as value.
|
||||
* @param urls list of asset URLs
|
||||
* @return map with as key the operating system and as value the corresponding asset URL
|
||||
* @return map with as key the operating platform name and as value the corresponding asset URL
|
||||
*/
|
||||
public static Map<String, String> mapURLToOSName(List<String> urls) {
|
||||
public static Map<String, String> mapURLToPlatformName(List<String> urls) {
|
||||
Map<String, String> output = new TreeMap<>();
|
||||
if (urls == null) return null;
|
||||
|
||||
for (String url : urls) {
|
||||
for (String ext : mapExtensionToOS.keySet()) {
|
||||
for (String ext : mapExtensionToPlatform.keySet()) {
|
||||
if (url.endsWith(ext)) {
|
||||
output.put(mapOSToName.get(mapExtensionToOS.get(ext)), url);
|
||||
output.put(mapPlatformToName.get(mapExtensionToPlatform.get(ext)), url);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -50,12 +50,13 @@ public class AssetHandler {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the OS name based on the operating system that the user is running on, or the value stored in preferences.
|
||||
* @return operating system name
|
||||
* Returns the operating platform name based on the operating system that the user is running on, or the value
|
||||
* stored in preferences.
|
||||
* @return operating platform name
|
||||
*/
|
||||
public static String getOSName() {
|
||||
public static String getPlatformName() {
|
||||
Platform currentPlatform = SystemInfo.getPlatform();
|
||||
// TODO: select right option based on preference
|
||||
return mapOSToName.get(currentPlatform);
|
||||
return mapPlatformToName.get(currentPlatform);
|
||||
}
|
||||
}
|
||||
|
@ -29,7 +29,6 @@ import net.sf.openrocket.gui.util.SwingPreferences;
|
||||
import net.sf.openrocket.l10n.Translator;
|
||||
import net.sf.openrocket.startup.Application;
|
||||
import net.sf.openrocket.gui.widgets.SelectColorButton;
|
||||
import net.sf.openrocket.util.ArrayList;
|
||||
import net.sf.openrocket.util.BuildProperties;
|
||||
import net.sf.openrocket.util.MarkdownUtil;
|
||||
import org.slf4j.Logger;
|
||||
@ -114,7 +113,7 @@ public class UpdateInfoDialog extends JDialog {
|
||||
|
||||
// Install operating system combo box
|
||||
List<String> assetURLs = release.getAssetURLs();
|
||||
Map<String, String> mappedAssets = AssetHandler.mapURLToOSName(assetURLs);
|
||||
Map<String, String> mappedAssets = AssetHandler.mapURLToPlatformName(assetURLs);
|
||||
JComboBox<String> comboBox;
|
||||
if (mappedAssets == null || mappedAssets.size() == 0) {
|
||||
comboBox = new JComboBox<>(new String[]{
|
||||
@ -124,8 +123,8 @@ public class UpdateInfoDialog extends JDialog {
|
||||
comboBox = new JComboBox<>(mappedAssets.keySet().toArray(new String[0]));
|
||||
}
|
||||
panel.add(comboBox, "pushx, right");
|
||||
String os = AssetHandler.getOSName();
|
||||
comboBox.setSelectedItem(os);
|
||||
String platformName = AssetHandler.getPlatformName();
|
||||
comboBox.setSelectedItem(platformName);
|
||||
|
||||
// Install update button
|
||||
JButton btnInstall = new SelectColorButton(trans.get("update.dlg.updateAvailable.but.install"));
|
||||
|
Loading…
x
Reference in New Issue
Block a user