Skip to content

Commit

Permalink
Configs: Fix import edge case with nested zips (GDrive crap)
Browse files Browse the repository at this point in the history
  • Loading branch information
praydog committed Dec 29, 2023
1 parent c655a38 commit e8c9a7f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
19 changes: 18 additions & 1 deletion UEVR/GameConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down
12 changes: 10 additions & 2 deletions UEVR/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit e8c9a7f

Please sign in to comment.