diff --git a/agsget/agsget/.editorconfig b/agsget/agsget/.editorconfig index 5b4c441..d5d6f9d 100644 --- a/agsget/agsget/.editorconfig +++ b/agsget/agsget/.editorconfig @@ -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 # ############################### diff --git a/agsget/agsget/Apply/ApplyCommand.cs b/agsget/agsget/Apply/ApplyCommand.cs index e0bea71..0173a27 100644 --- a/agsget/agsget/Apply/ApplyCommand.cs +++ b/agsget/agsget/Apply/ApplyCommand.cs @@ -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); } } } diff --git a/agsget/agsget/Apply/ApplyDo.cs b/agsget/agsget/Apply/ApplyDo.cs new file mode 100644 index 0000000..c442244 --- /dev/null +++ b/agsget/agsget/Apply/ApplyDo.cs @@ -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; + } + } +} diff --git a/agsget/agsget/Get/GetCommand.cs b/agsget/agsget/Get/GetCommand.cs index e31d5c9..8dee103 100644 --- a/agsget/agsget/Get/GetCommand.cs +++ b/agsget/agsget/Get/GetCommand.cs @@ -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); } } } diff --git a/agsget/agsget/Get/GetDo.cs b/agsget/agsget/Get/GetDo.cs new file mode 100644 index 0000000..19a735d --- /dev/null +++ b/agsget/agsget/Get/GetDo.cs @@ -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; + } + } +} diff --git a/agsget/agsget/Pack/PackCommand.cs b/agsget/agsget/Pack/PackCommand.cs index 49a6102..9c4b1f8 100644 --- a/agsget/agsget/Pack/PackCommand.cs +++ b/agsget/agsget/Pack/PackCommand.cs @@ -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); } } } diff --git a/agsget/agsget/Pack/PackDo.cs b/agsget/agsget/Pack/PackDo.cs new file mode 100644 index 0000000..cf228bc --- /dev/null +++ b/agsget/agsget/Pack/PackDo.cs @@ -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; + } + } +} diff --git a/agsget/agsget/Search/SearchCommand.cs b/agsget/agsget/Search/SearchCommand.cs index ce6305f..4c8e99e 100644 --- a/agsget/agsget/Search/SearchCommand.cs +++ b/agsget/agsget/Search/SearchCommand.cs @@ -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); } } } diff --git a/agsget/agsget/Search/SearchDo.cs b/agsget/agsget/Search/SearchDo.cs new file mode 100644 index 0000000..0324fd5 --- /dev/null +++ b/agsget/agsget/Search/SearchDo.cs @@ -0,0 +1,22 @@ +using System; + +namespace agsget +{ + public class SearchDo + { + public static int Do(string changeRunDir, string searchQuery) + { + Console.WriteLine("NOT IMPLEMENTED YET"); + Console.WriteLine("Search query: '{0}'", searchQuery); + + if (string.IsNullOrEmpty(searchQuery) == true) + { + Console.WriteLine("No query to use for search."); + return 1; + } + + Console.WriteLine(); + return 0; + } + } +} diff --git a/agsget/agsget/Update/UpdateCommand.cs b/agsget/agsget/Update/UpdateCommand.cs index ceaface..f5f7d85 100644 --- a/agsget/agsget/Update/UpdateCommand.cs +++ b/agsget/agsget/Update/UpdateCommand.cs @@ -12,24 +12,7 @@ class UpdateCommand : Command //to a general option available for all commands, but not sure yet public static int Run(UpdateOptions UpdateOptions) { - BaseFiles.SetRunDirectory(UpdateOptions.changeRunDir); - //1. Checks if the command is run from a folder containing a valid Game.agf project. - if (!GameAgfIO.Valid()) - { - Console.WriteLine("Not an AGS Game root directory."); - Console.WriteLine("You can only update agsget package cache for an AGS Game project."); - return 1; - } - - //2.If it is, creates a folder `./ ags_packages_cache /` on the directory if it doesn't exist. - BaseFiles.CreatePackageDirIfDoesntExist(); - - //3.Downloads the index of packages to `./ ags_packages_cache / package_index`. - //If it already exists, overwrites it. - PackageCacheIO.GetPackageIndex(UpdateOptions.PackageIndexURL); - - Console.WriteLine("Success."); - return 0; + return UpdateDo.Do(UpdateOptions.changeRunDir, UpdateOptions.PackageIndexURL); } } } diff --git a/agsget/agsget/Update/UpdateDo.cs b/agsget/agsget/Update/UpdateDo.cs new file mode 100644 index 0000000..379b7c2 --- /dev/null +++ b/agsget/agsget/Update/UpdateDo.cs @@ -0,0 +1,33 @@ +using System; + +namespace agsget +{ + public class UpdateDo + { + // If an INDEX_URL is provided, use the provided url for download operations. + // Otherwise, use default package index url. + // I think maybe the url should be moved + //to a general option available for all commands, but not sure yet + public static int Do(string changeRunDir, string packageIndexURL) + { + BaseFiles.SetRunDirectory(changeRunDir); + //1. Checks if the command is run from a folder containing a valid Game.agf project. + if (!GameAgfIO.Valid()) + { + Console.WriteLine("Not an AGS Game root directory."); + Console.WriteLine("You can only update agsget package cache for an AGS Game project."); + return 1; + } + + //2.If it is, creates a folder `./ ags_packages_cache /` on the directory if it doesn't exist. + BaseFiles.CreatePackageDirIfDoesntExist(); + + //3.Downloads the index of packages to `./ ags_packages_cache / package_index`. + //If it already exists, overwrites it. + PackageCacheIO.GetPackageIndex(packageIndexURL); + + Console.WriteLine("Success."); + return 0; + } + } +}