Esempio n. 1
0
        public static ValidationResult Validate(FrameworkElement element, string path, bool isOptional)
        {
            DirectoryMustExistsRule rule   = new DirectoryMustExistsRule(isOptional);
            ValidationResult        result = rule.Validate(path, CultureInfo.CurrentCulture);

            ValidationHelper.SetInvalid(element, result);
            return(result);
        }
Esempio n. 2
0
        public bool Check()
        {
            if (!DirectoryMustExistsRule.Validate(GameDirectoryControl, GameDirectoryControl.Path, false).IsValid)
            {
                return(false);
            }
            if (!DirectoryMustExistsRule.Validate(WorkingDirectoryControl, WorkingDirectoryControl.Path, false).IsValid)
            {
                return(false);
            }
            if (!DirectoryMustExistsRule.Validate(CVSDirectoryControl, CVSDirectoryControl.Path, true).IsValid)
            {
                return(false);
            }

            return(true);
        }
Esempio n. 3
0
        /// <summary>
        /// This method is being invoked during initialization.
        /// </summary>
        /// <param name="provider">Provides access to the bound items.</param>
        /// <returns>The binding expression that is created by
        /// the base class.</returns>
        public override object ProvideValue(IServiceProvider provider)
        {
            ValidationRule rule;

            switch (Rule)
            {
            case CustomRule.DirectoryMustExists:
                rule = new DirectoryMustExistsRule(false);
                break;

            case CustomRule.EmptyOrDirectoryMustExists:
                rule = new DirectoryMustExistsRule(true);
                break;

            default:
                rule = new ExceptionValidationRule();
                break;
            }

            Binding.ValidationRules.Add(rule);
            return(base.ProvideValue(provider));
        }
Esempio n. 4
0
        private ValidationResult ValidateGameDirectory()
        {
            try
            {
                string gameDirectoryPath = GameDirectoryControl.Path;

                ValidationResult result = DirectoryMustExistsRule.Validate(GameDirectoryControl, gameDirectoryPath, false);
                if (!result.IsValid)
                {
                    return(result);
                }

                string[] executables = Directory.GetFiles(gameDirectoryPath, Options.GameExecutableMask);
                if (executables.All(file => !Regex.IsMatch(file, Options.GameExecutablesExpression)))
                {
                    result = new ValidationResult(false, String.Format(Lang.ErrorFileNotFoundFormat, Options.GameExecutableMask));
                    ValidationHelper.SetInvalid(GameDirectoryControl, result);
                    return(result);
                }

                string dataDirectoryPath = Path.Combine(gameDirectoryPath, Options.GameDataDirectoryName);

                result = DirectoryMustExistsRule.Validate(GameDirectoryControl, dataDirectoryPath, false);
                if (!result.IsValid)
                {
                    return(result);
                }

                FileMustExistsRule fileMustExistsRule = new FileMustExistsRule(false);

                foreach (string archiveName in Options.GameArchivesNames)
                {
                    string archivePath = Path.Combine(dataDirectoryPath, archiveName);

                    result = fileMustExistsRule.Validate(Path.ChangeExtension(archivePath, ".fs"), CultureInfo.CurrentCulture);
                    if (!result.IsValid)
                    {
                        break;
                    }

                    result = fileMustExistsRule.Validate(Path.ChangeExtension(archivePath, ".fi"), CultureInfo.CurrentCulture);
                    if (!result.IsValid)
                    {
                        break;
                    }

                    result = fileMustExistsRule.Validate(Path.ChangeExtension(archivePath, ".fl"), CultureInfo.CurrentCulture);
                    if (!result.IsValid)
                    {
                        break;
                    }
                }

                return(result);
            }
            catch (Exception ex)
            {
                Log.Error(ex);
                ValidationResult result = new ValidationResult(false, ex.GetBaseException().Message);
                ValidationHelper.SetInvalid(GameDirectoryControl, result);
                return(result);
            }
        }
Esempio n. 5
0
 private ValidationResult ValidateCVSDirectory()
 {
     return(DirectoryMustExistsRule.Validate(CVSDirectoryControl, CVSDirectoryControl.Path, true));
 }
Esempio n. 6
0
 private ValidationResult ValidateWorkingDirectory()
 {
     return(DirectoryMustExistsRule.Validate(WorkingDirectoryControl, WorkingDirectoryControl.Path, false));
 }