Skip to content

Commit 5880722

Browse files
author
ozelot379
committed
Fix root folder in sub folder in some wrong texture packs
1 parent 3c3a89b commit 5880722

8 files changed

Lines changed: 117 additions & 4 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## [3.6.1]
4+
- Fix root folder in sub folder in some wrong texture packs
5+
- Fix rename files in local folder to not exists folder
6+
37
## [3.6.0]
48
- Convert new v1.16 textures
59
- Convert wither armor texture

‎package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "@ozelot379/convert-minecraft-java-texture-to-bedrock-api",
33
"type": "module",
44
"productName": "ConvertJavaTextureToBedrockApi",
5-
"version": "3.6.0",
5+
"version": "3.6.1",
66
"description": "API for convert Minecraft Java texture packs to Bedrock texture packs",
77
"keywords": [
88
"Minecraft",
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import {AbstractConverter} from "./AbstractConverter.mjs";
2+
3+
/**
4+
* Class FixWrongRootFolderConverter
5+
*/
6+
class FixWrongRootFolderConverter extends AbstractConverter {
7+
/**
8+
* @inheritDoc
9+
*/
10+
async convert() {
11+
const [pack_mcmeta, others] = this.data;
12+
13+
if (await this.output.exists(pack_mcmeta)) {
14+
return [];
15+
}
16+
17+
this.log.warn(`${pack_mcmeta} not found in root folder (But are needed in the root folder, even in the Java version) - Try to lookup in sub folders ...`);
18+
19+
const path = await this.output.lookupFile(pack_mcmeta);
20+
if (!path) {
21+
throw new Error(`${pack_mcmeta} not found! Is this really a Java texture pack?`);
22+
}
23+
24+
this.log.log(`Root folder found in sub folder ${path}`);
25+
26+
for (const file of [pack_mcmeta, ...others]) {
27+
if (await this.output.exists(`${path}/${file}`)) {
28+
await this.output.rename(`${path}/${file}`, `${file}`);
29+
}
30+
}
31+
32+
return [];
33+
}
34+
35+
/**
36+
* @inheritDoc
37+
*/
38+
static get DEFAULT_CONVERTER_DATA() {
39+
return [
40+
["pack.mcmeta", ["pack.png", "assets/", "bedrock_textures/", "bedrock_uuid_header", "bedrock_uuid_module"]]
41+
];
42+
}
43+
}
44+
45+
export {FixWrongRootFolderConverter};

‎src/converter/MetadataConverter.mjs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class MetadataConverter extends AbstractConverter {
1717
this.log.log(`Create metadata ${to}`);
1818

1919
if (!await this.output.exists(from)) {
20-
throw new Error(`Missing ${from}! Is this really a java texture pack?`);
20+
throw new Error(`Missing ${from}! Is this really a Java texture pack?`);
2121
}
2222

2323
let uuid_header = "";

‎src/converter/converters.mjs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {DrownedConverter} from "./DrownedConverter.mjs";
2121
import {EnchantedItemGlintConverter} from "./EnchantedItemGlintConverter.mjs";
2222
import {FishHookConverter} from "./FishingConverter.mjs";
2323
import {FireworksConverter} from "./FireworksConverter.mjs";
24+
import {FixWrongRootFolderConverter} from "./FixWrongRootFolderConverter.mjs";
2425
import {FoxConverter} from "./FoxConverter.mjs";
2526
import {HorseConverter} from "./HorseConverter.mjs";
2627
import {IconsConverter} from "./IconsConverter.mjs";
@@ -49,6 +50,7 @@ import {WeatherConverter} from "./WeatherConverter.mjs";
4950
* @type {AbstractConverter[]}
5051
*/
5152
const converters = [
53+
FixWrongRootFolderConverter,
5254
MetadataConverter,
5355
RenameConverter,
5456
AtlasConverter,

‎src/output/AbstractOutput.mjs‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,19 @@ class AbstractOutput {
156156
async copy(from, to) {
157157

158158
}
159+
160+
/**
161+
* @param {string} name
162+
*
163+
* @returns {Promise<string|null>}
164+
*
165+
* @throws {Error}
166+
*
167+
* @abstract
168+
*/
169+
async lookupFile(name) {
170+
171+
}
159172
}
160173

161174
export {AbstractOutput};

‎src/output/BufferOutput.mjs‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {AbstractOutput} from "./AbstractOutput.mjs";
2+
import {basename, dirname} from "path";
23
import JSZip from "jszip";
34

45
/**
@@ -107,6 +108,21 @@ class BufferOutput extends AbstractOutput {
107108
}
108109
}
109110
}
111+
112+
/**
113+
* @inheritDoc
114+
*/
115+
async lookupFile(name) {
116+
const entry = Object.values(this.zip.files).find((entry) => {
117+
return (!entry.dir && basename(entry.name) === name);
118+
});
119+
120+
if (entry) {
121+
return dirname(entry.name);
122+
} else {
123+
return null;
124+
}
125+
}
110126
}
111127

112128
export {BufferOutput};

‎src/output/LocalFolderOutput.mjs‎

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,11 @@ class LocalFolderOutput extends AbstractOutput {
6363
* @inheritDoc
6464
*/
6565
async rename(from, to) {
66-
if (await this.output.exists(to)) {
66+
if (await this.exists(to)) {
6767
await this.delete(to);
6868
}
6969

70+
await mkdir(dirname(this.p(to)), {recursive: true});
7071
await rename(this.p(from), this.p(to));
7172
}
7273

@@ -99,7 +100,7 @@ class LocalFolderOutput extends AbstractOutput {
99100
if ((await stat(this.p(from))).isDirectory()) {
100101
await this.copyScanFiles(from, to);
101102
} else {
102-
await mkdir(this.p(dirname(to)), {recursive: true});
103+
await mkdir(dirname(this.p(to)), {recursive: true});
103104
await copyFile(this.p(from), this.p(to));
104105
}
105106
}
@@ -124,6 +125,38 @@ class LocalFolderOutput extends AbstractOutput {
124125
}
125126
}
126127

128+
/**
129+
* @inheritDoc
130+
*/
131+
async lookupFile(name) {
132+
return this.lookupFileScanFiles(name, ".");
133+
}
134+
135+
/**
136+
* @param {string} name
137+
* @param {string} p
138+
*
139+
* @returns {Promise<string|null>}
140+
*
141+
* @private
142+
*/
143+
async lookupFileScanFiles(name, p) {
144+
for (const dirent of await readdir(join(this.path, p), {withFileTypes: true})) {
145+
if (dirent.isDirectory()) {
146+
const path = await this.lookupFileScanFiles(name, join(p, dirent.name));
147+
if (path) {
148+
return path;
149+
}
150+
} else {
151+
if (dirent.name === name) {
152+
return p;
153+
}
154+
}
155+
}
156+
157+
return null;
158+
}
159+
127160
/**
128161
* @param {string} p
129162
*

0 commit comments

Comments
 (0)