Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/IntelOrca.OpenLauncher.Core/Shell.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,26 @@ public void StartProcess(string name, params string[] args)
Process.Start(psi);
}

public void OpenDirectory(string path)
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
Process.Start(new ProcessStartInfo(path) { UseShellExecute = true });
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
StartProcess("open", path);
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
StartProcess("xdg-open", path);
}
else
{
throw new PlatformNotSupportedException();
}
}

public int RunProcess(string name, params string[] args)
{
var psi = new ProcessStartInfo(name);
Expand Down
26 changes: 21 additions & 5 deletions src/openlauncher/MainWindow.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,26 @@
Padding="4">
<TextBlock x:Name="installedVersionTextBlock" HorizontalAlignment="Stretch" />
</Border>
<Button Grid.Column="2"
x:Name="playButton"
IsEnabled="False"
Content="{x:Static p:Resources.Play}"
Click="playButton_Click" />
<StackPanel Grid.Column="2" x:Name="playSplitButton" Orientation="Horizontal">
<StackPanel.ContextMenu>
<ContextMenu x:Name="playMenu">
<MenuItem x:Name="openInstallFolderMenuItem"
Click="openInstallFolderMenuItem_Click" />
</ContextMenu>
</StackPanel.ContextMenu>
<Button x:Name="playButton"
CornerRadius="4,0,0,4"
IsEnabled="False"
Content="{x:Static p:Resources.Play}"
Click="playButton_Click" />
<Button x:Name="playMenuButton"
Width="32"
Margin="-1,0,0,0"
CornerRadius="0,4,4,0"
IsEnabled="False"
Content="▼"
Click="playMenuButton_Click" />
</StackPanel>
</Grid>
<TextBlock Text="{x:Static p:Resources.AvailableLabel}" />
<StackPanel Margin="4">
Expand All @@ -101,6 +116,7 @@
Value="0.5" />
<Button x:Name="downloadButton"
Grid.Column="2"
Width="141"
IsEnabled="False"
Content="{x:Static p:Resources.Download}"
Click="downloadButton_Click" />
Expand Down
51 changes: 50 additions & 1 deletion src/openlauncher/MainWindow.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ public MainWindow()
{
InitializeComponent();

openInstallFolderMenuItem.Header = GetOpenInstallFolderText();
ToolTip.SetPlacement(playButton, PlacementMode.Bottom);

if (!Design.IsDesignMode)
{
downloadProgress.IsVisible = false;
Expand Down Expand Up @@ -229,6 +232,26 @@ private async void playButton_Click(object sender, RoutedEventArgs e)
}
}

private void playMenuButton_Click(object sender, RoutedEventArgs e)
{
playMenu.Open(playSplitButton);
}

private void openInstallFolderMenuItem_Click(object sender, RoutedEventArgs e)
{
if (_selectedMenuItem == null)
return;

try
{
new Shell().OpenDirectory(_selectedMenuItem.Game!.BinPath);
}
catch (Exception ex)
{
ShowError(string.Format(StringResources.FailedToOpenInstallFolder, _selectedMenuItem.Game!.Name), ex);
}
}

private async Task RefreshInstalledVersionAsync()
{
if (_selectedMenuItem == null)
Expand All @@ -253,8 +276,18 @@ private async Task RefreshInstalledVersionAsync()
if (!_isBusy)
{
playButton.IsEnabled = installService.CanLaunch();
playMenuButton.IsEnabled = CanOpenInstallFolder();
}
ToolTip.SetTip(playButton, installService.ExecutablePath);
ToolTip.SetTip(playButton, new ToolTip
{
MaxWidth = double.PositiveInfinity,
Content = new TextBlock
{
Text = installService.ExecutablePath,
TextWrapping = Avalonia.Media.TextWrapping.NoWrap
}
});
ToolTip.SetHorizontalOffset(playButton, -playSplitButton.Bounds.Width);
}
}

Expand Down Expand Up @@ -403,15 +436,31 @@ private void SetAllInteractionEnabled(bool value)
if (value)
{
playButton.IsEnabled = _selectedMenuItem?.InstallService.CanLaunch() ?? false;
playMenuButton.IsEnabled = CanOpenInstallFolder();
downloadButton.IsEnabled = buildsAvailable && !AutoUpdateEnabled();
versionDropdown.IsEnabled = !AutoUpdateEnabled();
}
else
{
playButton.IsEnabled = value;
playMenuButton.IsEnabled = value;
downloadButton.IsEnabled = value;
}
}

private bool CanOpenInstallFolder()
{
return _selectedMenuItem != null && Directory.Exists(_selectedMenuItem.Game!.BinPath);
}

private static string GetOpenInstallFolderText()
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
return StringResources.OpenInFileExplorer;
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
return StringResources.OpenInFinder;
return StringResources.OpenInFileManager;
}

private bool AutoUpdateEnabled()
{
Expand Down
20 changes: 20 additions & 0 deletions src/openlauncher/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions src/openlauncher/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,18 @@
<data name="FailedToLaunchGame" xml:space="preserve">
<value>Failed to launch {0}</value>
</data>
<data name="OpenInFileExplorer" xml:space="preserve">
<value>Open in File Explorer</value>
</data>
<data name="OpenInFileManager" xml:space="preserve">
<value>Open in File Manager</value>
</data>
<data name="OpenInFinder" xml:space="preserve">
<value>Open in Finder</value>
</data>
<data name="FailedToOpenInstallFolder" xml:space="preserve">
<value>Failed to open the installation folder for {0}</value>
</data>
<data name="DownloadBuildFailedTitle" xml:space="preserve">
<value>Failed to download build</value>
</data>
Expand Down