Skip to content
This repository was archived by the owner on Jun 27, 2024. It is now read-only.

Commit a6a6315

Browse files
committed
Implement MigrateEconomyJob
1 parent 0090817 commit a6a6315

4 files changed

Lines changed: 63 additions & 6 deletions

File tree

.github/workflows/deployment.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
- name: Install dependencies
2323
run: dotnet restore src/OpenMod.Installer.RocketMod.csproj
2424
- name: Update version
25-
run: "sed -i \"s#<Version>0.0.0</Version>#<Version>${{ github.event.inputs.version }}</Version>#\" src/OpenMod.Installer.RocketMod.csproj"
25+
run: "sed -i \"s#<Version>0.0.0</Version>#<Version>${{ github.event.inputs.version }}</Version>#\" src/OpenMod.Installer.RocketMod.csproj"
2626
- name: Build
2727
run: dotnet build src/OpenMod.Installer.RocketMod.csproj --configuration Release --no-restore
2828
- name: Create Release
@@ -32,7 +32,7 @@ jobs:
3232
GITHUB_TOKEN: ${{ github.token }}
3333
with:
3434
tag_name: ${{ github.event.inputs.version }}
35-
release_name: Release v${{ github.event.inputs.version }}
35+
release_name: v${{ github.event.inputs.version }}
3636
draft: false
3737
prerelease: false
3838
- name: Upload release asset
@@ -41,6 +41,6 @@ jobs:
4141
GITHUB_TOKEN: ${{ github.token }}
4242
with:
4343
upload_url: ${{ steps.create_release.outputs.upload_url }}
44-
asset_path: ./src/bin/Release/netstandard2.0/OpenMod.Installer.RocketMod.dll
44+
asset_path: ./src/bin/Release/net461/OpenMod.Installer.RocketMod.dll
4545
asset_name: OpenMod.Installer.RocketMod-v${{ github.event.inputs.version }}.dll
46-
asset_content_type: application/octet-stream
46+
asset_content_type: application/octet-stream

src/Helpers/AsyncHelperEx.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,10 @@ public static void RunSync(Func<Task> task)
1010
{
1111
AsyncContext.Run(task);
1212
}
13+
14+
public static T RunSync<T>(Func<Task<T>> task)
15+
{
16+
return AsyncContext.Run(task);
17+
}
1318
}
1419
}

src/Jobs/MigrateEconomyJob.cs

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
1-
using Rocket.Core.Logging;
1+
using System.Collections.Generic;
2+
using System.IO;
3+
using System.Linq;
4+
using OpenMod.API.Jobs;
5+
using OpenMod.API.Persistence;
6+
using OpenMod.Core.Helpers;
7+
using OpenMod.Core.Jobs;
8+
using OpenMod.Core.Persistence;
9+
using OpenMod.Installer.RocketMod.Helpers;
10+
using Rocket.Core.Logging;
211

312
namespace OpenMod.Installer.RocketMod.Jobs
413
{
@@ -7,7 +16,49 @@ public class MigrateEconomyJob : IJob
716
public void ExecuteMigration(string[] args)
817
{
918
Logger.Log("Adding economy migration job to autoexec.yaml...");
10-
//todo check if job exists
19+
var openmodDirectory = OpenModInstallerPlugin.Instance.OpenModManager.WorkingDirectory;
20+
var autoexecYaml = Path.Combine(openmodDirectory, "autoexec.yaml");
21+
22+
var dataStore = new YamlDataStore(new DataStoreCreationParameters
23+
{
24+
WorkingDirectory = openmodDirectory,
25+
LogOnChange = false
26+
}, null, null);
27+
28+
if (!AsyncHelper.RunSync(() => dataStore.ExistsAsync("autoexec")))
29+
{
30+
var openmodAssembly = typeof(YamlDataStore).Assembly;
31+
using var autoexecFileStream = openmodAssembly.GetManifestResourceStream("OpenMod.Core.autoexec.yaml");
32+
using var ms = new MemoryStream();
33+
autoexecFileStream!.CopyTo(ms);
34+
35+
ms.Seek(0, SeekOrigin.Begin);
36+
File.WriteAllBytes(autoexecYaml, ms.ToArray());
37+
}
38+
39+
var jobsFile = AsyncHelperEx.RunSync(() => dataStore.LoadAsync<ScheduledJobsFile>("autoexec"));
40+
if (jobsFile!.Jobs!.Any(d => d.Name?.Equals("OpenMod.Installer.EconomyMigration") ?? false))
41+
{
42+
return;
43+
}
44+
45+
jobsFile.Jobs.Add(new ScheduledJob
46+
{
47+
Name = "OpenMod.Installer.EconomyMigration",
48+
Enabled = true,
49+
Task = "openmod_command",
50+
Args = new Dictionary<string, object>
51+
{
52+
{ "commands", new List<string>
53+
{
54+
"MigrateUconomy"
55+
}
56+
}
57+
},
58+
Schedule = "@single_exec"
59+
});
60+
61+
AsyncHelperEx.RunSync(() => dataStore.SaveAsync("autoexec", jobsFile));
1162
}
1263
}
1364
}

src/OpenMod.Installer.RocketMod.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
<ItemGroup>
1010
<PackageReference Include="Nito.AsyncEx.Context" Version="5.1.0" />
11+
<PackageReference Include="OpenMod.Core" Version="3.0.0-beta1" />
1112
<PackageReference Include="OpenMod.NuGet" Version="3.0.0-beta1" />
1213
<PackageReference Include="OpenMod.UnityEngine.Redist" Version="2019.4.10" />
1314
<PackageReference Include="OpenMod.Unturned.Redist" Version="3.20.14" />

0 commit comments

Comments
 (0)