Add some more helpers
This commit is contained in:
parent
d6f0e05713
commit
71f028f25c
2 changed files with 68 additions and 1 deletions
67
lib/utils/IOTools.dart
Normal file
67
lib/utils/IOTools.dart
Normal file
|
@ -0,0 +1,67 @@
|
||||||
|
import 'dart:io';
|
||||||
|
|
||||||
|
class PathHelper {
|
||||||
|
String pth = "";
|
||||||
|
PathHelper({required this.pth});
|
||||||
|
|
||||||
|
static String combine(String path1, String path2) {
|
||||||
|
return path1 + Platform.pathSeparator + path2;
|
||||||
|
}
|
||||||
|
|
||||||
|
static PathHelper builder(String startPath) {
|
||||||
|
return PathHelper(pth: startPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
PathHelper resolve(String path2) {
|
||||||
|
pth += Platform.pathSeparator + path2;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
PathHelper conditionalResolve(bool flag, String path) {
|
||||||
|
if (flag) pth += Platform.pathSeparator + path;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool deleteDirectory({bool recursive = false}) {
|
||||||
|
Directory dir = new Directory(build());
|
||||||
|
try {
|
||||||
|
dir.deleteSync(recursive: recursive);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
} catch (E) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool deleteFile() {
|
||||||
|
File file = new File(build());
|
||||||
|
try {
|
||||||
|
file.deleteSync(recursive: true);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
} catch (E) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
PathHelper removeDir() {
|
||||||
|
deleteDirectory(recursive: true);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
PathHelper removeFile() {
|
||||||
|
deleteFile();
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
PathHelper mkdir() {
|
||||||
|
Directory dir = new Directory(build());
|
||||||
|
dir.createSync(recursive: true);
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
String build() {
|
||||||
|
return pth;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,6 +1,6 @@
|
||||||
name: libac_flutter
|
name: libac_flutter
|
||||||
description: "Aria's Creations code library"
|
description: "Aria's Creations code library"
|
||||||
version: 1.0.6
|
version: 1.0.7
|
||||||
homepage: "https://zontreck.com"
|
homepage: "https://zontreck.com"
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue