Skip to content

Commit

Permalink
Merge pull request #600 from fixrtm/fix-encodig-error-on-model-load
Browse files Browse the repository at this point in the history
fix: shift-jis based modelpack will cause crash
  • Loading branch information
anatawa12 committed Jan 5, 2023
2 parents 5cdc0a7 + fb18de6 commit 29fca16
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 15 deletions.
1 change: 1 addition & 0 deletions CHANGELOG-SNAPSHOTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ The changelog for 2.0.23 and earlier is generated by [anatawa12's fork of `auto-
### Fixed
- Formation is broken when we disconnected long formation `#596`
- Signal Converter Setting is not loaded correctly `#597`
- shift-jis based modelpack will cause crash `#600`

### Security

Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Thanks to prepare-changelog.sh, we have some macros.
### Fixed
- Formation is broken when we disconnected long formation `#596`
- Signal Converter Setting is not loaded correctly `#597`
- shift-jis based modelpack will cause crash `#600`

### Security

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,27 +38,22 @@

TimeTableManager.INSTANCE.load();
par1.loadFinished = true;
@@ -143,29 +146,43 @@
@@ -143,29 +146,32 @@
public ResourceType getType(String name) {
return this.typeMap.get(name);
}

public String registerResourceSet(ResourceType type, File file) throws IOException {
+ List<String> json = null;
for(String s : ENCODING) {
try {
- for(String s : ENCODING) {
- try {
- String s1 = NGTText.readText(file, false, s);
- ResourceConfig resourceconfig = (ResourceConfig)NGTJson.getObjectFromJson(s1, type.cfgClass);
- return this.registerResourceSet(type, resourceconfig, s1);
+ json = NGTText.readText(file, s);
+ break;
} catch (IOException ioexception) {
ioexception.printStackTrace();
}
}
+ if (json == null)
+ throw new ModelPackException("Can't load json. please check encoding of json " +
+ "file and file is exists.", file.getAbsolutePath());
- } catch (IOException ioexception) {
- ioexception.printStackTrace();
- }
- }
+ List<String> json = NGTText.readText(file, null);;

- throw new ModelPackException("Can't load model", file.getAbsolutePath());
+ ResourceConfig resourceconfig = (ResourceConfig)NGTJson.getObjectFromJson(com.anatawa12.fixRtm.UtilsKt.joinLinesForJsonReading(json), type.cfgClass);
Expand Down Expand Up @@ -87,7 +82,7 @@
return cfg.getName();
} else {
throw new ModelPackException("Failed to create ResourceSet", cfg.getName());
@@ -177,15 +194,16 @@
@@ -177,15 +183,16 @@

for(Entry<ResourceType, Map<String, ResourceSet>> entry : this.allModelSetMap.entrySet()) {
for(ResourceSet resourceset : entry.getValue().values()) {
Expand All @@ -105,7 +100,7 @@
public void addModelSetName(int count, String typeName, String name) {
assert NGTUtil.isSMP() && !NGTUtil.isServer();

@@ -227,16 +245,13 @@
@@ -227,16 +234,13 @@
resourcetype = type.parent;
}

Expand Down

0 comments on commit 29fca16

Please sign in to comment.