-
Notifications
You must be signed in to change notification settings - Fork 0
/
LocalProjectList.cs
39 lines (31 loc) · 1.19 KB
/
LocalProjectList.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
using System.Collections.Generic;
using System.IO;
using System.Linq;
using DemonCastle.ProjectFiles;
using DemonCastle.ProjectFiles.Projects;
namespace DemonCastle;
public static class LocalProjectList {
private static string GodotPath => "user://ProjectList.json";
private static string GlobalPath => Godot.ProjectSettings.GlobalizePath(GodotPath);
private static ProjectListFile GetProjectList() {
if (!File.Exists(GlobalPath)) return new ProjectListFile();
var contents = File.ReadAllText(GlobalPath);
return Serializer.Deserialize<ProjectListFile>(contents);
}
public static IEnumerable<string> ProjectFiles => GetProjectList().Projects;
public static void AddProject(string filePath) {
var project = GetProjectList();
project.Projects.Add(filePath);
SaveProjectList(project);
}
private static void SaveProjectList(ProjectListFile project) {
project.Projects = project.Projects.Where(File.Exists).Distinct().ToList();
var content = Serializer.Serialize(project);
File.WriteAllText(GlobalPath, content);
}
public static void RemoveProject(string projectFilePath) {
var project = GetProjectList();
project.Projects.Remove(projectFilePath);
SaveProjectList(project);
}
}