Skip to content

Commit 2e2708d

Browse files
committed
fix for changed/missing files and added MIT license cooment on the top of the file
1 parent 7ba8620 commit 2e2708d

2 files changed

Lines changed: 49 additions & 4 deletions

File tree

src/Main.hx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import src.utils.DevKitProUtils;
2222
*/
2323
class Main {
2424
public static var haxenxcompilerString = "\x1b[38;5;214mHaxe\033[0m\x1b[38;5;81mN\x1b[38;5;1mX\033[0mCompiler (Based on \x1b[38;5;214mHx\033[0mCompile\x1b[38;5;74mU\033[0m)";
25-
public static final version:String = "1.1.0";
25+
public static final version:String = "1.1.1";
2626
static var stdin = Sys.stdin();
2727
static var stdout = Sys.stdout();
2828
static var args = Sys.args();

src/utils/AssetsManager.hx

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
// Copyright (c) 2025 Andrés E. G.
2+
//
3+
// This software is licensed under the MIT License.
4+
// See the LICENSE file for more details.
5+
6+
17
package utils;
28

39
import sys.FileSystem;
@@ -22,6 +28,14 @@ class AssetsManager {
2228
static var cacheFile:String;
2329
private static final jsonCacheFileName:String = "HxNX_AssetsCache.json";
2430

31+
/*
32+
* List of files found in the assets
33+
*/
34+
static var foundFiles:Array<String> = [];
35+
36+
/**
37+
* Search for assets and copy them to the output folder
38+
*/
2539
public static function searchAndGetAssets():Void {
2640
var outputDir = jsonFile.haxeConfig.cppOutDir;
2741
var basePath = SlushiUtils.getPathFromCurrentTerminal();
@@ -70,7 +84,7 @@ class AssetsManager {
7084

7185
var versionFolder =
7286
if (libVersion != null) libVersion.replace(".", ",")
73-
else if (FileSystem.exists(Path.join([libFolder, ".current"])))
87+
else if (FileSystem.exists(Path.join([libFolder, ".current"])) )
7488
File.getContent(Path.join([libFolder, ".current"])).trim().replace(".", ",")
7589
else "";
7690

@@ -92,6 +106,9 @@ class AssetsManager {
92106
}
93107
}
94108

109+
// Clean removed assets
110+
cleanRemovedAssets(outputPath);
111+
95112
// Save cache
96113
saveCache();
97114
}
@@ -107,10 +124,12 @@ class AssetsManager {
107124
for (sub in FileSystem.readDirectory(srcFile)) {
108125
var from = Path.join([srcFile, sub]);
109126
var to = Path.join([dstFile, sub]);
110-
copyIfChanged(from, to, libName + "/ROMFS/" + f + "/" + sub);
127+
var key = libName + "/ROMFS/" + f + "/" + sub;
128+
copyIfChanged(from, to, key);
111129
}
112130
} else {
113-
copyIfChanged(srcFile, dstFile, libName + "/ROMFS/" + f);
131+
var key = libName + "/ROMFS/" + f;
132+
copyIfChanged(srcFile, dstFile, key);
114133
}
115134
}
116135
}
@@ -119,6 +138,8 @@ class AssetsManager {
119138
var newHash = Md5.make(File.getBytes(from)).toHex();
120139
var oldHash = cache.exists(key) ? cache.get(key) : null;
121140

141+
foundFiles.push(key);
142+
122143
if (oldHash != null && oldHash == newHash && FileSystem.exists(to)) {
123144
SlushiUtils.printMsg("Skipped (unchanged): " + to, INFO);
124145
return;
@@ -129,6 +150,30 @@ class AssetsManager {
129150
SlushiUtils.printMsg("Copied: " + from + " -> " + to, SUCCESS);
130151
}
131152

153+
// 🔥 Elimina archivos que estaban en cache pero ya no existen en origen
154+
static function cleanRemovedAssets(outputPath:String):Void {
155+
var toRemove:Array<String> = [];
156+
157+
for (k in cache.keys()) {
158+
if (!foundFiles.contains(k)) {
159+
// Archivo estaba en cache pero no se detectó en esta ejecución
160+
var relative = k.split("/ROMFS/").length > 1 ? k.split("/ROMFS/")[1] : k;
161+
var dstFile = Path.join([outputPath, "romfs", relative]);
162+
if (FileSystem.exists(dstFile)) {
163+
try {
164+
FileSystem.deleteFile(dstFile);
165+
SlushiUtils.printMsg("Removed missing asset: " + dstFile, WARN);
166+
} catch (e:Dynamic) {
167+
SlushiUtils.printMsg("Failed to remove old asset: " + dstFile + " (" + e + ")", ERROR);
168+
}
169+
}
170+
toRemove.push(k);
171+
}
172+
}
173+
174+
for (r in toRemove) cache.remove(r);
175+
}
176+
132177
static function saveCache():Void {
133178
var obj:Dynamic = {};
134179
for (k in cache.keys()) {

0 commit comments

Comments
 (0)