Skip to content

Commit

Permalink
Improve error handling and handle more edge cases
Browse files Browse the repository at this point in the history
KV files having no real structure is a real pain.
related: #51
  • Loading branch information
Dylancyclone committed May 15, 2024
1 parent 71dd02e commit 333a1c5
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
8 changes: 7 additions & 1 deletion src/main/java/com/lathrum/VMF2OBJ/VMF2OBJ.java
Original file line number Diff line number Diff line change
Expand Up @@ -1010,8 +1010,14 @@ public void run() {
if (crowbarSubfolderSetting) {
path += File.separator + entity.modelName;
}
String smdText = readFile(formatPath(
String smdText = "";
try {
smdText = readFile(formatPath(
tempDir + File.separator + "models" + path + File.separator + bodyGroup));
} catch (IOException e) {
printProgressBar("Error: Could not find SMD file for model, skipping bodygroup: " + bodyGroup);
continue;
}

SMDTriangles.addAll(Arrays.asList(SMDTriangle.parseSMD(smdText)));
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/lathrum/VMF2OBJ/dataStructure/model/QC.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ public static QC parseQC(String text) {
text = text.replaceAll("//(.*)", ""); // Remove all commented lines
text = text.replaceAll("\\$[^\" \\t]+\\n", ""); // Remove all keyless values
text = text.replaceAll("[^\"](\\$[^\" \\t]+)", "\"$1\""); // fix unquoted keys
text = text.replaceAll("(\".+\"[ \\t]+)([^\" \\t\\s].*)", "$1\"$2\""); // fix unquoted values
text = text.replaceAll("(\".+\"[ \\t]+)([^\" \\t\\s\\{].*)", "$1\"$2\""); // fix unquoted values
text = text.replaceAll("\\$", ""); // Remove all key prefixes
text = text.replaceAll("\\{ (\".+\") +\"\\}\"", "$1"); // Fix texturegroup formatting
text = text.replaceAll("[\\t\\r\\n]", ""); // Remove all whitespaces and newlines not in quotes
text = text.replaceAll("\" +\"", "\"\""); // Remove all whitespaces and newlines not in quotes
// text = text.replaceAll("\\s+(?=([^\"]*\"[^\"]*\")*[^\"]*$)", ""); // Remove all whitespaces and newlines not in quotes

Matcher modelNameMatcher = Pattern.compile("\"modelname\"\"([a-zA-Z0-9._/-]+)\"").matcher(text);
String modelName = "";
Matcher modelNameMatcher = Pattern.compile("\"modelname\"\"([,a-zA-Z0-9._/-]+)\"").matcher(text);
String modelName = "model.smd";
if (modelNameMatcher.find()) {
modelName = modelNameMatcher.group(1);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,13 @@ public static VMT parseVMT(String text) {
text = text.replaceAll("//(.*)", ""); // Remove all commented lines
text = text.replaceAll("\\x1B", ""); // Remove all illegal characters
text = text.replaceAll("!?srgb\\?", ""); // Remove all weirdos
text = text.replaceAll("360\\?", ""); // Remove all weirdos
text = text.replaceAll("!*360\\?", ""); // Remove all weirdos
text = text.replaceAll("-dx10", ""); // Remove all dx10 fallback textures
text = text.replaceAll("GPU[<>=]{1,2}[0-3]\\?", ""); // Remove all GPU conditional textures
text = text.replaceAll("[^\"](\\$[^\" \\t]+)", "\"$1\""); // fix unquoted keys
text = text.replaceAll("(\".+\"[ \\t]+)([^\" \\t\\s].*)", "$1\"$2\""); // fix unquoted values
text = text.replaceAll("(\".+\"[ \\t]+)([^\" \\t\\s\\{].*)", "$1\"$2\""); // fix unquoted values
text = text.replaceAll("\\$", ""); // Remove all key prefixes
text = text.replaceAll("\"%.+", ""); // Remove all lines with keys that start with percentage signs
text = text.replaceAll("\"*%.+", ""); // Remove all lines with keys that start with percentage signs
// text = text.replaceAll("(\".+)[{}](.+\")", "$1$2"); // Remove brackets in quotes
text = text.replaceAll("[\\t\\r\\n]", ""); // Remove all whitespaces and newlines not in quotes
text = text.replaceAll("\" +\"", "\"\""); // Remove all whitespaces and newlines not in quotes
Expand Down

0 comments on commit 333a1c5

Please sign in to comment.