Skip to content

Commit

Permalink
a bit convoluted but got a core and a console interface.
Browse files Browse the repository at this point in the history
  • Loading branch information
ericoporto committed Jan 26, 2020
1 parent 155e394 commit 513b98a
Show file tree
Hide file tree
Showing 18 changed files with 75 additions and 35 deletions.
2 changes: 1 addition & 1 deletion agsget/agsget/CommandLine/Apply/ApplyCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public static int Run(ApplyOptions ApplyOptions)
throw new ArgumentNullException(nameof(ApplyOptions));
}

return ApplyDo.Do(Console.WriteLine, ApplyOptions.changeRunDir, ApplyOptions.PackageName);
return AgsGetCore.AgsGetCore.Apply(Console.WriteLine, ApplyOptions.changeRunDir, ApplyOptions.PackageName);
}
}
}
2 changes: 1 addition & 1 deletion agsget/agsget/CommandLine/Get/GetCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public static int Run(GetOptions GetOptions)
throw new ArgumentNullException(nameof(GetOptions));
}

return GetDo.Do(Console.WriteLine, GetOptions.changeRunDir, GetOptions.PackageName);
return AgsGetCore.AgsGetCore.Get(Console.WriteLine, GetOptions.changeRunDir, GetOptions.PackageName);
}
}
}
2 changes: 1 addition & 1 deletion agsget/agsget/CommandLine/Pack/PackCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class PackCommand : Command
{
public static int RunPackCommand(PackOptions PackOptions)
{
return PackDo.Do(Console.WriteLine, PackOptions.changeRunDir, PackOptions.PairName);
return AgsGetCore.AgsGetCore.Pack(Console.WriteLine, PackOptions.changeRunDir, PackOptions.PairName);
}
}
}
2 changes: 1 addition & 1 deletion agsget/agsget/CommandLine/Search/SearchCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class SearchCommand : Command
{
public static int Run(SearchOptions SearchOptions)
{
return SearchDo.Do(Console.WriteLine, SearchOptions.changeRunDir, SearchOptions.SearchQuery);
return AgsGetCore.AgsGetCore.Search(Console.WriteLine, SearchOptions.changeRunDir, SearchOptions.SearchQuery);
}
}
}
2 changes: 1 addition & 1 deletion agsget/agsget/CommandLine/Update/UpdateCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class UpdateCommand : Command
//to a general option available for all commands, but not sure yet
public static int Run(UpdateOptions UpdateOptions)
{
return UpdateDo.Do(Console.WriteLine, UpdateOptions.changeRunDir, UpdateOptions.PackageIndexURL);
return AgsGetCore.AgsGetCore.Update(Console.WriteLine, UpdateOptions.changeRunDir, UpdateOptions.PackageIndexURL);
}
}
}
7 changes: 5 additions & 2 deletions agsget/agsget/Core/Actions/ApplyDo.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;

namespace agsget
namespace AgsGetCore.Actions
{
public class ApplyDo
{
Expand Down Expand Up @@ -41,7 +41,7 @@ public static int Do(Action<string> writerMethod, string changeRunDir, string pa

//Update.3.Downloads the index of packages to `./ ags_packages_cache / package_index`.
//If it already exists, overwrites it.
PackageCacheIO.GetPackageIndex(null);
PackageCacheIO.GetPackageIndex(writerMethod, null);
}

//5. Check if PACKAGE_NAME exists on `./ ags_packages_cache / PACKAGE_NAME`,
Expand All @@ -59,6 +59,7 @@ public static int Do(Action<string> writerMethod, string changeRunDir, string pa

//Get.5. Download PACKAGE_NAME to `./ags_packages_cache/PACKAGE_NAME`.
if (!PackageCacheIO.GetPackage(
writerMethod,
Configuration.PackageIndexURL,
packageName))
{
Expand All @@ -73,6 +74,8 @@ public static int Do(Action<string> writerMethod, string changeRunDir, string pa
if (GameAgfIO.IsScriptPairInserted(packageName))
{
Console.WriteLine("Script already found on Game.agf.");

//TODO: This question must be console on console or a callback to an yes/no GUI, need to figure out how
if (!ConsoleExtra.ConfirmYN("Are you sure you want to replace?"))
{
writerMethod("Package already inserted and will not be replaced.");
Expand Down
5 changes: 3 additions & 2 deletions agsget/agsget/Core/Actions/GetDo.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;

namespace agsget
namespace AgsGetCore.Actions
{
public class GetDo
{
Expand Down Expand Up @@ -32,7 +32,7 @@ public static int Do(Action<string> writerMethod, string changeRunDir, string pa

//Update.3.Downloads the index of packages to `./ ags_packages_cache / package_index`.
//If it already exists, overwrites it.
PackageCacheIO.GetPackageIndex(null);
PackageCacheIO.GetPackageIndex(writerMethod, null);
}

//4.Check if PACKAGE_NAME exists on `./ ags_packages_cache / package_index`, if not, exit with error.
Expand All @@ -45,6 +45,7 @@ public static int Do(Action<string> writerMethod, string changeRunDir, string pa

//5. Download PACKAGE_NAME to `./ags_packages_cache/PACKAGE_NAME`.
if(!PackageCacheIO.GetPackage(
writerMethod,
Configuration.PackageIndexURL,
packageName))
{
Expand Down
2 changes: 1 addition & 1 deletion agsget/agsget/Core/Actions/PackDo.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;

namespace agsget
namespace AgsGetCore.Actions
{
public class PackDo
{
Expand Down
2 changes: 1 addition & 1 deletion agsget/agsget/Core/Actions/SearchDo.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;

namespace agsget
namespace AgsGetCore.Actions
{
public class SearchDo
{
Expand Down
4 changes: 2 additions & 2 deletions agsget/agsget/Core/Actions/UpdateDo.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;

namespace agsget
namespace AgsGetCore.Actions
{
public class UpdateDo
{
Expand All @@ -24,7 +24,7 @@ public static int Do(Action<string> writerMethod, string changeRunDir, string pa

//3.Downloads the index of packages to `./ ags_packages_cache / package_index`.
//If it already exists, overwrites it.
PackageCacheIO.GetPackageIndex(packageIndexURL);
PackageCacheIO.GetPackageIndex(writerMethod, packageIndexURL);

writerMethod("Success.");
return 0;
Expand Down
36 changes: 36 additions & 0 deletions agsget/agsget/Core/AgsGetCore.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System;
using System.Collections.Generic;
using System.Text;

using AgsGetCore.Actions;
namespace AgsGetCore
{
class AgsGetCore
{
public static int Apply(Action<string> writerMethod, string changeRunDir, string packageName)
{

return ApplyDo.Do(writerMethod, changeRunDir, packageName);
}

public static int Get(Action<string> writerMethod, string changeRunDir, string packageName)
{
return GetDo.Do(writerMethod, changeRunDir, packageName);
}

public static int Pack(Action<string> writerMethod, string changeRunDir, string pairName)
{
return PackDo.Do(writerMethod, changeRunDir, pairName);
}

public static int Search(Action<string> writerMethod, string changeRunDir, string searchQuery)
{
return SearchDo.Do(writerMethod, changeRunDir, searchQuery);
}

public static int Update(Action<string> writerMethod, string changeRunDir, string packageIndexURL)
{
return UpdateDo.Do(writerMethod, changeRunDir, packageIndexURL);
}
}
}
4 changes: 2 additions & 2 deletions agsget/agsget/Core/BaseFiles.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using System;
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;


namespace agsget
namespace AgsGetCore
{
public class BaseFiles
{
Expand Down
4 changes: 2 additions & 2 deletions agsget/agsget/Core/Configuration.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using System;
using System;
using System.Collections.Generic;
using System.Text;

namespace agsget
namespace AgsGetCore
{
class Configuration
{
Expand Down
4 changes: 2 additions & 2 deletions agsget/agsget/Core/GameAgfIO.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using System;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Linq;
using System.Xml.Linq;

namespace agsget
namespace AgsGetCore
{
//I think I may need to refactor this for GameProjectIO
public class GameAgfIO
Expand Down
14 changes: 7 additions & 7 deletions agsget/agsget/Core/PackageCacheIO.cs
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
using System;
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace agsget
namespace AgsGetCore
{
// This class should be the interface when interacting with the package cache
// some commands are distributed on BaseFiles, maybe they need to be here and not there?
public class PackageCacheIO
{
public static void GetPackageIndex(string packageIndexUrl)
public static void GetPackageIndex(Action<string> writerMethod, string packageIndexUrl)
{
if (string.IsNullOrEmpty(packageIndexUrl))
{
DownloadPretty.File(Configuration.PackageIndexURL + "index/package_index.json", BaseFiles.GetIndexFilePath());
DownloadPretty.File(writerMethod, Configuration.PackageIndexURL + "index/package_index.json", BaseFiles.GetIndexFilePath());
}
else
{
DownloadPretty.File(packageIndexUrl + "index/package_index.json", BaseFiles.GetIndexFilePath());
DownloadPretty.File(writerMethod, packageIndexUrl + "index/package_index.json", BaseFiles.GetIndexFilePath());
}
}

Expand Down Expand Up @@ -52,7 +52,7 @@ public static bool IsPackageOnLocalCache(string packageName)
return File.Exists(scriptModuleFile);
}

public static bool GetPackage(string packageIndexUrl, string packageName)
public static bool GetPackage(Action<string> writerMethod, string packageIndexUrl, string packageName)
{
var packageDirPath = Path.Combine(BaseFiles.GetCacheDirectoryPath(), packageName);

Expand All @@ -67,7 +67,7 @@ public static bool GetPackage(string packageIndexUrl, string packageName)
// for the package.
var destinationFile = Path.Combine(packageDirPath, packageName + ".scm");

if (!DownloadPretty.File(
if (!DownloadPretty.File(writerMethod,
packageIndexUrl + "pkgs/" + packageName + "/" + packageName + ".scm",
destinationFile))
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using System;
using System;
using System.Collections.Generic;
using System.Text;

namespace agsget
namespace AgsGetCore
{
public class ConsoleExtra
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
using System;
using System;
using System.Collections.Generic;
using System.Text;
using System.Net;

namespace agsget
namespace AgsGetCore
{
public class DownloadPretty
{
public static bool File(string url, string filename) {
public static bool File(Action<string> writerMethod, string url, string filename) {
var webClient = new WebClient();

Console.WriteLine("Will download from:"+ url);
writerMethod("Will download from:"+ url);

webClient.DownloadFileTaskAsync(
new Uri(url),
filename,
new Progress<Tuple<long, int, long>>(t =>
{
Console.Write($"\r({t.Item2,25:#,###}) Bytes received: {t.Item1,25:#,###}/{t.Item3,25:#,###}" );
writerMethod(string.Format($"\r({t.Item2,25:#,###}) Bytes received: {t.Item1,25:#,###}/{t.Item3,25:#,###}" ));
// Console.WriteLine($@"
// Bytes received: {t.Item1,25:#,###}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using System;
using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.ComponentModel;
using System.Threading.Tasks;

namespace agsget
namespace AgsGetCore
{
public static class WebClientExtensios
{
Expand Down

0 comments on commit 513b98a

Please sign in to comment.