Update
CurrentSdkVersion is null by default now Adjusted README LocalPackageManager and RemotePackageManager are internal classes now Added checks for initialization in PackageManager
This commit is contained in:
@ -1,7 +1,7 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>netcoreapp2.0</TargetFramework>
|
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||||
|
|
||||||
<IsPackable>false</IsPackable>
|
<IsPackable>false</IsPackable>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
@ -13,4 +13,8 @@
|
|||||||
<PackageReference Include="coverlet.collector" Version="1.2.0" />
|
<PackageReference Include="coverlet.collector" Version="1.2.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\PMF\PMF.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
using PMF.Managers;
|
||||||
using System;
|
using System;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
@ -8,7 +9,11 @@ namespace PMF.Tests
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void Test1()
|
public void Test1()
|
||||||
{
|
{
|
||||||
|
PackageManager.Start();
|
||||||
|
|
||||||
|
// Do stuff
|
||||||
|
|
||||||
|
PackageManager.Stop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -25,7 +25,7 @@ namespace PMF
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// The current SDK version
|
/// The current SDK version
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static string CurrentSdkVersion { get; set; }
|
public static string CurrentSdkVersion { get; set; } = null;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Internal flag to spit out debug info
|
/// Internal flag to spit out debug info
|
||||||
|
|||||||
@ -11,7 +11,7 @@ namespace PMF.Managers
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Manages all the local files
|
/// Manages all the local files
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static class LocalPackageManager
|
internal static class LocalPackageManager
|
||||||
{
|
{
|
||||||
public static List<Package> PackageList { get; private set; }
|
public static List<Package> PackageList { get; private set; }
|
||||||
|
|
||||||
@ -55,7 +55,7 @@ namespace PMF.Managers
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static void validateManifestFile()
|
public static void validateManifestFile()
|
||||||
{
|
{
|
||||||
if (!File.Exists(Config.ManifestFileName))
|
if (!File.Exists(Config.ManifestFileName))
|
||||||
File.Create(Config.ManifestFileName).Close();
|
File.Create(Config.ManifestFileName).Close();
|
||||||
|
|||||||
@ -7,6 +7,30 @@ namespace PMF.Managers
|
|||||||
{
|
{
|
||||||
public static class PackageManager
|
public static class PackageManager
|
||||||
{
|
{
|
||||||
|
private static bool initialized = false;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes the package manager. Required
|
||||||
|
/// </summary>
|
||||||
|
public static void Start()
|
||||||
|
{
|
||||||
|
LocalPackageManager.Start();
|
||||||
|
initialized = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Cleans up package manager. Required
|
||||||
|
/// </summary>
|
||||||
|
public static void Stop()
|
||||||
|
{
|
||||||
|
LocalPackageManager.Stop();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void notInitialized()
|
||||||
|
{
|
||||||
|
Console.WriteLine("You must initialize PMF first before using it");
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Installs a package given a version
|
/// Installs a package given a version
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -15,6 +39,12 @@ 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 (!initialized)
|
||||||
|
{
|
||||||
|
notInitialized();
|
||||||
|
return PackageState.Failed;
|
||||||
|
}
|
||||||
|
|
||||||
string zipFile = RemotePackageManager.DownloadAsset(package.ID, asset);
|
string zipFile = RemotePackageManager.DownloadAsset(package.ID, asset);
|
||||||
LocalPackageManager.InstallPackage(package, asset, zipFile);
|
LocalPackageManager.InstallPackage(package, asset, zipFile);
|
||||||
return PackageState.Installed;
|
return PackageState.Installed;
|
||||||
@ -31,6 +61,12 @@ namespace PMF.Managers
|
|||||||
{
|
{
|
||||||
package = null;
|
package = null;
|
||||||
|
|
||||||
|
if (!initialized)
|
||||||
|
{
|
||||||
|
notInitialized();
|
||||||
|
return PackageState.Failed;
|
||||||
|
}
|
||||||
|
|
||||||
// check if is already installed
|
// check if is already installed
|
||||||
if (!LocalPackageManager.IsPackageInstalled(id, out Package localPackage, out string packageDirectory))
|
if (!LocalPackageManager.IsPackageInstalled(id, out Package localPackage, out string packageDirectory))
|
||||||
{
|
{
|
||||||
@ -64,6 +100,12 @@ namespace PMF.Managers
|
|||||||
{
|
{
|
||||||
package = null;
|
package = null;
|
||||||
|
|
||||||
|
if (!initialized)
|
||||||
|
{
|
||||||
|
notInitialized();
|
||||||
|
return PackageState.Failed;
|
||||||
|
}
|
||||||
|
|
||||||
// check if is already installed
|
// check if is already installed
|
||||||
if (!LocalPackageManager.IsPackageInstalled(id, out Package localPackage, out string packageDirectory))
|
if (!LocalPackageManager.IsPackageInstalled(id, out Package localPackage, out string packageDirectory))
|
||||||
{
|
{
|
||||||
@ -97,6 +139,12 @@ namespace PMF.Managers
|
|||||||
{
|
{
|
||||||
package = null;
|
package = null;
|
||||||
|
|
||||||
|
if (!initialized)
|
||||||
|
{
|
||||||
|
notInitialized();
|
||||||
|
return PackageState.Failed;
|
||||||
|
}
|
||||||
|
|
||||||
// check if is already installed
|
// check if is already installed
|
||||||
if (LocalPackageManager.IsPackageInstalled(id, out Package localPackage, out string packageDirectory))
|
if (LocalPackageManager.IsPackageInstalled(id, out Package localPackage, out string packageDirectory))
|
||||||
return PackageState.AlreadyInstalled;
|
return PackageState.AlreadyInstalled;
|
||||||
@ -122,6 +170,12 @@ namespace PMF.Managers
|
|||||||
/// <returns>True if success, false otherwise</returns>
|
/// <returns>True if success, false otherwise</returns>
|
||||||
public static bool Uninstall(string id)
|
public static bool Uninstall(string id)
|
||||||
{
|
{
|
||||||
|
if (!initialized)
|
||||||
|
{
|
||||||
|
notInitialized();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
return LocalPackageManager.RemovePackage(id);
|
return LocalPackageManager.RemovePackage(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -135,6 +189,12 @@ namespace PMF.Managers
|
|||||||
{
|
{
|
||||||
package = null;
|
package = null;
|
||||||
|
|
||||||
|
if (!initialized)
|
||||||
|
{
|
||||||
|
notInitialized();
|
||||||
|
return PackageState.Failed;
|
||||||
|
}
|
||||||
|
|
||||||
// check if is already installed
|
// check if is already installed
|
||||||
if (!LocalPackageManager.IsPackageInstalled(id, out Package localPackage, out string packageDirectory))
|
if (!LocalPackageManager.IsPackageInstalled(id, out Package localPackage, out string packageDirectory))
|
||||||
return PackageState.NotInstalled;
|
return PackageState.NotInstalled;
|
||||||
@ -164,6 +224,12 @@ namespace PMF.Managers
|
|||||||
{
|
{
|
||||||
package = null;
|
package = null;
|
||||||
|
|
||||||
|
if (!initialized)
|
||||||
|
{
|
||||||
|
notInitialized();
|
||||||
|
return PackageState.Failed;
|
||||||
|
}
|
||||||
|
|
||||||
// check if is already installed
|
// check if is already installed
|
||||||
if (!LocalPackageManager.IsPackageInstalled(id, out Package localPackage, out string packageDirectory))
|
if (!LocalPackageManager.IsPackageInstalled(id, out Package localPackage, out string packageDirectory))
|
||||||
return PackageState.NotInstalled;
|
return PackageState.NotInstalled;
|
||||||
@ -195,6 +261,12 @@ namespace PMF.Managers
|
|||||||
{
|
{
|
||||||
package = null;
|
package = null;
|
||||||
|
|
||||||
|
if (!initialized)
|
||||||
|
{
|
||||||
|
notInitialized();
|
||||||
|
return PackageState.Failed;
|
||||||
|
}
|
||||||
|
|
||||||
if (!LocalPackageManager.IsPackageInstalled(id, out Package localPackage, out string pd))
|
if (!LocalPackageManager.IsPackageInstalled(id, out Package localPackage, out string pd))
|
||||||
return PackageState.NotInstalled;
|
return PackageState.NotInstalled;
|
||||||
|
|
||||||
|
|||||||
@ -7,7 +7,7 @@ using System.Text;
|
|||||||
|
|
||||||
namespace PMF.Managers
|
namespace PMF.Managers
|
||||||
{
|
{
|
||||||
public static class RemotePackageManager
|
internal static class RemotePackageManager
|
||||||
{
|
{
|
||||||
/// <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
|
||||||
|
|||||||
14
README.md
14
README.md
@ -31,11 +31,11 @@ PMF is a barebones C# library that provides basic support for package management
|
|||||||
These functions need to be called at the beggining of the program and at the end, respectively, they handle the manifest.json file that is saved with information regarding packages installed
|
These functions need to be called at the beggining of the program and at the end, respectively, they handle the manifest.json file that is saved with information regarding packages installed
|
||||||
|
|
||||||
```csharp
|
```csharp
|
||||||
LocalPackageManager.Start();
|
PackageManager.Start();
|
||||||
|
|
||||||
// Do stuff
|
// Do stuff
|
||||||
|
|
||||||
LocalPackageManager.Stop();
|
PackageManager.Stop();
|
||||||
```
|
```
|
||||||
|
|
||||||
### Install
|
### Install
|
||||||
@ -88,10 +88,10 @@ public static PackageState UpdateBySdkVersion(string id, out Package package, bo
|
|||||||
|
|
||||||
### Configuration
|
### Configuration
|
||||||
|
|
||||||
Defines the manifest file name, by default is manifest.json
|
Defines the manifest file name
|
||||||
|
|
||||||
```csharp
|
```csharp
|
||||||
string Config.ManifestFileName
|
string Config.ManifestFileName = "manifest.json";
|
||||||
```
|
```
|
||||||
|
|
||||||
Defines the folder where packages are to be installed
|
Defines the folder where packages are to be installed
|
||||||
@ -106,16 +106,16 @@ The http server where you will be sending information about the packages
|
|||||||
string Config.RepositoryEndpoint
|
string Config.RepositoryEndpoint
|
||||||
```
|
```
|
||||||
|
|
||||||
Current SDK version, if you are not using this just use null
|
Current SDK version
|
||||||
|
|
||||||
```csharp
|
```csharp
|
||||||
Version Config.CurrentSdkVersion
|
Version Config.CurrentSdkVersion = null;
|
||||||
```
|
```
|
||||||
|
|
||||||
Temporary folder where zip files will be downloaded to, gets deleted at the end of execution
|
Temporary folder where zip files will be downloaded to, gets deleted at the end of execution
|
||||||
|
|
||||||
```csharp
|
```csharp
|
||||||
string Config.TemporaryFolder
|
string Config.TemporaryFolder = ".pmf-temp";
|
||||||
```
|
```
|
||||||
|
|
||||||
## JSON
|
## JSON
|
||||||
|
|||||||
Reference in New Issue
Block a user