📄 wwdotnetlayersetinstaller.java
字号:
{
result = Logging.getMessage("DataStoreProducer.WWDotNetPermanentDirectoryInvalid", s);
}
}
else
{
result = Logging.getMessage("DataStoreProducer.WWDotNetPermanentDirectoryMissing", dataSource);
}
}
return result;
}
protected Object installLocationFor(AVList installParams, DataSource dataSource, DataDescriptor descriptor)
{
String path = null;
String s = installParams.getStringValue(AVKey.FILE_STORE_LOCATION);
if (s != null)
path = appendPathPart(path, s);
s = installParams.getStringValue(AVKey.DATA_CACHE_NAME);
if (s != null)
path = appendPathPart(path, s);
if (descriptor != null)
if (descriptor.getName() != null)
path = appendPathPart(path, descriptor.getName());
if (path == null || path.length() < 1)
return Logging.getMessage("DataStoreProducer.InvalidDataSource", dataSource);
return new java.io.File(path);
}
protected String filenameFor(DataDescriptor descriptor)
{
String name = descriptor.getStringValue(AVKey.DATASET_NAME);
if (name != null)
name = WWIO.replaceSuffix(name, ".xml");
if (name == null)
name = "WorldWindDotNetLayerSet.xml";
return WWIO.formPath(name);
}
private static String appendPathPart(String firstPart, String secondPart)
{
if (secondPart == null || secondPart.length() == 0)
return firstPart;
if (firstPart == null || firstPart.length() == 0)
return secondPart;
firstPart = WWIO.stripTrailingSeparator(firstPart);
secondPart = WWIO.stripLeadingSeparator(secondPart);
return firstPart + System.getProperty("file.separator") + secondPart;
}
//**************************************************************//
//******************** Imagery Installation ******************//
//**************************************************************//
private void installWWDotNetDiretory(java.io.File source, java.io.File destination, String installMimeType,
ProductionState productionState) throws java.io.IOException
{
if (!destination.exists())
{
//noinspection ResultOfMethodCallIgnored
destination.mkdirs();
}
if (!destination.exists())
{
String message = Logging.getMessage("generic.CannotCreateFile", destination);
Logging.logger().severe(message);
throw new java.io.IOException(message);
}
java.io.File[] fileList = source.listFiles();
if (fileList == null)
return;
java.util.List<java.io.File> childFiles = new java.util.ArrayList<java.io.File>();
java.util.List<java.io.File> childDirs = new java.util.ArrayList<java.io.File>();
for (java.io.File child : fileList)
{
if (child == null) // Don't allow null subfiles.
continue;
if (child.isHidden()) // Ignore hidden files.
continue;
if (child.isDirectory())
childDirs.add(child);
else
childFiles.add(child);
}
for (java.io.File childFile : childFiles)
{
if (!isWWDotNetFile(childFile))
continue;
java.io.File destFile = makeWWJavaFile(destination, childFile.getName(), installMimeType);
this.installWWDotNetFile(childFile, destFile, productionState);
if (!destFile.exists())
{
String message = Logging.getMessage("generic.CannotCreateFile", destFile);
Logging.logger().severe(message);
throw new java.io.IOException(message);
}
}
for (java.io.File childDir : childDirs)
{
if (!isWWDotNetDirectory(childDir))
continue;
java.io.File destDir = makeWWJavaDirectory(destination, childDir.getName());
this.installWWDotNetDiretory(childDir, destDir, installMimeType, productionState);
}
}
private void installWWDotNetFile(java.io.File source, java.io.File destination, ProductionState productionState)
throws java.io.IOException
{
// Bypass file installation if:
// (a) destination is newer than source, and
// (b) source and destination have identical size.
if (destination.exists() && source.lastModified() >= destination.lastModified()
&& source.length() == destination.length())
{
return;
}
String sourceSuffix = WWIO.getSuffix(source.getName());
String destinationSuffix = WWIO.getSuffix(destination.getName());
// Source and destination types match. Copy the source file directly.
if (sourceSuffix.equalsIgnoreCase(destinationSuffix))
{
WWIO.copyFile(source, destination);
}
// Destination type is different. Convert the source file and write the converstion to the destionation.
else
{
if (destinationSuffix.equalsIgnoreCase("dds"))
{
java.nio.ByteBuffer sourceBuffer = DDSCompressor.compressImageFile(source);
WWIO.saveBuffer(sourceBuffer, destination);
}
else
{
java.awt.image.BufferedImage sourceImage = javax.imageio.ImageIO.read(source);
javax.imageio.ImageIO.write(sourceImage, destinationSuffix, destination);
}
}
this.updateProgress(productionState);
}
private static java.io.File makeWWJavaDirectory(java.io.File dir, String dirname)
{
return new java.io.File(dir, WWIO.stripLeadingZeros(dirname));
}
private static java.io.File makeWWJavaFile(java.io.File dir, String filename, String installMimeType)
{
// If the filename does not match the standard pattern, then return a file with that name.
String[] tokens = filename.split("[._]");
if (tokens == null || tokens.length < 3 || tokens[0].length() < 1 || tokens[1].length() < 1)
return new java.io.File(dir, filename);
// If an installation type is specified, override the file extension with the new type.
if (installMimeType != null)
tokens[2] = WWIO.makeSuffixForMimeType(installMimeType);
// Otherwise keep the existing extension. Add a leading '.' so that both cases can be handled transparently.
else if (tokens[2].length() > 1)
tokens[2] = "." + tokens[2];
// If the filename is "000n_000m.foo", then the contents of tokens[] are:
// tokens[0] = "000n"
// tokens[1] = "000m"
// tokens[2] = "foo"
StringBuilder sb = new StringBuilder();
sb.append(WWIO.stripLeadingZeros(tokens[0])).append("_").append(WWIO.stripLeadingZeros(tokens[1]));
sb.append(tokens[2]);
return new java.io.File(dir, sb.toString());
}
private static boolean isWWDotNetDirectory(java.io.File file)
{
String pattern = "\\d+";
return file.getName().matches(pattern);
}
private static boolean isWWDotNetFile(java.io.File file)
{
String pattern = "\\d+[_]\\d+[.]\\w+";
return file.getName().matches(pattern);
}
//**************************************************************//
//******************** Progress and Verification *************//
//**************************************************************//
private int countWWDotNetFiles(java.io.File source)
{
int count = 0;
java.io.File[] fileList = source.listFiles();
if (fileList == null)
return count;
java.util.List<java.io.File> childFiles = new java.util.ArrayList<java.io.File>();
java.util.List<java.io.File> childDirs = new java.util.ArrayList<java.io.File>();
for (java.io.File child : fileList)
{
if (child == null) // Don't allow null subfiles.
continue;
if (child.isHidden()) // Ignore hidden files.
continue;
if (child.isDirectory())
childDirs.add(child);
else
childFiles.add(child);
}
for (java.io.File childFile : childFiles)
{
if (!isWWDotNetFile(childFile))
continue;
count++;
}
for (java.io.File childDir : childDirs)
{
if (!isWWDotNetDirectory(childDir))
continue;
count += countWWDotNetFiles(childDir);
}
return count;
}
//**************************************************************//
//******************** Progress Parameters *******************//
//**************************************************************//
protected void setProgressParameters(Iterable<?> dataSources, ProductionState productionState)
{
int numSources = 0;
//noinspection UnusedDeclaration
for (Object o : dataSources)
numSources++;
productionState.numSources = numSources;
productionState.curSource = -1;
productionState.numSourceFiles = new int[numSources];
productionState.numInstalledFiles = new int[numSources];
}
private void updateProgress(ProductionState productionState)
{
double oldProgress = this.computeProgress(productionState);
productionState.numInstalledFiles[productionState.curSource]++;
double newProgress = this.computeProgress(productionState);
this.firePropertyChange(AVKey.PROGRESS, oldProgress, newProgress);
}
private double computeProgress(ProductionState productionState)
{
double progress = 0.0;
for (int i = 0; i <= productionState.curSource; i++)
{
progress += (productionState.numInstalledFiles[i] /
(double) productionState.numSourceFiles[i]) * (1.0 / (double) productionState.numSources);
}
return progress;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -