-DuseCreationDate=true

This commit is contained in:
Reinhard Pointner 2014-01-26 03:51:47 +00:00
parent 9574172b35
commit 6996914492
11 changed files with 79 additions and 106 deletions

View File

@ -15,6 +15,7 @@
# use NTFS extended attributes for storing metadata
-DuseExtendedFileAttributes=true
-DuseCreationDate=true
# look for native libs here
-Djna.library.path="%EXEDIR%"

View File

@ -19,6 +19,7 @@
# use NTFS extended attributes for storing metadata
-DuseExtendedFileAttributes=true
-DuseCreationDate=true
# look for native libs here
-Djna.library.path="%EXEDIR%"

View File

@ -23,6 +23,7 @@
# do not use NTFS extended attributes for storing metadata
-DuseExtendedFileAttributes=false
-DuseCreationDate=false
# look for native libs here
-Djna.library.path="%EXEDIR%"

View File

@ -17,6 +17,7 @@
# do not use NTFS extended attributes for storing metadata
-DuseExtendedFileAttributes=false
-DuseCreationDate=false
# put all temporary files here
-Djava.io.tmpdir="%EXEDIR%\temp"

View File

@ -156,6 +156,7 @@ public class Main {
}
if (args.disableExtendedAttributes) {
System.setProperty("useExtendedFileAttributes", "false");
System.setProperty("useCreationDate", "false");
}
if (args.action.equalsIgnoreCase("test")) {
System.setProperty("useExtendedFileAttributes", "false");

View File

@ -1,7 +1,5 @@
package net.sourceforge.filebot;
import static net.sourceforge.tuned.StringUtilities.*;
import java.awt.GraphicsEnvironment;
@ -17,19 +15,16 @@ import net.sourceforge.tuned.PreferencesMap;
import net.sourceforge.tuned.PreferencesMap.PreferencesEntry;
import net.sourceforge.tuned.PreferencesMap.StringAdapter;
public final class Settings {
public static String getApplicationName() {
return getApplicationProperty("application.name");
}
public static String getApplicationVersion() {
return getApplicationProperty("application.version");
}
public static int getApplicationRevisionNumber() {
try {
return Integer.parseInt(getApplicationProperty("application.revision"));
@ -37,33 +32,31 @@ public final class Settings {
return 0;
}
}
public static String getApplicationProperty(String key) {
return ResourceBundle.getBundle(Settings.class.getName(), Locale.ROOT).getString(key);
}
public static boolean isUnixFS() {
return Boolean.parseBoolean(System.getProperty("unixfs"));
}
public static boolean useNativeShell() {
return Boolean.parseBoolean(System.getProperty("useNativeShell"));
}
public static boolean useGVFS() {
return Boolean.parseBoolean(System.getProperty("useGVFS"));
}
public static boolean useExtendedFileAttributes() {
return Boolean.parseBoolean(System.getProperty("useExtendedFileAttributes"));
}
public static boolean useCreationDate() {
return Boolean.parseBoolean(System.getProperty("useCreationDate"));
}
public static boolean useDonationReminder() {
String deployment = getApplicationDeployment();
for (String it : new String[] { "ppa", "appstore" }) {
@ -73,8 +66,7 @@ public final class Settings {
}
return true;
}
public static int getPreferredThreadPoolSize() {
try {
return Integer.parseInt(System.getProperty("threadPool"));
@ -82,24 +74,22 @@ public final class Settings {
return Runtime.getRuntime().availableProcessors();
}
}
public static String getApplicationDeployment() {
String deployment = System.getProperty("application.deployment");
if (deployment != null)
return deployment;
if (System.getProperty("javawebstart.version") != null)
return "webstart";
return null;
}
public static File getApplicationFolder() {
String applicationDirPath = System.getProperty("application.dir");
File applicationFolder = null;
if (applicationDirPath != null && applicationDirPath.length() > 0) {
// use given path
applicationFolder = new File(applicationDirPath);
@ -107,43 +97,37 @@ public final class Settings {
// create folder in user home (can't use working directory for web start applications)
applicationFolder = new File(System.getProperty("user.home"), ".filebot");
}
// create folder if necessary
if (!applicationFolder.exists()) {
applicationFolder.mkdirs();
}
return applicationFolder;
}
public static Settings forPackage(Class<?> type) {
return new Settings(Preferences.userNodeForPackage(type));
}
private final Preferences prefs;
private Settings(Preferences prefs) {
this.prefs = prefs;
}
public Settings node(String nodeName) {
return new Settings(prefs.node(nodeName));
}
public String get(String key) {
return get(key, null);
}
public String get(String key, String def) {
return prefs.get(key, def);
}
public void put(String key, String value) {
if (value != null) {
prefs.put(key, value);
@ -151,53 +135,46 @@ public final class Settings {
remove(key);
}
}
public void remove(String key) {
prefs.remove(key);
}
public PreferencesEntry<String> entry(String key) {
return new PreferencesEntry<String>(prefs, key, new StringAdapter());
}
public PreferencesMap<String> asMap() {
return PreferencesMap.map(prefs);
}
public PreferencesList<String> asList() {
return PreferencesList.map(prefs);
}
public void clear() {
try {
// remove child nodes
for (String nodeName : prefs.childrenNames()) {
prefs.node(nodeName).removeNode();
}
// remove entries
prefs.clear();
} catch (BackingStoreException e) {
throw ExceptionUtilities.asRuntimeException(e);
}
}
public static String getApplicationIdentifier() {
return joinBy(" ", getApplicationName(), getApplicationVersion(), String.format("(r%s)", getApplicationRevisionNumber()));
}
public static String getJavaRuntimeIdentifier() {
String name = System.getProperty("java.runtime.name");
String version = System.getProperty("java.version");
String headless = GraphicsEnvironment.isHeadless() ? "(headless)" : null;
return joinBy(" ", name, version, headless);
}
}

View File

@ -609,7 +609,7 @@ public class CmdlineOperations implements CmdlineInterface {
}
// write metadata into xattr if xattr is enabled
if (matches != null && useExtendedFileAttributes()) {
if (matches != null && (useExtendedFileAttributes() || useCreationDate())) {
try {
for (Match<File, ?> match : matches) {
File file = match.getValue();
@ -617,7 +617,7 @@ public class CmdlineOperations implements CmdlineInterface {
if (renameMap.containsKey(file) && meta != null) {
File destination = resolveDestination(file, renameMap.get(file), false);
if (destination.isFile()) {
MediaDetection.storeMetaInfo(destination, meta, file.getName());
MediaDetection.storeMetaInfo(destination, meta, file.getName(), useExtendedFileAttributes(), useCreationDate());
}
}
}

View File

@ -3,7 +3,6 @@ package net.sourceforge.filebot.format;
import static java.util.Arrays.*;
import static java.util.Collections.*;
import static net.sourceforge.filebot.MediaTypes.*;
import static net.sourceforge.filebot.Settings.*;
import static net.sourceforge.filebot.format.Define.*;
import static net.sourceforge.filebot.hash.VerificationUtilities.*;
import static net.sourceforge.filebot.media.MediaDetection.*;
@ -358,13 +357,13 @@ public class MediaBindingBean {
}
@Define("original")
public String getOriginalFileName() {
public String getOriginalFileName() throws Exception {
return getOriginalFileName(mediaFile);
}
@Define("xattr")
public Object getMetaAttributesObject() {
return getMetaAttributesObject(mediaFile);
public Object getMetaAttributesObject() throws Exception {
return new MetaAttributes(mediaFile).getObject();
}
@Define("crc32")
@ -860,25 +859,11 @@ public class MediaBindingBean {
}
private String getOriginalFileName(File file) {
if (useExtendedFileAttributes()) {
try {
return new MetaAttributes(file).getOriginalName();
} catch (Throwable e) {
// ignore
}
try {
return new MetaAttributes(file).getOriginalName();
} catch (Throwable e) {
return null;
}
return null;
}
private Object getMetaAttributesObject(File file) {
if (useExtendedFileAttributes()) {
try {
return new MetaAttributes(file).getObject();
} catch (Throwable e) {
// ignore
}
}
return null;
}
}

View File

@ -1312,37 +1312,41 @@ public class MediaDetection {
}
};
public static void storeMetaInfo(File file, Object model, String original) {
public static void storeMetaInfo(File file, Object model, String original, boolean useExtendedFileAttributes, boolean useCreationDate) {
// only for Episode / Movie objects
if ((model instanceof Episode || model instanceof Movie) && file.exists()) {
if ((useExtendedFileAttributes || useCreationDate) && (model instanceof Episode || model instanceof Movie) && file.isFile()) {
try {
MetaAttributes xattr = new MetaAttributes(file);
// set creation date to episode / movie release date
try {
if (model instanceof Episode) {
Episode episode = (Episode) model;
if (episode.getAirdate() != null) {
xattr.setCreationDate(episode.getAirdate().getTimeStamp());
}
} else if (model instanceof Movie) {
Movie movie = (Movie) model;
if (movie.getYear() > 0) {
xattr.setCreationDate(new Date(movie.getYear(), 1, 1).getTimeStamp());
if (useCreationDate) {
try {
if (model instanceof Episode) {
Episode episode = (Episode) model;
if (episode.getAirdate() != null) {
xattr.setCreationDate(episode.getAirdate().getTimeStamp());
}
} else if (model instanceof Movie) {
Movie movie = (Movie) model;
if (movie.getYear() > 0) {
xattr.setCreationDate(new Date(movie.getYear(), 1, 1).getTimeStamp());
}
}
} catch (Exception e) {
Logger.getLogger(MediaDetection.class.getClass().getName()).warning("Failed to set creation date: " + e.getMessage());
}
} catch (Exception e) {
Logger.getLogger(MediaDetection.class.getClass().getName()).warning("Failed to set creation date: " + e.getMessage());
}
// store original name and model as xattr
try {
xattr.setObject(model);
if (xattr.getOriginalName() == null && original != null) {
xattr.setOriginalName(original);
if (useExtendedFileAttributes) {
try {
xattr.setObject(model);
if (xattr.getOriginalName() == null && original != null) {
xattr.setOriginalName(original);
}
} catch (Exception e) {
Logger.getLogger(MediaDetection.class.getClass().getName()).warning("Failed to set xattr: " + e.getMessage());
}
} catch (Exception e) {
Logger.getLogger(MediaDetection.class.getClass().getName()).warning("Failed to set xattr: " + e.getMessage());
}
} catch (Throwable t) {
Logger.getLogger(MediaDetection.class.getClass().getName()).warning(t.toString());

View File

@ -115,7 +115,7 @@ class RenameAction extends AbstractAction {
}
// write metadata into xattr if xattr is enabled
if (useExtendedFileAttributes()) {
if (useExtendedFileAttributes() || useCreationDate()) {
try {
for (Match<Object, File> match : matches) {
File file = match.getCandidate();
@ -123,7 +123,7 @@ class RenameAction extends AbstractAction {
if (renameMap.containsKey(file) && meta != null) {
File destination = resolveDestination(file, renameMap.get(file), false);
if (destination.isFile()) {
MediaDetection.storeMetaInfo(destination, meta, file.getName());
MediaDetection.storeMetaInfo(destination, meta, file.getName(), useExtendedFileAttributes(), useCreationDate());
}
}
}

View File

@ -1284,6 +1284,7 @@ LeON
LEVERAGE
LEViTY
LF
LFF
LGLuX
Lightmaker
lilwoodenboy
@ -2338,6 +2339,7 @@ x4subs
XanaX
xander
XC
Xell
XF
XiA
XII