mirror of
https://github.com/DSheirer/sdrtrunk.git
synced 2026-11-12 08:37:25 -05:00
#829 Integrates JMBE Creator with new user preferences editor for auto-downloading and compiling the JMBE library from within sdrtrunk. (#844)
Co-authored-by: Denny <denny@denny-desktop>
This commit is contained in:
@@ -22,6 +22,7 @@
|
||||
|
||||
package io.github.dsheirer.preference.decoder;
|
||||
|
||||
import io.github.dsheirer.jmbe.github.Version;
|
||||
import io.github.dsheirer.preference.Preference;
|
||||
import io.github.dsheirer.preference.PreferenceType;
|
||||
import io.github.dsheirer.sample.Listener;
|
||||
@@ -32,6 +33,8 @@ import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.prefs.Preferences;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* Decoder preferences
|
||||
@@ -42,7 +45,10 @@ public class JmbeLibraryPreference extends Preference
|
||||
private Preferences mPreferences = Preferences.userNodeForPackage(JmbeLibraryPreference.class);
|
||||
|
||||
private static final String PREFERENCE_KEY_PATH_JMBE_LIBRARY = "path.jmbe.library.1.0.0";
|
||||
private static final String PREFERENCE_KEY_PATH_ALERT_LIBRARY_REQUIRED = "alert.jmbe.required";
|
||||
private final Pattern VERSION_PATTERN = Pattern.compile(".*jmbe-(\\d{1,5}.\\d{1,5}.\\d{1,5}\\w*)\\.jar");
|
||||
private Path mPathJmbeLibrary;
|
||||
private Boolean mAlertIfMissingLibraryRequired;
|
||||
|
||||
/**
|
||||
* Constructs this preference with an update listener
|
||||
@@ -60,6 +66,23 @@ public class JmbeLibraryPreference extends Preference
|
||||
return PreferenceType.JMBE_LIBRARY;
|
||||
}
|
||||
|
||||
public Version getCurrentVersion()
|
||||
{
|
||||
Path path = getPathJmbeLibrary();
|
||||
|
||||
if(path != null)
|
||||
{
|
||||
Matcher m = VERSION_PATTERN.matcher(path.toString());
|
||||
|
||||
if(m.matches())
|
||||
{
|
||||
return Version.fromString(m.group(1));
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/*
|
||||
* Path to the JMBE audio codec library
|
||||
*/
|
||||
@@ -73,6 +96,14 @@ public class JmbeLibraryPreference extends Preference
|
||||
return mPathJmbeLibrary;
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates if a path to a JMBE library is setup (ie non-null).
|
||||
*/
|
||||
public boolean hasJmbeLibraryPath()
|
||||
{
|
||||
return getPathJmbeLibrary() != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the path to the JMBE library
|
||||
*/
|
||||
@@ -93,6 +124,30 @@ public class JmbeLibraryPreference extends Preference
|
||||
notifyPreferenceUpdated();
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates if the user should be alerted when the JMBE library is not setup, but required for decoding.
|
||||
*/
|
||||
public boolean getAlertIfMissingLibraryRequired()
|
||||
{
|
||||
if(mAlertIfMissingLibraryRequired == null)
|
||||
{
|
||||
mAlertIfMissingLibraryRequired = mPreferences.getBoolean(PREFERENCE_KEY_PATH_ALERT_LIBRARY_REQUIRED, true);
|
||||
}
|
||||
|
||||
return mAlertIfMissingLibraryRequired;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value for alerting when the library is required for decoding but the library is not currently setup.
|
||||
* @param alert true if the user should be alerted when the library is not setup, but required for decoding.
|
||||
*/
|
||||
public void setAlertIfMissingLibraryRequired(boolean alert)
|
||||
{
|
||||
mAlertIfMissingLibraryRequired = alert;
|
||||
mPreferences.putBoolean(PREFERENCE_KEY_PATH_ALERT_LIBRARY_REQUIRED, mAlertIfMissingLibraryRequired);
|
||||
notifyPreferenceUpdated();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the path stored in preferences and referenced by the key argument if it exists, otherwise returns the
|
||||
* default path.
|
||||
|
||||
Reference in New Issue
Block a user