Skip to content

Commit

Permalink
Configs: Add warning prompt when DLL is detected in the ZIP file
Browse files Browse the repository at this point in the history
  • Loading branch information
praydog committed Feb 25, 2024
1 parent edc4a62 commit cdbf10b
Show file tree
Hide file tree
Showing 6 changed files with 156 additions and 15 deletions.
17 changes: 17 additions & 0 deletions UEVR/GameConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,23 @@ private static string GetRelativePath(string fullPath, string basePath) {
return fullPath.Substring(basePath.Length);
}

public static bool ZipContainsDLL(string sourceArchiveFileName) {
try {
using (ZipArchive archive = ZipFile.OpenRead(sourceArchiveFileName)) {
foreach (ZipArchiveEntry entry in archive.Entries) {
if (entry.FullName.ToLower().EndsWith(".dll", StringComparison.OrdinalIgnoreCase)) {
return true;
}
}
}
} catch (Exception ex) {
Console.WriteLine($"An error occurred: {ex.Message}");
}

// No .DLL files found
return false;
}

public static string? ExtractZipToDirectory(string sourceArchiveFileName, string destinationDirectoryName, string gameName) {
try {
string tempExtractionPath = Path.Combine(destinationDirectoryName, "temp_extraction");
Expand Down
32 changes: 23 additions & 9 deletions UEVR/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -531,21 +531,35 @@ private void ImportConfig_Clicked(object sender, RoutedEventArgs e) {
Directory.CreateDirectory(gameGlobalDir);
}

var finalGameName = GameConfig.ExtractZipToDirectory(importPath, gameGlobalDir, gameName);
bool wantsExtract = true;

if (finalGameName == null) {
MessageBox.Show("Failed to extract the ZIP file.");
return;
if (GameConfig.ZipContainsDLL(importPath)) {
string message = "The selected config file includes a DLL (plugin), which may execute actions on your system.\n" +
"Only import configs with DLLs from trusted sources to avoid potential risks.\n" +
"Do you still want to proceed with the import?";
var dialog = new YesNoDialog("DLL Warning", message);
dialog.ShowDialog();

wantsExtract = dialog.DialogResultYes;
}

var finalDirectory = System.IO.Path.Combine(globalDir, finalGameName);
NavigateToDirectory(finalDirectory);
if (wantsExtract) {
var finalGameName = GameConfig.ExtractZipToDirectory(importPath, gameGlobalDir, gameName);

RefreshCurrentConfig();
if (finalGameName == null) {
MessageBox.Show("Failed to extract the ZIP file.");
return;
}

var finalDirectory = System.IO.Path.Combine(globalDir, finalGameName);
NavigateToDirectory(finalDirectory);

if (m_connected) {
SharedMemory.SendCommand(SharedMemory.Command.ReloadConfig);
RefreshCurrentConfig();


if (m_connected) {
SharedMemory.SendCommand(SharedMemory.Command.ReloadConfig);
}
}
} catch (Exception ex) {
MessageBox.Show("An error occurred: " + ex.Message);
Expand Down
33 changes: 27 additions & 6 deletions UEVR/VDWarnDialog.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,32 @@
WindowStartupLocation="CenterScreen"
WindowStyle="None"
Title="VD Warning" Height="200" Width="400">
<StackPanel>
<TextBlock Text="Virtual Desktop has been detected running.&#x0a;Make sure you use OpenXR for the least issues." Margin="10" />
<CheckBox x:Name="chkHideWarning" Content="Hide future warnings" Margin="10" />
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Margin="10">
<Button x:Name="btnOK" Content="OK" Width="75" Margin="5" Click="btnOK_Click" />
<Border BorderBrush="#FF3D3D40" BorderThickness="2">
<StackPanel>
<Border MouseLeftButtonDown="TitleBar_MouseLeftButtonDown" Background="#FF1A1B1C">
<Border.Style>
<Style TargetType="{x:Type Border}">
<Setter Property="Cursor" Value="Hand"/>
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Cursor" Value="SizeAll"/>
</Trigger>
</Style.Triggers>
</Style>
</Border.Style>
<DockPanel Height="30">
<TextBlock Text="{Binding Title, RelativeSource={RelativeSource FindAncestor, AncestorType=Window}}"
VerticalAlignment="Center"
Margin="25,0,0,0"
FontWeight="Bold"
Foreground="White" />
</DockPanel>
</Border>
<TextBlock Text="Virtual Desktop has been detected running.&#x0a;Make sure you use OpenXR for the least issues." Margin="10" />
<CheckBox x:Name="chkHideWarning" Content="Hide future warnings" Margin="10" />
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Margin="10">
<Button x:Name="btnOK" Content="OK" Width="75" Margin="5" Click="btnOK_Click" />
</StackPanel>
</StackPanel>
</StackPanel>
</Border>
</Window>
7 changes: 7 additions & 0 deletions UEVR/VDWarnDialog.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;

namespace UEVR {
public partial class VDWarnDialog : Window {
Expand All @@ -24,5 +25,11 @@ private void btnCancel_Click(object sender, RoutedEventArgs e) {
DialogResultOK = false;
this.Close();
}

private void TitleBar_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) {
if (e.ChangedButton == MouseButton.Left) {
this.DragMove();
}
}
}
}
47 changes: 47 additions & 0 deletions UEVR/YesNoDialog.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<Window x:Class="UEVR.YesNoDialog"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:UEVR"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
TextElement.Foreground="{DynamicResource MaterialDesignBody}"
TextElement.FontWeight="Regular"
TextElement.FontSize="13"
TextOptions.TextFormattingMode="Ideal"
TextOptions.TextRenderingMode="Auto"
FontFamily="{DynamicResource MaterialDesignFont}"
Background="#FF1A1B1C"
SizeToContent="WidthAndHeight" ResizeMode="NoResize" Icon="/UEVR2.png"
WindowStartupLocation="CenterScreen"
WindowStyle="None"
Title="Prompt" Height="200" Width="400">
<Border BorderBrush="#FF3D3D40" BorderThickness="2">
<StackPanel>
<Border MouseLeftButtonDown="TitleBar_MouseLeftButtonDown" Background="#FF1A1B1C">
<Border.Style>
<Style TargetType="{x:Type Border}">
<Setter Property="Cursor" Value="Hand"/>
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Cursor" Value="SizeAll"/>
</Trigger>
</Style.Triggers>
</Style>
</Border.Style>
<DockPanel Height="30">
<TextBlock Text="{Binding Title, RelativeSource={RelativeSource FindAncestor, AncestorType=Window}}"
VerticalAlignment="Center"
Margin="25,0,0,0"
FontWeight="Bold"
Foreground="White" />
</DockPanel>
</Border>
<TextBlock x:Name="m_dialogText" Margin="10" />
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Margin="10">
<Button x:Name="btnYes" Content="Yes" Width="75" Margin="5" Click="btnYes_Click" />
<Button x:Name="btnNo" Content="No" Width="75" Margin="5" Click="btnNo_Click" />
</StackPanel>
</StackPanel>
</Border>
</Window>
35 changes: 35 additions & 0 deletions UEVR/YesNoDialog.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;

namespace UEVR {
public partial class YesNoDialog : Window {
public bool DialogResultYes { get; private set; } = false;

public YesNoDialog(string windowTitle, string txt) {
InitializeComponent();
m_dialogText.Text = txt;
this.Title = windowTitle;
}

private void btnYes_Click(object sender, RoutedEventArgs e) {
DialogResultYes = true;
this.Close();
}

private void btnNo_Click(object sender, RoutedEventArgs e) {
DialogResultYes = false;
this.Close();
}

private void TitleBar_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) {
if (e.ChangedButton == MouseButton.Left) {
this.DragMove();
}
}
}
}

0 comments on commit cdbf10b

Please sign in to comment.