-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
253 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
language: csharp | ||
mono: none | ||
dotnet: 5.0.302 | ||
solution: Castoreum.sln | ||
before_install: | ||
- dotnet --info | ||
install: | ||
- dotnet restore | ||
- dotnet tool install dotnet-format | ||
script: | ||
- dotnet test | ||
- dotnet dotnet-format --check | ||
- dotnet publish |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,11 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net5.0</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Castoreum.Interface\Castoreum.Interface.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
using Castoreum.Interface.Service.Compression; | ||
using Castoreum.Interface.Service.Config; | ||
using System.IO; | ||
using System.IO.Compression; | ||
|
||
namespace Castoreum.Compression | ||
{ | ||
public class CompressionManager : ICompressionManager | ||
{ | ||
public void BuildMod(ZipArchive archive, IConfig config, DirectoryInfo directoryInfo) | ||
{ | ||
string[] directoryPath = Directory.GetCurrentDirectory().Split('\\'); | ||
string rootDirectory = directoryPath[^1]; | ||
string formattedPath = directoryInfo.FullName.Split(rootDirectory)[1].Remove(0, 1); | ||
|
||
var files = directoryInfo.GetFiles(); | ||
foreach (var file in files) | ||
{ | ||
if (config.Type == "module" || config.Type == "package") | ||
{ | ||
archive.CreateEntryFromFile(file.FullName, $"modules\\{config.RepoName}\\{formattedPath}\\{file.Name}"); | ||
} | ||
archive.CreateEntryFromFile(file.FullName, $"{formattedPath}\\{file.Name}"); | ||
} | ||
var directories = directoryInfo.GetDirectories(); | ||
bool exclude; | ||
string subDirectoryPath; | ||
foreach (var directory in directories) | ||
{ | ||
exclude = false; | ||
subDirectoryPath = directory.FullName.Split(rootDirectory)[1].Remove(0, 1); | ||
foreach (var excludedPath in config.ExcludeFolders) | ||
{ | ||
if (subDirectoryPath == excludedPath || subDirectoryPath == excludedPath.Replace('/', '\\')) | ||
exclude = true; | ||
} | ||
|
||
foreach (var dependencyPath in config.Dependencies) | ||
{ | ||
if (subDirectoryPath == dependencyPath || subDirectoryPath == dependencyPath.Replace('/', '\\')) | ||
exclude = true; | ||
} | ||
|
||
if (!exclude) | ||
BuildMod(archive, config, directory); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
using Castoreum.Config.Models; | ||
using Castoreum.Interface.Service.Config; | ||
using Castoreum.Interface.Service.Installation; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.IO.Compression; | ||
using System.Net; | ||
|
||
namespace Castoreum.Installation | ||
{ | ||
public class InstallationManager : IInstallationManager | ||
{ | ||
public IConfig InstallDependency(IConfig config, string packageName) | ||
{ | ||
InstallPackage(packageName); | ||
List<string> dependencies = (List<string>)config.Dependencies; | ||
if (!dependencies.Contains(packageName)) | ||
{ | ||
dependencies.Add(packageName); | ||
} | ||
return config; | ||
} | ||
|
||
public IConfig InstallDevDependency(IConfig config, string packageName) | ||
{ | ||
InstallPackage(packageName); | ||
List<string> dependencies = (List<string>)config.DevDependencies; | ||
if (!dependencies.Contains(packageName)) | ||
{ | ||
dependencies.Add(packageName); | ||
} | ||
return config; | ||
} | ||
|
||
public IConfig RemoveDependency(IConfig config, string packageName) | ||
{ | ||
UninstallPackage(packageName); | ||
List<string> dependencies = (List<string>)config.Dependencies; | ||
if (!dependencies.Contains(packageName)) | ||
{ | ||
dependencies.RemoveAll(p => p == packageName); | ||
} | ||
return config; | ||
} | ||
|
||
public IConfig RemoveDevDependency(IConfig config, string packageName) | ||
{ | ||
UninstallPackage(packageName); | ||
List<string> dependencies = (List<string>)config.DevDependencies; | ||
if (!dependencies.Contains(packageName)) | ||
{ | ||
dependencies.RemoveAll(p => p == packageName); | ||
} | ||
return config; | ||
} | ||
|
||
public void InstallPackage(string packageName) | ||
{ | ||
using WebClient client = new(); | ||
Guid guid = Guid.NewGuid(); | ||
string[] packageArgs = packageName.Split('/'); | ||
client.DownloadFile($"https://github.com/{packageArgs[0]}/{packageArgs[1]}/archive/refs/tags/{packageArgs[2]}.zip", $"{guid}.zip"); | ||
ZipFile.ExtractToDirectory($"{guid}.zip", $"{guid}"); | ||
|
||
// remove the package's modules folder if the dev didn't exclude it | ||
if (Directory.Exists($"{guid}/modules")) | ||
Directory.Delete($"{guid}/modules"); | ||
|
||
string[] subDirectories = Directory.GetDirectories($"{guid}"); | ||
string firstSubDir = ""; | ||
if (subDirectories.Length > 0) | ||
{ | ||
firstSubDir = subDirectories[0]; | ||
} | ||
|
||
CopyFilesRecursively($"{guid}/{firstSubDir.Split('\\')[1]}", $"modules/{packageArgs[0]}/{packageArgs[1]}"); | ||
|
||
var directory = new DirectoryInfo($"{guid}") { Attributes = FileAttributes.Normal }; | ||
foreach (var info in directory.GetFileSystemInfos("*", SearchOption.AllDirectories)) | ||
{ | ||
info.Attributes = FileAttributes.Normal; | ||
} | ||
|
||
Directory.Delete($"{guid}", true); | ||
File.Delete($"{guid}.zip"); | ||
} | ||
|
||
private void UninstallPackage(string packageName) | ||
{ | ||
if (Directory.Exists($"modules/{packageName}")) | ||
Directory.Delete($"modules/{packageName}"); | ||
} | ||
|
||
private static void CopyFilesRecursively(string sourcePath, string targetPath) | ||
{ | ||
foreach (string dirPath in Directory.GetDirectories(sourcePath, "*", SearchOption.AllDirectories)) | ||
{ | ||
Directory.CreateDirectory(dirPath.Replace(sourcePath, targetPath)); | ||
} | ||
|
||
foreach (string newPath in Directory.GetFiles(sourcePath, "*.*", SearchOption.AllDirectories)) | ||
{ | ||
File.Copy(newPath, newPath.Replace(sourcePath, targetPath), true); | ||
} | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,11 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net5.0</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Castoreum.Interface\Castoreum.Interface.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using Castoreum.Interface.Service.Watch; | ||
using System; | ||
using System.Diagnostics; | ||
using System.IO; | ||
|
||
namespace Castoreum.Watch | ||
{ | ||
public class ProcessWatcher : IProcessWatcher | ||
{ | ||
public void Watch(string program, string arg) | ||
{ | ||
using var process = new Process(); | ||
process.StartInfo.FileName = program; | ||
process.StartInfo.Arguments = arg; | ||
process.StartInfo.RedirectStandardOutput = true; | ||
process.StartInfo.UseShellExecute = false; | ||
process.Start(); | ||
|
||
using (StreamWriter writer = new("castorlog.txt")) | ||
{ | ||
while (!process.StandardOutput.EndOfStream) | ||
{ | ||
string line = process.StandardOutput.ReadLine(); | ||
Console.WriteLine($"{line}"); | ||
writer.WriteLine($"{line}"); | ||
} | ||
} | ||
|
||
process.WaitForExit(); | ||
} | ||
} | ||
} |
Oops, something went wrong.