Skip to content

Commit

Permalink
181 paratext data linux support (#216)
Browse files Browse the repository at this point in the history
Co-Authored-By: Matt Lyons <[email protected]>
  • Loading branch information
lyonsil authored Jun 21, 2023
2 parents 6b5a007 + 675ed46 commit f1bd945
Show file tree
Hide file tree
Showing 94 changed files with 77,570 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@
*.ttf binary
*.woff binary
*.woff2 binary
*.ldml binary
1 change: 1 addition & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"args": [],
"cwd": "${workspaceFolder}",
"stopAtEntry": false,
"justMyCode": false,
"windows": {
"program": "${workspaceFolder}/c-sharp/bin/Debug/net7.0/win-x64/ParanextDataProvider.exe"
},
Expand Down
99 changes: 99 additions & 0 deletions c-sharp-tests/ParatextDataConnectionTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
using System.ComponentModel;
using System.Configuration;
using System.IO;
using System.Reflection;
using Paranext.DataProvider;
using Paratext.Data;
using PtxUtils;

namespace TestParanextDataProvider
{
internal class ParatextDataConnectionTests
{
// Work around a known issue where NUnit doesn't pick up config files
// https://github.com/nunit/nunit3-vs-adapter/issues/356
private void EnsureIcuConfigFileIsInPlace()
{
string appConfigFile = ConfigurationManager
.OpenExeConfiguration(ConfigurationUserLevel.None)
.FilePath;
string? appConfigDirectory = Path.GetDirectoryName(appConfigFile);
string icuConfigFile = Path.Join(appConfigDirectory, "icu.net.dll.config");
if (!File.Exists(icuConfigFile))
{
// It's a bit hacky to hard code the config file here, but there isn't a great
// source that we can reliably get to from within a test.
File.WriteAllText(
icuConfigFile,
@"<?xml version=""1.0"" encoding=""utf-8"" ?>
<configuration>
<dllmap os=""!windows,osx"" dll=""libdl.so"" target=""libdl.so.2"" />
<dllmap os=""osx"" dll=""libdl.so"" target=""libdl.dylib""/>
</configuration>"
);
}
}

/// <summary>
/// This test is to try figure out if ParatextData will work on Linux and Mac.
/// It may be removed in the future for a more useful test.
/// </summary>
[Test]
public void LoadPackagedWEB_LoadsProject()
{
// This functionality doesn't work on macOS for now
if (OperatingSystem.IsMacOS())
return;

Alert.Implementation = new DummyAlert();
EnsureIcuConfigFileIsInPlace();

Console.WriteLine(Assembly.GetExecutingAssembly().Location);
Program.InitializeParatextData("assets");

ScrText scrText = ScrTextCollection.Find("WEB");
Assert.That(scrText, Is.Not.Null);
Assert.That(scrText.Name, Is.EqualTo("WEB"));
Assert.That(scrText.Settings.BooksPresentSet.Count, Is.EqualTo(83));
}

#region DummyAlert class
private sealed class DummyAlert : Alert
{
protected override AlertResult ShowInternal(
IComponent? owner,
string text,
string caption,
AlertButtons alertButtons,
AlertLevel alertLevel,
AlertDefaultButton defaultButton,
bool showInTaskbar
)
{
if (text.Contains("unable to find a language definition file for English"))
return AlertResult.Positive;

Assert.Fail("Unexpected dialog box:\n" + text);
return AlertResult.Negative;
}

protected override void ShowLaterInternal(
string text,
string caption,
AlertLevel alertLevel
)
{
ShowInternal(
null,
text,
caption,
AlertButtons.Ok,
alertLevel,
AlertDefaultButton.Button1,
false
);
}
}
#endregion
}
}
2 changes: 2 additions & 0 deletions c-sharp-tests/c-sharp-tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
<PlatformTarget>x64</PlatformTarget>
<RootNamespace>TestParanextDataProvider</RootNamespace>
</PropertyGroup>

<ItemGroup>
Expand All @@ -16,6 +17,7 @@
<PackageReference Include="NUnit3TestAdapter" Version="4.3.0" />
<PackageReference Include="NUnit.Analyzers" Version="3.5.0" />
<PackageReference Include="coverlet.collector" Version="3.1.2" />
<PackageReference Include="ParatextData" Version="9.4.0-beta" />
</ItemGroup>

<ItemGroup>
Expand Down
13 changes: 12 additions & 1 deletion c-sharp/ParanextDataProvider.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,19 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="ParatextData" Version="9.3.0.9" />
<PackageReference Include="ParatextData" Version="9.4.0-beta" />
<PackageReference Include="SIL.Core" Version="12.0.0.0" />
<PackageReference Include="SIL.Scripture" Version="12.0.0.0" />
<PackageReference Include="SIL.WritingSystems" Version="12.0.0.0" />
<PackageReference Include="System.Net.WebSockets" Version="4.3.0" />
<PackageReference Include="icu.net" Version="2.9.0" />
<PackageReference Include="Microsoft.ICU.ICU4C.Runtime" Version="68.2.0.9" Condition="$([MSBuild]::IsOsPlatform('Windows'))" />
</ItemGroup>

<ItemGroup>
<Content Include="assets\**\*.*">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>

</Project>
79 changes: 79 additions & 0 deletions c-sharp/Program.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using System.Text.Json;
using NetLoc;
using Paranext.DataProvider.MessageHandlers;
using Paranext.DataProvider.Messages;
using Paranext.DataProvider.MessageTransports;
using Paranext.DataProvider.NetworkObjects;
using Paratext.Data;
using PtxUtils;

namespace Paranext.DataProvider;
Expand All @@ -13,6 +15,8 @@ public static async Task Main()
{
Console.WriteLine("Paranext data provider starting up");

InitializeParatextData("assets");

using PapiClient papi = new();
try
{
Expand Down Expand Up @@ -42,6 +46,17 @@ public static async Task Main()
Console.WriteLine("Paranext data provider shutting down");
}

internal static void InitializeParatextData(string paratextDataFolder)
{
// ParatextData doesn't support macOS at the moment
if (OperatingSystem.IsMacOS())
return;

RegistryU.Implementation = new DummyRegistry();
ICUDllLocator.Initialize(false, false);
ParatextData.Initialize(paratextDataFolder, false);
}

#region Request handlers

private static ResponseToRequest RequestAddOne(dynamic val)
Expand All @@ -58,4 +73,68 @@ private static ResponseToRequest RequestAddOne(dynamic val)
}

#endregion

#region DummyRegistry class
private sealed class DummyRegistry : RegistryU
{
protected override string? GetStringInternal(string registryPath)
{
return null;
}

protected override string? GetStringInternal(string basekey, string path, string key)
{
return null;
}

protected override object? GetValInternal(string registryPath)
{
return null;
}

protected override object? GetValInternal(string baseKey, string subKey, string key)
{
return null;
}

protected override object? GetValIfExistsInternal(string registryPath)
{
return null;
}

protected override bool HasWritePermissionInternal(string registryPath)
{
return false;
}

protected override bool KeyExistsInternal(string registryPath)
{
return false;
}

// TODO: If this is needed, it might cause problems since it references RegistryKey. >.<
//protected override bool KeyExistsInternal(RegistryKey key, string subKey)
//{
// return false;
//}

protected override bool ValueExistsInternal(string registryPath)
{
return false;
}

protected override void SetValInternal(string registryPath, object theValue) { }

protected override void SetValInternal(
string baseKey,
string subKey,
string key,
object theValue
) { }

protected override void DelKeyInternal(string registryPath) { }

protected override void DelKeyInternal(string baseKey, string subKey) { }
}
#endregion
}
4 changes: 4 additions & 0 deletions c-sharp/assets/Attribution.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Attribution

`usfm.sty` comes from https://github.com/ubsicap/usfm/tree/master/sty
All other files in `/WEB` come from https://ebible.org/
Loading

0 comments on commit f1bd945

Please sign in to comment.