add cleaner

This commit is contained in:
Eero Holmala 2022-10-28 16:42:47 +03:00
parent 8b52b24644
commit e84ecce3b5
7 changed files with 130 additions and 0 deletions

1
utils/cleaner/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
bin/

15
utils/cleaner/.vscode/launch.json vendored Normal file
View File

@ -0,0 +1,15 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "HashLink",
"request": "launch",
"type": "hl",
"cwd": "${workspaceFolder}",
"preLaunchTask": {
"type": "haxe",
"args": "active configuration"
}
}
]
}

13
utils/cleaner/.vscode/tasks.json vendored Normal file
View File

@ -0,0 +1,13 @@
{
"version": "2.0.0",
"tasks": [
{
"type": "haxe",
"args": "active configuration",
"group": {
"kind": "build",
"isDefault": true
}
}
]
}

9
utils/cleaner/README.md Normal file
View File

@ -0,0 +1,9 @@
# Haxe project
This is an example Haxe project scaffolded by Visual Studio Code.
Without further changes the structure is following:
* `src/Main.hx`: Entry point Haxe source file
* `build.hxml`: Haxe command line file used to build the project
* `README.md`: This file

View File

@ -0,0 +1,5 @@
-cp src
-D analyzer-optimize
-main Main
--cpp bin/cpp

5
utils/cleaner/build.hxml Normal file
View File

@ -0,0 +1,5 @@
-cp src
-D analyzer-optimize
-main Main
--hl bin/cleaner.hl

82
utils/cleaner/src/Main.hx Normal file
View File

@ -0,0 +1,82 @@
import haxe.macro.Expr.Catch;
import Sys;
import sys.FileSystem;
class Main {
static var dir: String = "C:\\Users\\Eero\\AppData\\Local\\Temp";
static function main() {
clean(dir);
}
static function deleteFile(path) {
var stat = FileSystem.stat(path);
if(stat.size == 0){
try {
Sys.println("Deleting file: "+path);
FileSystem.deleteFile(path);
} catch(e: Any) {
Sys.println("Could not delete file: "+path);
}
}
}
static function deleteDirectory(path) {
if(!FileSystem.isDirectory(path))
return false;
for (e in FileSystem.readDirectory(path)){
var temp = path+"/"+e;
if(!FileSystem.isDirectory(temp))
continue; // Go next
try {
if(FileSystem.readDirectory(temp).length == 0){
Sys.println("Deleting directory: "+temp);
FileSystem.deleteDirectory(temp);
} else if (FileSystem.readDirectory(temp).length != 0){
deleteDirectory(temp);
} else if(!FileSystem.isDirectory(temp)){
deleteFile(temp);
}
} catch(e: SysError){
Sys.println("Failed: Cannot access directory " + temp);
}
}
return true;
}
static function clean(path: String) {
if(FileSystem.exists(path) && FileSystem.isDirectory(path)){
deleteDirectory(path);
// for (e in FileSystem.readDirectory(path)){
// var temp = path+"/"+e;
// try {
// if(FileSystem.isDirectory(temp) && FileSystem.readDirectory(temp).length == 0){
// Sys.println("Deleting directory: "+temp);
// FileSystem.deleteDirectory(temp);
// } else if (FileSystem.isDirectory(temp) && FileSystem.readDirectory(temp).length != 0) {
// for(ent in FileSystem.readDirectory(temp)){
// var subDir = temp+"/"+ent;
// // Sys.println(subDir);
// clean(subDir);
// }
// } else if(!FileSystem.isDirectory(temp)){
// deleteFile(temp);
// }
// } catch(e: SysError){
// Sys.println("Failed: Cannot access directory " + temp);
// }
// // pathData.push(Sha256.encode(temp));
// // readDirectory(temp);
// }
} else if(FileSystem.exists(path) && !FileSystem.isDirectory(path)){
deleteFile(path);
}
}
}