Skip to content
Merged
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
10 changes: 10 additions & 0 deletions WheelWizard/Features/CustomDistributions/IDistribution.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,16 @@ public interface IDistribution
/// </summary>
string FolderName { get; }

/// <summary>
/// The name of the wiiDisc .xml file in XMLFolderName
/// </summary>
string XMLFileName { get; }

/// <summary>
/// The name of the folder containing the distributions wiiDisc .xml file
/// </summary>
string XMLFolderName { get; }

/// <summary>
/// Install the distribution.
/// </summary>
Expand Down
53 changes: 45 additions & 8 deletions WheelWizard/Features/CustomDistributions/RetroRewind.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ public RetroRewind(IFileSystem fileSystem, IApiCaller<IRetroRewindApi> api)

// Keep in mind, whenever we download update files from the server, they are actually 1 folder higher, so it contains this folder.
public string FolderName => "RetroRewind6";
public string XMLFolderName => "riivolution";
public string XMLFileName => "RetroRewind6";

public async Task<OperationResult> InstallAsync(ProgressWindow progressWindow)
{
Expand Down Expand Up @@ -68,9 +70,17 @@ private async Task<OperationResult> DownloadAndExtractRetroRewind(ProgressWindow
var tempZipPath = PathManager.RetroRewindTempFile;
// where we'll do the extraction
var tempExtractionPath = PathManager.TempModsFolderPath;
// where the final RR folder should live
var finalDestination = _fileSystem.Path.Combine(PathManager.RiivolutionWhWzFolderPath, FolderName);

//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;
try
{
// 1) Download
Expand Down Expand Up @@ -101,11 +111,38 @@ private async Task<OperationResult> DownloadAndExtractRetroRewind(ProgressWindow
}

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

// 5) Move into place
_fileSystem.Directory.Move(sourceFolder, finalDestination);
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);

// 6) Move over 'riivolution/' folder. skip existing files
var xmlFolderSource = _fileSystem.Path.Combine(tempExtractionPath, XMLFolderName);
foreach (var file in _fileSystem.Directory.EnumerateFiles(xmlFolderSource, "*", SearchOption.AllDirectories))
{
var destinationPath = _fileSystem.Path.Combine(riivolutionFolderDestination, _fileSystem.Path.GetRelativePath(xmlFolderSource, 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);
}
}
catch (Exception e)
{
exception = e;
}
finally
{
Expand All @@ -115,7 +152,7 @@ private async Task<OperationResult> DownloadAndExtractRetroRewind(ProgressWindow
if (_fileSystem.Directory.Exists(tempExtractionPath))
_fileSystem.Directory.Delete(tempExtractionPath, recursive: true);
}
return Ok();
return exception is null ? Ok() : Fail(exception);
}

private async Task BackupOldrksys()
Expand Down
10 changes: 9 additions & 1 deletion WheelWizard/Services/Launcher/RrLauncher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,16 @@ public async Task Install()
{
var progressWindow = new ProgressWindow();
progressWindow.Show();
await CustomDistributionSingletonService.RetroRewind.InstallAsync(progressWindow);
var installResult = await CustomDistributionSingletonService.RetroRewind.InstallAsync(progressWindow);
progressWindow.Close();
if (installResult.IsFailure)
{
await new MessageBoxWindow()
.SetMessageType(MessageBoxWindow.MessageType.Error)
.SetTitleText("Unable to install RetroRewind")
.SetInfoText(installResult.Error.Message)
.ShowDialog();
}
}

public async Task Update()
Expand Down
3 changes: 2 additions & 1 deletion WheelWizard/Services/PathManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ public static class PathManager

// This is not the folder your save file is located in, but its the folder where every Region folder is, so the save file is in SaveFolderPath/Region
public static string SaveFolderPath => Path.Combine(RiivolutionWhWzFolderPath, "riivolution", "save", "RetroWFC");
public static string XmlFilePath => Path.Combine(RiivolutionWhWzFolderPath, "riivolution", "RetroRewind6.xml");
public static string RiivolutionXmlFolderPath => Path.Combine(RiivolutionWhWzFolderPath, "riivolution");
public static string XmlFilePath => Path.Combine(RiivolutionXmlFolderPath, "RetroRewind6.xml");

private static string PortableUserFolderPath =>
Path.Combine(GetDolphinExeDirectory(), RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ? "user" : "User");
Expand Down
Loading