108 lines
2.2 KiB
Dart
108 lines
2.2 KiB
Dart
import 'package:prod/models/editor.dart';
|
|
import "dart:io";
|
|
import "package:path/path.dart" as p;
|
|
|
|
class Project {
|
|
String name;
|
|
String language;
|
|
File path;
|
|
String e0;
|
|
String e1;
|
|
String e2;
|
|
String e3;
|
|
bool isGit;
|
|
|
|
Project(
|
|
this.name,
|
|
this.language,
|
|
this.path,
|
|
this.isGit, {
|
|
this.e0 = "",
|
|
this.e1 = "",
|
|
this.e2 = "",
|
|
this.e3 = "",
|
|
});
|
|
|
|
factory Project.newValidated(String name, String lang, String path) {
|
|
final File fpath = File(path);
|
|
print(fpath.absolute.path);
|
|
if (fpath.existsSync()) {
|
|
print("Project not found!!!");
|
|
} else {
|
|
print("Project Exists on disk");
|
|
}
|
|
String gitPath = p.join(path, ".git", "HEAD");
|
|
final bool isGit = File(gitPath).existsSync();
|
|
|
|
return Project(name, lang, fpath, isGit);
|
|
}
|
|
|
|
Map<String, dynamic> toJson() {
|
|
Map<String, dynamic> fin = {
|
|
"name": name,
|
|
"language": language,
|
|
"path": path.path,
|
|
"isGit": isGit,
|
|
"e0": e0,
|
|
"e1": e1,
|
|
"e2": e2,
|
|
"e3": e3,
|
|
};
|
|
return fin;
|
|
}
|
|
|
|
factory Project.fromJson(Map<String, dynamic> data, List<String> editorList) {
|
|
final String e0 = editorList.contains(data["e0"]) ? data["e0"] : "";
|
|
final String e1 = editorList.contains(data["e1"]) ? data["e1"] : "";
|
|
final String e2 = editorList.contains(data["e2"]) ? data["e2"] : "";
|
|
final String e3 = editorList.contains(data["e3"]) ? data["e3"] : "";
|
|
return Project(
|
|
data["name"] as String,
|
|
data["language"] as String,
|
|
File(data["path"] as String),
|
|
data["isGit"] as bool,
|
|
e0: e0,
|
|
e1: e1,
|
|
e2: e2,
|
|
e3: e3,
|
|
);
|
|
}
|
|
|
|
String getEditor(int enumb) {
|
|
switch (enumb) {
|
|
case 0:
|
|
return e0;
|
|
case 1:
|
|
return e1;
|
|
case 2:
|
|
return e2;
|
|
case 3:
|
|
return e3;
|
|
default:
|
|
return "";
|
|
}
|
|
}
|
|
|
|
void setEditor(int enumb, String edt) {
|
|
switch (enumb) {
|
|
case 0:
|
|
e0 = edt;
|
|
break;
|
|
case 1:
|
|
e1 = edt;
|
|
break;
|
|
case 2:
|
|
e2 = edt;
|
|
break;
|
|
case 3:
|
|
e3 = edt;
|
|
break;
|
|
default:
|
|
}
|
|
}
|
|
|
|
// bool validatePath(){
|
|
// return File
|
|
// }
|
|
}
|