-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathProjectExaminer.cs
More file actions
60 lines (54 loc) · 2.25 KB
/
ProjectExaminer.cs
File metadata and controls
60 lines (54 loc) · 2.25 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
using DMPackageManager.CLI.Models;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
namespace DMPackageManager.CLI {
/// <summary>
/// Examines the CWD for whether the project is setup with DMPM, as well as having the setup handler
/// </summary>
public static class ProjectExaminer {
/// <summary>
/// Is the current directory setup for use with DMPM
/// </summary>
/// <returns>A true/false boolean depending on if the CWD is valid for DMPM use</returns>
public static bool IsSetup() {
if(ReportFailures().Count == 0) {
return true;
} else {
return false;
}
}
/// <summary>
/// Detailed reporting of failures.
/// </summary>
/// <returns>A list of failures</returns>
public static List<string> ReportFailures() {
List<string> issues = new List<string>();
string cwd = Directory.GetCurrentDirectory();
// Check if the DMPM directory exists
if (!Directory.Exists(String.Format("{0}/_dmpm", cwd))) {
issues.Add("The DMPM directory does not exist. Please run 'dmpm init'");
// This is fatal so we may as well leave now
return issues;
}
if (!File.Exists(String.Format("{0}/_dmpm/dmpm.json", cwd))) {
issues.Add("The DMPM data file does not exist. Please run 'dmpm init'");
// This is fatal so we may as well leave now
return issues;
}
string raw_json = File.ReadAllText(String.Format("{0}/_dmpm/dmpm.json", cwd));
try {
DataFile data = JsonConvert.DeserializeObject<DataFile>(raw_json);
} catch {
issues.Add("Failed to load the DMPM data file. It may be corrupted. Please run 'dmpm init'");
return issues; // Again, fatal
}
// After writing this, I realise that pretty much every failure means the next step wont work
// I designed this to be multi-error reporting, but clearly that was a waste of time
// Oh well
return issues;
}
}
}