-
Notifications
You must be signed in to change notification settings - Fork 0
/
UnityCli.cs
60 lines (53 loc) · 1.8 KB
/
UnityCli.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
using System.Diagnostics;
using UnityQuickStart.App.IO;
using UnityQuickStart.App.Project;
namespace UnityQuickStart.App.Unity
{
public class UnityCli
{
private string GetPathToUnityVersion(string installPath, string version)
{
return Path.Combine(installPath, version, "Editor", "Unity.exe");
}
public async Task OpenUnityProject(QuickStartProject project, string unityVersion, string installPath)
{
var createRepo = UserInput.GetYesNo($"Would you like to open the Unity project at {project.ProjectPath}:");
if (!createRepo)
{
Output.WriteSuccessWithTick($"Ok skip opening the project");
return;
}
const string processMsg = "Opening Unity project";
var fileName = GetPathToUnityVersion(installPath, unityVersion);
var args = $"-projectPath {project.ProjectPath}";
ProcessExecutor.ExecuteProcess(fileName,args, processMsg,
(output) =>
{
Output.WriteSuccessWithTick($"Ok Unity {unityVersion} project opened at {project.ProjectPath}");
},
(error) =>
{
Output.WriteError($"Opening Unity project at {project.ProjectPath} failed: {error}");
});
}
public async Task<bool> CreateUnityProject(QuickStartProject project, string unityVersion, string installPath)
{
const string processMsg = "Creating Unity project";
var fileName = GetPathToUnityVersion(installPath, unityVersion);
var args = @$"-batchmode -quit -createProject {project.ProjectPath}";
var success = false;
await ProcessExecutor.ExecuteProcess(fileName,args, processMsg,
(output) =>
{
success = true;
Output.WriteSuccessWithTick($"Ok Unity {unityVersion} project created at {project.ProjectPath}");
},
(error) =>
{
success = false;
Output.WriteError($"Unity project creation failed: {error}");
});
return success;
}
}
}