Removed the asking stuff
This commit is contained in:
xx-TheDoctor-xx
2020-04-18 06:33:58 +01:00
parent da00e35d09
commit 8c9c03cd42
3 changed files with 12 additions and 59 deletions

View File

@ -112,14 +112,9 @@ namespace PMF.Managers
if (asset == null) if (asset == null)
return PackageState.VersionNotFound; return PackageState.VersionNotFound;
if (validateSdkVersion(asset)) // If it is not installed, packageDirectory will have the value of the directory where the package should be
{ package = remotePackage;
// If it is not installed, packageDirectory will have the value of the directory where the package should be return InstallPackage(remotePackage, asset);
package = remotePackage;
return InstallPackage(remotePackage, asset);
}
return PackageState.Cancelled;
} }
public static bool Uninstall(string id) public static bool Uninstall(string id)
@ -151,13 +146,8 @@ namespace PMF.Managers
if (localPackage.Assets[0].Version == asset.Version) if (localPackage.Assets[0].Version == asset.Version)
return PackageState.UpToDate; return PackageState.UpToDate;
if (validateSdkVersion(asset)) Uninstall(id);
{ return InstallPackage(remotePackage, asset);
Uninstall(id);
return InstallPackage(remotePackage, asset);
}
return PackageState.Cancelled;
} }
/// <summary> /// <summary>
@ -184,13 +174,8 @@ namespace PMF.Managers
var asset = remotePackage.GetAssetVersion(version); var asset = remotePackage.GetAssetVersion(version);
if (validateSdkVersion(asset)) Uninstall(id);
{ return InstallPackage(remotePackage, asset);
Uninstall(id);
return InstallPackage(remotePackage, asset);
}
return PackageState.Cancelled;
} }
/// <summary> /// <summary>
@ -198,7 +183,7 @@ namespace PMF.Managers
/// </summary> /// </summary>
/// <param name="id"></param> /// <param name="id"></param>
/// <returns>true if update success, false if package is not installed</returns> /// <returns>true if update success, false if package is not installed</returns>
public static PackageState UpdateBySdkVersion(string id, out Package package, bool dontAsk = false) public static PackageState UpdateBySdkVersion(string id, out Package package)
{ {
package = null; package = null;
@ -220,41 +205,8 @@ namespace PMF.Managers
if (localPackage.Assets[0].Version == asset.Version) if (localPackage.Assets[0].Version == asset.Version)
return PackageState.UpToDate; return PackageState.UpToDate;
if (dontAsk || validateSdkVersion(asset)) Uninstall(id);
{ return InstallPackage(remotePackage, asset);
Uninstall(id);
return InstallPackage(remotePackage, asset);
}
return PackageState.Cancelled;
}
private static bool validateSdkVersion(Asset asset)
{
if (asset.SdkVersion > Config.CurrentSdkVersion)
return askUser("You are installing a package which the sdk version is more recent than what you have. Would you like to continue?");
else if (asset.SdkVersion < Config.CurrentSdkVersion)
return askUser("You are installing a package which the sdk version is older than what you have. Would you like to continue?");
return true;
}
/// <summary>
/// Just asks the user something
/// </summary>
/// <returns>true yes, false no</returns>
private static bool askUser(string question)
{
Console.WriteLine($"{question} [Y][N]");
while (true)
{
char answer = char.ToLower(Console.ReadKey().KeyChar);
if (answer == 'n')
return false;
else if (answer == 'y')
return true;
}
} }
} }
} }

View File

@ -16,7 +16,6 @@ namespace PMF
NotExisting, NotExisting,
VersionNotFound, VersionNotFound,
Cancelled,
Failed Failed
} }
} }

View File

@ -1,5 +1,7 @@
# PMF - Package Management Framework # PMF - Package Management Framework
[![Build Status](https://travis-ci.com/xX-TheDoctor-Xx/PMF.svg?branch=master)](https://travis-ci.com/xX-TheDoctor-Xx/PMF)
PMF is a barebones C# library that provides basic support for package management PMF is a barebones C# library that provides basic support for package management
# Features # Features