Esempio n. 1
0
        public int CompareTo(object obj)
        {
            //Only of use in Testing.
            TSSTEntry x = obj as TSSTEntry;

            if (x == null)
            {
                return(-1);
            }
            int Result = OptionFlags.CompareTo(x.OptionFlags);

            if (Result != 0)
            {
                return(Result);
            }
            Result = Data.CompareTo(x.Data);
            if (Result != 0)
            {
                return(Result);
            }
            Result = BitOps.CompareMemOrdinal(RichTextFormats, x.RichTextFormats);
            if (Result != 0)
            {
                return(Result);
            }
            Result = BitOps.CompareMemOrdinal(x.FarEastData, x.FarEastData);
            if (Result != 0)
            {
                return(Result);
            }
            return(0);
        }
Esempio n. 2
0
        public void get_overworld_sprites_seed_0()
        {
            Randomization r = new Randomization();
            OptionFlags   o = new OptionFlags()
            {
                RandomizeBosses  = true,
                RandomizeEnemies = true,
                GenerateSpoilers = true
            };

            FileStream fs = new FileStream("alttp - VT_no-glitches-26_normal_open_none_830270265.sfc", FileMode.Open, FileAccess.Read);

            byte[] rom_data = new byte[fs.Length];
            fs.Read(rom_data, 0, (int)fs.Length);
            fs.Close();

            RomData romData = new RomData(rom_data);

            romData = r.MakeRandomization("", 0, o, romData, "");

            //var romData = Utilities.LoadRom("rando.sfc");

            OverworldAreaCollection areas = new OverworldAreaCollection(romData, new Random(), new SpriteGroupCollection(romData, new Random(), new SpriteRequirementCollection()), new SpriteRequirementCollection());

            foreach (var owArea in areas.OverworldAreas)
            {
                output.WriteLine($"Map: {owArea.AreaId.ToString("X3")} ({owArea.AreaName})\tGraphics Block: {owArea.GraphicsBlockId} ({owArea.GraphicsBlockAddress.ToString("X4")})");

                foreach (var s in owArea.Sprites)
                {
                    output.WriteLine($"Address: {s.SpriteAddress.ToString("X6")}\tSpriteId: {s.SpriteId.ToString("X2")}\t{SpriteConstants.GetSpriteName(s.SpriteId)}\tX: {s.SpriteX}\tY: {s.SpriteY}\tOverlord: {(s.SpriteId >= 0xF3 ? true : false).ToString()}");
                }
            }
        }
Esempio n. 3
0
 /// <summary>
 /// </summary>
 /// <param name="parent"> </param>
 public Option(IContentContainer parent)
 {
     _parent = parent;
     _parent.Items.Add(this);
     _isGlobalVariable = false;
     _flags = OptionFlags.None;
 }
Esempio n. 4
0
        ///////////////////////////////////////////////////////////////////////

        public bool HasFlags(
            OptionFlags flags,
            bool all
            )
        {
            return(FlagOps.HasFlags(this.flags, flags, all));
        }
Esempio n. 5
0
        //[InlineData("")]
        //[InlineData("")]
        //[InlineData("")]
        public void randomize_test_roms_10_times_each_chaos(string filename)
        {
            if (false == File.Exists(filename))
            {
                output.WriteLine($"File {filename} not found. Skipping test.");
                return;
            }

            byte[] rom_data = LoadRom(filename);

            Random rand = new Random(0);

            OptionFlags options = MakeOptions();

            options.EnemiesAbsorbable   = true;
            options.RandomizeBosses     = true;
            options.RandomizeBossesType = RandomizeBossesType.Chaos;

            Randomization randomizer = new Randomization();

            for (int i = 0; i < 10; i++)
            {
                RomData romData = new RomData(rom_data);
                randomizer.MakeRandomization("", rand.Next(), options, romData);
            }
        }
Esempio n. 6
0
        static List <PatchObject> GenerateSeed(int seed, byte[] rom_data, OptionFlags optionFlags)
        {
            RomData       romData       = new RomData(rom_data);
            Randomization randomize     = new Randomization();
            RomData       randomizedRom = randomize.MakeRandomization("", seed, optionFlags, romData, "");

            return(randomizedRom.GeneratePatch());
        }
Esempio n. 7
0
        private static RomData RandomizeRom(int seed, byte[] rom_data, OptionFlags optionFlags)
        {
            RomData       romData       = new RomData(rom_data);
            Randomization randomize     = new Randomization();
            RomData       randomizedRom = randomize.MakeRandomization("", seed, optionFlags, romData, "");

            return(randomizedRom);
        }
Esempio n. 8
0
        ///////////////////////////////////////////////////////////////////////

        #region Static "Factory" Methods
        private static IEnumerable <IOption> CreateSystemOptions(
            )
        {
            OptionFlags flags = OptionFlags.System;

            return(new IOption[] {
                new Option(null, flags | OptionFlags.ListOfOptions,
                           Index.Invalid, Index.Invalid, Option.ListOfOptions, null),
            });
        }
Esempio n. 9
0
        static byte[] GenerateRom(int seed, byte[] rom_data, OptionFlags optionFlags)
        {
            RomData randomizedRom = RandomizeRom(seed, rom_data, optionFlags);

            var romfs = new MemoryStream();

            randomizedRom.WriteRom(romfs);
            romfs.Flush();

            var romBytes = romfs.ToArray();

            return(romBytes);
        }
Esempio n. 10
0
        ///////////////////////////////////////////////////////////////////////

        public static bool HasFlags(
            OptionFlags flags,
            OptionFlags hasFlags,
            bool all
            )
        {
            if (all)
            {
                return((flags & hasFlags) == hasFlags);
            }
            else
            {
                return((flags & hasFlags) != OptionFlags.None);
            }
        }
Esempio n. 11
0
        public void randomize_100_seeds_in_memory()
        {
            byte[] rom_data = LoadRom("rando.sfc");

            Random rand = new Random(0);

            OptionFlags options = MakeOptions();

            Randomization randomizer = new Randomization();

            for (int i = 0; i < 100; i++)
            {
                RomData romData = new RomData(rom_data);
                randomizer.MakeRandomization("", rand.Next(), options, romData);
            }
        }
Esempio n. 12
0
        /// <summary>
        /// Unite the git repository index file paths with the same case the OS is using
        /// </summary>
        /// <param name = "gitPath">
        ///   The path to the git repository to open, can be either the path to the git directory (for non-bare repositories this
        ///   would be the ".git" folder inside the working directory) or the path to the working directory.
        /// </param>
        /// <param name="options">Runtime command line options specified</param>
        public static void Process(string gitPath, OptionFlags options)
        {
            var gitPathInfo = new DirectoryInfo(gitPath);

            using (var repo = new UniteRepository(gitPathInfo.FullName, options))
            {
                // Build a list of directory names as seen by the host operating system
                var folders = repo.GetHostDirectoryInfo(gitPathInfo);

                if(options.HasFlag(OptionFlags.UniteDirectories))
                    repo.UniteFolderCasing(folders);

                if (options.HasFlag(OptionFlags.UniteFiles))
                    repo.UniteFilenameCasing(gitPathInfo, folders);
            }
        }
Esempio n. 13
0
        ///////////////////////////////////////////////////////////////////////

        #region Public Constructors
        public Option(
            Type type,
            OptionFlags flags,
            int groupIndex,
            int index,
            string name,
            Variant value
            )
        {
            this.kind        = IdentifierKind.Option;
            this.name        = name;
            this.description = null;
            this.clientData  = null;
            this.type        = type;
            this.flags       = flags;
            this.groupIndex  = groupIndex;
            this.index       = index;
            this.value       = value;
        }
Esempio n. 14
0
        ///////////////////////////////////////////////////////////////////////

        public void SetPresent(
            OptionDictionary options,
            bool present,
            int index,
            Variant value
            )
        {
            if (present)
            {
                this.flags |= OptionFlags.Present;
                this.index  = index;
                this.value  = value;
            }
            else
            {
                this.flags &= ~OptionFlags.Present;
                this.index  = _Constants.Index.Invalid;
                this.value  = null;
            }

            //
            // NOTE: Now mark all the other options in this option group as
            //       "not present".
            //
            if ((options != null) && (options.Values != null))
            {
                foreach (IOption option in options.Values)
                {
                    if ((option != null) &&
                        !Object.ReferenceEquals(option, this) &&
                        (option.GroupIndex != _Constants.Index.Invalid) &&
                        (option.GroupIndex == this.groupIndex))
                    {
                        //
                        // NOTE: Only modify the flags since that is how we detect
                        //       whether the option is considered to be "present".
                        //
                        option.Flags &= ~OptionFlags.Present;
                    }
                }
            }
        }
Esempio n. 15
0
        /// <summary>
        /// Unite the git repository index file paths with the same case the OS is using
        /// </summary>
        /// <param name = "gitPath">
        ///   The path to the git repository to open, can be either the path to the git directory (for non-bare repositories this
        ///   would be the ".git" folder inside the working directory) or the path to the working directory.
        /// </param>
        /// <param name="options">Runtime command line options specified</param>
        public static void Process(string gitPath, OptionFlags options)
        {
            var gitPathInfo = new DirectoryInfo(gitPath);

            using (var repo = new UniteRepository(GetFullName(gitPathInfo), options))
            {
                // Build a list of directory names as seen by the host operating system
                var folders = repo.GetHostDirectoryInfo(gitPathInfo);

                if (options.HasFlag(OptionFlags.UniteDirectories))
                {
                    repo.UniteFolderCasing(folders);
                }

                if (options.HasFlag(OptionFlags.UniteFiles))
                {
                    repo.UniteFilenameCasing(gitPathInfo, folders);
                }
            }
        }
Esempio n. 16
0
        internal static bool Parse(IEnumerable <string> args)
        {
            var options = new OptionFlags();
            var parser  = new Parser(with =>
            {
                with.EnableDashDash         = true;
                with.CaseSensitive          = false;
                with.AutoVersion            = false;
                with.IgnoreUnknownArguments = true;
                with.AutoHelp   = false;
                with.HelpWriter = null;
            });
            var parserResults = parser
                                .ParseArguments <OptionFlags>(args)
                                .WithParsed(o => options = o);

            if (!string.IsNullOrEmpty(options.Host))
            {
                options.Host = options.Host.TrimEnd(Convert.ToChar("/"));
                Console.WriteLine($"Host set to {options.Host}");
            }
            else
            {
                throw new Exception("Host not set");
            }

            if (!string.IsNullOrEmpty(options.UpdatesFile))
            {
                Console.WriteLine($"Client updates file set to {options.UpdatesFile}");
            }
            else
            {
                throw new Exception("Client updates file not set");
            }

            Program.Options = options;

            return(true);
        }
Esempio n. 17
0
 public StockIcon(Identifier id, OptionFlags options)
 {
     _identifier = id;
     _flags = options & ~(OptionFlags.HANDLE | OptionFlags.SYSTEM_INDEX);
 }
Esempio n. 18
0
 private static ImageSource MakeImage(Identifier id, OptionFlags options)
 {
     IntPtr hIcon = GetIconHandle(id, options);
     ImageSource imageSource;
     try
     {
         imageSource = System.Windows.Interop.Imaging.CreateBitmapSourceFromHIcon(hIcon, Int32Rect.Empty, null);
     }
     finally
     {
         DestroyIcon(hIcon);
     }
     return imageSource;
 }
Esempio n. 19
0
 private static extern IntPtr SHGetStockIconInfo(Identifier id, OptionFlags options, ref Info info);
Esempio n. 20
0
 public static BitmapSource GetBitmapSource(Identifier id, OptionFlags options)
 {
     BitmapSource result = (BitmapSource)MakeImage(id, OptionFlags.HANDLE | options);
     result.Freeze();
     return result;
 }
Esempio n. 21
0
 private static IntPtr GetIconHandle(Identifier id, OptionFlags options)
 {
     Info info = new Info();
     info.Size = Marshal.SizeOf(typeof(Info));
     IntPtr hResult = SHGetStockIconInfo(id, options, ref info);
     return info.Handle;
 }
Esempio n. 22
0
        static List <PatchObject> GenerateSeed(int seed, byte[] rom_data, OptionFlags optionFlags)
        {
            RomData randomizedRom = RandomizeRom(seed, rom_data, optionFlags);

            return(randomizedRom.GeneratePatch());
        }
Esempio n. 23
0
 public OptionDefinition(TValue defaultValue, string key, string configurationKey, string environmentKey, OptionFlags flags = 0)
 {
     Key          = key;
     DefaultValue = defaultValue;
     Flags        = flags;
 }
Esempio n. 24
0
 /// <summary>
 /// Extended LibGit2Sharp.Repository with the Unite version of the Move command
 /// </summary>
 /// <param name = "path">
 ///   The path to the git repository to open, can be either the path to the git directory (for non-bare repositories this
 ///   would be the ".git" folder inside the working directory) or the path to the working directory.
 /// </param>
 /// <param name="options">Runtime command line options specified</param>
 public UniteRepository(string path, OptionFlags options)
 {
     _gitDirectoryInfo = new DirectoryInfo(path);
     _gitRepository    = new Repository(GetFullName(_gitDirectoryInfo));
     _options          = options;
 }
Esempio n. 25
0
 public OverworldGlitchedGraphData(RomData romData, OptionFlags optionFlags, RomEntranceCollection romEntrances, RomExitCollection romExits, RomChestCollection romChests)
     : base(romData, optionFlags, romEntrances, romExits, romChests)
 {
 }
Esempio n. 26
0
        ///////////////////////////////////////////////////////////////////////

        //
        // HACK: This is a horrible hack to workaround the issue with not being
        //       able to use plugin enumerated types from the "primary"
        //       application domain when the plugin has been loaded in isolated
        //       mode.
        //
        public static ReturnCode FixupOptions(
            IPluginData pluginData,
            OptionDictionary options,
            bool strict,
            ref Result error
            )
        {
            if (pluginData == null)
            {
                if (strict)
                {
                    error = "invalid plugin data";
                    return(ReturnCode.Error);
                }

                return(ReturnCode.Ok);
            }

            if (options == null)
            {
                if (strict)
                {
                    error = "invalid options";
                    return(ReturnCode.Error);
                }

                return(ReturnCode.Ok);
            }

            if (!IsIsolated(pluginData))
            {
                return(ReturnCode.Ok);
            }

            Assembly assembly = pluginData.Assembly;

            foreach (KeyValuePair <string, IOption> pair in options)
            {
                IOption option = pair.Value;

                if (option == null)
                {
                    continue;
                }

                //
                // HACK: Skip options that do not have enumerated types.
                //       For now, these are the only options we really have to
                //       worry about because they are the only ones that can
                //       directly refer to user-defined types [of any kind].
                //
                if (!option.HasFlags(OptionFlags.MustBeEnum, true))
                {
                    continue;
                }

                //
                // NOTE: Grab the enumerated (?) type and figure out if it
                //       came from the plugin assembly.  If not, ignore it and
                //       continue.
                //
                Type type = option.Type;

                if ((type == null) || !type.IsEnum ||
                    !Object.ReferenceEquals(type.Assembly, assembly))
                {
                    continue;
                }

                //
                // NOTE: Get the current value of the option.
                //
                object   oldValue = option.InnerValue;
                TypeCode typeCode = TypeCode.Empty;

                //
                // NOTE: Attempt to get the new value for the integral type for
                //       the enumeration value of this option, if any.  We must
                //       do this even if the original value is null because we
                //       must have the type code to properly reset the option
                //       flags.
                //
                object newValue = EnumOps.ConvertToTypeCodeValue(
                    type, (oldValue != null) ? oldValue : 0, ref typeCode,
                    ref error);

                if (newValue == null)
                {
                    return(ReturnCode.Error);
                }

                //
                // NOTE: Get the option flags required for the integral type.
                //
                OptionFlags flags = GetEnumOptionFlags(typeCode, strict);

                if (flags == OptionFlags.None)
                {
                    error = String.Format(
                        "unsupported type code for enumerated type \"{0}\"",
                        type);

                    return(ReturnCode.Error);
                }

                //
                // NOTE: Special handling for "flags" enumerations here.
                //
                if (EnumOps.IsFlagsEnum(type))
                {
                    //
                    // HACK: Substitute our placeholder flags enumerated type.
                    //       It does not know about the textual values provided
                    //       by the actual enumerated type; however, at least
                    //       they can use the custom flags enumeration handling
                    //       (i.e. the "+" and "-" operators, etc).
                    //
                    option.Type = typeof(StubFlagsEnum);
                }
                else
                {
                    //
                    // NOTE: Remove the MustBeEnum flag for this option and add
                    //       the flag(s) needed for its integral type.
                    //
                    option.Flags &= ~OptionFlags.MustBeEnum;
                    option.Flags |= flags;

                    //
                    // NOTE: Clear the type for the option.  The type property
                    //       is only meaningful for enumeration-based options
                    //       and we are converting this option to use some kind
                    //       of integral type.
                    //
                    option.Type = null;
                }

                //
                // NOTE: If necessary, set the new [default] value for this
                //       option to the one we converted to an integral type
                //       value above.  If the old (original) value was null, we
                //       just discard the new value which will be zero anyhow.
                //
                option.Value = (oldValue != null) ? new Variant(newValue) : null;
            }

            return(ReturnCode.Ok);
        }
Esempio n. 27
0
        ///////////////////////////////////////////////////////////////////////

        public string ToString(
            OptionFlags flags
            )
        {
            string result;

            if (FlagOps.HasFlags(flags, OptionFlags.MustHaveValue, true))
            {
                if (FlagOps.HasFlags(
                        flags, OptionFlags.MustBeExecute, true))
                {
                    result = "execute";
                }
                else if (FlagOps.HasFlags(
                             flags, OptionFlags.MustBePlugin, true))
                {
                    result = "plugin";
                }
                else if (FlagOps.HasFlags(
                             flags, OptionFlags.MustBeEncoding, true))
                {
                    result = "encoding";
                }
                else if (FlagOps.HasFlags(
                             flags, OptionFlags.MustBeSecureString, true))
                {
                    result = "secure string";
                }
#if NATIVE && TCL
                else if (FlagOps.HasFlags(
                             flags, OptionFlags.MustBeTclInterpreter, true))
                {
                    result = "tcl interpreter";
                }
#endif
                else if (FlagOps.HasFlags(
                             flags, OptionFlags.MustBeRelativeNamespace, true))
                {
                    result = "relative namespace";
                }
                else if (FlagOps.HasFlags(
                             flags, OptionFlags.MustBeAbsoluteNamespace, true))
                {
                    result = "absolute namespace";
                }
                else if (FlagOps.HasFlags(
                             flags, OptionFlags.MustBeOption, true))
                {
                    result = "option";
                }
                else if (FlagOps.HasFlags(
                             flags, OptionFlags.MustBeAlias, true))
                {
                    result = "alias";
                }
                else if (FlagOps.HasFlags(
                             flags, OptionFlags.MustBeReturnCodeList, true))
                {
                    result = "return code list";
                }
                else if (FlagOps.HasFlags(
                             flags, OptionFlags.MustBeAbsoluteUri, true))
                {
                    result = "absolute uri";
                }
                else if (FlagOps.HasFlags(
                             flags, OptionFlags.MustBeVersion, true))
                {
                    result = "version";
                }
                else if (FlagOps.HasFlags(
                             flags, OptionFlags.MustBeTypeList, true))
                {
                    result = "type list";
                }
                else if (FlagOps.HasFlags(
                             flags, OptionFlags.MustBeType, true))
                {
                    result = "type";
                }
                else if (FlagOps.HasFlags(
                             flags, OptionFlags.MustBeInterpreter, true))
                {
                    result = "interpreter";
                }
                else if (FlagOps.HasFlags(
                             flags, OptionFlags.MustBeObject, true))
                {
                    result = "object";
                }
                else if (FlagOps.HasFlags(
                             flags, OptionFlags.MustBeValue, true))
                {
                    result = "numeric";
                }
                else if (FlagOps.HasFlags(
                             flags, OptionFlags.MustBeMatchMode, true))
                {
                    result = "match mode";
                }
                else if (FlagOps.HasFlags(
                             flags, OptionFlags.MustBeDictionary, true))
                {
                    result = "dictionary";
                }
                else if (FlagOps.HasFlags(
                             flags, OptionFlags.MustBeList, true))
                {
                    result = "list";
                }
                else if (FlagOps.HasFlags(
                             flags, OptionFlags.MustBeTimeSpan, true))
                {
                    result = "time-span";
                }
                else if (FlagOps.HasFlags(
                             flags, OptionFlags.MustBeDateTime, true))
                {
                    result = "date-time";
                }
                else if (FlagOps.HasFlags(
                             flags, OptionFlags.MustBeGuid, true))
                {
                    result = "guid";
                }
                else if (FlagOps.HasFlags(
                             flags, OptionFlags.MustBeEnum, true))
                {
                    result = (type != null) ?
                             String.Format("{0} enumeration",
                                           FormatOps.TypeNameOrFullName(type)) :
                             "enumeration";
                }
                else if (FlagOps.HasFlags(
                             flags, OptionFlags.MustBeEnumList, true))
                {
                    result = (type != null) ?
                             String.Format("{0} enumeration list",
                                           FormatOps.TypeNameOrFullName(type)) :
                             "enumeration list";
                }
                else if (FlagOps.HasFlags(
                             flags, OptionFlags.MustBeReturnCode, true))
                {
                    result = "return code";
                }
                else if (FlagOps.HasFlags(
                             flags, OptionFlags.MustBeLevel, true))
                {
                    result = "level";
                }
                else if (FlagOps.HasFlags(
                             flags, OptionFlags.MustBeIndex, true))
                {
                    result = "index";
                }
                else if (FlagOps.HasFlags(
                             flags, OptionFlags.MustBeUnsignedWideInteger, true))
                {
                    result = "unsigned wide integer";
                }
                else if (FlagOps.HasFlags(
                             flags, OptionFlags.MustBeWideInteger, true))
                {
                    result = "wide integer";
                }
                else if (FlagOps.HasFlags(
                             flags, OptionFlags.MustBeUnsignedInteger, true))
                {
                    result = "unsigned integer";
                }
                else if (FlagOps.HasFlags(
                             flags, OptionFlags.MustBeInteger, true))
                {
                    result = "integer";
                }
                else if (FlagOps.HasFlags(
                             flags, OptionFlags.MustBeUnsignedNarrowInteger, true))
                {
                    result = "unsigned narrow integer";
                }
                else if (FlagOps.HasFlags(
                             flags, OptionFlags.MustBeNarrowInteger, true))
                {
                    result = "narrow integer";
                }
                else if (FlagOps.HasFlags(
                             flags, OptionFlags.MustBeByte, true))
                {
                    result = "byte";
                }
                else if (FlagOps.HasFlags(
                             flags, OptionFlags.MustBeSignedByte, true))
                {
                    result = "signed byte";
                }
                else if (FlagOps.HasFlags(
                             flags, OptionFlags.MustBeBoolean, true))
                {
                    result = "boolean";
                }
                else
                {
                    result = "string";
                }
            }
            else if (FlagOps.HasFlags(flags, OptionFlags.EndOfOptions, true))
            {
                result = "end of options";
            }
            else if (FlagOps.HasFlags(flags, OptionFlags.ListOfOptions, true))
            {
                result = "list of options";
            }
            else
            {
                result = "nothing";
            }

            return(result);
        }
Esempio n. 28
0
        ///////////////////////////////////////////////////////////////////////

        public static IOption FromString( /* COMPAT: Eagle beta. */
            Interpreter interpreter,
            string text,
            AppDomain appDomain,
            bool allowInteger,
            bool strict,
            bool verbose,
            bool noCase,
            CultureInfo cultureInfo,
            ref Result error
            )
        {
            StringList list = null;

            if (Parser.SplitList(
                    interpreter, text, 0, Length.Invalid, true,
                    ref list, ref error) != ReturnCode.Ok)
            {
                return(null);
            }

            if (list.Count < StandardElementCount)
            {
                error = String.Format(
                    "cannot create option, only {0} of {1} " +
                    "required elements were specified", list.Count,
                    StandardElementCount);

                return(null);
            }

            Type       type   = null;
            ResultList errors = null;

            if (_Public.Value.GetType(
                    interpreter, list[0], null, appDomain,
                    _Public.Value.GetTypeValueFlags(
                        allowInteger, strict, verbose,
                        noCase), cultureInfo, ref type,
                    ref errors) != ReturnCode.Ok)
            {
                error = errors;
                return(null);
            }

            object enumValue = EnumOps.TryParseFlagsEnum(
                interpreter, typeof(OptionFlags), null,
                list[1], cultureInfo, allowInteger, strict,
                noCase, ref error);

            if (!(enumValue is OptionFlags))
            {
                return(null);
            }

            OptionFlags optionFlags = (OptionFlags)enumValue;
            int         groupIndex  = 0;

            if (_Public.Value.GetInteger2(
                    list[2], ValueFlags.AnyInteger, cultureInfo,
                    ref groupIndex, ref error) != ReturnCode.Ok)
            {
                return(null);
            }

            int index = 0;

            if (_Public.Value.GetInteger2(
                    list[3], ValueFlags.AnyInteger, cultureInfo,
                    ref index, ref error) != ReturnCode.Ok)
            {
                return(null);
            }

            string name = list[4];

            if (name == null)
            {
                error = "invalid option name";
                return(null);
            }

            int     nextIndex = StandardElementCount;
            Variant value     = null;

            if (ScriptOps.GetOptionValue(
                    interpreter, list, type, optionFlags, true, allowInteger,
                    strict, noCase, cultureInfo, ref value, ref nextIndex,
                    ref error) != ReturnCode.Ok)
            {
                return(null);
            }

            return(new Option(
                       type, optionFlags, groupIndex, index, name, value));
        }
Esempio n. 29
0
        ///////////////////////////////////////////////////////////////////////

        public static IOption FromString(
            Interpreter interpreter,
            string text,
            AppDomain appDomain,
            ValueFlags valueFlags,
            CultureInfo cultureInfo,
            ref Result error
            )
        {
            StringList list = null;

            if (Parser.SplitList(
                    interpreter, text, 0, Length.Invalid, true,
                    ref list, ref error) != ReturnCode.Ok)
            {
                return(null);
            }

            if (list.Count < MinimumElementCount)
            {
                error = String.Format(
                    "cannot create option, only {0} of {1} " +
                    "required elements were specified", list.Count,
                    MinimumElementCount);

                return(null);
            }

            bool allowInteger;
            bool strict;
            bool verbose;
            bool noCase;

            _Public.Value.ExtractTypeValueFlags(
                valueFlags, out allowInteger, out strict,
                out verbose, out noCase);

            object enumValue = EnumOps.TryParseFlagsEnum(
                interpreter, typeof(OptionFlags), null,
                list[0], cultureInfo, allowInteger, strict,
                noCase, ref error);

            if (!(enumValue is OptionFlags))
            {
                return(null);
            }

            OptionFlags optionFlags = (OptionFlags)enumValue;
            string      name        = list[1];

            if (name == null)
            {
                error = "invalid option name";
                return(null);
            }

            int  nextIndex = MinimumElementCount;
            Type type      = null;

            if (FlagOps.HasFlags(
                    optionFlags, OptionFlags.MustBeEnumMask, false))
            {
                if (nextIndex >= list.Count)
                {
                    error = String.Format(
                        "option with {0} or {1} flags must have type name",
                        FormatOps.WrapOrNull(OptionFlags.MustBeEnum),
                        FormatOps.WrapOrNull(OptionFlags.MustBeEnumList));

                    return(null);
                }

                ResultList errors = null;

                if (_Public.Value.GetType(
                        interpreter, list[nextIndex], null, appDomain,
                        _Public.Value.GetTypeValueFlags(optionFlags),
                        cultureInfo, ref type, ref errors) != ReturnCode.Ok)
                {
                    error = errors;
                    return(null);
                }

                nextIndex++;
            }

            Variant value = null;

            if (ScriptOps.GetOptionValue(
                    interpreter, list, type, optionFlags, false, allowInteger,
                    strict, noCase, cultureInfo, ref value, ref nextIndex,
                    ref error) != ReturnCode.Ok)
            {
                return(null);
            }

            int groupIndex = _Constants.Index.Invalid;

            if (nextIndex < list.Count)
            {
                if (_Public.Value.GetInteger2(
                        list[nextIndex], ValueFlags.AnyInteger, cultureInfo,
                        ref groupIndex, ref error) != ReturnCode.Ok)
                {
                    return(null);
                }

                nextIndex++;
            }

            return(new Option(
                       type, optionFlags, groupIndex, _Constants.Index.Invalid,
                       name, value));
        }
Esempio n. 30
0
 public View FirstMatch(StateFlags AState, OptionFlags AOptions)
 {
     _AState   = AState;
     _AOptions = AOptions;
     return(FirstThat(new FirstThatProc(Matches)));
 }