2020-04-19 05:37:29 +00:00
using System ;
using System.Collections.Generic ;
using System.IO ;
using System.Linq ;
using System.Text ;
using System.Threading.Tasks ;
using McMaster.Extensions.CommandLineUtils ;
using McMaster.Extensions.CommandLineUtils.Validation ;
using System.ComponentModel.DataAnnotations ;
2020-04-23 08:16:16 +00:00
using HeliosPlus.Shared ;
2020-04-27 10:55:44 +00:00
using HeliosPlus.GameLibraries ;
2020-05-17 09:19:55 +00:00
using System.Text.RegularExpressions ;
using System.ServiceModel.Dispatcher ;
2020-04-19 05:37:29 +00:00
2020-04-23 08:16:16 +00:00
namespace HeliosPlus
2020-04-19 05:37:29 +00:00
{
2020-11-22 08:27:29 +00:00
class ProfileMustExistValidator : IArgumentValidator
2020-04-19 05:37:29 +00:00
{
2020-11-22 08:27:29 +00:00
public ValidationResult GetValidationResult ( CommandArgument argumentProfileName , ValidationContext context )
2020-04-19 05:37:29 +00:00
{
// This validator only runs if there is a value
2020-11-22 08:27:29 +00:00
if ( argumentProfileName . Value = = "" ) return ValidationResult . Success ;
var profileName = ( string ) argumentProfileName . Value ;
2020-04-19 05:37:29 +00:00
2020-07-21 11:40:33 +00:00
// Try to find the Profile Name
if ( ! ProfileRepository . ContainsProfile ( profileName ) )
2020-04-19 05:37:29 +00:00
{
2020-07-21 11:40:33 +00:00
return new ValidationResult ( $"Couldn't find Profile Name or ID supplied via command line: '{profileName}'. Please check the Profile Name or ID you supplied on the command line is correct." ) ;
2020-04-19 05:37:29 +00:00
}
2020-07-21 11:40:33 +00:00
ProfileItem profile = ProfileRepository . GetProfile ( profileName ) ;
Console . WriteLine ( $"Using Profile: '{profile.Name}' (ID:{profile.UUID})" ) ;
2020-04-19 05:37:29 +00:00
return ValidationResult . Success ;
}
}
2020-05-17 09:19:55 +00:00
class ShortcutMustExistValidator : IArgumentValidator
{
public ValidationResult GetValidationResult ( CommandArgument argumentShortcutName , ValidationContext context )
{
// This validator only runs if there is a string provided
if ( argumentShortcutName . Value = = "" ) return ValidationResult . Success ;
2020-07-21 11:40:33 +00:00
string shortcutName = ( string ) argumentShortcutName . Value ;
2020-05-17 09:19:55 +00:00
2020-07-21 11:40:33 +00:00
// Check if the UUID or ShortcutName are provided
if ( ! ShortcutRepository . ContainsShortcut ( shortcutName ) )
2020-05-17 09:19:55 +00:00
{
return new ValidationResult ( $"Couldn't find Shortcut Name supplied via command line: '{shortcutName}'. Please check the Shortcut Name you supplied on the command line is correct." ) ;
}
2020-07-21 11:40:33 +00:00
ShortcutItem shortcut = ShortcutRepository . GetShortcut ( shortcutName ) ;
Console . WriteLine ( $"Using Shortcut: '{shortcut.Name}' (ID: {shortcut.UUID})" ) ;
2020-05-17 09:19:55 +00:00
return ValidationResult . Success ;
}
}
2020-04-19 05:37:29 +00:00
class FileOptionMustExistValidator : IOptionValidator
{
public ValidationResult GetValidationResult ( CommandOption optionFullFileName , ValidationContext context )
{
// This validator only runs if there is a string provided
if ( optionFullFileName . Value ( ) = = "" ) return ValidationResult . Success ;
var fileNameAndPath = optionFullFileName . Value ( ) ;
// Check that the file exists
if ( ! File . Exists ( fileNameAndPath ) )
{
return new ValidationResult ( $"Couldn't find the file '{optionFullFileName.Value()}' supplied to '{optionFullFileName.LongName}'. Please check you specified the full path to the file on the command line." ) ;
}
return ValidationResult . Success ;
}
}
class FileArgumentMustExistValidator : IArgumentValidator
{
public ValidationResult GetValidationResult ( CommandArgument argumentFullFileName , ValidationContext context )
{
// This validator only runs if there is a string provided
if ( argumentFullFileName . Value = = "" ) return ValidationResult . Success ;
var fileNameAndPath = argumentFullFileName . Value ;
// Check that the file exists
if ( ! File . Exists ( fileNameAndPath ) )
{
return new ValidationResult ( $"Couldn't find the file '{argumentFullFileName.Value}' supplied to '{argumentFullFileName.Name}'. Please check you specified the full path to the file on the command line." ) ;
}
return ValidationResult . Success ;
}
}
}