Minor bug fixes
This commit is contained in:
@ -20,17 +20,9 @@ namespace PMF.Managers
|
|||||||
public static void Start()
|
public static void Start()
|
||||||
{
|
{
|
||||||
validateManifestFile();
|
validateManifestFile();
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var json = File.ReadAllText(Config.ManifestFileName);
|
var json = File.ReadAllText(Config.ManifestFileName);
|
||||||
PackageManager.PackageList = JsonConvert.DeserializeObject<List<Package>>(json);
|
PackageManager.PackageList = JsonConvert.DeserializeObject<List<Package>>(json);
|
||||||
}
|
}
|
||||||
catch (FileNotFoundException)
|
|
||||||
{
|
|
||||||
// Something failed with validateManifestFile()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Saves everything to disk
|
/// Saves everything to disk
|
||||||
@ -41,17 +33,9 @@ namespace PMF.Managers
|
|||||||
validateManifestFile();
|
validateManifestFile();
|
||||||
|
|
||||||
var json = JsonConvert.SerializeObject(PackageManager.PackageList);
|
var json = JsonConvert.SerializeObject(PackageManager.PackageList);
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
File.WriteAllText(Config.ManifestFileName, json);
|
File.WriteAllText(Config.ManifestFileName, json);
|
||||||
Directory.Delete(Config.TemporaryFolder, true);
|
Directory.Delete(Config.TemporaryFolder, true);
|
||||||
}
|
}
|
||||||
catch (IOException)
|
|
||||||
{
|
|
||||||
// Something failed with validateManifestFile()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void validateManifestFile()
|
public static void validateManifestFile()
|
||||||
{
|
{
|
||||||
|
|||||||
@ -5,6 +5,10 @@ using System.Text;
|
|||||||
|
|
||||||
namespace PMF.Managers
|
namespace PMF.Managers
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Global Package manager for PMF
|
||||||
|
/// Combines RemotePackageManager and LocalPackageManager
|
||||||
|
/// </summary>
|
||||||
public static class PackageManager
|
public static class PackageManager
|
||||||
{
|
{
|
||||||
public static List<Package> PackageList { get; internal set; }
|
public static List<Package> PackageList { get; internal set; }
|
||||||
@ -15,9 +19,21 @@ namespace PMF.Managers
|
|||||||
/// Initializes the package manager. Required
|
/// Initializes the package manager. Required
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static void Start()
|
public static void Start()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (!initialized)
|
||||||
{
|
{
|
||||||
LocalPackageManager.Start();
|
LocalPackageManager.Start();
|
||||||
initialized = true;
|
initialized = true;
|
||||||
|
Console.WriteLine("PMF intialized succesfully");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Console.Error.WriteLine($"PMF failed to initialize. \n${ex.InnerException.Message}\nClosing.");
|
||||||
|
Environment.Exit(0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -25,12 +41,21 @@ namespace PMF.Managers
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public static void Stop()
|
public static void Stop()
|
||||||
{
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (initialized)
|
||||||
LocalPackageManager.Stop();
|
LocalPackageManager.Stop();
|
||||||
}
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Console.Error.WriteLine($"Something failed while cleaning up PMF - \n{ex.InnerException.Message}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static void notInitialized()
|
private static void notInitialized()
|
||||||
{
|
{
|
||||||
Console.WriteLine("You must initialize PMF first before using it");
|
Console.WriteLine("You must initialize PMF first before using it.\nClosing");
|
||||||
|
Environment.Exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -42,10 +67,7 @@ namespace PMF.Managers
|
|||||||
public static PackageState InstallPackage(Package package, Asset asset)
|
public static PackageState InstallPackage(Package package, Asset asset)
|
||||||
{
|
{
|
||||||
if (!initialized)
|
if (!initialized)
|
||||||
{
|
|
||||||
notInitialized();
|
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);
|
||||||
@ -64,15 +86,11 @@ namespace PMF.Managers
|
|||||||
package = null;
|
package = null;
|
||||||
|
|
||||||
if (!initialized)
|
if (!initialized)
|
||||||
{
|
|
||||||
notInitialized();
|
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))
|
||||||
{
|
{
|
||||||
// get package info for version
|
|
||||||
Package remotePackage = RemotePackageManager.GetPackageInfo(id);
|
Package remotePackage = RemotePackageManager.GetPackageInfo(id);
|
||||||
|
|
||||||
if (remotePackage == null)
|
if (remotePackage == null)
|
||||||
@ -103,10 +121,7 @@ namespace PMF.Managers
|
|||||||
package = null;
|
package = null;
|
||||||
|
|
||||||
if (!initialized)
|
if (!initialized)
|
||||||
{
|
|
||||||
notInitialized();
|
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))
|
||||||
@ -142,10 +157,7 @@ namespace PMF.Managers
|
|||||||
package = null;
|
package = null;
|
||||||
|
|
||||||
if (!initialized)
|
if (!initialized)
|
||||||
{
|
|
||||||
notInitialized();
|
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))
|
||||||
@ -173,10 +185,7 @@ namespace PMF.Managers
|
|||||||
public static bool Uninstall(string id)
|
public static bool Uninstall(string id)
|
||||||
{
|
{
|
||||||
if (!initialized)
|
if (!initialized)
|
||||||
{
|
|
||||||
notInitialized();
|
notInitialized();
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return LocalPackageManager.RemovePackage(id);
|
return LocalPackageManager.RemovePackage(id);
|
||||||
}
|
}
|
||||||
@ -192,10 +201,7 @@ namespace PMF.Managers
|
|||||||
package = null;
|
package = null;
|
||||||
|
|
||||||
if (!initialized)
|
if (!initialized)
|
||||||
{
|
|
||||||
notInitialized();
|
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))
|
||||||
@ -227,10 +233,7 @@ namespace PMF.Managers
|
|||||||
package = null;
|
package = null;
|
||||||
|
|
||||||
if (!initialized)
|
if (!initialized)
|
||||||
{
|
|
||||||
notInitialized();
|
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))
|
||||||
@ -264,10 +267,7 @@ namespace PMF.Managers
|
|||||||
package = null;
|
package = null;
|
||||||
|
|
||||||
if (!initialized)
|
if (!initialized)
|
||||||
{
|
|
||||||
notInitialized();
|
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;
|
||||||
|
|||||||
@ -16,6 +16,7 @@ namespace PMF
|
|||||||
NotExisting,
|
NotExisting,
|
||||||
VersionNotFound,
|
VersionNotFound,
|
||||||
|
|
||||||
|
// Common
|
||||||
Failed
|
Failed
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
using PMF.Exceptions;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
@ -42,7 +43,6 @@ namespace PMF.Managers
|
|||||||
using (WebClient client = new WebClient())
|
using (WebClient client = new WebClient())
|
||||||
{
|
{
|
||||||
var zipPath = Path.Combine(Config.TemporaryFolder, id);
|
var zipPath = Path.Combine(Config.TemporaryFolder, id);
|
||||||
Directory.CreateDirectory(zipPath);
|
|
||||||
client.DownloadFile(asset.Url, Path.Combine(zipPath, asset.FileName));
|
client.DownloadFile(asset.Url, Path.Combine(zipPath, asset.FileName));
|
||||||
foreach (var dependency in asset.Dependencies)
|
foreach (var dependency in asset.Dependencies)
|
||||||
client.DownloadFile(dependency.Url, Path.Combine(zipPath, dependency.FileName));
|
client.DownloadFile(dependency.Url, Path.Combine(zipPath, dependency.FileName));
|
||||||
@ -60,9 +60,8 @@ namespace PMF.Managers
|
|||||||
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");
|
return null;
|
||||||
|
|
||||||
Asset ret_asset = null;
|
Asset ret_asset = null;
|
||||||
foreach (var asset in package.Assets)
|
foreach (var asset in package.Assets)
|
||||||
@ -84,7 +83,7 @@ namespace PMF.Managers
|
|||||||
if (package == null)
|
if (package == null)
|
||||||
throw new ArgumentNullException();
|
throw new ArgumentNullException();
|
||||||
if (package.Assets.Count == 0)
|
if (package.Assets.Count == 0)
|
||||||
throw new ArgumentNullException("asset count");
|
return null;
|
||||||
|
|
||||||
Asset ret_asset = null;
|
Asset ret_asset = null;
|
||||||
foreach (var asset in package.Assets)
|
foreach (var asset in package.Assets)
|
||||||
|
|||||||
@ -7,6 +7,9 @@ using System.Text;
|
|||||||
|
|
||||||
namespace PMF
|
namespace PMF
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Asset version of a Package
|
||||||
|
/// </summary>
|
||||||
public class Asset
|
public class Asset
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user