Skip to content

Commit

Permalink
Test Mac build
Browse files Browse the repository at this point in the history
  • Loading branch information
NoahStolk committed Apr 14, 2023
1 parent 100830d commit 708b1f5
Show file tree
Hide file tree
Showing 13 changed files with 143 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ public enum SupportedOperatingSystem
{
Windows = 1,
Linux = 2,
Osx = 3,
}
3 changes: 3 additions & 0 deletions src/app-launcher/DevilDaggersInfo.App.Launcher/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ public static class Constants
#if WINDOWS
public const ToolBuildType AppBuildType = ToolBuildType.WindowsWarp;
public const ToolBuildType AppLauncherBuildType = ToolBuildType.WindowsConsole;
#elif OSX
public const ToolBuildType AppBuildType = ToolBuildType.MacWarp;
public const ToolBuildType AppLauncherBuildType = ToolBuildType.MacConsole;
#elif LINUX
public const ToolBuildType AppBuildType = ToolBuildType.LinuxWarp;
public const ToolBuildType AppLauncherBuildType = ToolBuildType.LinuxConsole;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
<DefineConstants>$(DefineConstants);WINDOWS</DefineConstants>
</PropertyGroup>
</When>
<When Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::OSX)))' == 'true'">
<PropertyGroup>
<DefineConstants>$(DefineConstants);OSX</DefineConstants>
</PropertyGroup>
</When>
<Otherwise>
<PropertyGroup>
<DefineConstants>$(DefineConstants);LINUX</DefineConstants>
Expand All @@ -30,6 +35,11 @@
<DefineConstants>$(DefineConstants);WINDOWS</DefineConstants>
</PropertyGroup>
</When>
<When Condition="'$(RuntimeIdentifier)' == 'osx-x64'">
<PropertyGroup>
<DefineConstants>$(DefineConstants);OSX</DefineConstants>
</PropertyGroup>
</When>
<Otherwise>
<PropertyGroup>
<DefineConstants>$(DefineConstants);LINUX</DefineConstants>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
namespace DevilDaggersInfo.App.Core.NativeInterface.Services.Osx;

public class OsxDialogService : INativeDialogService
{
public void ReportError(string message, Exception? exception = null)
{
ReportError("Error", message, exception);
}

public void ReportError(string title, string message, Exception? exception = null)
{
if (exception != null)
message += Environment.NewLine + exception.Message;

Console.WriteLine($"{title}: {message}");
}

public void ReportMessage(string title, string message)
{
Console.WriteLine($"{title}{Environment.NewLine}{message}");
}

public bool? PromptYesNo(string title, string message)
{
Console.WriteLine($"{title}{Environment.NewLine}{message}");
Console.WriteLine("Y/N");
ConsoleKeyInfo key = Console.ReadKey();
return key.Key switch
{
ConsoleKey.Y => true,
ConsoleKey.N => false,
_ => null,
};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using NativeFileDialogSharp;

namespace DevilDaggersInfo.App.Core.NativeInterface.Services.Osx;

/// <summary>
/// Platform-specific code for interacting with the Linux file system.
/// </summary>
public class OsxFileSystemService : INativeFileSystemService
{
public string? CreateOpenFileDialog(string dialogTitle, string? extensionFilter)
{
return Dialog.FileOpen().Path;
}

public string? CreateSaveFileDialog(string dialogTitle, string? extensionFilter)
{
return Dialog.FileSave().Path;
}

public string? SelectDirectory()
{
return Dialog.FolderPicker().Path;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System.Diagnostics;

namespace DevilDaggersInfo.App.Core.NativeInterface.Services.Osx;

public class OsxMemoryService : INativeMemoryService
{
public void WriteMemory(Process process, long address, byte[] bytes, int offset, int size)
{
// TODO: Implement.
}

public void ReadMemory(Process process, long address, byte[] bytes, int offset, int size)
{
// TODO: Implement.
}

public Process? GetDevilDaggersProcess()
{
return Array.Find(Process.GetProcesses(), p => p.ProcessName.StartsWith("devildaggers"));
}
}
13 changes: 13 additions & 0 deletions src/app/DevilDaggersInfo.App.Ui.Base/Platforms/OsxValues.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using DevilDaggersInfo.Api.App.ProcessMemory;
using DevilDaggersInfo.Types.Web;

namespace DevilDaggersInfo.App.Ui.Base.Platforms;

public class OsxValues : IPlatformSpecificValues
{
public ToolBuildType BuildType => ToolBuildType.OsxWarp;

public SupportedOperatingSystem OperatingSystem => SupportedOperatingSystem.Osx;

public string DefaultInstallationPath => string.Empty;
}
13 changes: 10 additions & 3 deletions src/app/DevilDaggersInfo.App/DependencyContainer.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#if LINUX
using DevilDaggersInfo.App.Core.NativeInterface.Services.Linux;
#elif WINDOWS
#if WINDOWS
using DevilDaggersInfo.App.Core.NativeInterface.Services.Windows;
#elif OSX
using DevilDaggersInfo.App.Core.NativeInterface.Services.Osx;
#elif LINUX
using DevilDaggersInfo.App.Core.NativeInterface.Services.Linux;
#endif

using DevilDaggersInfo.App.Core.GameMemory;
Expand All @@ -25,6 +27,11 @@ public DependencyContainer()
PlatformSpecificValues = new WindowsValues();
NativeFileSystemService = new WindowsFileSystemService();
NativeDialogService = new WindowsDialogService();
#elif OSX
GameMemoryService = new(new OsxMemoryService());
PlatformSpecificValues = new OsxValues();
NativeFileSystemService = new OsxFileSystemService();
NativeDialogService = new OsxDialogService();
#elif LINUX
GameMemoryService = new(new LinuxMemoryService());
PlatformSpecificValues = new LinuxValues();
Expand Down
12 changes: 12 additions & 0 deletions src/app/DevilDaggersInfo.App/DevilDaggersInfo.App.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@
<OutputType>WinExe</OutputType>
</PropertyGroup>
</When>
<When Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::OSX)))' == 'true'">
<PropertyGroup>
<DefineConstants>$(DefineConstants);OSX</DefineConstants>
<OutputType>Exe</OutputType>
</PropertyGroup>
</When>
<Otherwise>
<PropertyGroup>
<DefineConstants>$(DefineConstants);LINUX</DefineConstants>
Expand All @@ -33,6 +39,12 @@
<OutputType>WinExe</OutputType>
</PropertyGroup>
</When>
<When Condition="'$(RuntimeIdentifier)' == 'osx-x64'">
<PropertyGroup>
<DefineConstants>$(DefineConstants);OSX</DefineConstants>
<OutputType>Exe</OutputType>
</PropertyGroup>
</When>
<Otherwise>
<PropertyGroup>
<DefineConstants>$(DefineConstants);LINUX</DefineConstants>
Expand Down
8 changes: 5 additions & 3 deletions src/app/DevilDaggersInfo.App/Layouts/ConfigLayout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,12 @@ public void Render()
Game.Self.MonoSpaceFontRenderer32.Schedule(Vector2i<int>.One, new(512, 64), 0, Color.White, "Configuration", TextAlign.Middle);

#pragma warning disable S1075
#if LINUX
const string examplePath = "/home/{USERNAME}/.local/share/Steam/steamapps/common/devildaggers/";
#elif WINDOWS
#if WINDOWS
const string examplePath = """C:\Program Files (x86)\Steam\steamapps\common\devildaggers""";
#elif OSX
const string examplePath = "TODO: default path to Devil Daggers on OSX";
#elif LINUX
const string examplePath = "/home/{USERNAME}/.local/share/Steam/steamapps/common/devildaggers/";
#endif
#pragma warning restore S1075

Expand Down
1 change: 1 addition & 0 deletions src/tool/DevilDaggersInfo.Tool.DistributeApp/AppBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ private static string GetArguments(string projectFilePath, string publishDirecto
{
ToolBuildType.LinuxWarp or ToolBuildType.LinuxConsole => "linux-x64",
ToolBuildType.WindowsWarp or ToolBuildType.WindowsConsole => "win-x64",
ToolBuildType.OsxWarp or ToolBuildType.OsxConsole => "osx-x64",
_ => throw new NotImplementedException(),
};

Expand Down
6 changes: 6 additions & 0 deletions src/tool/DevilDaggersInfo.Tool.DistributeApp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,18 @@
if (Question("Build app for Windows?"))
await DistributeAsync("ddinfo-tools", "app", "DevilDaggersInfo.App", ToolBuildType.WindowsWarp, ToolPublishMethod.SelfContained);

if (Question("Build app for OSX?"))
await DistributeAsync("ddinfo-tools", "app", "DevilDaggersInfo.App", ToolBuildType.OsxWarp, ToolPublishMethod.SelfContained);

if (Question("Build app for Linux?"))
await DistributeAsync("ddinfo-tools", "app", "DevilDaggersInfo.App", ToolBuildType.LinuxWarp, ToolPublishMethod.SelfContained);

if (Question("Build app launcher for Windows?"))
await DistributeAsync("ddinfo-tools-launcher", "app-launcher", "DevilDaggersInfo.App.Launcher", ToolBuildType.WindowsConsole, ToolPublishMethod.Aot);

if (Question("Build app launcher for OSX?"))
await DistributeAsync("ddinfo-tools-launcher", "app-launcher", "DevilDaggersInfo.App.Launcher", ToolBuildType.OsxConsole, ToolPublishMethod.Aot);

if (Question("Build app launcher for Linux?"))
await DistributeAsync("ddinfo-tools-launcher", "app-launcher", "DevilDaggersInfo.App.Launcher", ToolBuildType.LinuxConsole, ToolPublishMethod.Aot);

Expand Down
2 changes: 2 additions & 0 deletions src/types/DevilDaggersInfo.Types.Web/ToolBuildType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ public enum ToolBuildType : byte
WindowsWarp = 4,
LinuxWarp = 5,
LinuxConsole = 6,
OsxWarp = 7,
OsxConsole = 8,
}

0 comments on commit 708b1f5

Please sign in to comment.