Skip to content

Commit

Permalink
configurable temp folder (#287)
Browse files Browse the repository at this point in the history
* temp directory for downloads and extracting

* missed one

* Update README.md
  • Loading branch information
mattpannella authored Apr 4, 2024
1 parent 6c0a731 commit 61f9932
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 13 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ This contains a list of alternate core setups. These take existing cores and mak
| config.custom_archive | You can set a custom URL here, if you don't want to use the default. `index` is a relative path to the index of your custom site's files. This is not required, but it's needed for CRC checking. If you have CRC checking enabled, the setting will be ignored unless this provides the necessary format. It must match the output of archive.org's json endpoint. https://archive.org/developers/md-read.html |
| config.backup_saves | Set this to `true` if you want your Saves directory to be backed up automatically during `Update All` |
| config.backup_saves_location | Put the absolute path to the backup location here to backup your `Saves` directory to. This defaults to `Backups` in the current directory when not set. |
| config.temp_directory | When left `null` all zip files are downloaded and extracted using a temp directory in your pocket install location. If you supply a path, that will be used, instead |
| coreSettings | This allows you to set a subset of settings on a per core basis. It contains a list of every core, with 3 options. `skip`, `download_assets`, and `platform_rename`. You can use these to override your global defaults |

## CLI Commands and Parameters
Expand Down
2 changes: 2 additions & 0 deletions src/helpers/ServiceHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ namespace Pannella.Helpers;
public static class ServiceHelper
{
public static string UpdateDirectory { get; private set; } // move off this
public static string TempDirectory { get; private set; }
public static CoresService CoresService { get; private set; }
public static SettingsService SettingsService { get; private set ;}
public static PlatformImagePacksService PlatformImagePacksService { get; private set; }
Expand All @@ -25,6 +26,7 @@ public static void Initialize(string path, EventHandler<StatusUpdatedEventArgs>
SettingsService = new SettingsService(path);
ArchiveService = new ArchiveService(SettingsService.GetConfig().archives,
SettingsService.GetConfig().crc_check, SettingsService.GetConfig().use_custom_archive);
TempDirectory = SettingsService.GetConfig().temp_directory ?? UpdateDirectory;
AssetsService = new AssetsService(SettingsService.GetConfig().use_local_blacklist);
CoresService = new CoresService(path, SettingsService, ArchiveService, AssetsService);
SettingsService.InitializeCoreSettings(CoresService.Cores);
Expand Down
3 changes: 3 additions & 0 deletions src/models/Settings/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ public class Config
[Description("Use custom asset archive")]
public bool use_custom_archive { get; set; } = false;

[Description("Use custom temp directory when downloading files to be extracted")]
public string temp_directory { get; set; } = null;

[JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
public bool use_local_blacklist { get; set; } = false;

Expand Down
4 changes: 2 additions & 2 deletions src/partials/Program.GameBoyPalettes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ private static void DownloadGameBoyPalettes()

if (asset != null)
{
string localFile = Path.Combine(ServiceHelper.UpdateDirectory, asset.name);
string extractPath = Path.Combine(ServiceHelper.UpdateDirectory, "temp");
string localFile = Path.Combine(ServiceHelper.TempDirectory, asset.name);
string extractPath = Path.Combine(ServiceHelper.TempDirectory, "temp");

try
{
Expand Down
6 changes: 3 additions & 3 deletions src/partials/Program.PocketLibraryImages.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ private static void DownloadPockLibraryImages()

if (archiveFile != null)
{
string localFile = Path.Combine(ServiceHelper.UpdateDirectory, fileName);
string extractPath = Path.Combine(ServiceHelper.UpdateDirectory, "temp");
string localFile = Path.Combine(ServiceHelper.TempDirectory, fileName);
string extractPath = Path.Combine(ServiceHelper.TempDirectory, "temp");

try
{
ServiceHelper.ArchiveService.DownloadArchiveFile(archive, archiveFile, ServiceHelper.UpdateDirectory);
ServiceHelper.ArchiveService.DownloadArchiveFile(archive, archiveFile, ServiceHelper.TempDirectory);
Console.WriteLine("Installing...");

if (Directory.Exists(extractPath))
Expand Down
4 changes: 2 additions & 2 deletions src/services/CoresService.Extras.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ private void DownloadPocketExtrasPlatform(PocketExtra pocketExtra, string path,
return;
}

string localFile = Path.Combine(path, asset.name);
string extractPath = Path.Combine(path, "temp");
string localFile = Path.Combine(ServiceHelper.TempDirectory, asset.name);
string extractPath = Path.Combine(ServiceHelper.TempDirectory, "temp");

try
{
Expand Down
8 changes: 4 additions & 4 deletions src/services/CoresService.Helpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@ private bool InstallGithubAsset(string identifier, string platformId, string dow

WriteMessage($"Downloading file {downloadUrl}...");

string zipPath = Path.Combine(this.installPath, ZIP_FILE_NAME);
string zipPath = Path.Combine(ServiceHelper.TempDirectory, ZIP_FILE_NAME);

HttpHelper.Instance.DownloadFile(downloadUrl, zipPath);

WriteMessage("Extracting...");

string tempDir = Path.Combine(this.installPath, "temp", identifier);
string tempDir = Path.Combine(ServiceHelper.TempDirectory, "temp", identifier);

ZipHelper.ExtractToDirectory(zipPath, tempDir, true);

Expand All @@ -73,9 +73,9 @@ private bool InstallGithubAsset(string identifier, string platformId, string dow

// See if the temp directory itself can be removed.
// Probably not needed if we aren't going to multi-thread this, but this is an async function so let's future proof.
if (!Directory.GetFiles(Path.Combine(this.installPath, "temp")).Any())
if (!Directory.GetFiles(Path.Combine(ServiceHelper.TempDirectory, "temp")).Any())
{
Directory.Delete(Path.Combine(this.installPath, "temp"));
Directory.Delete(Path.Combine(ServiceHelper.TempDirectory, "temp"));
}

File.Delete(zipPath);
Expand Down
4 changes: 2 additions & 2 deletions src/services/PlatformImagePacksService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public PlatformImagePacksService(string path, string githubToken = null, bool us

public void Install(string owner, string repository, string variant)
{
string localFile = Path.Combine(this.installPath, "image_pack.zip");
string localFile = Path.Combine(ServiceHelper.TempDirectory, "image_pack.zip");
Release release = GithubApiService.GetLatestRelease(owner, repository, this.githubToken);

if (release.assets == null)
Expand All @@ -69,7 +69,7 @@ public void Install(string owner, string repository, string variant)

WriteMessage("Installing...");

string extractPath = Path.Combine(this.installPath, "temp");
string extractPath = Path.Combine(ServiceHelper.TempDirectory, "temp");
ZipHelper.ExtractToDirectory(localFile, extractPath, true);

string imagePack = FindPlatformImagePack(extractPath);
Expand Down

0 comments on commit 61f9932

Please sign in to comment.