Skip to content

Commit

Permalink
change my mind on where the files should go
Browse files Browse the repository at this point in the history
  • Loading branch information
ItsMajestiX committed Apr 15, 2019
1 parent 0ddae19 commit 5bb7a66
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 27 deletions.
6 changes: 3 additions & 3 deletions ServerModManager/Commands/Install.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ private static async Task GetFile(Package package, PackageOverview overview, Val
bool incompat = false;
foreach (string i in package.incompatibilities)
{
if (overview.DoesPackageExist(i))
if (PackageUtil.DoesPackageExist(overview.GetPackageWithName(i)))
{
Console.WriteLine("WARNING: " + package.name + " is incompatiable with " + i + ", skipping.");
incompat = true;
Expand All @@ -28,14 +28,14 @@ private static async Task GetFile(Package package, PackageOverview overview, Val
if (!incompat)
{
//Check if file already exists
if (!overview.DoesPackageExist(package))
if (!PackageUtil.DoesPackageExist(package))
{
using (WebClient client = new WebClient())
{
//Setup loading bar
client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(LoadingBar.DownloadProgressCallback);
//Download file to directory after checking if the folders exist
if (Directory.Exists(Path.GetDirectoryName("../sm_plugins/" + package.downloadLocation)))
if (PackageUtil.DoesDirectoryExist(package))
{
await client.DownloadFileTaskAsync(package.downloadLink, "../sm_plugins/" + package.downloadLocation);
}
Expand Down
6 changes: 3 additions & 3 deletions ServerModManager/Commands/Remover.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ class Remover
private static void Remove(Package package, Validator val, PackageOverview overview)
{
//Check if it exists.
if (overview.DoesPackageExist(package))
if (PackageUtil.DoesPackageExist(package))
{
Console.WriteLine("Removing package " + package.name);
//Remove
if (Directory.Exists(Path.GetDirectoryName("../sm_plugins/" + package.downloadLocation)))
if (PackageUtil.DoesDirectoryExist(package))
{
File.Delete("../sm_plugins/" + package.downloadLocation);
}
Expand All @@ -34,7 +34,7 @@ public static void RemovePackages(Validator val, PackageOverview overview)
foreach (Package i in overview.packages)
{
//It's redundant, but prevents spamming errors.
if (overview.DoesPackageExist(i))
if (PackageUtil.DoesPackageExist(i))
{
Remove(i, val, overview);
}
Expand Down
4 changes: 2 additions & 2 deletions ServerModManager/Commands/Updater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public static void Update(Package package, Validator val, PackageOverview overvi
using (WebClient client = new WebClient())
{
//Check if it exists
if (overview.DoesPackageExist(package))
if (PackageUtil.DoesPackageExist(package))
{
string filename = Path.GetFileName(package.downloadLocation);
Console.WriteLine("Getting newest version of package " + package.name);
Expand Down Expand Up @@ -46,7 +46,7 @@ public static void UpdatePackages(Validator val, PackageOverview overview)
{
foreach (Package i in overview.packages)
{
if (File.Exists("../sm_plugins/" + i.downloadLocation))
if (PackageUtil.DoesPackageExist(i))
{
Update(i, val, overview);
}
Expand Down
18 changes: 0 additions & 18 deletions ServerModManager/Package/PackageOverview.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,24 +45,6 @@ public Package GetPackageWithName(string name)
return null;
}

public bool DoesPackageExist(Package package)
{
if (File.Exists("../sm_plugins/" + package.downloadLocation))
{
return true;
}
return false;
}

public bool DoesPackageExist(String name)
{
if (File.Exists("../sm_plugins/" + GetPackageWithName(name).downloadLocation))
{
return true;
}
return false;
}

//So the main method doesn't have to use async and to catch errors.
public bool GenPackages()
{
Expand Down
2 changes: 1 addition & 1 deletion ServerModManager/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"profiles": {
"ServerModManager": {
"commandName": "Project",
"commandLineArgs": "remove *"
"commandLineArgs": "update smod2"
}
}
}
10 changes: 10 additions & 0 deletions ServerModManager/Util/PackageUtil.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System.IO;

namespace ServerModManager
{
class PackageUtil
{
public static bool DoesPackageExist(Package package) => File.Exists("../sm_plugins/" + package.downloadLocation);
public static bool DoesDirectoryExist(Package package) => Directory.Exists(Path.GetDirectoryName("../sm_plugins/" + package.downloadLocation));
}
}

0 comments on commit 5bb7a66

Please sign in to comment.