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 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"; public static string ManifestFileName { get; set; } = "manifest.json";
/// <summary>
/// Installation folder containing the packages
/// </summary>
public static string PackageInstallationFolder { get; set; } public static string PackageInstallationFolder { get; set; }
/// <summary>
/// Repository endpoint for the database of packages
/// </summary>
public static string RepositoryEndpoint { get; set; } public static string RepositoryEndpoint { get; set; }
/// <summary>
/// The current SDK version
/// </summary>
public static string CurrentSdkVersion { get; set; } public static string CurrentSdkVersion { get; set; }
/// <summary>
/// Internal flag to spit out debug info
/// </summary>
public static bool IsDebugging { get; set; } public static bool IsDebugging { get; set; }
/// <summary>
/// Temporary folder where downloads will go to
/// </summary>
public static string TemporaryFolder { get; set; } = ".pmf-temp"; public static string TemporaryFolder { get; set; } = ".pmf-temp";
} }
} }

View File

@ -10,8 +10,9 @@ namespace PMF
/// <summary> /// <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 /// 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> /// </summary>
/// <param name="list"></param> /// <param name="list">This is not an actual parameter</param>
/// <param name="id"></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) public static bool Remove(this List<Package> list, string id)
{ {
for (int i = 0; i < list.Count; i++) for (int i = 0; i < list.Count; i++)
@ -30,9 +31,9 @@ namespace PMF
/// <summary> /// <summary>
/// Same as Remove, but it Retrieves /// Same as Remove, but it Retrieves
/// </summary> /// </summary>
/// <param name="list"></param> /// <param name="list">This is not an actual parameter</param>
/// <param name="id"></param> /// <param name="id">The id of the package</param>
/// <returns></returns> /// <returns>The package that was retrieved</returns>
public static Package GetPackage(this List<Package> list, string id) public static Package GetPackage(this List<Package> list, string id)
{ {
if (id == null || id.Length == 0) 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)) if (!File.Exists(Config.ManifestFileName))
File.Create(Config.ManifestFileName).Close(); 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) public static bool IsPackageInstalled(string id, out Package package, out string packageDirectory)
{ {
package = null; 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) public static bool RemovePackage(string id)
{ {
if (string.IsNullOrEmpty(id)) if (string.IsNullOrEmpty(id))
@ -105,8 +115,9 @@ namespace PMF.Managers
/// </summary> /// </summary>
/// <param name="remotePackage">The package which is to be installed</param> /// <param name="remotePackage">The package which is to be installed</param>
/// <param name="asset">The version of the asset being installed</param> /// <param name="asset">The version of the asset being installed</param>
/// <param name="zipPath"></param> /// <param name="zipPath">The path to the zip file that is to be installed</param>
public static void InstallPackage(Package remotePackage, Asset asset, string zipPath, out Package package) /// <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)); 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.Clear();
remotePackage.Assets.Add(asset); remotePackage.Assets.Add(asset);
package = remotePackage;
PackageList.Add(remotePackage); PackageList.Add(remotePackage);
return remotePackage;
} }
} }
} }

View File

@ -15,9 +15,8 @@ namespace PMF.Managers
/// <returns>true Installation successful, false already installed</returns> /// <returns>true Installation successful, false already installed</returns>
public static PackageState InstallPackage(Package package, Asset asset) 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); string zipFile = RemotePackageManager.DownloadAsset(package.ID, asset);
LocalPackageManager.InstallPackage(package, asset, zipFile, out package); LocalPackageManager.InstallPackage(package, asset, zipFile);
return PackageState.Installed; return PackageState.Installed;
} }
@ -26,6 +25,7 @@ namespace PMF.Managers
/// </summary> /// </summary>
/// <param name="id">The id of the package</param> /// <param name="id">The id of the package</param>
/// <param name="version">The version of the asset</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> /// <returns>true Installation successful, false already installed</returns>
public static PackageState Install(string id, Version version, out Package package) public static PackageState Install(string id, Version version, out Package package)
{ {
@ -45,7 +45,6 @@ namespace PMF.Managers
if (asset == null) if (asset == null)
return PackageState.VersionNotFound; return PackageState.VersionNotFound;
// 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);
} }
@ -59,7 +58,7 @@ namespace PMF.Managers
/// Installs a package given a version /// Installs a package given a version
/// </summary> /// </summary>
/// <param name="id">The id of the package</param> /// <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> /// <returns>true Installation successful, false already installed</returns>
public static PackageState InstallLatest(string id, out Package package) public static PackageState InstallLatest(string id, out Package package)
{ {
@ -79,7 +78,6 @@ namespace PMF.Managers
if (asset == null) if (asset == null)
return PackageState.VersionNotFound; return PackageState.VersionNotFound;
// 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);
} }
@ -92,7 +90,8 @@ namespace PMF.Managers
/// <summary> /// <summary>
/// Installs a package to the most recent version given an sdk version /// Installs a package to the most recent version given an sdk version
/// </summary> /// </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> /// <returns>true update succes, false update failed or cancelled</returns>
public static PackageState InstallBySdkVersion(string id, out Package package) public static PackageState InstallBySdkVersion(string id, out Package package)
{ {
@ -112,11 +111,15 @@ namespace PMF.Managers
if (asset == null) if (asset == null)
return PackageState.VersionNotFound; return PackageState.VersionNotFound;
// 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);
} }
/// <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) public static bool Uninstall(string id)
{ {
return LocalPackageManager.RemovePackage(id); return LocalPackageManager.RemovePackage(id);
@ -125,7 +128,8 @@ namespace PMF.Managers
/// <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>
/// <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> /// <returns>true update succes, false update failed or cancelled</returns>
public static PackageState UpdateLatest(string id, out Package package) public static PackageState UpdateLatest(string id, out Package package)
{ {
@ -153,8 +157,9 @@ namespace PMF.Managers
/// <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>
/// <param name="id"></param> /// <param name="id">The id of the package</param>
/// <returns>true update succes, false update failed or cancelled</returns> /// <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) public static PackageState UpdatePackage(string id, Version version, out Package package)
{ {
package = null; package = null;
@ -174,15 +179,18 @@ namespace PMF.Managers
var asset = remotePackage.GetAssetVersion(version); 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); Uninstall(id);
return InstallPackage(remotePackage, asset); return InstallPackage(remotePackage, asset);
} }
/// <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">The id of the package</param>
/// <returns>true if update success, false if package is not installed</returns> /// <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) public static PackageState UpdateBySdkVersion(string id, out Package package)
{ {
package = null; package = null;

View File

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

View File

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

View File

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

View File

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