Added #2260 GFX - Configure path resolving dialog for file paths that use prefixes like data:

This commit is contained in:
Jindra Petřík
2024-07-31 21:06:20 +02:00
parent 5654497a52
commit 45199d043f
10 changed files with 219 additions and 5 deletions

View File

@@ -29,4 +29,5 @@ public class CustomConfigurationKeys {
public static final String KEY_LOADED_IMPORT_ASSETS = "loadedImportAssets";
public static final String KEY_ABC_DEPENDENCIES = "abcDependencies";
public static final String KEY_BREAKPOINTS = "breakpoints";
public static final String KEY_PATH_RESOLVING = "pathResolving";
}

View File

@@ -17,6 +17,9 @@
package com.jpexs.decompiler.flash.tags.gfx;
import com.jpexs.decompiler.flash.SWF;
import com.jpexs.decompiler.flash.configuration.Configuration;
import com.jpexs.decompiler.flash.configuration.CustomConfigurationKeys;
import com.jpexs.decompiler.flash.configuration.SwfSpecificCustomConfiguration;
import com.jpexs.decompiler.flash.gfx.TgaSupport;
import com.jpexs.decompiler.flash.tags.base.ImageTag;
import com.jpexs.decompiler.flash.tags.gfx.enums.FileFormatType;
@@ -24,6 +27,7 @@ import com.jpexs.helpers.ByteArrayRange;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.InvalidPathException;
import java.nio.file.Path;
import java.nio.file.Paths;
import javax.imageio.ImageIO;
@@ -47,9 +51,50 @@ public abstract class AbstractGfxImageTag extends ImageTag {
}
protected BufferedImage getExternalBufferedImage(String fileName, int bitmapFormat) {
Path imagePath = getSwf().getFile() == null ? null : Paths.get(getSwf().getFile()).getParent().resolve(Paths.get(fileName));
Path imagePath = null;
try {
imagePath = getSwf().getFile() == null ? null : Paths.get(getSwf().getFile()).getParent().resolve(Paths.get(fileName));
} catch (InvalidPathException ip) {
//ignore
}
if (imagePath == null || !imagePath.toFile().exists()) {
return null;
SwfSpecificCustomConfiguration cc = Configuration.getSwfSpecificCustomConfiguration(getSwf().getShortPathTitle());
if (cc == null) {
return null;
}
String paths = cc.getCustomData(CustomConfigurationKeys.KEY_PATH_RESOLVING, "");
if (paths.trim().isEmpty()) {
return null;
}
String[] rows = paths.trim().split("\r\n");
boolean found = false;
for (String row : rows) {
String prefix = "";
String searchPath;
if (row.contains("|")) {
prefix = row.substring(0, row.indexOf("|"));
searchPath = row.substring(row.indexOf("|") + 1);
} else {
searchPath = row;
}
String fileNameNoPrefix = fileName;
if (!prefix.isEmpty() && fileName.startsWith(prefix)) {
fileNameNoPrefix = fileName.substring(prefix.length());
}
if (!searchPath.isEmpty()) {
Path newImagePath = Paths.get(searchPath).resolve(fileNameNoPrefix);
if (newImagePath.toFile().exists()) {
found = true;
imagePath = newImagePath;
break;
}
}
}
if (!found) {
return null;
}
}
byte[] imageData;

View File

@@ -172,7 +172,7 @@ public class DefineExternalImage extends AbstractGfxImageTag {
if (shortFormat) {
//Just guessing how this may work...
return exportName + "." + FileFormatType.fileFormatExtension(bitmapFormat);
}
}
return fileName;
}