@@ -97,7 +97,7 @@ public class Main {
9797 @ Getter
9898 private static long startupAt = System .currentTimeMillis ();
9999 private static String userAgent ;
100- public static final int PBH_BTN_PROTOCOL_IMPL_VERSION = 8 ;
100+ public static final int PBH_BTN_PROTOCOL_IMPL_VERSION = 10 ;
101101 public static final String PBH_BTN_PROTOCOL_READABLE_VERSION = "0.0.3" ;
102102
103103 public static void main (String [] args ) {
@@ -112,7 +112,7 @@ public static void main(String[] args) {
112112 log .info ("Current system language tag: {}" , defLocaleTag );
113113 DEF_LOCALE = mainConfig .getString ("language" );
114114 if (DEF_LOCALE == null || DEF_LOCALE .equalsIgnoreCase ("default" )) {
115- DEF_LOCALE = System . getenv ("PBH_USER_LOCALE" );
115+ DEF_LOCALE = ExternalSwitch . parse ("PBH_USER_LOCALE" );
116116 if (DEF_LOCALE == null ) {
117117 DEF_LOCALE = defLocaleTag ;
118118 }
@@ -180,7 +180,7 @@ public static void setupLogback() {
180180 }
181181
182182 try {
183- var targetLevel = System . getProperty ("pbh.log.level" );
183+ var targetLevel = ExternalSwitch . parse ("pbh.log.level" );
184184 if (targetLevel != null ) {
185185 var rootLogger = LoggerFactory .getLogger (Logger .ROOT_LOGGER_NAME );
186186 ch .qos .logback .classic .Logger logbackLogger = (ch .qos .logback .classic .Logger ) rootLogger ;
@@ -230,7 +230,7 @@ private static void setupProxySettings() {
230230 private static void setupConfDirectory (String [] args ) {
231231 String osName = System .getProperty ("os.name" );
232232 String root = "data" ;
233- if ("true" . equalsIgnoreCase ( System . getProperty ( "pbh.usePlatformConfigLocation" ) )) {
233+ if (ExternalSwitch . parseBoolean ( "pbh.usePlatformConfigLocation" )) {
234234 if (osName .contains ("Windows" )) {
235235 root = new File (System .getenv ("LOCALAPPDATA" ), "PeerBanHelper" ).getAbsolutePath ();
236236 } else {
@@ -243,20 +243,20 @@ private static void setupConfDirectory(String[] args) {
243243 root = dataDirectory .resolve ("PeerBanHelper" ).toAbsolutePath ().toString ();
244244 }
245245 }
246- if (System . getProperty ("pbh.datadir" ) != null ) {
247- root = System . getProperty ("pbh.datadir" );
246+ if (ExternalSwitch . parse ("pbh.datadir" ) != null ) {
247+ root = ExternalSwitch . parse ("pbh.datadir" );
248248 }
249249
250250 dataDirectory = new File (root );
251251 logsDirectory = new File (dataDirectory , "logs" );
252252 configDirectory = new File (dataDirectory , "config" );
253253 pluginDirectory = new File (dataDirectory , "plugins" );
254254 debugDirectory = new File (dataDirectory , "debug" );
255- if (System . getProperty ("pbh.configdir" ) != null ) {
256- configDirectory = new File (System . getProperty ("pbh.configdir" ));
255+ if (ExternalSwitch . parse ("pbh.configdir" ) != null ) {
256+ configDirectory = new File (ExternalSwitch . parse ("pbh.configdir" ));
257257 }
258- if (System . getProperty ("pbh.logsdir" ) != null ) {
259- logsDirectory = new File (System . getProperty ("pbh.logsdir" ));
258+ if (ExternalSwitch . parse ("pbh.logsdir" ) != null ) {
259+ logsDirectory = new File (ExternalSwitch . parse ("pbh.logsdir" ));
260260 }
261261 // other directories aren't allowed to change by user to keep necessary structure
262262 }
@@ -270,7 +270,7 @@ private static YamlConfiguration loadConfiguration(File file) {
270270 configuration .load (file );
271271 } catch (IOException | InvalidConfigurationException e ) {
272272 log .error ("Unable to load configuration: invalid YAML configuration // 无法加载配置文件:无效的 YAML 配置,请检查是否有语法错误" , e );
273- if (!Desktop .isDesktopSupported () || System . getProperty ("pbh.nogui" ) != null || Arrays .stream (startupArgs ).anyMatch (arg -> arg .equalsIgnoreCase ("nogui" ))) {
273+ if (!Desktop .isDesktopSupported () || ExternalSwitch . parse ("pbh.nogui" ) != null || Arrays .stream (startupArgs ).anyMatch (arg -> arg .equalsIgnoreCase ("nogui" ))) {
274274 try {
275275 log .error ("Bad configuration: {}" , Files .readString (file .toPath ()));
276276 } catch (IOException ex ) {
@@ -338,7 +338,7 @@ private static void setupShutdownHook() {
338338
339339 private static void initGUI (String [] args ) {
340340 String guiType = "swing" ;
341- if (!Desktop .isDesktopSupported () || System . getProperty ("pbh.nogui" ) != null || Arrays .stream (args ).anyMatch (arg -> arg .equalsIgnoreCase ("nogui" ))) {
341+ if (!Desktop .isDesktopSupported () || ExternalSwitch . parse ("pbh.nogui" ) != null || Arrays .stream (args ).anyMatch (arg -> arg .equalsIgnoreCase ("nogui" ))) {
342342 guiType = "console" ;
343343 } else if (Arrays .stream (args ).anyMatch (arg -> arg .equalsIgnoreCase ("swing" ))) {
344344 guiType = "swing" ;
@@ -354,7 +354,7 @@ public static String getUserAgent() {
354354 if (userAgent != null ) return userAgent ;
355355 String userAgentTemplate = "PeerBanHelper/%s (%s; %s,%s,%s) BTN-Protocol/%s BTN-Protocol-Version/%s" ;
356356 var osMXBean = ManagementFactory .getOperatingSystemMXBean ();
357- String release = System . getProperty ("pbh.release" );
357+ String release = ExternalSwitch . parse ("pbh.release" );
358358 if (release == null ) {
359359 release = "unknown" ;
360360 }
0 commit comments