-
Notifications
You must be signed in to change notification settings - Fork 21
/
ClassAppHelper.cs
82 lines (74 loc) · 2.24 KB
/
ClassAppHelper.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace GitForce
{
/// <summary>
/// Structure describing application helper programs (Diff, Merge)
/// </summary>
public struct AppHelper : IComparable<AppHelper>
{
/// <summary>
/// User-friendly name of an application helper tool
/// </summary>
public readonly string Name;
/// <summary>
/// Full path/name to the tool
/// </summary>
public readonly string Path;
/// <summary>
/// Arguments needed when executing the tool for a particular purpose
/// </summary>
public readonly string Args;
/// <summary>
/// Constructor that simply assigns fields
/// </summary>
public AppHelper(string appName, string appPath, string appArgs)
{
Name = appName;
Path = appPath;
Args = appArgs;
}
/// <summary>
/// Constructor that deserialize fields into a new structure
/// </summary>
public AppHelper(string appCombined)
{
Name = string.Empty;
Path = appCombined;
Args = string.Empty;
string[] parts = appCombined.Split('\t');
if (parts.Length == 3)
{
Name = parts[0];
Path = parts[1];
Args = parts[2];
}
}
/// <summary>
/// ToString override returns serialized fields
/// </summary>
public override string ToString()
{
return Name + '\t' + Path + '\t' + Args;
}
/// <summary>
/// Implements comparator
/// </summary>
public int CompareTo(AppHelper other)
{
return other.Name.CompareTo(Name);
}
/// <summary>
/// Given a list of candidate programs, return only those that actually exist
/// </summary>
public static List<AppHelper> Scan(List<AppHelper> candidates)
{
return (from appHelper in candidates
let path = appHelper.Path
where File.Exists(path)
select appHelper).ToList();
}
}
}