Skip to content
Merged
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
56 changes: 28 additions & 28 deletions WheelWizard/Features/CustomDistributions/RetroRewind.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,8 @@ private async Task<OperationResult> DownloadAndExtractRetroRewind(ProgressWindow
//where all distributions are stored
var destinationParentDir = _fileSystem.DirectoryInfo.New(PathManager.RiivolutionWhWzFolderPath);

//where the RR distribution lives
var distributionDataDestination = _fileSystem.Path.Combine(destinationParentDir.FullName, FolderName);
//where the RR wiiDisc xml file lives
var riivolutionFolderDestination = PathManager.RiivolutionXmlFolderPath;
var riivolutionDiscXMLFile = _fileSystem.Path.Combine(riivolutionFolderDestination, $"{XMLFileName}.xml");

Exception? exception = null;
OperationResult? result = null;
try
{
// 1) Download
Expand Down Expand Up @@ -110,34 +105,30 @@ private async Task<OperationResult> DownloadAndExtractRetroRewind(ProgressWindow
return new DirectoryNotFoundException($"Could not find a '{FolderName}' folder inside {tempExtractionPath}");
}

// 4) Replace existing install, if any
if (_fileSystem.Directory.Exists(distributionDataDestination))
_fileSystem.Directory.Delete(distributionDataDestination, recursive: true);
if (_fileSystem.File.Exists(riivolutionDiscXMLFile))
_fileSystem.File.Delete(riivolutionDiscXMLFile);

// 5) Make sure the target directory exists
var parentDirectory = _fileSystem.DirectoryInfo.New(distributionDataDestination).Parent;
parentDirectory?.Create();
if ((!parentDirectory?.Exists) ?? true)
throw new DirectoryNotFoundException($"Could not find destination `{parentDirectory?.FullName}`");

// 5) Move over distribution data
_fileSystem.Directory.Move(sourceFolder, distributionDataDestination);
// 4) Remove existing install, if any
var removeResult = await RemoveAsync(progressWindow);
if (removeResult.IsFailure)
{
result = removeResult;
throw new Exception(removeResult.Error.Message);
}

// 6) Move over 'riivolution/' folder. skip existing files
// 5) Move over RetroRewind
var xmlFolderSource = _fileSystem.Path.Combine(tempExtractionPath, XMLFolderName);
foreach (var file in _fileSystem.Directory.EnumerateFiles(xmlFolderSource, "*", SearchOption.AllDirectories))
var riivolutionFiles = _fileSystem.Directory.EnumerateFiles(xmlFolderSource, "*", SearchOption.AllDirectories);
var folderSource = _fileSystem.Path.Combine(tempExtractionPath, FolderName);
var retroRewindFiles = _fileSystem.Directory.EnumerateFiles(folderSource, "*", SearchOption.AllDirectories);
foreach (var file in riivolutionFiles.Concat(retroRewindFiles))
{
var destinationPath = _fileSystem.Path.Combine(riivolutionFolderDestination, _fileSystem.Path.GetRelativePath(xmlFolderSource, file));
var destinationPath = _fileSystem.Path.Combine(destinationParentDir.FullName, _fileSystem.Path.GetRelativePath(tempExtractionPath, file));
var destinationDirectoryName = _fileSystem.Path.GetDirectoryName(destinationPath);
if (destinationDirectoryName != null)
{
var directory = _fileSystem.DirectoryInfo.New(destinationDirectoryName);
if (!directory?.Exists ?? false)
directory?.Create();
}
_fileSystem.File.Move(file, destinationPath, false);
_fileSystem.File.Move(file, destinationPath, false); //skip existing files for safety
}
}
catch (Exception e)
Expand All @@ -152,7 +143,7 @@ private async Task<OperationResult> DownloadAndExtractRetroRewind(ProgressWindow
if (_fileSystem.Directory.Exists(tempExtractionPath))
_fileSystem.Directory.Delete(tempExtractionPath, recursive: true);
}
return exception is null ? Ok() : Fail(exception);
return result ?? (exception is not null ? Fail(exception) : Ok());
}

private async Task BackupOldrksys()
Expand Down Expand Up @@ -371,6 +362,8 @@ private OperationResult ExtractZipFile(string path, string destinationDirectory,
if (!string.IsNullOrEmpty(dir))
_fileSystem.Directory.CreateDirectory(dir);

// Ensure read permission is set
entry.ExternalAttributes |= Convert.ToInt32("644", 8) << 16;
// Extract the file
entry.ExtractToFile(destinationPath, overwrite: true);
}
Expand Down Expand Up @@ -542,9 +535,16 @@ List<DeletionData> allDeletions

public Task<OperationResult> RemoveAsync(ProgressWindow progressWindow)
{
var retroRewindPath = _fileSystem.Path.Combine(PathManager.RiivolutionWhWzFolderPath, FolderName);
if (_fileSystem.Directory.Exists(retroRewindPath))
_fileSystem.Directory.Delete(retroRewindPath, true);
//where the RR distribution lives
var distributionDataDestination = _fileSystem.Path.Combine(PathManager.RiivolutionWhWzFolderPath, FolderName);
//where the RR wiiDisc xml file lives
var riivolutionDiscXMLFile = _fileSystem.Path.Combine(PathManager.RiivolutionWhWzFolderPath, XMLFolderName, $"{XMLFileName}.xml");

if (_fileSystem.Directory.Exists(distributionDataDestination))
_fileSystem.Directory.Delete(distributionDataDestination, recursive: true);
if (_fileSystem.File.Exists(riivolutionDiscXMLFile))
_fileSystem.File.Delete(riivolutionDiscXMLFile);

return Task.FromResult(Ok());
}

Expand Down
Loading