* disable java.util.prefs.WindowsPreferences warnings
This commit is contained in:
parent
6519e872c2
commit
7a11589bc4
|
@ -1,7 +1,5 @@
|
||||||
|
|
||||||
package net.sourceforge.filebot;
|
package net.sourceforge.filebot;
|
||||||
|
|
||||||
|
|
||||||
import static com.dmurph.tracking.JGoogleAnalyticsTracker.GoogleAnalyticsVersion.*;
|
import static com.dmurph.tracking.JGoogleAnalyticsTracker.GoogleAnalyticsVersion.*;
|
||||||
import static net.sourceforge.filebot.Settings.*;
|
import static net.sourceforge.filebot.Settings.*;
|
||||||
|
|
||||||
|
@ -18,52 +16,49 @@ import com.dmurph.tracking.JGoogleAnalyticsTracker;
|
||||||
import com.dmurph.tracking.VisitorData;
|
import com.dmurph.tracking.VisitorData;
|
||||||
import com.sun.jna.Platform;
|
import com.sun.jna.Platform;
|
||||||
|
|
||||||
|
|
||||||
public class Analytics {
|
public class Analytics {
|
||||||
|
|
||||||
private static JGoogleAnalyticsTracker tracker;
|
private static JGoogleAnalyticsTracker tracker;
|
||||||
private static VisitorData visitorData;
|
private static VisitorData visitorData;
|
||||||
|
|
||||||
private static String host = "filebot.sourceforge.net";
|
private static String host = "filebot.sourceforge.net";
|
||||||
private static String currentView = null;
|
private static String currentView = null;
|
||||||
|
|
||||||
private static boolean enabled = false;
|
private static boolean enabled = false;
|
||||||
|
|
||||||
|
|
||||||
public static synchronized JGoogleAnalyticsTracker getTracker() throws Throwable {
|
public static synchronized JGoogleAnalyticsTracker getTracker() throws Throwable {
|
||||||
if (tracker != null)
|
if (tracker != null)
|
||||||
return tracker;
|
return tracker;
|
||||||
|
|
||||||
// disable useless background logging, if it doesn't work it doesn't work, won't affect anything (putting it here works for Java 6)
|
// disable useless background logging, if it doesn't work it doesn't work, won't affect anything (putting it here works for Java 6)
|
||||||
Logger.getLogger("com.dmurph.tracking").setLevel(Level.OFF);
|
Logger.getLogger("com.dmurph.tracking").setLevel(Level.OFF);
|
||||||
|
Logger.getLogger("java.util.prefs").setLevel(Level.OFF);
|
||||||
|
|
||||||
// initialize tracker
|
// initialize tracker
|
||||||
visitorData = restoreVisitorData();
|
visitorData = restoreVisitorData();
|
||||||
tracker = new JGoogleAnalyticsTracker(getConfig(getApplicationProperty("analytics.WebPropertyID"), visitorData), V_4_7_2);
|
tracker = new JGoogleAnalyticsTracker(getConfig(getApplicationProperty("analytics.WebPropertyID"), visitorData), V_4_7_2);
|
||||||
|
|
||||||
// store session data on shutdown
|
// store session data on shutdown
|
||||||
Runtime.getRuntime().addShutdownHook(new Thread("AnalyticsShutdownHook") {
|
Runtime.getRuntime().addShutdownHook(new Thread("AnalyticsShutdownHook") {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
storeVisitorData(visitorData);
|
storeVisitorData(visitorData);
|
||||||
JGoogleAnalyticsTracker.completeBackgroundTasks(2000);
|
JGoogleAnalyticsTracker.completeBackgroundTasks(2000);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return tracker;
|
return tracker;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static void trackView(Class<?> view, String title) {
|
public static void trackView(Class<?> view, String title) {
|
||||||
trackView(view.getName().replace('.', '/'), title);
|
trackView(view.getName().replace('.', '/'), title);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static synchronized void trackView(String view, String title) {
|
public static synchronized void trackView(String view, String title) {
|
||||||
if (!enabled)
|
if (!enabled)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (currentView == null) {
|
if (currentView == null) {
|
||||||
// track application startup
|
// track application startup
|
||||||
try {
|
try {
|
||||||
|
@ -79,58 +74,56 @@ public class Analytics {
|
||||||
Logger.getLogger(Analytics.class.getName()).log(Level.WARNING, e.toString());
|
Logger.getLogger(Analytics.class.getName()).log(Level.WARNING, e.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
currentView = view;
|
currentView = view;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static void trackEvent(String category, String action, String label) {
|
public static void trackEvent(String category, String action, String label) {
|
||||||
trackEvent(category, action, label, null);
|
trackEvent(category, action, label, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static synchronized void trackEvent(String category, String action, String label, Integer value) {
|
public static synchronized void trackEvent(String category, String action, String label, Integer value) {
|
||||||
if (!enabled)
|
if (!enabled)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
getTracker().trackEvent(normalize(category), normalize(action), normalize(label), value);
|
getTracker().trackEvent(normalize(category), normalize(action), normalize(label), value);
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
Logger.getLogger(Analytics.class.getName()).log(Level.WARNING, e.toString());
|
Logger.getLogger(Analytics.class.getName()).log(Level.WARNING, e.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static String normalize(String label) {
|
private static String normalize(String label) {
|
||||||
if (label == null)
|
if (label == null)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
// trim braces
|
// trim braces
|
||||||
return label.replaceAll("[*()]", "").trim();
|
return label.replaceAll("[*()]", "").trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static synchronized void setEnabled(boolean b) {
|
public static synchronized void setEnabled(boolean b) {
|
||||||
enabled = b;
|
enabled = b;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean isEnabled() {
|
||||||
|
return enabled;
|
||||||
|
}
|
||||||
|
|
||||||
private static String getDeploymentMethod() {
|
private static String getDeploymentMethod() {
|
||||||
return getApplicationDeployment() == null ? "fatjar" : getApplicationDeployment();
|
return getApplicationDeployment() == null ? "fatjar" : getApplicationDeployment();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static AnalyticsConfigData getConfig(String webPropertyID, VisitorData visitorData) {
|
private static AnalyticsConfigData getConfig(String webPropertyID, VisitorData visitorData) {
|
||||||
AnalyticsConfigData config = new AnalyticsConfigData(webPropertyID, visitorData);
|
AnalyticsConfigData config = new AnalyticsConfigData(webPropertyID, visitorData);
|
||||||
|
|
||||||
config.setUserAgent(getUserAgent());
|
config.setUserAgent(getUserAgent());
|
||||||
config.setEncoding(System.getProperty("file.encoding"));
|
config.setEncoding(System.getProperty("file.encoding"));
|
||||||
config.setUserLanguage(getUserLanguage());
|
config.setUserLanguage(getUserLanguage());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (GraphicsEnvironment.isHeadless())
|
if (GraphicsEnvironment.isHeadless())
|
||||||
throw new HeadlessException();
|
throw new HeadlessException();
|
||||||
|
|
||||||
// desktop environment
|
// desktop environment
|
||||||
GraphicsDevice[] display = GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices();
|
GraphicsDevice[] display = GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices();
|
||||||
config.setScreenResolution(getScreenResolution(display));
|
config.setScreenResolution(getScreenResolution(display));
|
||||||
|
@ -140,16 +133,15 @@ public class Analytics {
|
||||||
config.setScreenResolution("80x25");
|
config.setScreenResolution("80x25");
|
||||||
config.setColorDepth("1");
|
config.setColorDepth("1");
|
||||||
}
|
}
|
||||||
|
|
||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static String getUserAgent() {
|
private static String getUserAgent() {
|
||||||
// initialize with default values
|
// initialize with default values
|
||||||
String wm = System.getProperty("os.name");
|
String wm = System.getProperty("os.name");
|
||||||
String os = System.getProperty("os.name") + " " + System.getProperty("os.version");
|
String os = System.getProperty("os.name") + " " + System.getProperty("os.version");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (Platform.isWindows()) {
|
if (Platform.isWindows()) {
|
||||||
wm = "Windows";
|
wm = "Windows";
|
||||||
|
@ -160,7 +152,7 @@ public class Analytics {
|
||||||
} else {
|
} else {
|
||||||
if (!GraphicsEnvironment.isHeadless() && Platform.isX11())
|
if (!GraphicsEnvironment.isHeadless() && Platform.isX11())
|
||||||
wm = "X11";
|
wm = "X11";
|
||||||
|
|
||||||
if (Platform.isLinux())
|
if (Platform.isLinux())
|
||||||
os = "Linux " + System.getProperty("os.arch");
|
os = "Linux " + System.getProperty("os.arch");
|
||||||
else if (Platform.isSolaris())
|
else if (Platform.isSolaris())
|
||||||
|
@ -173,62 +165,58 @@ public class Analytics {
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
// ignore any Platform detection issues and especially ignore LinkageErrors that might occur on headless machines
|
// ignore any Platform detection issues and especially ignore LinkageErrors that might occur on headless machines
|
||||||
}
|
}
|
||||||
|
|
||||||
return String.format("%s/%s (%s; U; %s; JRE %s)", getApplicationName(), getApplicationVersion(), wm, os, System.getProperty("java.version"));
|
return String.format("%s/%s (%s; U; %s; JRE %s)", getApplicationName(), getApplicationVersion(), wm, os, System.getProperty("java.version"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static String getUserLanguage() {
|
private static String getUserLanguage() {
|
||||||
String language = System.getProperty("user.language");
|
String language = System.getProperty("user.language");
|
||||||
|
|
||||||
// user region or country
|
// user region or country
|
||||||
String region = System.getProperty("user.region");
|
String region = System.getProperty("user.region");
|
||||||
if (region == null)
|
if (region == null)
|
||||||
region = System.getProperty("user.country");
|
region = System.getProperty("user.country");
|
||||||
|
|
||||||
// return language string user language with or without user region
|
// return language string user language with or without user region
|
||||||
if (region == null)
|
if (region == null)
|
||||||
return language;
|
return language;
|
||||||
|
|
||||||
return language + "-" + region;
|
return language + "-" + region;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static String getScreenResolution(GraphicsDevice[] display) {
|
private static String getScreenResolution(GraphicsDevice[] display) {
|
||||||
int screenHeight = 0;
|
int screenHeight = 0;
|
||||||
int screenWidth = 0;
|
int screenWidth = 0;
|
||||||
|
|
||||||
// get size of each screen
|
// get size of each screen
|
||||||
for (int i = 0; i < display.length; i++) {
|
for (int i = 0; i < display.length; i++) {
|
||||||
DisplayMode dm = display[i].getDisplayMode();
|
DisplayMode dm = display[i].getDisplayMode();
|
||||||
screenWidth += dm.getWidth();
|
screenWidth += dm.getWidth();
|
||||||
screenHeight += dm.getHeight();
|
screenHeight += dm.getHeight();
|
||||||
}
|
}
|
||||||
|
|
||||||
return screenWidth + "x" + screenHeight;
|
return screenWidth + "x" + screenHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static String getColorDepth(GraphicsDevice[] display) {
|
private static String getColorDepth(GraphicsDevice[] display) {
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
|
|
||||||
for (int i = 0; i < display.length; i++) {
|
for (int i = 0; i < display.length; i++) {
|
||||||
if (sb.length() > 0) {
|
if (sb.length() > 0) {
|
||||||
sb.append(", ");
|
sb.append(", ");
|
||||||
}
|
}
|
||||||
|
|
||||||
sb.append(display[i].getDisplayMode().getBitDepth());
|
sb.append(display[i].getDisplayMode().getBitDepth());
|
||||||
}
|
}
|
||||||
|
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final String VISITOR_ID = "visitorId";
|
private static final String VISITOR_ID = "visitorId";
|
||||||
private static final String TIMESTAMP_FIRST = "timestampFirst";
|
private static final String TIMESTAMP_FIRST = "timestampFirst";
|
||||||
private static final String TIMESTAMP_LAST = "timestampLast";
|
private static final String TIMESTAMP_LAST = "timestampLast";
|
||||||
private static final String VISITS = "visits";
|
private static final String VISITS = "visits";
|
||||||
|
|
||||||
|
|
||||||
private synchronized static VisitorData restoreVisitorData() {
|
private synchronized static VisitorData restoreVisitorData() {
|
||||||
try {
|
try {
|
||||||
// try to restore visitor
|
// try to restore visitor
|
||||||
|
@ -237,15 +225,14 @@ public class Analytics {
|
||||||
long timestampFirst = Long.parseLong(data.get(TIMESTAMP_FIRST));
|
long timestampFirst = Long.parseLong(data.get(TIMESTAMP_FIRST));
|
||||||
long timestampLast = Long.parseLong(data.get(TIMESTAMP_LAST));
|
long timestampLast = Long.parseLong(data.get(TIMESTAMP_LAST));
|
||||||
int visits = Integer.parseInt(data.get(VISITS));
|
int visits = Integer.parseInt(data.get(VISITS));
|
||||||
|
|
||||||
return VisitorData.newSession(visitorId, timestampFirst, timestampLast, visits);
|
return VisitorData.newSession(visitorId, timestampFirst, timestampLast, visits);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// new visitor
|
// new visitor
|
||||||
return VisitorData.newVisitor();
|
return VisitorData.newVisitor();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private synchronized static void storeVisitorData(VisitorData visitor) {
|
private synchronized static void storeVisitorData(VisitorData visitor) {
|
||||||
Map<String, String> data = getPersistentData();
|
Map<String, String> data = getPersistentData();
|
||||||
data.put(VISITOR_ID, String.valueOf(visitor.getVisitorId()));
|
data.put(VISITOR_ID, String.valueOf(visitor.getVisitorId()));
|
||||||
|
@ -253,23 +240,21 @@ public class Analytics {
|
||||||
data.put(TIMESTAMP_LAST, String.valueOf(visitor.getTimestampPrevious()));
|
data.put(TIMESTAMP_LAST, String.valueOf(visitor.getTimestampPrevious()));
|
||||||
data.put(VISITS, String.valueOf(visitor.getVisits()));
|
data.put(VISITS, String.valueOf(visitor.getVisits()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static Map<String, String> getPersistentData() {
|
private static Map<String, String> getPersistentData() {
|
||||||
return Settings.forPackage(Analytics.class).node("analytics").asMap();
|
return Settings.forPackage(Analytics.class).node("analytics").asMap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Dummy constructor to prevent instantiation
|
* Dummy constructor to prevent instantiation
|
||||||
*/
|
*/
|
||||||
private Analytics() {
|
private Analytics() {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
static {
|
static {
|
||||||
// disable useless background logging, if it doesn't work it doesn't work, won't affect anything (putting it here works for Java 7)
|
// disable useless background logging, if it doesn't work it doesn't work, won't affect anything (putting it here works for Java 7)
|
||||||
Logger.getLogger("com.dmurph.tracking").setLevel(Level.OFF);
|
Logger.getLogger("com.dmurph.tracking").setLevel(Level.OFF);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@ import javax.swing.AbstractAction;
|
||||||
import javax.swing.Icon;
|
import javax.swing.Icon;
|
||||||
import javax.swing.JFileChooser;
|
import javax.swing.JFileChooser;
|
||||||
|
|
||||||
|
import net.sourceforge.filebot.Analytics;
|
||||||
import net.sourceforge.filebot.ResourceManager;
|
import net.sourceforge.filebot.ResourceManager;
|
||||||
import net.sourceforge.filebot.Settings;
|
import net.sourceforge.filebot.Settings;
|
||||||
import net.sourceforge.filebot.ui.transfer.TransferablePolicy.TransferAction;
|
import net.sourceforge.filebot.ui.transfer.TransferablePolicy.TransferAction;
|
||||||
|
@ -53,8 +54,10 @@ public class LoadAction extends AbstractAction {
|
||||||
chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
|
chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
|
||||||
chooser.setMultiSelectionEnabled(true);
|
chooser.setMultiSelectionEnabled(true);
|
||||||
|
|
||||||
// tell noobs to use drag-n-drop
|
// tell noobs to use drag-n-drop (but avoid annoying people that got it from the app stores)
|
||||||
UILogger.info("Why do you not use drag-and-drop to directly drop in your files?");
|
if (Analytics.isEnabled()) {
|
||||||
|
UILogger.info("Why do you not use drag-and-drop to directly drop in your files?");
|
||||||
|
}
|
||||||
|
|
||||||
if (chooser.showOpenDialog(null) != JFileChooser.APPROVE_OPTION) {
|
if (chooser.showOpenDialog(null) != JFileChooser.APPROVE_OPTION) {
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -94,6 +94,7 @@
|
||||||
^TV$
|
^TV$
|
||||||
^user$
|
^user$
|
||||||
^utorrent$
|
^utorrent$
|
||||||
|
^vari$
|
||||||
^VCD$
|
^VCD$
|
||||||
^VIDEO_TS$
|
^VIDEO_TS$
|
||||||
^volume[0-9]?$
|
^volume[0-9]?$
|
||||||
|
|
Loading…
Reference in New Issue