1
1
using Castor . Interfaces ;
2
- using Castor . Models ;
2
+ using Castoreum . Config . Models ;
3
+ using Castoreum . Interface . Service . Compression ;
4
+ using Castoreum . Interface . Service . Config ;
5
+ using Castoreum . Interface . Service . Installation ;
6
+ using Castoreum . Interface . Service . Watch ;
3
7
using System ;
4
- using System . Diagnostics ;
5
8
using System . IO ;
6
9
using System . IO . Compression ;
7
10
using System . Reflection ;
@@ -11,14 +14,21 @@ namespace Castor.Services
11
14
{
12
15
class CommandService : ICommandService
13
16
{
14
- private static IFileService _fileService ;
15
- private static IInstallerService _installerService ;
16
- private static IZippingService _zippingService ;
17
- public CommandService ( IFileService fileService , IInstallerService installerService , IZippingService zippingService )
17
+ private static ICompressionManager _compressionManager ;
18
+ private static IConfigManager _configManager ;
19
+ private static IInstallationManager _installationManager ;
20
+ private static IProcessWatcher _processWatcher ;
21
+ public CommandService (
22
+ ICompressionManager compressionManager ,
23
+ IConfigManager configManager ,
24
+ IInstallationManager installationManager ,
25
+ IProcessWatcher processWatcher
26
+ )
18
27
{
19
- _fileService = fileService ;
20
- _installerService = installerService ;
21
- _zippingService = zippingService ;
28
+ _compressionManager = compressionManager ;
29
+ _configManager = configManager ;
30
+ _installationManager = installationManager ;
31
+ _processWatcher = processWatcher ;
22
32
}
23
33
24
34
public void Build ( string [ ] args )
@@ -33,7 +43,7 @@ public void Build(string[] args)
33
43
}
34
44
35
45
string castorConfigText = File . ReadAllText ( "castor.json" ) ;
36
- CastorConfig castorConfig = JsonSerializer . Deserialize < CastorConfig > ( castorConfigText ) ;
46
+ IConfig castorConfig = JsonSerializer . Deserialize < CastorConfig > ( castorConfigText ) ;
37
47
38
48
string archiveName = $ "{ castorConfig . ArchiveName } .zip";
39
49
@@ -50,7 +60,7 @@ public void Build(string[] args)
50
60
}
51
61
52
62
DirectoryInfo directory = new ( folder ) ;
53
- _zippingService . Zip ( archive , castorConfig , directory ) ;
63
+ _compressionManager . BuildMod ( archive , castorConfig , directory ) ;
54
64
}
55
65
}
56
66
@@ -111,12 +121,12 @@ public void Init(string[] args)
111
121
archiveName = directoryPath [ ^ 1 ] ;
112
122
}
113
123
114
- CastorConfig newConfig = _fileService . NewConfig ( archiveName ) ;
115
- _fileService . CreateConfigFile ( newConfig ) ;
124
+ IConfig newConfig = _configManager . CreateConfigFile ( archiveName ) ;
125
+ _configManager . PlaceConfigFile ( newConfig , "castor.json" ) ;
116
126
117
127
if ( ! File . Exists ( ".gitignore" ) )
118
128
{
119
- _fileService . CreateGitignoreFile ( ) ;
129
+ _configManager . PlaceGitIgnore ( "" ) ;
120
130
}
121
131
else
122
132
{
@@ -128,21 +138,34 @@ public void Init(string[] args)
128
138
129
139
public void Install ( string [ ] args )
130
140
{
141
+ string castorConfigText = File . ReadAllText ( "castor.json" ) ;
142
+ IConfig castorConfig = JsonSerializer . Deserialize < CastorConfig > ( castorConfigText ) ;
131
143
if ( args . Length > 1 )
132
144
{
133
- _installerService . InstallModule ( args [ 1 ] , true ) ;
145
+ if ( args . Length > 2 )
146
+ {
147
+ if ( args [ 2 ] == "--dev" )
148
+ castorConfig = _installationManager . InstallDevDependency ( castorConfig , args [ 1 ] ) ;
149
+ }
150
+ else
151
+ {
152
+ castorConfig = _installationManager . InstallDependency ( castorConfig , args [ 1 ] ) ;
153
+ }
154
+
155
+ _configManager . PlaceConfigFile ( castorConfig , "castor.json" ) ;
134
156
}
135
157
else
136
158
{
137
- string castorConfigText = File . ReadAllText ( "castor.json" ) ;
138
- CastorConfig castorConfig = JsonSerializer . Deserialize < CastorConfig > ( castorConfigText ) ;
139
-
140
- if ( castorConfig . DevDependencies . Count == 0 )
141
- Environment . Exit ( 1 ) ;
159
+ foreach ( var package in castorConfig . Dependencies )
160
+ {
161
+ Console . WriteLine ( $ "installing package { package } " ) ;
162
+ _installationManager . InstallPackage ( package ) ;
163
+ }
142
164
143
165
foreach ( var package in castorConfig . DevDependencies )
144
166
{
145
- _installerService . InstallModule ( package ) ;
167
+ Console . WriteLine ( $ "installing package { package } ") ;
168
+ _installationManager . InstallPackage ( package ) ;
146
169
}
147
170
148
171
Console . ForegroundColor = ConsoleColor . Green ;
@@ -163,7 +186,7 @@ public void Serve(string[] args)
163
186
}
164
187
165
188
string castorConfigText = File . ReadAllText ( "castor.json" ) ;
166
- CastorConfig castorConfig = JsonSerializer . Deserialize < CastorConfig > ( castorConfigText ) ;
189
+ IConfig castorConfig = JsonSerializer . Deserialize < CastorConfig > ( castorConfigText ) ;
167
190
168
191
string [ ] buildArgs = new string [ 1 ] ;
169
192
buildArgs [ 0 ] = "--ztroot" ;
@@ -177,34 +200,12 @@ public void Serve(string[] args)
177
200
string ZTarg = $ "{ baseDirectory } castor-serve-save.z2s";
178
201
179
202
Console . WriteLine ( "watching Zoo Tycoon 2..." ) ;
180
- ConsoleCommand ( ZTprogram , ZTarg ) ;
203
+ _processWatcher . Watch ( ZTprogram , ZTarg ) ;
181
204
}
182
205
183
206
public void Version ( )
184
207
{
185
208
Console . WriteLine ( $ "Castor v{ Assembly . GetExecutingAssembly ( ) . GetName ( ) . Version } ") ;
186
209
}
187
-
188
- public void ConsoleCommand ( string program , string arg )
189
- {
190
- using var process = new Process ( ) ;
191
- process . StartInfo . FileName = program ;
192
- process . StartInfo . Arguments = arg ;
193
- process . StartInfo . RedirectStandardOutput = true ;
194
- process . StartInfo . UseShellExecute = false ;
195
- process . Start ( ) ;
196
-
197
- using ( StreamWriter writer = new ( "castorlog.txt" ) )
198
- {
199
- while ( ! process . StandardOutput . EndOfStream )
200
- {
201
- string line = process . StandardOutput . ReadLine ( ) ;
202
- Console . WriteLine ( $ "{ line } ") ;
203
- writer . WriteLine ( $ "{ line } ") ;
204
- }
205
- }
206
-
207
- process . WaitForExit ( ) ;
208
- }
209
210
}
210
211
}
0 commit comments