Removed check in validateManifestFile and added a bunch of comments

This commit is contained in:
xx-TheDoctor-xx
2020-05-14 16:48:51 +01:00
parent bf3ced4d54
commit ac5b76139b
8 changed files with 128 additions and 35 deletions

View File

@ -7,16 +7,34 @@ namespace PMF
{
public static class Config
{
/// <summary>
/// Manifest file name, the library will look for it in the directory that is being run
/// </summary>
public static string ManifestFileName { get; set; } = "manifest.json";
/// <summary>
/// Installation folder containing the packages
/// </summary>
public static string PackageInstallationFolder { get; set; }
/// <summary>
/// Repository endpoint for the database of packages
/// </summary>
public static string RepositoryEndpoint { get; set; }
/// <summary>
/// The current SDK version
/// </summary>
public static string CurrentSdkVersion { get; set; }
/// <summary>
/// Internal flag to spit out debug info
/// </summary>
public static bool IsDebugging { get; set; }
/// <summary>
/// Temporary folder where downloads will go to
/// </summary>
public static string TemporaryFolder { get; set; } = ".pmf-temp";
}
}

View File

@ -10,8 +10,9 @@ namespace PMF
/// <summary>
/// Nice hack to reuse this bit of code very effectively, this method is just used in List<T> where T is Package, otherwise this method doesn't even show up
/// </summary>
/// <param name="list"></param>
/// <param name="id"></param>
/// <param name="list">This is not an actual parameter</param>
/// <param name="id">The id of the package</param>
/// <returns>True if removed, false if not found</returns>
public static bool Remove(this List<Package> list, string id)
{
for (int i = 0; i < list.Count; i++)
@ -30,9 +31,9 @@ namespace PMF
/// <summary>
/// Same as Remove, but it Retrieves
/// </summary>
/// <param name="list"></param>
/// <param name="id"></param>
/// <returns></returns>
/// <param name="list">This is not an actual parameter</param>
/// <param name="id">The id of the package</param>
/// <returns>The package that was retrieved</returns>
public static Package GetPackage(this List<Package> list, string id)
{
if (id == null || id.Length == 0)

View File

@ -55,14 +55,19 @@ namespace PMF.Managers
}
}
private static void validateManifestFile()
internal static void validateManifestFile()
{
if (!File.Exists(Config.ManifestFileName))
File.Create(Config.ManifestFileName).Close();
if (PackageList == null)
PackageList = new List<Package>();
}
/// <summary>
/// Checks if a given package is installed
/// </summary>
/// <param name="id">The id of the package</param>
/// <param name="package">This value is defined if the package exists, its contents will be the actual package</param>
/// <param name="packageDirectory">The directory which the package is installed</param>
/// <returns>True if package is installed, false otherwise</returns>
public static bool IsPackageInstalled(string id, out Package package, out string packageDirectory)
{
package = null;
@ -82,6 +87,11 @@ namespace PMF.Managers
}
}
/// <summary>
/// Uninstalls a package
/// </summary>
/// <param name="id">The id of the package</param>
/// <returns>True if uninstalled correctly, false otherwise</returns>
public static bool RemovePackage(string id)
{
if (string.IsNullOrEmpty(id))
@ -105,8 +115,9 @@ namespace PMF.Managers
/// </summary>
/// <param name="remotePackage">The package which is to be installed</param>
/// <param name="asset">The version of the asset being installed</param>
/// <param name="zipPath"></param>
public static void InstallPackage(Package remotePackage, Asset asset, string zipPath, out Package package)
/// <param name="zipPath">The path to the zip file that is to be installed</param>
/// <returns>The package that was installed</returns>
public static Package InstallPackage(Package remotePackage, Asset asset, string zipPath)
{
ZipFile.ExtractToDirectory(Path.Combine(zipPath, asset.FileName), Path.Combine(Config.PackageInstallationFolder, remotePackage.ID));
@ -116,9 +127,9 @@ namespace PMF.Managers
remotePackage.Assets.Clear();
remotePackage.Assets.Add(asset);
package = remotePackage;
PackageList.Add(remotePackage);
return remotePackage;
}
}
}

View File

@ -15,9 +15,8 @@ namespace PMF.Managers
/// <returns>true Installation successful, false already installed</returns>
public static PackageState InstallPackage(Package package, Asset asset)
{
// If it is not installed, packageDirectory will have the value of the directory where the package should be
string zipFile = RemotePackageManager.DownloadAsset(package.ID, asset);
LocalPackageManager.InstallPackage(package, asset, zipFile, out package);
LocalPackageManager.InstallPackage(package, asset, zipFile);
return PackageState.Installed;
}
@ -26,6 +25,7 @@ namespace PMF.Managers
/// </summary>
/// <param name="id">The id of the package</param>
/// <param name="version">The version of the asset</param>
/// <param name="package">The package that was installed</param>
/// <returns>true Installation successful, false already installed</returns>
public static PackageState Install(string id, Version version, out Package package)
{
@ -45,7 +45,6 @@ namespace PMF.Managers
if (asset == null)
return PackageState.VersionNotFound;
// If it is not installed, packageDirectory will have the value of the directory where the package should be
package = remotePackage;
return InstallPackage(remotePackage, asset);
}
@ -59,7 +58,7 @@ namespace PMF.Managers
/// Installs a package given a version
/// </summary>
/// <param name="id">The id of the package</param>
/// <param name="version">The version of the asset</param>
/// <param name="package">The package that was installed</param>
/// <returns>true Installation successful, false already installed</returns>
public static PackageState InstallLatest(string id, out Package package)
{
@ -79,7 +78,6 @@ namespace PMF.Managers
if (asset == null)
return PackageState.VersionNotFound;
// If it is not installed, packageDirectory will have the value of the directory where the package should be
package = remotePackage;
return InstallPackage(remotePackage, asset);
}
@ -92,7 +90,8 @@ namespace PMF.Managers
/// <summary>
/// Installs a package to the most recent version given an sdk version
/// </summary>
/// <param name="id"></param>
/// <param name="id">The id of the package</param>
/// <param name="package">The package that was installed</param>
/// <returns>true update succes, false update failed or cancelled</returns>
public static PackageState InstallBySdkVersion(string id, out Package package)
{
@ -112,11 +111,15 @@ namespace PMF.Managers
if (asset == null)
return PackageState.VersionNotFound;
// If it is not installed, packageDirectory will have the value of the directory where the package should be
package = remotePackage;
return InstallPackage(remotePackage, asset);
}
/// <summary>
/// Uninstalls a package
/// </summary>
/// <param name="id">The id of the package</param>
/// <returns>True if success, false otherwise</returns>
public static bool Uninstall(string id)
{
return LocalPackageManager.RemovePackage(id);
@ -125,7 +128,8 @@ namespace PMF.Managers
/// <summary>
/// Updates a package to the most recent version regardless of sdk version
/// </summary>
/// <param name="id"></param>
/// <param name="id">The id of the package</param>
/// <param name="package">The package that was installed</param>
/// <returns>true update succes, false update failed or cancelled</returns>
public static PackageState UpdateLatest(string id, out Package package)
{
@ -153,8 +157,9 @@ namespace PMF.Managers
/// <summary>
/// Updates a package to the most recent version regardless of sdk version
/// </summary>
/// <param name="id"></param>
/// <returns>true update succes, false update failed or cancelled</returns>
/// <param name="id">The id of the package</param>
/// <param name="package">The package that was installed</param>
/// <returns>True update success, false update failed or cancelled</returns>
public static PackageState UpdatePackage(string id, Version version, out Package package)
{
package = null;
@ -174,15 +179,18 @@ namespace PMF.Managers
var asset = remotePackage.GetAssetVersion(version);
// We don't want to check here if it was success, we just was to remove the package if it is installed
Uninstall(id);
return InstallPackage(remotePackage, asset);
}
/// <summary>
/// Updates a package to the most recent version given an sdk version
/// </summary>
/// <param name="id"></param>
/// <returns>true if update success, false if package is not installed</returns>
/// <param name="id">The id of the package</param>
/// <param name="package">The package that was installed</param>
/// <returns>True if update success, false if package is not installed</returns>
public static PackageState UpdateBySdkVersion(string id, out Package package)
{
package = null;

View File

@ -12,7 +12,7 @@ namespace PMF.Managers
/// <summary>
/// Gets package info from the server along with ALL the assets in the json
/// </summary>
/// <param name="id"></param>
/// <param name="id">The id of the package</param>
/// <returns>The package object downloaded</returns>
public static Package GetPackageInfo(string id)
{
@ -34,7 +34,8 @@ namespace PMF.Managers
/// <summary>
/// Downloads a specific version of a certain package
/// </summary>
/// <param name="asset"></param>
/// <param name="id">The id of the package</param>
/// <param name="asset">The asset that is to be downloaded</param>
/// <returns>The zip file which was downloaded</returns>
public static string DownloadAsset(string id, Asset asset)
{
@ -52,12 +53,14 @@ namespace PMF.Managers
/// <summary>
/// Gets you the latest version of a package
/// </summary>
/// <param name="package"></param>
/// <param name="package">The package object to get the latest version</param>
/// <returns>The latest asset version of a given package</returns>
public static Asset GetAssetLatestVersion(Package package)
{
if (package == null)
throw new ArgumentNullException();
// Maybe throw a different exception here
if (package.Assets.Count == 0)
throw new ArgumentNullException("asset count");
@ -74,8 +77,7 @@ namespace PMF.Managers
/// <summary>
/// Gets you the latest version of a package given an SDK version
/// </summary>
/// <param name="package"></param>
/// <param name="sdkVersion"></param>
/// <param name="package">The package object to get the asset</param>
/// <returns>The latest asset version of a given package and given SDK version</returns>
public static Asset GetAssetLatestVersionBySdkVersion(Package package)
{

View File

@ -9,18 +9,35 @@ namespace PMF
{
public class Asset
{
// This ensures the version object is correctly converted
[JsonConverter(typeof(VersionConverter))]
/// <summary>
/// The version of this asset
/// </summary>
[JsonConverter(typeof(VersionConverter))] // This ensures the version object is correctly converted
public Version Version { get; set; }
/// <summary>
/// The SDK version that this asset is for
/// </summary>
public string SdkVersion { get; set; }
/// <summary>
/// Checksum //TODO: implement
/// </summary>
public string Checksum { get; set; }
/// <summary>
/// The filename of the asset
/// </summary>
public string FileName { get; set; }
/// <summary>
/// Download link
/// </summary>
public string Url { get; set; }
/// <summary>
/// Dependencies of this asset
/// </summary>
public List<Dependency> Dependencies { get; set; }
}
}

View File

@ -4,14 +4,29 @@ using System.Text;
namespace PMF
{
/// <summary>
/// Files that an asset depends on
/// </summary>
public class Dependency
{
/// <summary>
/// The id of the dependency
/// </summary>
public string ID { get; set; }
/// <summary>
/// Checksum of the dependency // TODO: implement
/// </summary>
public string Checksum { get; set; }
/// <summary>
/// The file name of the dependecy
/// </summary>
public string FileName { get; set; }
/// <summary>
/// Link where the dependecy is located
/// </summary>
public string Url { get; set; }
}
}

View File

@ -9,21 +9,42 @@ namespace PMF
{
public class Package
{
/// <summary>
/// The id of the package
/// </summary>
public string ID { get; set; }
// This converts enum to string and vice versa when generating or parsing json
[JsonConverter(typeof(StringEnumConverter))]
/// <summary>
/// The type of this package
/// </summary>
[JsonConverter(typeof(StringEnumConverter))] // This converts enum to string and vice versa when generating or parsing json
public PackageType Type { get; set; }
/// <summary>
/// The full name of the package
/// </summary>
public string Name { get; set; }
/// <summary>
/// The author of the package
/// </summary>
public string Author { get; set; }
/// <summary>
/// Full description of this package
/// </summary>
public string Description { get; set; }
// If the package is a local one the list will only have one asset which is the version installed
public List<Asset> Assets { get; set; }
/// <summary>
/// List of assets that can be downloaded
/// </summary>
public List<Asset> Assets { get; set; } // If the package is a local one the list will only have one asset which is the version installed
/// <summary>
/// Gets an asset of the package given a version
/// </summary>
/// <param name="version">The version which we want to get</param>
/// <returns>The asset of that version or null</returns>
public Asset GetAssetVersion(Version version)
{
if (version == null)