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

Commit 76ac249

Browse files
committed
Improve nuget install messages
1 parent 909e859 commit 76ac249

1 file changed

Lines changed: 37 additions & 31 deletions

File tree

src/Jobs/NuGetInstallJob.cs

Lines changed: 37 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -19,50 +19,56 @@ protected NuGetInstallJob(string packageId)
1919

2020
public void ExecuteMigration()
2121
{
22-
Logger.Log($"Installing package \"{m_PackageId}\"...");
2322
AsyncHelperEx.RunSync(DownloadPackage);
24-
Logger.Log($"Installed package \"{m_PackageId}\".");
2523
}
2624

2725
private async Task DownloadPackage()
2826
{
27+
Logger.Log($"Installing package \"{m_PackageId}\"...");
2928
var nuGetPackageManager = NuGetHelper.GetNuGetPackageManager();
3029

3130
const bool c_AllowPreReleaseVersion = false;
3231

33-
var OldPackageidentity = await nuGetPackageManager.GetLatestPackageIdentityAsync(m_PackageId);
34-
if (OldPackageidentity == null)
32+
var oldIdentity = await nuGetPackageManager.GetLatestPackageIdentityAsync(m_PackageId);
33+
if (oldIdentity != null)
3534
{
36-
var package = await nuGetPackageManager.QueryPackageExactAsync(m_PackageId, null, c_AllowPreReleaseVersion);
37-
if (package == null || package.Identity == null)
38-
{
39-
Logger.Log($"Downloading has failed for {m_PackageId}: {NuGetInstallCode.PackageOrVersionNotFound}");
40-
return;
41-
}
42-
var identity = package.Identity;
35+
Logger.Log($"Package \"{m_PackageId}\" is already installed.");
36+
return;
37+
}
4338

44-
var installResult = await nuGetPackageManager.InstallAsync(identity, c_AllowPreReleaseVersion);
45-
bool isInstalled;
46-
if (Enum.GetValues(typeof(NuGetInstallCode)).Length == 3) // loaded 3.0 version openmod
47-
{
48-
isInstalled = (int)installResult.Code is 0 or 1; // Success / NoUpdatesFound
49-
}
50-
else
51-
{
52-
isInstalled = installResult.Code == NuGetInstallCode.Success;
53-
}
39+
var package = await nuGetPackageManager.QueryPackageExactAsync(m_PackageId, null, c_AllowPreReleaseVersion);
40+
if (package?.Identity == null)
41+
{
42+
Logger.Log($"Downloading has failed for {m_PackageId}: {NuGetInstallCode.PackageOrVersionNotFound}");
43+
return;
44+
}
5445

55-
if (isInstalled)
56-
{
57-
m_PackageDirectory = Path.Combine(OpenModInstallerPlugin.Instance.OpenModManager.WorkingDirectory, "packages",
58-
identity.ToString());
59-
Logger.Log($"Finished downloading \"{m_PackageId}\".");
60-
}
61-
else
62-
{
63-
Logger.Log($"Downloading has failed for {m_PackageId}: {installResult.Code}");
64-
}
46+
var identity = package.Identity;
47+
48+
var installResult = await nuGetPackageManager.InstallAsync(identity, c_AllowPreReleaseVersion);
49+
bool isInstalled;
50+
if (Enum.GetValues(typeof(NuGetInstallCode)).Length == 3) // loaded 3.0 version openmod
51+
{
52+
isInstalled = (int) installResult.Code is 0 or 1; // Success / NoUpdatesFound
6553
}
54+
else
55+
{
56+
isInstalled = installResult.Code == NuGetInstallCode.Success;
57+
}
58+
59+
if (isInstalled)
60+
{
61+
m_PackageDirectory = Path.Combine(OpenModInstallerPlugin.Instance.OpenModManager.WorkingDirectory,
62+
"packages",
63+
identity.ToString());
64+
Logger.Log($"Finished downloading \"{m_PackageId}\".");
65+
}
66+
else
67+
{
68+
Logger.Log($"Downloading has failed for {m_PackageId}: {installResult.Code}");
69+
}
70+
71+
Logger.Log($"Installed package \"{m_PackageId}\"@{identity.Version}.");
6672
}
6773

6874
public void Revert()

0 commit comments

Comments
 (0)