Merge pull request #2606 from SignatureBeef/otapi3

Arm64 implementation for Raspberry PI
This commit is contained in:
Chris 2022-03-28 20:18:59 +10:30 committed by GitHub
commit 18ea183642
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 39 additions and 26 deletions

View file

@ -14,6 +14,8 @@ This is the rolling changelog for TShock for Terraria. Use past tense when addin
## Upcoming changes (TShock 5.0.0) ## Upcoming changes (TShock 5.0.0)
* Reduced load/save console spam. (@SignatureBeef, @YehnBeep) * Reduced load/save console spam. (@SignatureBeef, @YehnBeep)
* Replaced SQLite library with Microsoft.Data.Sqlite for arm64 support. (@SignatureBeef)
* Initial support for MonoMod hooks on Raspberry Pi (arm64). (@kevzhao2)
## Upcoming changes ## Upcoming changes

View file

@ -65,13 +65,13 @@ namespace TShockAPI.DB
try try
{ {
db.Open(); db.Open();
using (var com = db.CreateCommand()) var com = db.CreateCommand(); // this will be disposed via the QueryResult instance
{ {
com.CommandText = query; com.CommandText = query;
for (int i = 0; i < args.Length; i++) for (int i = 0; i < args.Length; i++)
com.AddParameter("@" + i, args[i]); com.AddParameter("@" + i, args[i]);
return new QueryResult(db, com.ExecuteReader()); return new QueryResult(db, com.ExecuteReader(), com);
} }
} }
catch (Exception ex) catch (Exception ex)
@ -117,13 +117,13 @@ namespace TShockAPI.DB
{ {
var db = olddb.CloneEx(); var db = olddb.CloneEx();
db.Open(); db.Open();
using (var com = db.CreateCommand()) var com = db.CreateCommand(); // this will be disposed via the QueryResult instance
{ {
com.CommandText = query; com.CommandText = query;
foreach (var kv in values) foreach (var kv in values)
com.AddParameter("@" + kv.Key, kv.Value); com.AddParameter("@" + kv.Key, kv.Value);
return new QueryResult(db, com.ExecuteReader()); return new QueryResult(db, com.ExecuteReader(), com);
} }
} }
@ -274,11 +274,13 @@ namespace TShockAPI.DB
{ {
public IDbConnection Connection { get; protected set; } public IDbConnection Connection { get; protected set; }
public IDataReader Reader { get; protected set; } public IDataReader Reader { get; protected set; }
public IDbCommand Command { get; protected set; }
public QueryResult(IDbConnection conn, IDataReader reader) public QueryResult(IDbConnection conn, IDataReader reader, IDbCommand command)
{ {
Connection = conn; Connection = conn;
Reader = reader; Reader = reader;
Command = command;
} }
~QueryResult() ~QueryResult()
@ -301,6 +303,11 @@ namespace TShockAPI.DB
Reader.Dispose(); Reader.Dispose();
Reader = null; Reader = null;
} }
if (Command != null)
{
Command.Dispose();
Command = null;
}
if (Connection != null) if (Connection != null)
{ {
Connection.Dispose(); Connection.Dispose();

View file

@ -28,7 +28,6 @@ using System.Linq;
using System.Net; using System.Net;
using System.Reflection; using System.Reflection;
using MaxMind; using MaxMind;
using System.Data.SQLite;
using MySql.Data.MySqlClient; using MySql.Data.MySqlClient;
using Newtonsoft.Json; using Newtonsoft.Json;
using Rests; using Rests;
@ -259,9 +258,6 @@ namespace TShockAPI
//TShock handles this //TShock handles this
args.Result = OTAPI.Hooks.NetMessage.PlayerAnnounceResult.None; args.Result = OTAPI.Hooks.NetMessage.PlayerAnnounceResult.None;
}; };
// if sqlite.interop cannot be found, try and search the runtimes folder. this usually happens when debugging tsapi
// since it does not have the dependency installed directly
NativeLibrary.SetDllImportResolver(typeof(SQLiteConnection).Assembly, ResolveNativeDep);
Main.SettingsUnlock_WorldEvil = true; Main.SettingsUnlock_WorldEvil = true;
@ -322,7 +318,7 @@ namespace TShockAPI
{ {
string sql = Path.Combine(SavePath, Config.Settings.SqliteDBPath); string sql = Path.Combine(SavePath, Config.Settings.SqliteDBPath);
Directory.CreateDirectory(Path.GetDirectoryName(sql)); Directory.CreateDirectory(Path.GetDirectoryName(sql));
DB = new SQLiteConnection(string.Format("Data Source={0},Version=3", sql)); DB = new Microsoft.Data.Sqlite.SqliteConnection(string.Format("Data Source={0}", sql));
} }
else if (Config.Settings.StorageType.ToLower() == "mysql") else if (Config.Settings.StorageType.ToLower() == "mysql")
{ {
@ -441,8 +437,16 @@ namespace TShockAPI
} }
catch (Exception ex) catch (Exception ex)
{ {
Log.ConsoleError("Fatal Startup Exception"); if (Log is not null)
Log.ConsoleError(ex.ToString()); {
Log.ConsoleError("Fatal Startup Exception");
Log.ConsoleError(ex.ToString());
}
else
{
Console.WriteLine("Fatal Startup Exception");
Console.WriteLine(ex.ToString());
}
Environment.Exit(1); Environment.Exit(1);
} }
} }

View file

@ -28,10 +28,9 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="BCrypt.Net-Next" Version="4.0.2" /> <PackageReference Include="BCrypt.Net-Next" Version="4.0.3" />
<PackageReference Include="MySql.Data" Version="8.0.27" /> <PackageReference Include="MySql.Data" Version="8.0.28" />
<PackageReference Include="SQLite" Version="3.13.0" /> <PackageReference Include="Microsoft.Data.Sqlite" Version="6.0.3" />
<PackageReference Include="System.Data.SQLite.Core" Version="1.0.115.5" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

View file

@ -7,10 +7,12 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" /> <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.7" /> <PackageReference Include="MSTest.TestAdapter" Version="2.2.8" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.7" /> <PackageReference Include="MSTest.TestFramework" Version="2.2.8" />
<PackageReference Include="coverlet.collector" Version="3.1.0" /> <PackageReference Include="coverlet.collector" Version="3.1.2"><IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

View file

@ -16,17 +16,16 @@
<ProjectReference Include="..\TerrariaServerAPI\TerrariaServerAPI\TerrariaServerAPI.csproj" ExcludeFromSingleFile="true" /> <ProjectReference Include="..\TerrariaServerAPI\TerrariaServerAPI\TerrariaServerAPI.csproj" ExcludeFromSingleFile="true" />
<ProjectReference Include="..\TShockAPI\TShockAPI.csproj" ExcludeFromSingleFile="true" Condition="'$(PublishSingleFile)' == 'true'" /> <ProjectReference Include="..\TShockAPI\TShockAPI.csproj" ExcludeFromSingleFile="true" Condition="'$(PublishSingleFile)' == 'true'" />
<ProjectReference Include="..\TShockAPI\TShockAPI.csproj" ReferenceOutputAssembly="false" Condition="'$(PublishSingleFile)' != 'true'" /> <ProjectReference Include="..\TShockAPI\TShockAPI.csproj" ReferenceOutputAssembly="false" Condition="'$(PublishSingleFile)' != 'true'" />
<Reference Include="HttpServer" ExcludeFromSingleFile="true" > <Reference Include="HttpServer" ExcludeFromSingleFile="true">
<HintPath>..\prebuilts\HttpServer.dll</HintPath> <HintPath>..\prebuilts\HttpServer.dll</HintPath>
</Reference> </Reference>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<!-- match tshocks dependencies so that publishing outputs all files to ./bin --> <!-- match tshocks dependencies so that publishing outputs all files to ./bin -->
<PackageReference Include="BCrypt.Net-Next" Version="4.0.2" /> <PackageReference Include="BCrypt.Net-Next" Version="4.0.3" />
<PackageReference Include="MySql.Data" Version="8.0.27" /> <PackageReference Include="MySql.Data" Version="8.0.28" />
<PackageReference Include="SQLite" Version="3.13.0" /> <PackageReference Include="Microsoft.Data.Sqlite" Version="6.0.3" />
<PackageReference Include="System.Data.SQLite.Core" Version="1.0.115.5" />
</ItemGroup> </ItemGroup>
<Target Name="MoveTShockDebug" AfterTargets="FinalCleanup;PostBuildEvent"> <Target Name="MoveTShockDebug" AfterTargets="FinalCleanup;PostBuildEvent">

@ -1 +1 @@
Subproject commit f386f7a09b488bb6363cd704ddf9b7359415218f Subproject commit 047baef38969ac1b8bc4b5c23a9f2fc7836f3751