diff --git a/UEVR/GameConfig.cs b/UEVR/GameConfig.cs index 2f1db64..9081dd4 100644 --- a/UEVR/GameConfig.cs +++ b/UEVR/GameConfig.cs @@ -62,11 +62,28 @@ private static string GetRelativePath(string fullPath, string basePath) { return fullPath.Substring(basePath.Length); } - public static void ExtractZipToDirectory(string sourceArchiveFileName, string destinationDirectoryName) { + public static string? ExtractZipToDirectory(string sourceArchiveFileName, string destinationDirectoryName, string gameName) { try { ZipFile.ExtractToDirectory(sourceArchiveFileName, destinationDirectoryName, overwriteFiles: true); + + var extractedFiles = Directory.GetFiles(destinationDirectoryName); + if (extractedFiles.Length == 1 && Path.GetExtension(extractedFiles[0]).Equals(".zip", StringComparison.OrdinalIgnoreCase)) { + string nestedZipFile = extractedFiles[0]; + string nestedZipName = Path.GetFileNameWithoutExtension(nestedZipFile); + + string nestedDestination = Path.Combine(destinationDirectoryName, "..", nestedZipName); + Directory.CreateDirectory(nestedDestination); // Ensure the directory is created + + ZipFile.ExtractToDirectory(nestedZipFile, nestedDestination, overwriteFiles: true); + File.Delete(nestedZipFile); // Optionally delete the nested zip file after extraction + + return nestedZipName; // Return the name of the nested zip + } + + return gameName; // Return the original game name if no nested zip } catch (Exception ex) { MessageBox.Show("An error occurred: " + ex.Message); + return null; // Return null in case of an error } } diff --git a/UEVR/MainWindow.xaml.cs b/UEVR/MainWindow.xaml.cs index 503bc9a..fd798a7 100644 --- a/UEVR/MainWindow.xaml.cs +++ b/UEVR/MainWindow.xaml.cs @@ -496,8 +496,16 @@ private void ImportConfig_Clicked(object sender, RoutedEventArgs e) { Directory.CreateDirectory(gameGlobalDir); } - GameConfig.ExtractZipToDirectory(importPath, gameGlobalDir); - NavigateToDirectory(gameGlobalDir); + var finalGameName = GameConfig.ExtractZipToDirectory(importPath, gameGlobalDir, gameName); + + 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);