Skip to content

Commit 1b6b7b7

Browse files
authored
Merge pull request #7 from ZtModArchive/develop
use castoreum
2 parents 43c1874 + 13829de commit 1b6b7b7

13 files changed

+78
-331
lines changed

Castor/Castor.csproj

+7-2
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,27 @@
66
<ApplicationIcon>castor-icon.ico</ApplicationIcon>
77
<Company>ZtModArchive</Company>
88
<Copyright>MIT License</Copyright>
9-
<Version>3.4.1</Version>
9+
<Version>4.0.0</Version>
1010
<PackageProjectUrl>https://github.com/ZtModArchive/Castor/tree/main/Castor</PackageProjectUrl>
1111
<PackageIcon>castor-icon.ico</PackageIcon>
1212
<PackageIconUrl />
1313
<RepositoryUrl>https://github.com/ZtModArchive/Castor/tree/main/Castor</RepositoryUrl>
1414
<RepositoryType>Git</RepositoryType>
1515
<SignAssembly>false</SignAssembly>
16+
<AssemblyVersion>4.0.0.0</AssemblyVersion>
1617
</PropertyGroup>
1718

1819
<ItemGroup>
1920
<None Remove="Files\gitignore.txt" />
2021
</ItemGroup>
2122

2223
<ItemGroup>
24+
<PackageReference Include="Castoreum.Compression" Version="1.0.0" />
25+
<PackageReference Include="Castoreum.Config" Version="1.0.1" />
26+
<PackageReference Include="Castoreum.Installation" Version="1.0.0" />
27+
<PackageReference Include="Castoreum.Interface" Version="1.0.0" />
28+
<PackageReference Include="Castoreum.Watch" Version="1.0.0" />
2329
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="5.0.2" />
24-
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
2530
</ItemGroup>
2631

2732
<ItemGroup>

Castor/Interfaces/ICastorConfig.cs

-21
This file was deleted.

Castor/Interfaces/ICommandService.cs

+9-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
1-
namespace Castor.Interfaces
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace Castor.Interfaces
28
{
39
interface ICommandService
410
{
511
void Build(string[] args);
6-
void Help();
712
void Init(string[] args);
13+
void Help();
814
void Install(string[] args);
9-
void Version();
1015
void Serve(string[] args);
11-
void ConsoleCommand(string program, string arg);
16+
void Version();
1217
}
1318
}

Castor/Interfaces/IFileService.cs

-11
This file was deleted.

Castor/Interfaces/IInstallerService.cs

-7
This file was deleted.

Castor/Interfaces/IZippingService.cs

-10
This file was deleted.

Castor/Models/CastorConfig.cs

-9
This file was deleted.

Castor/Program.cs

+14-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
using Castor.Interfaces;
22
using Castor.Services;
3+
using Castoreum.Compression;
4+
using Castoreum.Config.Models;
5+
using Castoreum.Config.Service;
6+
using Castoreum.Installation;
7+
using Castoreum.Interface.Service.Compression;
8+
using Castoreum.Interface.Service.Config;
9+
using Castoreum.Interface.Service.Installation;
10+
using Castoreum.Interface.Service.Watch;
11+
using Castoreum.Watch;
312
using Microsoft.Extensions.DependencyInjection;
413

514
namespace Castor
@@ -21,9 +30,11 @@ private static void ConfigureServices(IServiceCollection services)
2130
{
2231
services.AddTransient<CastorApp>();
2332
services.AddScoped<ICommandService, CommandService>();
24-
services.AddScoped<IFileService, FileService>();
25-
services.AddScoped<IInstallerService, InstallerService>();
26-
services.AddScoped<IZippingService, ZippingService>();
33+
services.AddScoped<ICompressionManager, CompressionManager>();
34+
services.AddScoped<IConfig, CastorConfig>();
35+
services.AddScoped<IConfigManager, ConfigManager>();
36+
services.AddScoped<IInstallationManager, InstallationManager>();
37+
services.AddScoped<IProcessWatcher, ProcessWatcher>();
2738
}
2839
}
2940
}

Castor/Properties/launchSettings.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
"profiles": {
33
"Castor": {
44
"commandName": "Project",
5-
"commandLineArgs": "version",
6-
"workingDirectory": "C:\\Program Files (x86)\\Microsoft Games\\Zoo Tycoon 2\\ModTest",
5+
"commandLineArgs": "build",
6+
"workingDirectory": "C:\\Program Files (x86)\\Microsoft Games\\projects\\ModTest",
77
"remoteDebugEnabled": false
88
}
99
}

Castor/Services/CommandService.cs

+46-45
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
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;
37
using System;
4-
using System.Diagnostics;
58
using System.IO;
69
using System.IO.Compression;
710
using System.Reflection;
@@ -11,14 +14,21 @@ namespace Castor.Services
1114
{
1215
class CommandService : ICommandService
1316
{
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+
)
1827
{
19-
_fileService = fileService;
20-
_installerService = installerService;
21-
_zippingService = zippingService;
28+
_compressionManager = compressionManager;
29+
_configManager = configManager;
30+
_installationManager = installationManager;
31+
_processWatcher = processWatcher;
2232
}
2333

2434
public void Build(string[] args)
@@ -33,7 +43,7 @@ public void Build(string[] args)
3343
}
3444

3545
string castorConfigText = File.ReadAllText("castor.json");
36-
CastorConfig castorConfig = JsonSerializer.Deserialize<CastorConfig>(castorConfigText);
46+
IConfig castorConfig = JsonSerializer.Deserialize<CastorConfig>(castorConfigText);
3747

3848
string archiveName = $"{castorConfig.ArchiveName}.zip";
3949

@@ -50,7 +60,7 @@ public void Build(string[] args)
5060
}
5161

5262
DirectoryInfo directory = new(folder);
53-
_zippingService.Zip(archive, castorConfig, directory);
63+
_compressionManager.BuildMod(archive, castorConfig, directory);
5464
}
5565
}
5666

@@ -111,12 +121,12 @@ public void Init(string[] args)
111121
archiveName = directoryPath[^1];
112122
}
113123

114-
CastorConfig newConfig = _fileService.NewConfig(archiveName);
115-
_fileService.CreateConfigFile(newConfig);
124+
IConfig newConfig = _configManager.CreateConfigFile(archiveName);
125+
_configManager.PlaceConfigFile(newConfig, "castor.json");
116126

117127
if (!File.Exists(".gitignore"))
118128
{
119-
_fileService.CreateGitignoreFile();
129+
_configManager.PlaceGitIgnore("");
120130
}
121131
else
122132
{
@@ -128,21 +138,34 @@ public void Init(string[] args)
128138

129139
public void Install(string[] args)
130140
{
141+
string castorConfigText = File.ReadAllText("castor.json");
142+
IConfig castorConfig = JsonSerializer.Deserialize<CastorConfig>(castorConfigText);
131143
if (args.Length > 1)
132144
{
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");
134156
}
135157
else
136158
{
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+
}
142164

143165
foreach (var package in castorConfig.DevDependencies)
144166
{
145-
_installerService.InstallModule(package);
167+
Console.WriteLine($"installing package {package}");
168+
_installationManager.InstallPackage(package);
146169
}
147170

148171
Console.ForegroundColor = ConsoleColor.Green;
@@ -163,7 +186,7 @@ public void Serve(string[] args)
163186
}
164187

165188
string castorConfigText = File.ReadAllText("castor.json");
166-
CastorConfig castorConfig = JsonSerializer.Deserialize<CastorConfig>(castorConfigText);
189+
IConfig castorConfig = JsonSerializer.Deserialize<CastorConfig>(castorConfigText);
167190

168191
string[] buildArgs = new string[1];
169192
buildArgs[0] = "--ztroot";
@@ -177,34 +200,12 @@ public void Serve(string[] args)
177200
string ZTarg = $"{baseDirectory}castor-serve-save.z2s";
178201

179202
Console.WriteLine("watching Zoo Tycoon 2...");
180-
ConsoleCommand(ZTprogram, ZTarg);
203+
_processWatcher.Watch(ZTprogram, ZTarg);
181204
}
182205

183206
public void Version()
184207
{
185208
Console.WriteLine($"Castor v{Assembly.GetExecutingAssembly().GetName().Version}");
186209
}
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-
}
209210
}
210211
}

0 commit comments

Comments
 (0)