Skip to content

Commit

Permalink
Introduce integrated package manager
Browse files Browse the repository at this point in the history
This commit introduces an integrated package manager into TShock
for the purpose of fetching and installing plugins and their dependencies
from NuGet repositories.

This makes getting new plugins easier for users, as well as simplifiying
more advanced deployment scenarios.
  • Loading branch information
sowelipililimute committed Nov 28, 2022
1 parent 4e59087 commit be8e519
Show file tree
Hide file tree
Showing 13 changed files with 849 additions and 8 deletions.
18 changes: 18 additions & 0 deletions TShock.sln
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TShockLauncher.Tests", "TSh
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TShockInstaller", "TShockInstaller\TShockInstaller.csproj", "{17AC4DD0-8334-4B5C-ABED-77EAF52D75FA}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TShockPluginManager", "TShockPluginManager\TShockPluginManager.csproj", "{9FFABC7D-B042-4B58-98F5-7FA787B9A757}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -120,6 +122,22 @@ Global
{17AC4DD0-8334-4B5C-ABED-77EAF52D75FA}.Release|x64.Build.0 = Release|Any CPU
{17AC4DD0-8334-4B5C-ABED-77EAF52D75FA}.Release|x86.ActiveCfg = Release|Any CPU
{17AC4DD0-8334-4B5C-ABED-77EAF52D75FA}.Release|x86.Build.0 = Release|Any CPU
{9FFABC7D-B042-4B58-98F5-7FA787B9A757}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9FFABC7D-B042-4B58-98F5-7FA787B9A757}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9FFABC7D-B042-4B58-98F5-7FA787B9A757}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{9FFABC7D-B042-4B58-98F5-7FA787B9A757}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{9FFABC7D-B042-4B58-98F5-7FA787B9A757}.Debug|x64.ActiveCfg = Debug|Any CPU
{9FFABC7D-B042-4B58-98F5-7FA787B9A757}.Debug|x64.Build.0 = Debug|Any CPU
{9FFABC7D-B042-4B58-98F5-7FA787B9A757}.Debug|x86.ActiveCfg = Debug|Any CPU
{9FFABC7D-B042-4B58-98F5-7FA787B9A757}.Debug|x86.Build.0 = Debug|Any CPU
{9FFABC7D-B042-4B58-98F5-7FA787B9A757}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9FFABC7D-B042-4B58-98F5-7FA787B9A757}.Release|Any CPU.Build.0 = Release|Any CPU
{9FFABC7D-B042-4B58-98F5-7FA787B9A757}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{9FFABC7D-B042-4B58-98F5-7FA787B9A757}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{9FFABC7D-B042-4B58-98F5-7FA787B9A757}.Release|x64.ActiveCfg = Release|Any CPU
{9FFABC7D-B042-4B58-98F5-7FA787B9A757}.Release|x64.Build.0 = Release|Any CPU
{9FFABC7D-B042-4B58-98F5-7FA787B9A757}.Release|x86.ActiveCfg = Release|Any CPU
{9FFABC7D-B042-4B58-98F5-7FA787B9A757}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
1 change: 1 addition & 0 deletions TShockLauncher/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/packages
15 changes: 14 additions & 1 deletion TShockLauncher/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,24 @@ You should have received a copy of the GNU General Public License
* - to copy/move around TShockAPI.dll (the TShock plugin to TSAPI)
* - to publish TShock releases.
* - move dependencies to a ./bin folder
*
*
* The assembly name of this launcher (TShock.exe) was decided on by a community poll.
*/

using System.Reflection;
using TShockPluginManager;

if (args.Length > 0 && args[0].ToLower() == "plugins")
{
var items = args.ToList();
items.RemoveAt(0);
await NugetCLI.Main(items);
return;
}
else
{
Start();
}

Dictionary<string, Assembly> _cache = new Dictionary<string, Assembly>();

Expand Down
3 changes: 2 additions & 1 deletion TShockLauncher/TShockLauncher.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<ItemGroup>
<ProjectReference Include="..\TerrariaServerAPI\TerrariaServerAPI\TerrariaServerAPI.csproj" ExcludeFromSingleFile="true" />
<ProjectReference Include="..\TShockAPI\TShockAPI.csproj" ExcludeFromSingleFile="true" ReferenceOutputAssembly="false" /> <!-- allow api to rebuilt with this project, so ServerPlugins are refreshed -->
<ProjectReference Include="..\TShockPluginManager\TShockPluginManager.csproj"/>
<Reference Include="HttpServer" ExcludeFromSingleFile="true">
<HintPath>..\prebuilts\HttpServer.dll</HintPath>
</Reference>
Expand Down Expand Up @@ -96,4 +97,4 @@
</ItemGroup>
<Move SourceFiles="@(MoveBinaries)" DestinationFolder="$(PublishDir)bin" ContinueOnError="true" />
</Target>
</Project>
</Project>
114 changes: 114 additions & 0 deletions TShockPluginManager/CLIHelpers.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
/*
TShock, a server mod for Terraria
Copyright (C) 2022 Janet Blackquill
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

using System.Text;

namespace TShockPluginManager
{
static class CLIHelpers
{
static public bool YesNo()
{
System.Console.Write("[y/n] ");
bool accept;
bool confirm = false;
do
{
ConsoleKey response = Console.ReadKey(true).Key;
(accept, confirm) = response switch {
ConsoleKey.Y => (true, true),
ConsoleKey.N => (false, true),
_ => (false, false)
};
} while (!confirm);
if (accept)
System.Console.WriteLine("yes");
else
System.Console.WriteLine("no");
return accept;
}
public enum Answers {
Yes,
No,
Explain
}
static public Answers YesNoExplain()
{
System.Console.Write("[y/n/e] ");
Answers ans;
bool confirm = false;
do
{
ConsoleKey response = Console.ReadKey(true).Key;
(ans, confirm) = response switch {
ConsoleKey.Y => (Answers.Yes, true),
ConsoleKey.N => (Answers.No, true),
ConsoleKey.E => (Answers.Explain, true),
_ => (Answers.Explain, false)
};
} while (!confirm);
if (ans == Answers.Yes)
System.Console.WriteLine("yes");
else if (ans == Answers.No)
System.Console.WriteLine("no");
else
System.Console.WriteLine("explain");
return ans;
}
static private string[] ColorNames = Enum.GetNames(typeof(ConsoleColor));
static public void Write(string text)
{
var initial = Console.ForegroundColor;

var buffer = new StringBuilder();
var chars = text.ToCharArray().ToList();
while (chars.Count > 0)
{
var ch = chars.First();
if (ch == '<')
{
var possibleColor = new string(chars.Skip(1).TakeWhile(c => c != '>').ToArray());
Func<string, bool> predicate = x => string.Equals(x, possibleColor, StringComparison.CurrentCultureIgnoreCase);
if (!ColorNames.Any(predicate))
goto breakFromIf;
var color = ColorNames.First(predicate);
if (buffer.Length > 0)
{
Console.Write(buffer.ToString());
buffer.Clear();
}
Console.ForegroundColor = Enum.Parse<ConsoleColor>(color);
chars = chars.Skip(2 + possibleColor.Length).ToList();
continue;
}
breakFromIf:
buffer.Append(ch);
chars.RemoveAt(0);
}

if (buffer.Length > 0)
Console.Write(buffer.ToString());

Console.ForegroundColor = initial;
}
static public void WriteLine(string text)
{
Write(text + "\n");
}
}
}
11 changes: 11 additions & 0 deletions TShockPluginManager/I18n.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using GetText;

namespace TShockPluginManager
{
static class I18n
{
static string TranslationsDirectory => Path.Combine(AppContext.BaseDirectory, "i18n");
// we share the same translations catalog as TShockAPI
public static Catalog C = new Catalog("TShockAPI", TranslationsDirectory);
}
}
Loading

0 comments on commit be8e519

Please sign in to comment.