Skip to content

Commit

Permalink
Remote: Save download location (breaking change)
Browse files Browse the repository at this point in the history
  • Loading branch information
suchmememanyskill committed Jun 15, 2024
1 parent c50299d commit 1603beb
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 25 deletions.
21 changes: 11 additions & 10 deletions RemoteDownloaderPlugin/Game/GameDownload.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public class GameDownload : ProgressStatus
public string Version { get; private set; }
public GameType Type { get; private set; }
public string BaseFileName { get; private set; }
public string BasePath { get; private set; }
public ContentTypes InstalledEntries { get; private set; }

private DateTimeOffset _downloadStart = DateTimeOffset.Now;
Expand Down Expand Up @@ -64,10 +65,10 @@ private async Task DownloadEmu(IApp app, EmuEntry entry)
}

Line2 = $"{entry.Files.Count(x => x.Type == "base")} base, {entry.Files.Count(x => x.Type == "update")} update, {entry.Files.Count(x => x.Type == "dlc")} dlc";
var basePath = Path.Join(app.GameDir, "Remote", entry.Emu);
BasePath = Path.Join(app.GameDir, "Remote", entry.Emu);
string baseGamePath = null;
var extraFilesPath = Path.Join(app.GameDir, "Remote", entry.Emu, entry.GameId);
Directory.CreateDirectory(basePath);
Directory.CreateDirectory(BasePath);
Directory.CreateDirectory(extraFilesPath);

using HttpClient client = new();
Expand All @@ -84,7 +85,7 @@ private async Task DownloadEmu(IApp app, EmuEntry entry)
};

var fileEntry = entry.Files[i];
var destPath = Path.Join(fileEntry.Type == "base" ? basePath : extraFilesPath, fileEntry.Name);
var destPath = Path.Join(fileEntry.Type == "base" ? BasePath : extraFilesPath, fileEntry.Name);
InstalledEntries.Add(fileEntry.Type);

if (fileEntry.Type == "base")
Expand Down Expand Up @@ -125,9 +126,9 @@ private async Task DownloadEmu(IApp app, EmuEntry entry)
private async Task DownloadPc(IApp app, PcEntry entry)
{
Type = GameType.Pc;
var basePath = Path.Join(app.GameDir, "Remote", "Pc", entry.GameId);
Directory.CreateDirectory(basePath);
var zipFilePath = Path.Join(basePath, "__game__.zip");
BasePath = Path.Join(app.GameDir, "Remote", "Pc", entry.GameId);
Directory.CreateDirectory(BasePath);
var zipFilePath = Path.Join(BasePath, "__game__.zip");

using HttpClient client = new();
var fs = new FileStream(zipFilePath, FileMode.Create);
Expand All @@ -143,7 +144,7 @@ private async Task DownloadPc(IApp app, PcEntry entry)
{
await Task.Run(() => fs.Dispose());

Directory.Delete(basePath);
Directory.Delete(BasePath);

throw;
}
Expand All @@ -155,15 +156,15 @@ private async Task DownloadPc(IApp app, PcEntry entry)
await Task.Run(() => fs.Dispose());
Line1 = "Unzipping...";
InvokeOnUpdate();
await Task.Run(() => ZipFile.ExtractToDirectory(zipFilePath, basePath));
await Task.Run(() => ZipFile.ExtractToDirectory(zipFilePath, BasePath));
File.Delete(zipFilePath);

if (_cts.IsCancellationRequested)
{
Directory.Delete(basePath);
Directory.Delete(BasePath);
}

TotalSize = await Task.Run(() => LauncherGamePlugin.Utils.DirSize(new(basePath)));
TotalSize = await Task.Run(() => LauncherGamePlugin.Utils.DirSize(new(BasePath)));
Version = entry.Version;
}

Expand Down
21 changes: 8 additions & 13 deletions RemoteDownloaderPlugin/Game/InstalledGame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public InstalledGame(IInstalledGame game, Plugin plugin)

if (_type == GameType.Pc)
{
var fullPath = Path.Join(plugin.App.GameDir, "Remote", "Pc", Game.Id, "game.json");
var fullPath = Path.Join(game.BasePath, "game.json");
_pcLaunchDetails = PcLaunchDetails.GetFromPath(fullPath);
}
else
Expand All @@ -88,7 +88,7 @@ public void Play()
throw new Exception($"No '{_emuGame!.Emu}' emulation profile exists");
}

var baseGamePath = Path.Join(_plugin.App.GameDir, "Remote", _emuGame!.Emu, _emuGame.BaseFilename);
var baseGamePath = Path.Join(Game.BasePath, _emuGame!.BaseFilename);

LaunchParams args = new(emuProfile.ExecPath,
emuProfile.CliArgs.Replace("{EXEC}", $"\"{baseGamePath}\""), emuProfile.WorkingDirectory, this,
Expand All @@ -97,8 +97,8 @@ public void Play()
}
else
{
var execPath = Path.Join(_plugin.App.GameDir, "Remote", "Pc", Game.Id, _pcLaunchDetails!.LaunchExec);
var workingDir = Path.Join(_plugin.App.GameDir, "Remote", "Pc", Game.Id, _pcLaunchDetails!.WorkingDir);
var execPath = Path.Join(Game.BasePath, _pcLaunchDetails!.LaunchExec);
var workingDir = Path.Join(Game.BasePath, _pcLaunchDetails!.WorkingDir);
LaunchParams args = new(execPath, _pcLaunchDetails.LaunchArgs, Path.GetDirectoryName(workingDir)!, this,
EstimatedGamePlatform);
_plugin.App.Launch(args);
Expand All @@ -114,8 +114,8 @@ public void Delete()
{
if (IsEmu)
{
var baseGamePath = Path.Join(_plugin.App.GameDir, "Remote", _emuGame!.Emu, _emuGame.BaseFilename);
var extraDir = Path.Join(_plugin.App.GameDir, "Remote", _emuGame!.Emu, Game.Id);
var baseGamePath = Path.Join(Game.BasePath, _emuGame.BaseFilename);
var extraDir = Path.Join(Game.BasePath, Game.Id);
var success = false;

try
Expand All @@ -136,12 +136,11 @@ public void Delete()
}
else
{
var path = Path.Join(_plugin.App.GameDir, "Remote", "Pc", Game.Id);
var success = false;

try
{
Directory.Delete(path, true);
Directory.Delete(Game.BasePath, true);
success = true;
}
catch {}
Expand All @@ -160,11 +159,7 @@ public void Delete()
}

public void OpenInFileManager()
{
LauncherGamePlugin.Utils.OpenFolder(IsEmu
? Path.Join(_plugin.App.GameDir, "Remote", _emuGame!.Emu)
: Path.Join(_plugin.App.GameDir, "Remote", "Pc", Game.Id));
}
=> LauncherGamePlugin.Utils.OpenFolder(Game.BasePath);

private Uri? ImageTypeToUri(ImageType type)
=> type switch
Expand Down
6 changes: 4 additions & 2 deletions RemoteDownloaderPlugin/Game/OnlineGame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ public async Task Download()
Version = _download.Version,
BaseFilename = _download.BaseFileName,
Images = Entry.Img,
Types = _download.InstalledEntries
Types = _download.InstalledEntries,
BasePath = _download.BasePath
});
}
else
Expand All @@ -109,7 +110,8 @@ public async Task Download()
Name = Entry.GameName,
GameSize = _download.TotalSize,
Version = _download.Version,
Images = Entry.Img
Images = Entry.Img,
BasePath = _download.BasePath
});
}

Expand Down
3 changes: 3 additions & 0 deletions RemoteDownloaderPlugin/Store.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public interface IInstalledGame
public string Version { get; }
public long GameSize { get; }
public Images Images { get; }
public string BasePath { get; set; }
}

public class ContentTypes
Expand Down Expand Up @@ -63,6 +64,7 @@ public class InstalledEmuGame : IInstalledGame
public string BaseFilename { get; set; }
public Images Images { get; set; }
public ContentTypes Types { get; set; } = new();
public string BasePath { get; set; }
}

public class InstalledPcGame : IInstalledGame
Expand All @@ -72,6 +74,7 @@ public class InstalledPcGame : IInstalledGame
public long GameSize { get; set; }
public string Version { get; set; }
public Images Images { get; set; }
public string BasePath { get; set; }
}

public class EmuProfile
Expand Down

0 comments on commit 1603beb

Please sign in to comment.