Skip to content

Commit

Permalink
isolated functionality so we can in the future separate this into Cor…
Browse files Browse the repository at this point in the history
…e, Command Line Interface, and Editor Plugin
  • Loading branch information
ericoporto committed Jan 25, 2020
1 parent 88fa28b commit 7863bfb
Show file tree
Hide file tree
Showing 11 changed files with 251 additions and 177 deletions.
2 changes: 1 addition & 1 deletion agsget/agsget/.editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ indent_style = space
[*.{cs,csx,vb,vbx}]
indent_size = 4
insert_final_newline = true
charset = utf-8-bom
charset = utf-8
###############################
# .NET Coding Conventions #
###############################
Expand Down
95 changes: 3 additions & 92 deletions agsget/agsget/Apply/ApplyCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,101 +10,12 @@ class ApplyCommand : Command
// Inserts a package from package cache into an AGS Game Project. If package not in cache, downloads it.
public static int Run(ApplyOptions ApplyOptions)
{
BaseFiles.SetRunDirectory(ApplyOptions.changeRunDir);

//1. If no PACKAGE_NAME is provided, exit with error.
// maybe the required keyword protects and we don't need this
if (string.IsNullOrEmpty(ApplyOptions.PackageName) == true)
{
Console.WriteLine("No Package Specified, will do nothing.");
return 1;
}

//2. Check if the command is run from a folder containing a valid Game.agf project. If not, exit with error.
if (!GameAgfIO.Valid())
{
Console.WriteLine("Not an AGS Game root directory.");
Console.WriteLine("You can only get packages for an AGS Game project.");
return 1;
}

//3. Check if AGS Editor is open by looking for a lockfile in the folder, if it is, exit with error.
if (GameAgfIO.IsProjectOpenOnAGSEditor())
{
Console.WriteLine("AGS Editor is open on project file.");
Console.WriteLine("Close AGS Editor, and try again.");
return 1;
}

//4. Check if a package index exists on `./ ags_packages_cache / package_index`,
// if not, it runs the functionality from `agsget update`.
if(!BaseFiles.ExistsIndexFile())
{
//Update.2.If it is, creates a folder `./ ags_packages_cache /` on the directory if it doesn't exist.
BaseFiles.CreatePackageDirIfDoesntExist();

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

//5. Check if PACKAGE_NAME exists on `./ ags_packages_cache / PACKAGE_NAME`,
// if not, exit with error Download PACKAGE_NAME to `./ ags_packages_cache / PACKAGE_NAME`.
//6.If download doesn't complete, exit with error.
if (!PackageCacheIO.IsPackageOnLocalCache(ApplyOptions.PackageName))
{
//Get.4. Check if PACKAGE_NAME exists on `./ ags_packages_cache / package_index`, if not, exit with error.
if (!PackageCacheIO.PackageOnIndex(ApplyOptions.PackageName))
{
Console.WriteLine("Package {0} not found on package index.", ApplyOptions.PackageName);
Console.WriteLine("If you are sure you spelled correctly, try updating your local package index.");
return 1;
}

//Get.5. Download PACKAGE_NAME to `./ags_packages_cache/PACKAGE_NAME`.
if (!PackageCacheIO.GetPackage(
Configuration.PackageIndexURL,
ApplyOptions.PackageName))
{
Console.WriteLine("Error downloading package {0}.", ApplyOptions.PackageName);
return 1;
}
}


//7.Check if a script pair with the same name already exists on Game.agf,
// if there is, ask about update, if the answer is no, exit with error.
if (GameAgfIO.IsScriptPairInserted(ApplyOptions.PackageName))
{
Console.WriteLine("Script already found on Game.agf.");
if (!ConsoleExtra.ConfirmYN("Are you sure you want to replace?"))
{
Console.WriteLine("Package already inserted and will not be replaced.");
return 1;
}
}

//8.Check if script pairs with the same name of dependencies already exists on Game.agf,
// and if they are above insert position, if they are not, exit with error.

//9.If dependencies are already the in Game.agf, ask the user if he
//wants to proceed, if not, exit with error.

//10.Insert or replace the script and dependencies in Game.agf, and
// copy(or overwrite) script pairs in the project folder.


Console.WriteLine("NOT IMPLEMENTED YET");
Console.WriteLine("Install Package: '{0}'", ApplyOptions.PackageName);

if (string.IsNullOrEmpty(ApplyOptions.PackageName) == true)
if (ApplyOptions == null)
{
Console.WriteLine("No Package Specified, will do nothing.");
return 1;
throw new ArgumentNullException(nameof(ApplyOptions));
}

Console.WriteLine();
return 0;
return ApplyDo.Do(ApplyOptions.changeRunDir, ApplyOptions.PackageName);
}
}
}
106 changes: 106 additions & 0 deletions agsget/agsget/Apply/ApplyDo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
using System;

namespace agsget
{
public class ApplyDo
{
public static int Do(string changeRunDir, string packageName)
{
BaseFiles.SetRunDirectory(changeRunDir);

//1. If no PACKAGE_NAME is provided, exit with error.
// maybe the required keyword protects and we don't need this
if (string.IsNullOrEmpty(packageName) == true)
{
Console.WriteLine("No Package Specified, will do nothing.");
return 1;
}

//2. Check if the command is run from a folder containing a valid Game.agf project. If not, exit with error.
if (!GameAgfIO.Valid())
{
Console.WriteLine("Not an AGS Game root directory.");
Console.WriteLine("You can only get packages for an AGS Game project.");
return 1;
}

//3. Check if AGS Editor is open by looking for a lockfile in the folder, if it is, exit with error.
if (GameAgfIO.IsProjectOpenOnAGSEditor())
{
Console.WriteLine("AGS Editor is open on project file.");
Console.WriteLine("Close AGS Editor, and try again.");
return 1;
}

//4. Check if a package index exists on `./ ags_packages_cache / package_index`,
// if not, it runs the functionality from `agsget update`.
if(!BaseFiles.ExistsIndexFile())
{
//Update.2.If it is, creates a folder `./ ags_packages_cache /` on the directory if it doesn't exist.
BaseFiles.CreatePackageDirIfDoesntExist();

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

//5. Check if PACKAGE_NAME exists on `./ ags_packages_cache / PACKAGE_NAME`,
// if not, exit with error Download PACKAGE_NAME to `./ ags_packages_cache / PACKAGE_NAME`.
//6.If download doesn't complete, exit with error.
if (!PackageCacheIO.IsPackageOnLocalCache(packageName))
{
//Get.4. Check if PACKAGE_NAME exists on `./ ags_packages_cache / package_index`, if not, exit with error.
if (!PackageCacheIO.PackageOnIndex(packageName))
{
Console.WriteLine("Package {0} not found on package index.", packageName);
Console.WriteLine("If you are sure you spelled correctly, try updating your local package index.");
return 1;
}

//Get.5. Download PACKAGE_NAME to `./ags_packages_cache/PACKAGE_NAME`.
if (!PackageCacheIO.GetPackage(
Configuration.PackageIndexURL,
packageName))
{
Console.WriteLine("Error downloading package {0}.", packageName);
return 1;
}
}


//7.Check if a script pair with the same name already exists on Game.agf,
// if there is, ask about update, if the answer is no, exit with error.
if (GameAgfIO.IsScriptPairInserted(packageName))
{
Console.WriteLine("Script already found on Game.agf.");
if (!ConsoleExtra.ConfirmYN("Are you sure you want to replace?"))
{
Console.WriteLine("Package already inserted and will not be replaced.");
return 1;
}
}

//8.Check if script pairs with the same name of dependencies already exists on Game.agf,
// and if they are above insert position, if they are not, exit with error.

//9.If dependencies are already the in Game.agf, ask the user if he
//wants to proceed, if not, exit with error.

//10.Insert or replace the script and dependencies in Game.agf, and
// copy(or overwrite) script pairs in the project folder.


Console.WriteLine("NOT IMPLEMENTED YET");
Console.WriteLine("Install Package: '{0}'", packageName);

if (string.IsNullOrEmpty(packageName) == true)
{
Console.WriteLine("No Package Specified, will do nothing.");
return 1;
}

Console.WriteLine();
return 0;
}
}
}
47 changes: 3 additions & 44 deletions agsget/agsget/Get/GetCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,53 +9,12 @@ class GetCommand : Command
// Downloads a package to package cache.
public static int Run(GetOptions GetOptions)
{
BaseFiles.SetRunDirectory(GetOptions.changeRunDir);

//1. If no PACKAGE_NAME is provided, exit with error.
// maybe the required keyword protects and we don't need this
if (string.IsNullOrEmpty(GetOptions.PackageName) == true)
{
Console.WriteLine("No Package Specified, will do nothing.");
return 1;
}

//2. Check if the command is run from a folder containing a valid Game.agf project. If not, exit with error.
if (!GameAgfIO.Valid())
{
Console.WriteLine("Not an AGS Game root directory.");
Console.WriteLine("You can only get packages for an AGS Game project.");
return 1;
}

//3. Check if a package index exists on `./ags_packages_cache/package_index`, if not, it runs the functionality from `agsget update`.
if(!BaseFiles.ExistsIndexFile())
{
//Update.2.If it is, creates a folder `./ ags_packages_cache /` on the directory if it doesn't exist.
BaseFiles.CreatePackageDirIfDoesntExist();

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

//4.Check if PACKAGE_NAME exists on `./ ags_packages_cache / package_index`, if not, exit with error.
if (!PackageCacheIO.PackageOnIndex(GetOptions.PackageName))
{
Console.WriteLine("Package {0} not found on package index.", GetOptions.PackageName);
Console.WriteLine("If you are sure you spelled correctly, try updating your local package index.");
return 1;
}

//5. Download PACKAGE_NAME to `./ags_packages_cache/PACKAGE_NAME`.
if(!PackageCacheIO.GetPackage(
Configuration.PackageIndexURL,
GetOptions.PackageName))
if (GetOptions == null)
{
Console.WriteLine("Error downloading package {0}.", GetOptions.PackageName);
return 1;
throw new ArgumentNullException(nameof(GetOptions));
}

return 0;
return GetDo.Do(GetOptions.changeRunDir, GetOptions.PackageName);
}
}
}
58 changes: 58 additions & 0 deletions agsget/agsget/Get/GetDo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
using System;

namespace agsget
{
public class GetDo
{
public static int Do(string changeRunDir, string packageName)
{
BaseFiles.SetRunDirectory(changeRunDir);

//1. If no PACKAGE_NAME is provided, exit with error.
// maybe the required keyword protects and we don't need this
if (string.IsNullOrEmpty(packageName) == true)
{
Console.WriteLine("No Package Specified, will do nothing.");
return 1;
}

//2. Check if the command is run from a folder containing a valid Game.agf project. If not, exit with error.
if (!GameAgfIO.Valid())
{
Console.WriteLine("Not an AGS Game root directory.");
Console.WriteLine("You can only get packages for an AGS Game project.");
return 1;
}

//3. Check if a package index exists on `./ags_packages_cache/package_index`, if not, it runs the functionality from `agsget update`.
if(!BaseFiles.ExistsIndexFile())
{
//Update.2.If it is, creates a folder `./ ags_packages_cache /` on the directory if it doesn't exist.
BaseFiles.CreatePackageDirIfDoesntExist();

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

//4.Check if PACKAGE_NAME exists on `./ ags_packages_cache / package_index`, if not, exit with error.
if (!PackageCacheIO.PackageOnIndex(packageName))
{
Console.WriteLine("Package {0} not found on package index.", packageName);
Console.WriteLine("If you are sure you spelled correctly, try updating your local package index.");
return 1;
}

//5. Download PACKAGE_NAME to `./ags_packages_cache/PACKAGE_NAME`.
if(!PackageCacheIO.GetPackage(
Configuration.PackageIndexURL,
packageName))
{
Console.WriteLine("Error downloading package {0}.", packageName);
return 1;
}

return 0;
}
}
}
12 changes: 1 addition & 11 deletions agsget/agsget/Pack/PackCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,7 @@ class PackCommand : Command
{
public static int RunPackCommand(PackOptions PackOptions)
{
Console.WriteLine("NOT IMPLEMENTED YET");
Console.WriteLine("Create Package: '{0}'", PackOptions.PairName);

if (string.IsNullOrEmpty(PackOptions.PairName) == true)
{
Console.WriteLine("No Script Pair Name Specified, will do nothing.");
return 1;
}

Console.WriteLine();
return 0;
return PackDo.Do(PackOptions.changeRunDir, PackOptions.PairName);
}
}
}
22 changes: 22 additions & 0 deletions agsget/agsget/Pack/PackDo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System;

namespace agsget
{
public class PackDo
{
public static int Do(string changeRunDir, string pairName)
{
Console.WriteLine("NOT IMPLEMENTED YET");
Console.WriteLine("Create Package: '{0}'", pairName);

if (string.IsNullOrEmpty(pairName) == true)
{
Console.WriteLine("No Script Pair Name Specified, will do nothing.");
return 1;
}

Console.WriteLine();
return 0;
}
}
}
12 changes: 1 addition & 11 deletions agsget/agsget/Search/SearchCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,7 @@ class SearchCommand : Command
{
public static int Run(SearchOptions SearchOptions)
{
Console.WriteLine("NOT IMPLEMENTED YET");
Console.WriteLine("Search query: '{0}'", SearchOptions.SearchQuery);

if (string.IsNullOrEmpty(SearchOptions.SearchQuery) == true)
{
Console.WriteLine("No query to use for search.");
return 1;
}

Console.WriteLine();
return 0;
return SearchDo.Do(SearchOptions.changeRunDir, SearchOptions.SearchQuery);
}
}
}
Loading

0 comments on commit 7863bfb

Please sign in to comment.