Пример #1
0
        // Loads a script's info to the labels
        private void LoadScriptInfo(String file)
        {
            try
            {
                si = ScriptLoader.ScriptLoader.LoadScriptInfo(file);

                lblName.Text     = si.Name;
                lblHomepage.Text = si.Homepage;
                lblFormat.Text   = si.URLFormat.ToString( );
                lblAuthor.Text   = si.Author;
                lblVersion.Text  = si.Version;
            }
            catch (Exception ex)
            {
                ErrorMessage(ex.ToString( ));
            }
        }
Пример #2
0
        public static ScriptInfo GetInfo(String Name)
        {
            var info = new ScriptInfo
            {
                Path = Name
            };
            var shouldParse       = false;
            var shouldStopParsing = false;

            using (var reader = new StreamReader(Name, Encoding.UTF8))
            {
                String line;
                while (!reader.EndOfStream && !shouldStopParsing && (line = reader.ReadLine( )) != null)
                {
                    ContainsSwitch.Do(
                        line,
                        ContainsSwitch.Case("==DLScript==", () => { shouldParse = true; }),
                        ContainsSwitch.Case("==/DLScript==", () =>
                    {
                        shouldParse       = false;
                        shouldStopParsing = true;
                    }),
                        ContainsSwitch.Case("@name", () =>
                    {
                        if (shouldParse)
                        {
                            info.Name = line.GetDLScriptInfoParam("@name");
                        }
                    }),
                        ContainsSwitch.Case("@url", () =>
                    {
                        if (shouldParse)
                        {
                            info.URLFormat = new Regex(line.GetDLScriptInfoParam("@url"), RegexOptions.ECMAScript | RegexOptions.IgnoreCase);
                        }
                    }),
                        ContainsSwitch.Case("@version", () =>
                    {
                        if (shouldParse)
                        {
                            info.Version = line.GetDLScriptInfoParam("@version");
                        }
                    }),
                        ContainsSwitch.Case("@author", () =>
                    {
                        if (shouldParse)
                        {
                            info.Author = line.GetDLScriptInfoParam("@author");
                        }
                    }),
                        ContainsSwitch.Case("@homepage", () =>
                    {
                        if (shouldParse)
                        {
                            info.Homepage = line.GetDLScriptInfoParam("@homepage");
                        }
                    })
                        );
                }
            }

            if (info.Name == null || info.Name == "" || info.URLFormat == null || info.URLFormat == default(Regex))
            {
                throw new Exception("No Name or URL Format were informed.");
            }

            return(info);
        }