Update
Removed the asking stuff
This commit is contained in:
@ -112,16 +112,11 @@ 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
|
// If it is not installed, packageDirectory will have the value of the directory where the package should be
|
||||||
package = remotePackage;
|
package = remotePackage;
|
||||||
return InstallPackage(remotePackage, asset);
|
return InstallPackage(remotePackage, asset);
|
||||||
}
|
}
|
||||||
|
|
||||||
return PackageState.Cancelled;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static bool Uninstall(string id)
|
public static bool Uninstall(string id)
|
||||||
{
|
{
|
||||||
return LocalPackageManager.RemovePackage(id);
|
return LocalPackageManager.RemovePackage(id);
|
||||||
@ -151,15 +146,10 @@ 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);
|
Uninstall(id);
|
||||||
return InstallPackage(remotePackage, asset);
|
return InstallPackage(remotePackage, asset);
|
||||||
}
|
}
|
||||||
|
|
||||||
return PackageState.Cancelled;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Updates a package to the most recent version regardless of sdk version
|
/// Updates a package to the most recent version regardless of sdk version
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -184,21 +174,16 @@ namespace PMF.Managers
|
|||||||
|
|
||||||
var asset = remotePackage.GetAssetVersion(version);
|
var asset = remotePackage.GetAssetVersion(version);
|
||||||
|
|
||||||
if (validateSdkVersion(asset))
|
|
||||||
{
|
|
||||||
Uninstall(id);
|
Uninstall(id);
|
||||||
return InstallPackage(remotePackage, asset);
|
return InstallPackage(remotePackage, asset);
|
||||||
}
|
}
|
||||||
|
|
||||||
return PackageState.Cancelled;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Updates a package to the most recent version given an sdk version
|
/// Updates a package to the most recent version given an sdk version
|
||||||
/// </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);
|
Uninstall(id);
|
||||||
return InstallPackage(remotePackage, asset);
|
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -16,7 +16,6 @@ namespace PMF
|
|||||||
NotExisting,
|
NotExisting,
|
||||||
VersionNotFound,
|
VersionNotFound,
|
||||||
|
|
||||||
Cancelled,
|
|
||||||
Failed
|
Failed
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1,5 +1,7 @@
|
|||||||
# PMF - Package Management Framework
|
# PMF - Package Management Framework
|
||||||
|
|
||||||
|
[](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
|
||||||
|
|||||||
Reference in New Issue
Block a user