Exemplo n.º 1
0
        private void LoadButton_Click(object sender, EventArgs e)
        {
            Cursor = Cursors.WaitCursor;
            try
            {
                using (var webClient = new WebClient())
                {
                    string xhtml = webClient.DownloadString("http://www.milovana.com/webteases/showflash.php?id=" + TeaseIdTextBox.Text);

                    var match = Regex.Match(xhtml, @"<div id=""headerbar"">\s*<div class=""title"">(?<title>.*?) by <a href=""webteases/#author=(?<authorid>\d+)"" [^>]*>(?<authorname>.*?)</a></div>", RegexOptions.Multiline | RegexOptions.Singleline);

                    TeaseTitleTextBox.Text = match.Groups["title"].Value;
                    AuthorNameTextBox.Text = match.Groups["authorname"].Value;
                    AuthorIdTextBox.Text = match.Groups["authorid"].Value;

                    string[] scriptLines = webClient.DownloadString("http://www.milovana.com/webteases/getscript.php?id=" + TeaseIdTextBox.Text).Split(new[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);

                    SelectedTease = new FlashTeaseConverter().Convert(TeaseIdTextBox.Text, TeaseTitleTextBox.Text, AuthorIdTextBox.Text, AuthorNameTextBox.Text, scriptLines);

                    ConverionErrorTextBox.Visible = SelectedTease.Pages.Exists(page => !String.IsNullOrEmpty(page.Errors));

                    Cursor = Cursors.Default;
                }
            }
            catch (Exception err)
            {
                Cursor = Cursors.Default;
                MessageBox.Show(err.Message, "Error while downloading tease", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemplo n.º 2
0
        public Tease LoadTease(string scriptFileName)
        {
            Tease  result       = null;
            string fileContents = File.ReadAllText(scriptFileName);

            if (fileContents.StartsWith("<?xml"))
            {
                var xmldoc = new ConfigXmlDocument();
                xmldoc.LoadXml(fileContents);

                if (xmldoc.DocumentElement != null)
                {
                    if (xmldoc.DocumentElement.LocalName == "Tease")
                    {
                        // Current file format.
                        if (xmldoc.DocumentElement.SelectSingleNode(String.Format("/Tease[@scriptVersion='{0}']", SupportedScriptVersion)) != null)
                        {
                            using (var reader = new StreamReader(scriptFileName))
                            {
                                result = new XmlSerializer(typeof(Tease)).Deserialize(reader) as Tease;
                            }
                        }
                    }
                }
            }

            if (result != null)
            {
                result.ScriptDirectory       = new FileInfo(scriptFileName).DirectoryName;
                Environment.CurrentDirectory = result.ScriptDirectory;
            }

            return(result);
        }
Exemplo n.º 3
0
        public Tease ConvertToTease()
        {
            if (!CanConvert())
            {
                return null;
            }

            var result = new Tease();

            var authorNode = xmldoc.SelectSingleNode("/pages/@author");
            if (authorNode != null)
            {
                result.Author = new Author { Name = authorNode.Value };
            }

            var titleNode = xmldoc.SelectSingleNode("/pages/@title");
            if (titleNode != null)
            {
                result.Title = titleNode.Value;
            }

            var urlNode = xmldoc.SelectSingleNode("/pages/@url");
            if (urlNode != null)
            {
                result.Url = urlNode.Value;
            }

            var mediafolderNode = xmldoc.SelectSingleNode("/pages/@mediafolder");
            if (mediafolderNode != null)
            {
                result.MediaDirectory = mediafolderNode.Value.TrimStart('/', '\\');
            }

            var pageNodes = xmldoc.SelectNodes("/pages/page");
            if (pageNodes != null)
            {
                foreach (XmlNode pageNode in pageNodes)
                {
                    var page = new TeasePage();

                    page.Id = pageNode.SelectSingleNode("pageid").InnerText;

                    var textNode = pageNode.SelectSingleNode("instruction");
                    if (textNode != null)
                    {
                        page.Text = textNode.InnerText;
                    }

                    page.Image = CreateImage(pageNode);
                    page.Video = CreateVideo(pageNode);
                    page.Delay = CreateDelay(pageNode);
                    page.Metronome = CreateMetronome(pageNode);
                    page.ButtonList.AddRange(CreateButtons(pageNode));

                    result.Pages.Add(page);
                }
            }
            return result;
        }
Exemplo n.º 4
0
 private void StartButton_Click(object sender, EventArgs e)
 {
     if (TeaseListView.SelectedItems.Count > 0)
     {
         SelectedTease = teaseLibrary.LoadTease(Path.Combine(teaseLibrary.TeasesFolder, TeaseListView.SelectedItems[0].Text + ".xml"));
         DialogResult = DialogResult.OK;
         Close();
     }
 }
Exemplo n.º 5
0
 private void OtherLocationButton_Click(object sender, EventArgs e)
 {
     if (DialogResult.OK == OpenScriptDialog.ShowDialog())
     {
         SelectedTease = teaseLibrary.LoadTease(OpenScriptDialog.FileName);
         DialogResult = DialogResult.OK;
         Close();
     }
 }
Exemplo n.º 6
0
 public Tease EmptyTease()
 {
     var tease = new Tease
     {
         ScriptDirectory = applicationDirectory
     };
     var welcomePage = new TeasePage();
     welcomePage.Id = "start";
     welcomePage.Text = "Welcome. Please open a tease.";
     welcomePage.AudioList.Add(new TeaseMedia { Id = ConfigurationManager.AppSettings["WelcomeAudio"] });
     welcomePage.ImageList.Add(new TeaseMedia { Id = ConfigurationManager.AppSettings["WelcomeImage"] });
     tease.Pages.Add(welcomePage);
     return tease;
 }
Exemplo n.º 7
0
 public Tease EmptyTease()
 {
     var tease = new Tease
     {
         ScriptDirectory = applicationDirectory
     };
     tease.Pages.Add(new TeasePage
     {
         Id = "start",
         Text = "Welcome. Please open a tease.",
         Audio = new TeaseMedia { Id = ConfigurationManager.AppSettings["WelcomeAudio"] },
         Image = new TeaseMedia { Id = ConfigurationManager.AppSettings["WelcomeImage"] }
     });
     return tease;
 }
Exemplo n.º 8
0
        public Tease EmptyTease()
        {
            var tease = new Tease
            {
                ScriptDirectory = applicationDirectory
            };
            var welcomePage = new TeasePage();

            welcomePage.Id   = "start";
            welcomePage.Text = "Welcome. Please open a tease.";
            welcomePage.AudioList.Add(new TeaseMedia {
                Id = ConfigurationManager.AppSettings["WelcomeAudio"]
            });
            welcomePage.ImageList.Add(new TeaseMedia {
                Id = ConfigurationManager.AppSettings["WelcomeImage"]
            });
            tease.Pages.Add(welcomePage);
            return(tease);
        }
Exemplo n.º 9
0
        public Tease Convert(string teaseId, string teaseTitle, string authorId, string authorName, string[] scriptLines)
        {
            var result = new Tease
            {
                Id = teaseId,
                Title = teaseTitle,
                Url = "http://www.milovana.com/webteases/showflash.php?id=" + teaseId,
                Author = new Author
                {
                    Id = authorId,
                    Name = authorName,
                    Url = "http://www.milovana.com/forum/memberlist.php?mode=viewprofile&u=" + authorId
                }
            };

            foreach (var line in scriptLines)
            {
                result.Pages.Add(CreatePage(line));
            }

            return result;
        }
Exemplo n.º 10
0
        public string ConvertToXmlString(Tease tease)
        {
            var xmldoc = new XmlDocument();

            // Normal XML serialization.
            using (var stream = new MemoryStream())
            {
                new XmlSerializer(typeof(Tease)).Serialize(stream, tease);
                stream.Position = 0;
                xmldoc.Load(stream);
            }

            // A little XML reordering to make a beautiful XML output format, easier than implementing IXmlSerializable
            // for all the tease classes.
            if (xmldoc.DocumentElement != null)
            {
                // Remove the nonused namespace definitions.
                xmldoc.DocumentElement.RemoveAttribute("xmlns:xsi");
                xmldoc.DocumentElement.RemoveAttribute("xmlns:xsd");

                // Make the XML more intuitive by moving the Pages after the genereal tease information.
                var pagesNode = xmldoc.DocumentElement["Pages"];
                if (pagesNode != null)
                {
                    var node = xmldoc.DocumentElement.RemoveChild(pagesNode);
                    xmldoc.DocumentElement.AppendChild(node);
                }

                // The same for the Buttons, put them at the end of a Page.
                var pageNodes = xmldoc.SelectNodes("/Tease/Pages/Page");
                if (pageNodes != null)
                {
                    foreach (XmlNode pageNode in pageNodes)
                    {
                        var buttonNodes = pageNode.SelectNodes("Button");
                        if (buttonNodes != null)
                        {
                            foreach (XmlNode buttonNode in buttonNodes)
                            {
                                pageNode.RemoveChild(buttonNode);
                            }
                            foreach (XmlNode buttonNode in buttonNodes)
                            {
                                pageNode.AppendChild(buttonNode);
                            }
                        }

                        var commentsNode = pageNode.SelectSingleNode("Comments");
                        if (commentsNode != null)
                        {
                            pageNode.RemoveChild(commentsNode);

                            // The replacement of -- is needed for the serializer to function correctly, an XML comment cannot contain --.
                            pageNode.InsertBefore(xmldoc.CreateComment(String.Format(" {0} ", HttpUtility.HtmlDecode(commentsNode.InnerXml).Replace("--", "- - "))), pageNode.FirstChild);
                        }

                        var errorsNode = pageNode.SelectSingleNode("Errors");
                        if (errorsNode != null)
                        {
                            pageNode.RemoveChild(errorsNode);
                            pageNode.InsertBefore(errorsNode, pageNode.FirstChild);
                        }
                    }
                }
            }

            // Convert the XML document to a string.
            using (var stream = new MemoryStream())
            {
                using (var writer = new XmlTextWriter(stream, Encoding.UTF8))
                {
                    writer.Formatting = Formatting.Indented;
                    xmldoc.Save(writer);

                    stream.Position = 0;
                    using (var reader = new StreamReader(stream, Encoding.UTF8))
                    {
                        return(reader.ReadToEnd());
                    }
                }
            }
        }
Exemplo n.º 11
0
 public void SaveTease(Tease tease, string scriptFileName)
 {
     File.WriteAllText(scriptFileName, new TeaseSerializer().ConvertToXmlString(tease));
 }
Exemplo n.º 12
0
        public string ConvertToXmlString(Tease tease)
        {
            var xmldoc = new XmlDocument();

            // Normal XML serialization.
            using (var stream = new MemoryStream())
            {
                new XmlSerializer(typeof(Tease)).Serialize(stream, tease);
                stream.Position = 0;
                xmldoc.Load(stream);
            }

            // A little XML reordering to make a beautiful XML output format, easier than implementing IXmlSerializable
            // for all the tease classes.
            if (xmldoc.DocumentElement != null)
            {
                // Remove the nonused namespace definitions.
                xmldoc.DocumentElement.RemoveAttribute("xmlns:xsi");
                xmldoc.DocumentElement.RemoveAttribute("xmlns:xsd");

                // Make the XML more intuitive by moving the Pages after the genereal tease information.
                var pagesNode = xmldoc.DocumentElement["Pages"];
                if (pagesNode != null)
                {
                    var node = xmldoc.DocumentElement.RemoveChild(pagesNode);
                    xmldoc.DocumentElement.AppendChild(node);
                }

                // The same for the Buttons, put them at the end of a Page.
                var pageNodes = xmldoc.SelectNodes("/Tease/Pages/Page");
                if (pageNodes != null)
                {
                    foreach (XmlNode pageNode in pageNodes)
                    {
                        var buttonNodes = pageNode.SelectNodes("Button");
                        if (buttonNodes != null)
                        {
                            foreach (XmlNode buttonNode in buttonNodes)
                            {
                                pageNode.RemoveChild(buttonNode);
                            }
                            foreach (XmlNode buttonNode in buttonNodes)
                            {
                                pageNode.AppendChild(buttonNode);
                            }
                        }

                        var commentsNode = pageNode.SelectSingleNode("Comments");
                        if (commentsNode != null)
                        {
                            pageNode.RemoveChild(commentsNode);

                            // The replacement of -- is needed for the serializer to function correctly, an XML comment cannot contain --.
                            pageNode.InsertBefore(xmldoc.CreateComment(String.Format(" {0} ", HttpUtility.HtmlDecode(commentsNode.InnerXml).Replace("--","- - "))), pageNode.FirstChild);
                        }

                        var errorsNode = pageNode.SelectSingleNode("Errors");
                        if (errorsNode != null)
                        {
                            pageNode.RemoveChild(errorsNode);
                            pageNode.InsertBefore(errorsNode, pageNode.FirstChild);
                        }
                    }
                }
            }

            // Convert the XML document to a string.
            using (var stream = new MemoryStream())
            {
                using (var writer = new XmlTextWriter(stream, Encoding.UTF8))
                {
                    writer.Formatting = Formatting.Indented;
                    xmldoc.Save(writer);

                    stream.Position = 0;
                    using (var reader = new StreamReader(stream, Encoding.UTF8))
                    {
                        return reader.ReadToEnd();
                    }
                }
            }
        }
Exemplo n.º 13
0
        public void AddPages(Tease tease, string script)
        {
            var mustCommands = new List<string>();

            // Do minor corrections first so that the parser can stay a bit simpler.
            foreach (var line in CorrectedLines(script))
            {
                var correctedLine = line;

                // The must/mustnot commands will be parsed separately.
                if (correctedLine.StartsWith("must(") || correctedLine.StartsWith("mustnot("))
                {
                    mustCommands.Add(correctedLine);
                }
                else
                {
                    var page = CreatePage(correctedLine);

                    if (!String.IsNullOrEmpty(page.Errors) && page.Errors.Contains("mismatched input '<EOF>' expecting ')'"))
                    {
                        correctedLine = correctedLine + ")";
                        page = CreatePage(correctedLine);
                    }

                    if (!String.IsNullOrEmpty(page.Errors) && page.Errors.Contains(" expecting QUOTED_STRING"))
                    {
                        // Some scripts don't have quotes when specifying sound, I could make the parser work correctly
                        // so I have to correct it before parsing.
                        var match = Regex.Match(correctedLine, @":sound\(id:(?<soundId>[^)]*)\)");
                        if (match.Success)
                        {
                            var soundId = match.Groups["soundId"].Value;
                            correctedLine = correctedLine.Replace(":sound(id:" + soundId + ")", ":sound(id:'" + soundId + "')");
                            page = CreatePage(correctedLine);
                        }
                    }

                    if (!String.IsNullOrEmpty(page.Errors) && correctedLine.Contains("text:'<") && correctedLine.Contains(">',"))
                    {
                        // Correct the unescaped quotes in the instruction text.
                        correctedLine =
                            correctedLine.BeforeFirst("text:'<") + "text:'<"
                            + correctedLine.AfterFirst("text:'<").BeforeFirst(">',").Replace("'", "&quot;")
                            + ">'," + correctedLine.AfterFirst("text:'<").AfterFirst(">',");
                        page = CreatePage(correctedLine);
                    }

                    if (!String.IsNullOrEmpty(page.Errors) && page.Errors.Contains("mismatched input '#' expecting ')'") && correctedLine.Contains("buttons("))
                    {
                        // There might be HTML in the button captions
                        int i = 0;
                        //e1:buttons(target0:rating1#,cap0:"<FONT COLOR="#B30033" SIZE="14"><b>1</b></FONT>",target1:rating2#,cap1:"<FONT COLOR="#B30033" SIZE="14"><b>2</b></FONT>",target2:rating3#,cap2:"<FONT COLOR="#B30033" SIZE="14"><b>3</b></FONT>",target3:rating4#,cap3:"<FONT COLOR="#B30033" SIZE="14"><b>4</b></FONT>
                        var tmp = correctedLine.BeforeFirst("buttons(") + "buttons(";
                        var rest = correctedLine.AfterFirst("buttons(");
                        var cap = String.Format("cap{0}:\"", i);
                        while (rest.Contains(cap))
                        {
                            tmp += rest.BeforeFirst(cap) + cap;
                            rest = rest.AfterFirst(cap);
                            if (rest.Contains("\",target" + (i+1)))
                            {
                                var caption = rest.BeforeFirst("\",target" + (i+1));
                                tmp += StripHtml(caption) + "\",target" + (i+1) + rest.AfterFirst("\",target" + (i+1));
                            }
                            else if (rest.Contains("\")"))
                            {
                                var caption = rest.BeforeFirst("\")");
                                tmp += StripHtml(caption) + "\")" + rest.AfterFirst("\")");
                                break;
                            }
                            i++;
                        }
                        correctedLine = tmp;
                        page = CreatePage(correctedLine);
                    }

                    tease.Pages.Add(page);
                }
            }

            foreach (var mustCommand in mustCommands)
            {
                var match = Regex.Match(mustCommand, @"(?<cmd>(must|mustnot))\(self:(?<self>(self:|:)?.*?)#,(?<actions>.*)\)");
                if (match.Success)
                {
                    var self = match.Groups["self"].Value;
                    var actions = match.Groups["actions"].Value;

                    var flags = new List<string>();
                    string[] actionArray = actions.Split(',');
                    foreach (var action in actionArray)
                    {
                        string id = action.AfterFirst(":").TrimEnd('#');
                        if (!String.IsNullOrEmpty(id))
                        {
                            flags.Add(id);
                        }
                    }

                    var page = tease.Pages.Find(p => p.Id.Equals(self));
                    if (page != null)
                    {
                        if (match.Groups["cmd"].Value.Equals("must"))
                        {
                            page.IfSetCondition = String.Format("{0},{1}", page.IfSetCondition, String.Join(",", flags.ToArray())).Trim(',');
                        }
                        if (match.Groups["cmd"].Value.Equals("mustnot"))
                        {
                            page.IfNotSetCondition = String.Format("{0},{1}", page.IfNotSetCondition, String.Join(",", flags.ToArray())).Trim(',');
                        }
                    }
                }
            }
        }
Exemplo n.º 14
0
        private void SetCurrentTease(Tease tease)
        {
            try
            {
                PictureBox1.SizeMode = PictureBoxSizeMode.Zoom;

                CurrentTease = tease;

                TeaseTitleLabel.Text = CurrentTease.Title;
                if (!String.IsNullOrEmpty(CurrentTease.Title))
                {
                    TeaseTitleLabel.Font = new Font("Microsoft Sans Serif", 12F, FontStyle.Underline, GraphicsUnit.Point, 0);
                    TeaseTitleLabel.ForeColor = Color.SkyBlue;
                    ToolTips.SetToolTip(TeaseTitleLabel, String.Format("Open {0} in web browser", CurrentTease.Url));
                }
                else
                {
                    TeaseTitleLabel.Font = new Font("Microsoft Sans Serif", 12F, FontStyle.Regular, GraphicsUnit.Point, 0);
                    TeaseTitleLabel.ForeColor = Color.Gainsboro;
                    ToolTips.SetToolTip(TeaseTitleLabel, null);
                }

                AuthorNameLabel.Text = (CurrentTease.Author != null) ? CurrentTease.Author.Name : String.Empty;
                if (CurrentTease.Author != null && !String.IsNullOrEmpty(CurrentTease.Author.Url))
                {
                    AuthorNameLabel.Font = new Font("Microsoft Sans Serif", 9.75F, FontStyle.Underline, GraphicsUnit.Point, 0);
                    AuthorNameLabel.ForeColor = Color.SkyBlue;
                    ToolTips.SetToolTip(AuthorNameLabel, String.Format("Open {0} in web browser", CurrentTease.Author.Url));
                }
                else
                {
                    AuthorNameLabel.Font = new Font("Microsoft Sans Serif", 9.75F, FontStyle.Regular, GraphicsUnit.Point, 0);
                    AuthorNameLabel.ForeColor = Color.Gainsboro;
                    ToolTips.SetToolTip(AuthorNameLabel, null);
                }

                debugForm.PagesComboBox.Sorted = true;
                debugForm.PagesComboBox.Items.Clear();
                CurrentTease.Pages.ForEach(page => debugForm.PagesComboBox.Items.Add(page.Id));

                CurrentTease.CurrentPageChanged += currentTease_CurrentPageChanged;

                CurrentTease.Start();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error: " + ex.Message);
            }
        }
Exemplo n.º 15
0
 public void SaveTease(Tease tease, string scriptFileName)
 {
     File.WriteAllText(scriptFileName, new TeaseSerializer().ConvertToXmlString(tease));
 }