Skip to content

Commit

Permalink
Initial Linux support (#781)
Browse files Browse the repository at this point in the history
Part of #143.
  • Loading branch information
lahm86 authored Oct 27, 2024
1 parent 63b97a6 commit 3b5f218
Show file tree
Hide file tree
Showing 22 changed files with 42 additions and 103 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
## [Unreleased](https://github.com/LostArtefacts/TR-Rando/compare/V1.9.3...master) - xxxx-xx-xx
- added (experimental) support for Linux (#143)
- changed the number of secrets in TR3R Coastal Village to four to match the statistics (#775)
- fixed unreachable item locations in Coastal Village (#774)

Expand Down
Binary file modified Deps/TRGE.Coord.dll
Binary file not shown.
Binary file modified Deps/TRGE.Core.dll
Binary file not shown.
15 changes: 8 additions & 7 deletions TRRandomizerView/Controls/FolderLoadControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
<StackPanel HorizontalAlignment="Center"
VerticalAlignment="Center"
Orientation="Horizontal">
<Image Source="..\Resources\rando_sm.png"/>
<Image Source="../Resources/rando_sm.png"/>
<TextBlock Text="{Binding AppTitle}"
VerticalAlignment="Center"
FontSize="40"
Expand Down Expand Up @@ -88,12 +88,13 @@
Visibility="{Binding RecentFoldersVisibility}">
<GroupBox.Header>
<StackPanel Orientation="Horizontal">
<Image x:Name="_historyIcon"
Width="18"
Height="18"/>

<TextBlock Margin="5,0,0,0"
Text="Recent Folders"/>
<Image
Source="../Resources/folder.png"
Height="18"/>
<TextBlock
Margin="3,0,0,0"
FontWeight="Bold"
Text="Recent Folders"/>
</StackPanel>
</GroupBox.Header>

Expand Down
1 change: 0 additions & 1 deletion TRRandomizerView/Controls/FolderLoadControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ public FolderLoadControl()
AppTitle = app.Title;
}
_content.DataContext = this;
_historyIcon.Source = ControlUtils.DefaultIcons.FolderSmall.ToImageSource();
}

private void HistoryListView_SelectionChanged(object sender, SelectionChangedEventArgs e)
Expand Down
Binary file added TRRandomizerView/Resources/folder.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions TRRandomizerView/TRRandomizerView.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
<None Remove="Resources\Darkness\TR2\8.jpg" />
<None Remove="Resources\Darkness\TR2\9.jpg" />
<None Remove="Resources\down.png" />
<None Remove="Resources\folder.png" />
<None Remove="Resources\loading.png" />
<None Remove="Resources\rando.ico" />
<None Remove="Resources\rando.png" />
Expand Down Expand Up @@ -88,6 +89,7 @@
<Resource Include="Resources\Darkness\TR2\8.jpg" />
<Resource Include="Resources\Darkness\TR2\9.jpg" />
<Resource Include="Resources\down.png" />
<Resource Include="Resources\folder.png" />
<Resource Include="Resources\loading.png" />
<Resource Include="Resources\rando.ico" />
<Resource Include="Resources\rando.png" />
Expand Down
77 changes: 2 additions & 75 deletions TRRandomizerView/Utilities/ControlUtils.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,12 @@
using System;
using System.ComponentModel;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Windows;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Interop;
using System.Windows.Media;
using System.Windows.Media.Imaging;

namespace TRRandomizerView.Utilities;

public static class ControlUtils
{
[DllImport("gdi32.dll", SetLastError = true)]
private static extern bool DeleteObject(IntPtr hObject);

public static ListViewItem GetItemAt(this ListView listView, System.Windows.Point clientRelativePosition)
public static ListViewItem GetItemAt(this ListView listView, Point clientRelativePosition)
{
HitTestResult hitTestResult = VisualTreeHelper.HitTest(listView, clientRelativePosition);
DependencyObject selectedItem = null;
Expand All @@ -33,68 +24,4 @@ public static ListViewItem GetItemAt(this ListView listView, System.Windows.Poin
}
return selectedItem == null ? null : selectedItem as ListViewItem;
}

public static ImageSource ToImageSource(this Icon icon)
{
Bitmap bitmap = icon.ToBitmap();
IntPtr hBitmap = bitmap.GetHbitmap();

ImageSource wpfBitmap = Imaging.CreateBitmapSourceFromHBitmap
(
hBitmap,
IntPtr.Zero,
Int32Rect.Empty,
BitmapSizeOptions.FromEmptyOptions()
);

if (!DeleteObject(hBitmap))
{
throw new Win32Exception();
}

return wpfBitmap;
}

public static class DefaultIcons
{
private static Icon _largeFolderIcon, _smallFolderIcon;

public static Icon FolderLarge => _largeFolderIcon ??= GetStockIcon(SHSIID_FOLDER, SHGSI_LARGEICON);
public static Icon FolderSmall => _smallFolderIcon ??= GetStockIcon(SHSIID_FOLDER, SHGSI_SMALLICON);

[DllImport("shell32.dll")]
private static extern int SHGetStockIconInfo(uint siid, uint uFlags, ref SHSTOCKICONINFO psii);

[DllImport("user32.dll")]
private static extern bool DestroyIcon(IntPtr handle);

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
private struct SHSTOCKICONINFO
{
public uint cbSize;
public IntPtr hIcon;
public int iSysIconIndex;
public int iIcon;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)]
public string szPath;
}

private const uint SHSIID_FOLDER = 0x3;
private const uint SHGSI_ICON = 0x100;
private const uint SHGSI_LARGEICON = 0x0;
private const uint SHGSI_SMALLICON = 0x1;

private static Icon GetStockIcon(uint type, uint size)
{
SHSTOCKICONINFO info = new();
info.cbSize = (uint)Marshal.SizeOf(info);

_ = SHGetStockIconInfo(type, SHGSI_ICON | size, ref info);

Icon icon = (Icon)Icon.FromHandle(info.hIcon).Clone();
DestroyIcon(info.hIcon);

return icon;
}
}
}
11 changes: 8 additions & 3 deletions TRRandomizerView/Utilities/ProcessUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,16 @@ public static void OpenFile(string fileName, string arguments = null)

public static void OpenFolder(string folder)
{
folder = Path.GetFullPath(folder);
if (!Path.EndsInDirectorySeparator(folder))
{
folder += Path.DirectorySeparatorChar;
}
Process.Start(new ProcessStartInfo
{
FileName = "explorer.exe",
Arguments = Path.GetFullPath(folder),
UseShellExecute = true
FileName = folder,
UseShellExecute = true,
Verb = "open",
});
}

Expand Down
4 changes: 2 additions & 2 deletions TRRandomizerView/Windows/AboutWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
ResizeMode="NoResize"
Icon="..\Resources\rando.ico"
Icon="../Resources/rando.ico"
FontFamily="Segoe UI"
FontSize="13"
WindowStartupLocation="CenterOwner"
Expand All @@ -29,7 +29,7 @@
Width="120"
Margin="0,5,10,0"
HorizontalAlignment="Center"
Source="..\Resources\rando.png"/>
Source="../Resources/rando.png"/>

<StackPanel Grid.Column="1">
<TextBlock FontSize="16"
Expand Down
4 changes: 2 additions & 2 deletions TRRandomizerView/Windows/AdvancedWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
xmlns:ctrl="clr-namespace:TRRandomizerView.Controls"
xmlns:cvt="clr-namespace:TRRandomizerView.Converters"
mc:Ignorable="d"
Icon="..\Resources\rando.ico"
Icon="../Resources/rando.ico"
ResizeMode="NoResize"
WindowStartupLocation="CenterOwner"
ShowInTaskbar="False"
Expand Down Expand Up @@ -999,7 +999,7 @@
<Image Width="186"
x:Name="_darknessPreview"
HorizontalAlignment="Left"
Source="..\Resources\Darkness\0.jpg"/>
Source="../Resources/Darkness/0.jpg"/>
</Border>
</Grid>
</StackPanel>
Expand Down
2 changes: 1 addition & 1 deletion TRRandomizerView/Windows/EnemyWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Icon="..\Resources\rando.ico"
Icon="../Resources/rando.ico"
ResizeMode="CanResizeWithGrip"
WindowStartupLocation="CenterOwner"
ShowInTaskbar="False"
Expand Down
2 changes: 1 addition & 1 deletion TRRandomizerView/Windows/GlobalSeedWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:ctrl="clr-namespace:TRRandomizerView.Controls"
mc:Ignorable="d"
Icon="..\Resources\rando.ico"
Icon="../Resources/rando.ico"
ResizeMode="NoResize"
WindowStartupLocation="CenterOwner"
ShowInTaskbar="False"
Expand Down
2 changes: 1 addition & 1 deletion TRRandomizerView/Windows/GlobalSettingsWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:cvt="clr-namespace:TRRandomizerView.Converters"
mc:Ignorable="d"
Icon="..\Resources\rando.ico"
Icon="../Resources/rando.ico"
ResizeMode="NoResize"
WindowStartupLocation="CenterOwner"
ShowInTaskbar="False"
Expand Down
2 changes: 1 addition & 1 deletion TRRandomizerView/Windows/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
xmlns:ctrl="clr-namespace:TRRandomizerView.Controls"
xmlns:vm="clr-namespace:TRRandomizerView.Model"
mc:Ignorable="d"
Icon="..\Resources\rando.ico"
Icon="../Resources/rando.ico"
ResizeMode="CanResizeWithGrip"
WindowStartupLocation="CenterScreen"
Closing="Window_Closing"
Expand Down
2 changes: 1 addition & 1 deletion TRRandomizerView/Windows/MessageWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
ResizeMode="NoResize"
Icon="..\Resources\rando.ico"
Icon="../Resources/rando.ico"
WindowStartupLocation="CenterOwner"
ShowInTaskbar="False"
Loaded="Window_Loaded"
Expand Down
4 changes: 2 additions & 2 deletions TRRandomizerView/Windows/OpenProgressWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
ResizeMode="NoResize"
Loaded="Window_Loaded"
Closing="Window_Closing"
Icon="..\Resources\rando.ico"
Icon="../Resources/rando.ico"
Title="Opening Data Folder" Height="100" Width="400">

<Grid Margin="10,10,10,15">
Expand All @@ -29,7 +29,7 @@

<Image
Grid.Column="1"
Source="..\Resources\loading.png"
Source="../Resources/loading.png"
Width="16"
Height="16"
VerticalAlignment="Bottom"
Expand Down
4 changes: 2 additions & 2 deletions TRRandomizerView/Windows/RandomizeProgressWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
ResizeMode="NoResize"
Loaded="Window_Loaded"
Closing="Window_Closing"
Icon="..\Resources\rando.ico"
Icon="../Resources/rando.ico"
SizeToContent="Height"
Title="Randomization In Progress" Width="440">
<Grid>
Expand All @@ -36,7 +36,7 @@
<!-- https://stackoverflow.com/a/56477427 -->
<Image
Grid.Column="1"
Source="..\Resources\loading.png"
Source="../Resources/loading.png"
Width="16"
Height="16"
VerticalAlignment="Bottom"
Expand Down
4 changes: 2 additions & 2 deletions TRRandomizerView/Windows/RestoreProgressWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
ResizeMode="NoResize"
Loaded="Window_Loaded"
Closing="Window_Closing"
Icon="..\Resources\rando.ico"
Icon="../Resources/rando.ico"
Title="Restoring Data Folder" Height="100" Width="400">

<Grid Margin="10,10,10,15">
Expand All @@ -29,7 +29,7 @@

<Image
Grid.Column="1"
Source="..\Resources\loading.png"
Source="../Resources/loading.png"
Width="16"
Height="16"
VerticalAlignment="Bottom"
Expand Down
2 changes: 1 addition & 1 deletion TRRandomizerView/Windows/TR1XWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:ctrl="clr-namespace:TRRandomizerView.Controls"
mc:Ignorable="d"
Icon="..\Resources\rando.ico"
Icon="../Resources/rando.ico"
ResizeMode="NoResize"
WindowStartupLocation="CenterOwner"
ShowInTaskbar="False"
Expand Down
2 changes: 1 addition & 1 deletion TRRandomizerView/Windows/UpdateAvailableWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
ShowInTaskbar="False"
Icon="..\Resources\rando.ico"
Icon="../Resources/rando.ico"
ResizeMode="CanResizeWithGrip"
WindowStartupLocation="CenterOwner"
Loaded="Window_Loaded"
Expand Down
4 changes: 4 additions & 0 deletions USING.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,10 @@ If you continue to experience issues, we have a friendly community [Discord serv
- For Steam, you can right-click on the game in your library and select `Manage` | `Browse Local Files`. This will open the folder where the game files are located in Explorer and you can then copy the address as necessary.
- For GoG, you can find the general installation folder under `Settings` | `Installing, updating` | `Game installation folder`. Browse to this folder in Explorer and then locate your game folder there.

- _Can I run TR-Rando on Linux?_

The core libraries used in the randomizer work fully in Linux; the sticking point is the user interface itself, which is Windows-only. However, there is at least one method available to make this work - refer to the steps [here](https://github.com/LostArtefacts/TR-Rando/issues/143#issuecomment-2439741066) for details.

- _I have installed TR1X but when I open the folder in the randomizer, it can't find the data files. What should I do?_

When you install TR1X using its installer and, for example, target your Steam copy of the game, TR1X will be installed by default into your Documents folder as opposed to the original Steam folder. You can change this folder when running the installer. So all you need to do is point the randomizer to this folder instead of your Steam/GOG/original folder.
Expand Down

0 comments on commit 3b5f218

Please sign in to comment.