Skip to content

Commit

Permalink
fixed core replacement logic (#233)
Browse files Browse the repository at this point in the history
* move directories

* check for directories

* woops

* fixed it

* remove debugging

* version bump
  • Loading branch information
mattpannella authored Feb 3, 2024
1 parent d1b2b13 commit f0abb1f
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 17 deletions.
2 changes: 1 addition & 1 deletion pupdate.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<Version>3.2.0</Version>
<Version>3.2.1</Version>
<Description>Keep your Analogue Pocket up to date</Description>
<Copyright>2024 Matt Pannella</Copyright>
<Authors>Matt Pannella</Authors>
Expand Down
2 changes: 0 additions & 2 deletions src/Updater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,6 @@ public async Task RunUpdates(string? id = null, bool clean = false)
_writeMessage("Checking Core: " + name);
var mostRecentRelease = core.version;

await core.ReplaceCheck();

if(mostRecentRelease == null) {
_writeMessage("No releases found. Skipping");
await CopyBetaKey(core);
Expand Down
42 changes: 32 additions & 10 deletions src/models/Core.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ public class Core : Base
public string? download_url { get; set; }
public string? release_date { get; set; }
public string? version { get; set; }
public string[]? replaces { get; set; }
public string? betaSlotId = null;
public int betaSlotPlatformIdIndex = 0;

Expand Down Expand Up @@ -50,7 +49,12 @@ public async Task<bool> Install(bool clean = false)
Delete();
}
//iterate through assets to find the zip release
return await _installGithubAsset();
if(await _installGithubAsset()) {
await this.ReplaceCheck();
return true;
} else {
return false;
}
}

private async Task<bool> _installGithubAsset()
Expand Down Expand Up @@ -335,11 +339,7 @@ public async Task<Dictionary<string, Object>> DownloadAssets()
return null;
}
string json = File.ReadAllText(file);
var options = new JsonSerializerOptions()
{
AllowTrailingCommas = true
};
Updater.Updaters? config = JsonSerializer.Deserialize<Updater.Updaters>(json, options);
Updater.Updaters? config = JsonSerializer.Deserialize<Updater.Updaters>(json);

if (config == null) {
return null;
Expand Down Expand Up @@ -565,17 +565,39 @@ public bool JTBetaCheck()

public async Task ReplaceCheck()
{
var replaces = this.getSubstitutes();
if (replaces != null) {
foreach(string id in replaces) {
Core c = new Core(){identifier = id};
foreach(var replacement in replaces) {
string identifier = $"{replacement.author}.{replacement.shortname}";
Core c = new Core(){identifier = identifier, platform_id = replacement.platform_id};
if (c.isInstalled()) {
Replace(c);
c.Uninstall();
_writeMessage($"Uninstalled {id}. It was replaced by this core.");
_writeMessage($"Uninstalled {identifier}. It was replaced by this core.");
}
}
}
}

private void Replace(Core core)
{
string root = Factory.GetGlobals().UpdateDirectory;
string path = Path.Combine(root, "Assets", core.platform_id, core.identifier);
if(Directory.Exists(path)) {
Directory.Move(path, Path.Combine(root, "Assets", core.platform_id, this.identifier));
}

path = Path.Combine(root, "Saves", core.platform_id, core.identifier);
if(Directory.Exists(path)) {
Directory.Move(path, Path.Combine(root, "Saves", core.platform_id, this.identifier));
}

path = Path.Combine(root, "Settings", core.identifier);
if(Directory.Exists(path)) {
Directory.Move(path, Path.Combine(root, "Settings", this.identifier));
}
}

public async Task<Analogue.Cores.Video.Video> GetVideoConfig()
{
checkUpdateDirectory();
Expand Down
6 changes: 3 additions & 3 deletions src/models/Updater/Substitute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ namespace pannella.analoguepocket.Updater;

public class Substitute
{
public string? platform{ get; set; }
public string? author { get; set; }
public string? shortname { get; set; }
public string shortname { get; set; }
public string author { get; set; }
public string platform_id { get; set; }
}
2 changes: 1 addition & 1 deletion src/models/Updater/Updaters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ namespace pannella.analoguepocket.Updater;

public class Updaters
{
public Substitute[]? previous;
public Substitute[] previous { get; set; }
}

0 comments on commit f0abb1f

Please sign in to comment.