From ac5b76139b8ed61890aad4ef445310c6301f7177 Mon Sep 17 00:00:00 2001 From: xx-TheDoctor-xx Date: Thu, 14 May 2020 16:48:51 +0100 Subject: [PATCH] Removed check in validateManifestFile and added a bunch of comments --- PMF/src/Config.cs | 18 +++++++++++++ PMF/src/Extensions.cs | 11 ++++---- PMF/src/Managers/LocalPackageManager.cs | 25 ++++++++++++------ PMF/src/Managers/PackageManager.cs | 32 +++++++++++++++--------- PMF/src/Managers/RemotePackageManager.cs | 12 +++++---- PMF/src/Package/Asset.cs | 21 ++++++++++++++-- PMF/src/Package/Dependency.cs | 15 +++++++++++ PMF/src/Package/Package.cs | 29 ++++++++++++++++++--- 8 files changed, 128 insertions(+), 35 deletions(-) diff --git a/PMF/src/Config.cs b/PMF/src/Config.cs index 4510afb..31113a1 100644 --- a/PMF/src/Config.cs +++ b/PMF/src/Config.cs @@ -7,16 +7,34 @@ namespace PMF { public static class Config { + /// + /// Manifest file name, the library will look for it in the directory that is being run + /// public static string ManifestFileName { get; set; } = "manifest.json"; + /// + /// Installation folder containing the packages + /// public static string PackageInstallationFolder { get; set; } + /// + /// Repository endpoint for the database of packages + /// public static string RepositoryEndpoint { get; set; } + /// + /// The current SDK version + /// public static string CurrentSdkVersion { get; set; } + /// + /// Internal flag to spit out debug info + /// public static bool IsDebugging { get; set; } + /// + /// Temporary folder where downloads will go to + /// public static string TemporaryFolder { get; set; } = ".pmf-temp"; } } diff --git a/PMF/src/Extensions.cs b/PMF/src/Extensions.cs index a1e2510..506e2f6 100644 --- a/PMF/src/Extensions.cs +++ b/PMF/src/Extensions.cs @@ -10,8 +10,9 @@ namespace PMF /// /// Nice hack to reuse this bit of code very effectively, this method is just used in List where T is Package, otherwise this method doesn't even show up /// - /// - /// + /// This is not an actual parameter + /// The id of the package + /// True if removed, false if not found public static bool Remove(this List list, string id) { for (int i = 0; i < list.Count; i++) @@ -30,9 +31,9 @@ namespace PMF /// /// Same as Remove, but it Retrieves /// - /// - /// - /// + /// This is not an actual parameter + /// The id of the package + /// The package that was retrieved public static Package GetPackage(this List list, string id) { if (id == null || id.Length == 0) diff --git a/PMF/src/Managers/LocalPackageManager.cs b/PMF/src/Managers/LocalPackageManager.cs index ebebe73..745ec45 100644 --- a/PMF/src/Managers/LocalPackageManager.cs +++ b/PMF/src/Managers/LocalPackageManager.cs @@ -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(); } + /// + /// Checks if a given package is installed + /// + /// The id of the package + /// This value is defined if the package exists, its contents will be the actual package + /// The directory which the package is installed + /// True if package is installed, false otherwise public static bool IsPackageInstalled(string id, out Package package, out string packageDirectory) { package = null; @@ -82,6 +87,11 @@ namespace PMF.Managers } } + /// + /// Uninstalls a package + /// + /// The id of the package + /// True if uninstalled correctly, false otherwise public static bool RemovePackage(string id) { if (string.IsNullOrEmpty(id)) @@ -105,8 +115,9 @@ namespace PMF.Managers /// /// The package which is to be installed /// The version of the asset being installed - /// - public static void InstallPackage(Package remotePackage, Asset asset, string zipPath, out Package package) + /// The path to the zip file that is to be installed + /// The package that was installed + 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; } } } diff --git a/PMF/src/Managers/PackageManager.cs b/PMF/src/Managers/PackageManager.cs index 20cdb33..f4ecbc1 100644 --- a/PMF/src/Managers/PackageManager.cs +++ b/PMF/src/Managers/PackageManager.cs @@ -15,9 +15,8 @@ namespace PMF.Managers /// true Installation successful, false already installed 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 /// /// The id of the package /// The version of the asset + /// The package that was installed /// true Installation successful, false already installed 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 /// /// The id of the package - /// The version of the asset + /// The package that was installed /// true Installation successful, false already installed 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 /// /// Installs a package to the most recent version given an sdk version /// - /// + /// The id of the package + /// The package that was installed /// true update succes, false update failed or cancelled 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); } + /// + /// Uninstalls a package + /// + /// The id of the package + /// True if success, false otherwise public static bool Uninstall(string id) { return LocalPackageManager.RemovePackage(id); @@ -125,7 +128,8 @@ namespace PMF.Managers /// /// Updates a package to the most recent version regardless of sdk version /// - /// + /// The id of the package + /// The package that was installed /// true update succes, false update failed or cancelled public static PackageState UpdateLatest(string id, out Package package) { @@ -153,8 +157,9 @@ namespace PMF.Managers /// /// Updates a package to the most recent version regardless of sdk version /// - /// - /// true update succes, false update failed or cancelled + /// The id of the package + /// The package that was installed + /// True update success, false update failed or cancelled 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); } /// /// Updates a package to the most recent version given an sdk version /// - /// - /// true if update success, false if package is not installed + /// The id of the package + /// The package that was installed + /// True if update success, false if package is not installed public static PackageState UpdateBySdkVersion(string id, out Package package) { package = null; diff --git a/PMF/src/Managers/RemotePackageManager.cs b/PMF/src/Managers/RemotePackageManager.cs index 3b24e0c..a32657d 100644 --- a/PMF/src/Managers/RemotePackageManager.cs +++ b/PMF/src/Managers/RemotePackageManager.cs @@ -12,7 +12,7 @@ namespace PMF.Managers /// /// Gets package info from the server along with ALL the assets in the json /// - /// + /// The id of the package /// The package object downloaded public static Package GetPackageInfo(string id) { @@ -34,7 +34,8 @@ namespace PMF.Managers /// /// Downloads a specific version of a certain package /// - /// + /// The id of the package + /// The asset that is to be downloaded /// The zip file which was downloaded public static string DownloadAsset(string id, Asset asset) { @@ -52,12 +53,14 @@ namespace PMF.Managers /// /// Gets you the latest version of a package /// - /// + /// The package object to get the latest version /// The latest asset version of a given package 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 /// /// Gets you the latest version of a package given an SDK version /// - /// - /// + /// The package object to get the asset /// The latest asset version of a given package and given SDK version public static Asset GetAssetLatestVersionBySdkVersion(Package package) { diff --git a/PMF/src/Package/Asset.cs b/PMF/src/Package/Asset.cs index 5f163ea..fb3fa7b 100644 --- a/PMF/src/Package/Asset.cs +++ b/PMF/src/Package/Asset.cs @@ -9,18 +9,35 @@ namespace PMF { public class Asset { - // This ensures the version object is correctly converted - [JsonConverter(typeof(VersionConverter))] + /// + /// The version of this asset + /// + [JsonConverter(typeof(VersionConverter))] // This ensures the version object is correctly converted public Version Version { get; set; } + /// + /// The SDK version that this asset is for + /// public string SdkVersion { get; set; } + /// + /// Checksum //TODO: implement + /// public string Checksum { get; set; } + /// + /// The filename of the asset + /// public string FileName { get; set; } + /// + /// Download link + /// public string Url { get; set; } + /// + /// Dependencies of this asset + /// public List Dependencies { get; set; } } } diff --git a/PMF/src/Package/Dependency.cs b/PMF/src/Package/Dependency.cs index 66d5c96..2585510 100644 --- a/PMF/src/Package/Dependency.cs +++ b/PMF/src/Package/Dependency.cs @@ -4,14 +4,29 @@ using System.Text; namespace PMF { + /// + /// Files that an asset depends on + /// public class Dependency { + /// + /// The id of the dependency + /// public string ID { get; set; } + /// + /// Checksum of the dependency // TODO: implement + /// public string Checksum { get; set; } + /// + /// The file name of the dependecy + /// public string FileName { get; set; } + /// + /// Link where the dependecy is located + /// public string Url { get; set; } } } diff --git a/PMF/src/Package/Package.cs b/PMF/src/Package/Package.cs index 90e5421..d1be4f7 100644 --- a/PMF/src/Package/Package.cs +++ b/PMF/src/Package/Package.cs @@ -9,21 +9,42 @@ namespace PMF { public class Package { + /// + /// The id of the package + /// public string ID { get; set; } - // This converts enum to string and vice versa when generating or parsing json - [JsonConverter(typeof(StringEnumConverter))] + /// + /// The type of this package + /// + [JsonConverter(typeof(StringEnumConverter))] // This converts enum to string and vice versa when generating or parsing json public PackageType Type { get; set; } + /// + /// The full name of the package + /// public string Name { get; set; } + /// + /// The author of the package + /// public string Author { get; set; } + /// + /// Full description of this package + /// 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 Assets { get; set; } + /// + /// List of assets that can be downloaded + /// + public List Assets { get; set; } // If the package is a local one the list will only have one asset which is the version installed + /// + /// Gets an asset of the package given a version + /// + /// The version which we want to get + /// The asset of that version or null public Asset GetAssetVersion(Version version) { if (version == null)