public static async Task<Script> GetNewScriptFromFile()
        {
            FileOpenPicker picker = new FileOpenPicker();
            picker.FileTypeFilter.Add(".mcr");

            StorageFile scriptFile = await picker.PickSingleFileAsync();
            try
            {
                Script script = new Script();
                script.Clear();
                char[] delimiterChars = { ' ', ',', '.', ':', '\t', '=', '/', '(', ')', '[', ']', '*', '+', '>', '<', '?', '!' };
                IList<string> allLines = await FileIO.ReadLinesAsync(scriptFile);
                bool atContents = false;
                foreach (string line in allLines)
                {
                    string[] words = line.Split(delimiterChars);

                    if (words.Length == 0) continue;

                    //__check for end of content section
                    if (words.Length == 1 && words[0] == "#End" && atContents) break;

                    //__check for start of content section
                    if (words.Contains("#BeginContents") && !atContents)
                    {
                        atContents = true;
                        continue;
                    }

                    if (!atContents)//__only interested in version number from header contents
                    {
                        if (words.Contains("#MajorVersion"))
                        {
                            if (words.Length > 1) script.Version = words[1];
                        }
                        if (words.Contains("#MinorVersion"))
                        {
                            if (words.Length > 1) script.Version += "." + words[1];
                        }
                    }

                    //__now done with header section, extract Variables & lines
                }

                script.Name = scriptFile.DisplayName;

                return script;
            }
            catch (Exception e)
            {
                return null;
            }
        }
Beispiel #2
0
 public virtual bool ParseScript(Script s)
 {
     s.Clear(); return ParseSpecialElement(s);
 }