From e84ecce3b5582ad6077051bb2a62660a208f35f3 Mon Sep 17 00:00:00 2001 From: Eero Holmala Date: Fri, 28 Oct 2022 16:42:47 +0300 Subject: [PATCH] add cleaner --- utils/cleaner/.gitignore | 1 + utils/cleaner/.vscode/launch.json | 15 ++++++ utils/cleaner/.vscode/tasks.json | 13 +++++ utils/cleaner/README.md | 9 ++++ utils/cleaner/build.cpp.hxml | 5 ++ utils/cleaner/build.hxml | 5 ++ utils/cleaner/src/Main.hx | 82 +++++++++++++++++++++++++++++++ 7 files changed, 130 insertions(+) create mode 100644 utils/cleaner/.gitignore create mode 100644 utils/cleaner/.vscode/launch.json create mode 100644 utils/cleaner/.vscode/tasks.json create mode 100644 utils/cleaner/README.md create mode 100644 utils/cleaner/build.cpp.hxml create mode 100644 utils/cleaner/build.hxml create mode 100644 utils/cleaner/src/Main.hx diff --git a/utils/cleaner/.gitignore b/utils/cleaner/.gitignore new file mode 100644 index 0000000..e660fd9 --- /dev/null +++ b/utils/cleaner/.gitignore @@ -0,0 +1 @@ +bin/ diff --git a/utils/cleaner/.vscode/launch.json b/utils/cleaner/.vscode/launch.json new file mode 100644 index 0000000..39b3dd7 --- /dev/null +++ b/utils/cleaner/.vscode/launch.json @@ -0,0 +1,15 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "name": "HashLink", + "request": "launch", + "type": "hl", + "cwd": "${workspaceFolder}", + "preLaunchTask": { + "type": "haxe", + "args": "active configuration" + } + } + ] +} \ No newline at end of file diff --git a/utils/cleaner/.vscode/tasks.json b/utils/cleaner/.vscode/tasks.json new file mode 100644 index 0000000..23c0b2b --- /dev/null +++ b/utils/cleaner/.vscode/tasks.json @@ -0,0 +1,13 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "type": "haxe", + "args": "active configuration", + "group": { + "kind": "build", + "isDefault": true + } + } + ] +} \ No newline at end of file diff --git a/utils/cleaner/README.md b/utils/cleaner/README.md new file mode 100644 index 0000000..0c56ef5 --- /dev/null +++ b/utils/cleaner/README.md @@ -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 diff --git a/utils/cleaner/build.cpp.hxml b/utils/cleaner/build.cpp.hxml new file mode 100644 index 0000000..b33ca8f --- /dev/null +++ b/utils/cleaner/build.cpp.hxml @@ -0,0 +1,5 @@ +-cp src +-D analyzer-optimize + +-main Main +--cpp bin/cpp diff --git a/utils/cleaner/build.hxml b/utils/cleaner/build.hxml new file mode 100644 index 0000000..66b6172 --- /dev/null +++ b/utils/cleaner/build.hxml @@ -0,0 +1,5 @@ +-cp src +-D analyzer-optimize + +-main Main +--hl bin/cleaner.hl diff --git a/utils/cleaner/src/Main.hx b/utils/cleaner/src/Main.hx new file mode 100644 index 0000000..f0d14b1 --- /dev/null +++ b/utils/cleaner/src/Main.hx @@ -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); + } + + } +}