Skip to content

Commit e03d7f2

Browse files
committed
2.0 release
1 parent cbc978b commit e03d7f2

8 files changed

Lines changed: 156 additions & 93 deletions

File tree

changelog.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
Version 2.0 (March 19, 2019)
2+
==============================
3+
Added "nexusModId" field to .version file format:
4+
- Optional field, adds support for nexusmods.com
5+
- ID is an integer, and should be the mod ID in the Nexus mod page's URL
6+
Ex: https://www.nexusmods.com/starsector/mods/3 has an ID of 3
7+
Added "preferNexusLinks" to data/config/version/version_checker.json:
8+
- When true, will open a mod's Nexus page instead of its forum thread,
9+
provided it has one listed in its .version file
10+
Added an option that opens threads for all updatable mods in one click
11+
Fixed RecheckVersions command not updating the version info dialog
12+
Fixed message spam when a user's connection drops during an update check
13+
114
Version 1.8b (December 1, 2018)
215
=================================
316
Fixed Bitbucket connection issue (enabled TLS v1.2)

mod_info.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"name": "Version Checker",
44
"author": "LazyWizard",
55
"utility": "true",
6-
"version": "1.8b",
6+
"version": "2.0",
77
"description": "Tells you whether Starsector or any of your mods have updates available. A mod must include a .version file and an entry in data/config/version/version_files.csv for this to work with them.",
88
"gameVersion": "0.9a",
99
"jars":["jars/lw_VersionChecker.jar"],

org/lazywizard/versionchecker/UpdateInfo.java

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
package org.lazywizard.versionchecker;
22

3-
import java.util.ArrayList;
4-
import java.util.List;
53
import org.json.JSONException;
64
import org.json.JSONObject;
75

6+
import java.util.ArrayList;
7+
import java.util.List;
8+
89
final class UpdateInfo
910
{
1011
private final List<ModInfo> hasUpdate = new ArrayList<>();
@@ -146,7 +147,9 @@ static final class VersionFile implements Comparable<VersionFile>
146147
{
147148
private static final String MOD_THREAD_FORMAT
148149
= "http://fractalsoftworks.com/forum/index.php?topic=%d.0";
149-
private final int major, minor, modThreadId;
150+
private static final String MOD_NEXUS_FORMAT
151+
= "https://www.nexusmods.com/starsector/mods/%d?tab=files";
152+
private final int major, minor, modThreadId, modNexusId;
150153
private final String patch, masterURL, modName;
151154

152155
VersionFile(final JSONObject json, boolean isMaster) throws JSONException
@@ -155,6 +158,7 @@ static final class VersionFile implements Comparable<VersionFile>
155158
masterURL = (isMaster ? null : json.getString("masterVersionFile"));
156159
modName = (isMaster ? null : json.optString("modName", "<unknown>"));
157160
modThreadId = (isMaster ? 0 : (int) json.optDouble("modThreadId", 0));
161+
modNexusId = (isMaster ? 0 : (int) json.optDouble("modNexusId", 0));
158162

159163
// Parse version number
160164
JSONObject modVersion = json.getJSONObject("modVersion");
@@ -212,14 +216,19 @@ String getMasterURL()
212216
return masterURL;
213217
}
214218

215-
String getThreadURL()
219+
String getUpdateURL()
216220
{
217-
if (modThreadId == 0)
221+
if (VCModPlugin.preferNexus)
218222
{
219-
return null;
223+
return (modNexusId == 0 ? modThreadId == 0 ? null
224+
: String.format(MOD_THREAD_FORMAT, modThreadId)
225+
: String.format(MOD_NEXUS_FORMAT, modNexusId));
220226
}
221227

222-
return String.format(MOD_THREAD_FORMAT, modThreadId);
228+
return (modThreadId == 0 ? modNexusId == 0 ? null
229+
: String.format(MOD_NEXUS_FORMAT, modNexusId)
230+
: String.format(MOD_THREAD_FORMAT, modThreadId));
231+
223232
}
224233

225234
@Override
@@ -248,9 +257,9 @@ private static String[] splitPatch(String patch)
248257

249258
//System.out.println(digit + " | " + str);
250259
return new String[]
251-
{
252-
digit.toString(), str
253-
};
260+
{
261+
digit.toString(), str
262+
};
254263
}
255264

256265
private static int comparePatch(String patch, String other)

org/lazywizard/versionchecker/UpdateNotificationScript.java

Lines changed: 59 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ private enum Menu
190190
LIST_FAILED,
191191
PREVIOUS_PAGE,
192192
NEXT_PAGE,
193+
OPEN_ALL_UPDATES,
193194
RETURN,
194195
EXIT
195196
}
@@ -328,7 +329,11 @@ private void generateModMenu()
328329
ModInfo mod = currentList.get(x);
329330
VersionFile local = mod.getLocalVersion();
330331
options.addOption(local.getName(), local);
331-
options.setEnabled(local, local.getThreadURL() != null);
332+
options.setEnabled(local, local.getUpdateURL() != null);
333+
if (local.getUpdateURL() != null)
334+
{
335+
options.setTooltip(local, "URL: " + local.getUpdateURL());
336+
}
332337
}
333338

334339
// Support for multiple pages of options
@@ -428,6 +433,19 @@ private void goToMenu(Menu menu)
428433
options.addOption("List mods with updates", Menu.LIST_UPDATES);
429434
options.setEnabled(Menu.LIST_UPDATES, !hasUpdate.isEmpty());
430435

436+
// Only show this option if there are updates available
437+
if (!hasUpdate.isEmpty())
438+
{
439+
options.addOption("Open page for all mods with an update available", Menu.OPEN_ALL_UPDATES);
440+
441+
// Launching the browser doesn't work on some Linux distros
442+
if (!Desktop.isDesktopSupported())
443+
{
444+
options.setEnabled(Menu.OPEN_ALL_UPDATES, false);
445+
options.setTooltip(Menu.OPEN_ALL_UPDATES, "Not supported on this OS!");
446+
}
447+
}
448+
431449
// Only show this option if an update check has actually failed
432450
if (!failedCheck.isEmpty())
433451
{
@@ -515,6 +533,14 @@ else if (ssUpdateError != null)
515533
currentPage++;
516534
generateModMenu();
517535
break;
536+
case OPEN_ALL_UPDATES:
537+
for (ModInfo mod : hasUpdate)
538+
{
539+
openModThread(mod.getLocalVersion());
540+
}
541+
goToMenu(Menu.MAIN_MENU);
542+
options.setEnabled(Menu.OPEN_ALL_UPDATES, false);
543+
break;
518544
case RETURN:
519545
generateModMenu();
520546
break;
@@ -536,6 +562,37 @@ public void init(InteractionDialogAPI dialog)
536562
goToMenu(Menu.MAIN_MENU);
537563
}
538564

565+
private void openModThread(VersionFile mod)
566+
{
567+
// Some flavors of Linux don't support the Desktop API without certain libraries installed
568+
if (!Desktop.isDesktopSupported())
569+
{
570+
final StringSelection modUrl = new StringSelection(mod.getUpdateURL());
571+
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(modUrl, modUrl);
572+
text.addParagraph("Opening the browser directly is not supported on this OS!\n" +
573+
"The forum thread URL has been copied to the clipboard instead.");
574+
return;
575+
}
576+
577+
// Open the mod forum thread in the user's default browser
578+
try
579+
{
580+
final String url = mod.getUpdateURL();
581+
if (url != null)
582+
{
583+
text.addParagraph("Opening " + mod.getName() + " forum thread...");
584+
options.setEnabled(mod, false);
585+
Desktop.getDesktop().browse(URI.create(url));
586+
}
587+
}
588+
catch (Exception ex)
589+
{
590+
Log.error("Failed to launch browser: ", ex);
591+
text.addParagraph("Failed to launch browser: "
592+
+ ex.getMessage(), Color.RED);
593+
}
594+
}
595+
539596
@Override
540597
public void optionSelected(String optionText, Object optionData)
541598
{
@@ -549,31 +606,7 @@ public void optionSelected(String optionText, Object optionData)
549606
// Option was version data? Launch that mod's forum thread
550607
else if (optionData instanceof VersionFile)
551608
{
552-
final VersionFile info = (VersionFile) optionData;
553-
554-
// Some flavors of Linux don't support the Desktop API without certain libraries installed
555-
if (!Desktop.isDesktopSupported())
556-
{
557-
final StringSelection modUrl = new StringSelection(info.getThreadURL());
558-
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(modUrl, modUrl);
559-
text.addParagraph("Opening the browser directly is not supported on this OS!\n" +
560-
"The forum thread URL has been copied to the clipboard instead.");
561-
return;
562-
}
563-
564-
// Open the mod forum thread in the user's default browser
565-
try
566-
{
567-
text.addParagraph("Opening " + info.getName() + " forum thread...");
568-
options.setEnabled(info, false);
569-
Desktop.getDesktop().browse(URI.create(info.getThreadURL()));
570-
}
571-
catch (Exception ex)
572-
{
573-
Log.error("Failed to launch browser: ", ex);
574-
text.addParagraph("Failed to launch browser: "
575-
+ ex.getMessage(), Color.RED);
576-
}
609+
openModThread((VersionFile) optionData);
577610
}
578611
}
579612

org/lazywizard/versionchecker/VCModPlugin.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public final class VCModPlugin extends BaseModPlugin
1919
private static final String SETTINGS_FILE = "data/config/version/version_checker.json";
2020
private static final String CSV_PATH = "data/config/version/version_files.csv";
2121
private static UpdateNotificationScript script = null;
22-
static boolean checkSSVersion = false;
22+
static boolean checkSSVersion = false, preferNexus = false;
2323
static int notificationKey;
2424

2525
private static boolean isIgnored(ModSpecAPI mod)
@@ -56,6 +56,7 @@ public void connect() throws IOException
5656
final JSONObject settings = Global.getSettings().loadJSON(SETTINGS_FILE);
5757
notificationKey = settings.getInt("summonUpdateNotificationKey");
5858
checkSSVersion = settings.getBoolean("checkStarsectorVersion");
59+
preferNexus = settings.getBoolean("preferNexusLinks");
5960
VersionChecker.setMaxThreads(settings.getInt("maxUpdateThreads"));
6061
Log.setLevel(Level.toLevel(settings.getString("logLevel"), Level.WARN));
6162

org/lazywizard/versionchecker/VersionChecker.java

Lines changed: 49 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
package org.lazywizard.versionchecker;
22

3+
import com.fs.starfarer.api.Global;
4+
import org.json.JSONException;
5+
import org.json.JSONObject;
6+
import org.lazywizard.versionchecker.UpdateInfo.ModInfo;
7+
import org.lazywizard.versionchecker.UpdateInfo.VersionFile;
8+
39
import java.io.IOException;
410
import java.io.InputStream;
511
import java.net.MalformedURLException;
@@ -8,20 +14,7 @@
814
import java.util.List;
915
import java.util.NoSuchElementException;
1016
import java.util.Scanner;
11-
import java.util.concurrent.Callable;
12-
import java.util.concurrent.CompletionService;
13-
import java.util.concurrent.ExecutionException;
14-
import java.util.concurrent.ExecutorCompletionService;
15-
import java.util.concurrent.ExecutorService;
16-
import java.util.concurrent.Executors;
17-
import java.util.concurrent.Future;
18-
import java.util.concurrent.FutureTask;
19-
import java.util.concurrent.ThreadFactory;
20-
import com.fs.starfarer.api.Global;
21-
import org.json.JSONException;
22-
import org.json.JSONObject;
23-
import org.lazywizard.versionchecker.UpdateInfo.ModInfo;
24-
import org.lazywizard.versionchecker.UpdateInfo.VersionFile;
17+
import java.util.concurrent.*;
2518

2619
// TEMP: runcode String path = (System.getProperty("user.dir")+"/"+System.getProperty("com.fs.starfarer.settings.paths.mods")); path = path.replace("\\\\", "\\").replace("\\","/");System.out.println(path);
2720
final class VersionChecker
@@ -84,7 +77,7 @@ private static Object getRemoteVersionFile(final String versionFileURL)
8477

8578
// Load JSON from external URL and parse version info from it
8679
try (InputStream stream = new URL(versionFileURL).openStream();
87-
Scanner scanner = new Scanner(stream, "UTF-8").useDelimiter("\\A"))
80+
Scanner scanner = new Scanner(stream, "UTF-8").useDelimiter("\\A"))
8881
{
8982
return new VersionFile(sanitizeJSON(scanner.next()), true);
9083

@@ -112,7 +105,7 @@ private static String getLatestSSVersion() throws IOException, NoSuchElementExce
112105

113106
// Get latest Starsector version from remote URL
114107
try (InputStream stream = new URL(VANILLA_UPDATE_URL).openStream();
115-
Scanner scanner = new Scanner(stream, "UTF-8").useDelimiter("\\A"))
108+
Scanner scanner = new Scanner(stream, "UTF-8").useDelimiter("\\A"))
116109
{
117110
return scanner.next();
118111
}
@@ -181,39 +174,45 @@ private CompletionService<ModInfo> createCompletionService()
181174
public static void main(String[] args)
182175
{
183176
final String[] allVersions = new String[]
184-
{
185-
"Starsector 0.35a-pre-RC2",
186-
"Starsector 0.5a-pre-RC3",
187-
"Starsector 0.51a-RC1",
188-
"Starsector 0.51a-RC3",
189-
"Starsector 0.52a-RC2",
190-
"Starsector 0.52.1a-RC4",
191-
"Starsector 0.53a-RC4",
192-
"Starsector 0.53.1a-RC5",
193-
"Starsector 0.54a-RC5",
194-
"Starsector 0.54.1a-RC2",
195-
"Starsector 0.6a-RC1",
196-
"Starsector 0.6a-RC4",
197-
"Starsector 0.6.1a-RC2",
198-
"Starsector 0.6.2a-RC2",
199-
"Starsector 0.6.2a-RC3",
200-
"Starsector 0.65a-RC1",
201-
"Starsector 0.65.1a-RC1",
202-
"Starsector 0.65.2a-RC1",
203-
"Starsector 0.7a-RC7",
204-
"Starsector 0.7a-RC10",
205-
"Starsector 0.7.1a-RC3",
206-
"Starsector 0.7.1a-RC4",
207-
"Starsector 0.7.1a-RC5",
208-
"Starsector 0.7.2a-RC1",
209-
"Starsector 0.7.2a-RC2",
210-
"Starsector 0.7.2a-RC3",
211-
"Starsector 0.8a-RC17",
212-
"Starsector 0.8a-RC18",
213-
"Starsector 0.8a-RC19",
214-
"Starsector 0.8.1a-RC5",
215-
"Starsector 0.8.1a-RC6"
216-
};
177+
{
178+
"Starsector 0.35a-pre-RC2",
179+
"Starsector 0.5a-pre-RC3",
180+
"Starsector 0.51a-RC1",
181+
"Starsector 0.51a-RC3",
182+
"Starsector 0.52a-RC2",
183+
"Starsector 0.52.1a-RC4",
184+
"Starsector 0.53a-RC4",
185+
"Starsector 0.53.1a-RC5",
186+
"Starsector 0.54a-RC5",
187+
"Starsector 0.54.1a-RC2",
188+
"Starsector 0.6a-RC1",
189+
"Starsector 0.6a-RC4",
190+
"Starsector 0.6.1a-RC2",
191+
"Starsector 0.6.2a-RC2",
192+
"Starsector 0.6.2a-RC3",
193+
"Starsector 0.65a-RC1",
194+
"Starsector 0.65.1a-RC1",
195+
"Starsector 0.65.2a-RC1",
196+
"Starsector 0.7a-RC7",
197+
"Starsector 0.7a-RC10",
198+
"Starsector 0.7.1a-RC3",
199+
"Starsector 0.7.1a-RC4",
200+
"Starsector 0.7.1a-RC5",
201+
"Starsector 0.7.2a-RC1",
202+
"Starsector 0.7.2a-RC2",
203+
"Starsector 0.7.2a-RC3",
204+
"Starsector 0.8a-RC17",
205+
"Starsector 0.8a-RC18",
206+
"Starsector 0.8a-RC19",
207+
"Starsector 0.8.1a-RC5",
208+
"Starsector 0.8.1a-RC6",
209+
"Starsector 0.9a-RC6",
210+
"Starsector 0.9a-RC7",
211+
"Starsector 0.9a-RC8",
212+
"Starsector 0.9a-RC9",
213+
"Starsector 0.9a-RC10",
214+
215+
};
217216

218217
// Proper order, all should be true
219218
System.out.println(" Proper order\n--------------");
@@ -321,7 +320,7 @@ public UpdateInfo call() throws InterruptedException, ExecutionException
321320
+ VANILLA_UPDATE_URL + "\"", ex);
322321
results.setFailedSSError(ex.getClass().getSimpleName());
323322
}
324-
catch(Exception ex)
323+
catch (Exception ex)
325324
{
326325
Log.error("Failed to parse vanilla update data from URL \""
327326
+ VANILLA_UPDATE_URL + "\"", ex);

version_checker.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,12 @@
77
# Whether to check if Starsector itself is up to date
88
"checkStarsectorVersion":true, # Default: true
99

10+
# Whether to launch a mod's Nexus page instead of its forum thread, if available
11+
"preferNexusLinks":false, # Default: false
12+
1013
# The maximum number of separate threads to use when checking for updates
1114
"maxUpdateThreads":8,
1215

1316
# Valid levels: OFF, FATAL, ERROR, WARN, INFO, DEBUG, ALL
1417
"logLevel":"INFO"
15-
}
18+
}

0 commit comments

Comments
 (0)