Пример #1
0
 public Resource(Parser.Resource pObj, int page, bool ix2)
 {
     pageId = page;
     x2 = ix2;
     data = pObj.data;
     originalFileName = pObj.originalFileName;
     titleText = pObj.titleText;
     isInPesterLog = pObj.isInPesterLog;
 }
Пример #2
0
 public Text(Parser.Text pObj, int pageno, bool ix2)
 {
     pageId = pageno;
     x2 = ix2;
     title = pObj.title;
     promptType = pObj.promptType;
     altText = pObj.altText;
     if(pObj.narr != null)
         narr = new ScriptLine(pObj.narr);
     if (pObj.lines != null)
     {
         lines = new List<ScriptLine>();
         foreach (var l in pObj.lines)
             lines.Add(new ScriptLine(l));
     }
 }
Пример #3
0
 public Page(int no, Parser.Text t, Parser.Resource[] r, Parser.Link[] l)
 {
     number = no;
     meta = t;
     resources = r;
     links = l;
 }
Пример #4
0
 public Link(Parser.Link pObj, int pageno)
 {
     pageId = pageno;
     linkTo = pObj.pageNumber;
     originalText = pObj.originalText;
 }
Пример #5
0
        bool SavePage(int currentPage, WrapBGW bgw = null, int currentProgress = 0)
        {
            if (Enum.IsDefined(typeof(PagesOfImportance), currentPage))
            {
                try
                {
                    switch ((PagesOfImportance)currentPage)
                    {
                        case PagesOfImportance.CASCADE:
                            HandleCascade(bgw, currentProgress);
                            break;
                        case PagesOfImportance.CALIBORN_PAGE_SMASH:
                            HandlePageSmash(bgw, currentProgress);
                            break;
                        case PagesOfImportance.CALIBORN_PAGE_SMASH2:
                            HandlePageSmash2(bgw, currentProgress);
                            break;
                        case PagesOfImportance.DOTA:
                            HandleDota(bgw, currentProgress);
                            break;
                        case PagesOfImportance.SHES8ACK:
                            FailToHandleVriska(bgw, currentProgress);
                            break;
                        case PagesOfImportance.GAMEOVER:
                            FailMiserably(bgw, currentProgress);
                            break;
                        case PagesOfImportance.OVERSHINE:
                            HandleOvershine(bgw, currentProgress);
                            break;
                        case PagesOfImportance.JAILBREAK_LAST_PAGE:
                            HandleJailbreakLast(bgw, currentProgress);
                            break;
                        case PagesOfImportance.COLLIDE:
                        case PagesOfImportance.ACT7:
                            HandleYoutubeVideo(bgw, currentProgress, (PagesOfImportance)currentPage == PagesOfImportance.COLLIDE);
                            break;
                    }
                    archivedPages.Add(currentPage);
                }
                catch
                {
                    if (bgw != null && !bgw.bgw.Cancelled())
                        bgw.ReportProgress(currentProgress, "Error parsing special page " + currentPage);
                    return false;
                }
                finally
                {
                    if (bgw != null)
                        bgw.ReportProgress(currentProgress, "");
                }
                return true;
            }
            if (archivedPages.IsPageArchived(currentPage))
                return true;

            if (Parser.IsTrickster(currentPage))
                ParseTrickster();
            if (Parser.Is2x(currentPage))
                Parsex2Header();
            if (Enum.IsDefined(typeof(PasswordPages), currentPage + 1))
                ParseTerezi();

            if(bgw != null && Parser.IsOpenBound(currentPage))
                bgw.ReportProgress(currentProgress, "Parsing an Openbound page. There are tons of tiny downloads and this will take a couple minutes...");

            using (var parser = new Parser())
            {
                if (parser.LoadPage(currentPage))
                {
                    int missedPages = 0;
                    if (!parser.x2Flag)
                    {
                        if (!WritePage(bgw, currentPage, currentProgress, 0, parser))
                            missedPages++;
                    }
                    else
                    {
                        if (!WritePage(bgw, currentPage, currentProgress, 1, parser))
                            missedPages += 2;
                        else
                        {
                            parser.Reparse();
                            if (!WritePage(bgw, currentPage, currentProgress, 2, parser))
                                missedPages += 2;
                        }
                    }
                    //simple enough, leave it to the reader to decode the multiple pages
                    return missedPages == 0;
                }
                else
                    return false;
            }
        }
Пример #6
0
        bool WritePage(WrapBGW bgw, int currentPage, int currentProgress, int x2phase, Parser parser)
        {
            try
            {
                var res = parser.GetResources();
                var links = parser.GetLinks();
                var text = parser.GetText();

                if (bgw != null)
                    bgw.ReportProgress(currentProgress, "Page " + currentPage + ": " + text.title);

                if (text.narr == null)
                {
                    if (bgw != null)
                        bgw.ReportProgress(currentProgress, text.promptType);
                    for (int i = 0; i < text.lines.Count(); ++i)
                    {
                        if (!text.lines[i].isImg)
                        {
                            if (bgw != null)
                                bgw.ReportProgress(currentProgress, (text.lines[i].subTexts != null ? text.lines[i].subTexts.Count() : 0) + " special subtexts, Colour: " + text.lines[i].hexColour + ": " + text.lines[i].text);
                        }
                        else
                            if (bgw != null)
                                bgw.ReportProgress(currentProgress, "Imageline");
                    }
                }
                else if(bgw != null)
                    bgw.ReportProgress(currentProgress, "Narrative: " + text.narr.text);

                if(bgw != null)
                    for (int i = 0; i < links.Count(); ++i)
                        bgw.ReportProgress(currentProgress, "\"" + links[i].originalText + "\" links to " + links[i].pageNumber);
                for (int i = 0; i < res.Count(); ++i)
                {
                    var fileSize = res[i].data.Count();
                    totalMegabytesDownloaded += (float)fileSize / (1024.0f * 1024.0f);
                    if (bgw != null)
                        bgw.ReportProgress(currentProgress, res[i].originalFileName + ": " + fileSize / 1024 + "KB");
                }
                if (bgw != null)
                    bgw.ReportProgress(currentProgress, "Total Data Downloaded: " + (int)totalMegabytesDownloaded + "MB");

                if (bgw != null && x2phase != 1)
                    bgw.ReportProgress(currentProgress, "");

                var p = new Page(currentPage, text, res, links);
                p.x2 = x2phase == 2;
                WritePageToDB(p);
                if (x2phase != 1)
                {
                    archivedPages.Add(currentPage);
                }

            }
            catch
            {
                Debugger.Break();
                if (bgw != null)
                    bgw.ReportProgress(currentProgress, "Error in archiving page: " + currentPage);
                return false;

            }
            return true;
        }
Пример #7
0
 protected void ParseTrickster()
 {
     if (!TricksterParsed())
     {
         if (!wl.TestAndSet())
         {
             using (var parser = new Parser())
             {
                 parser.LoadTricksterResources();
                 WriteResource(parser.GetResources(), (int)SpecialResources.TRICKSTER_HEADER);
             }
         }
     }
 }
Пример #8
0
 public TricksterShit(Reader p,Parser.Resource[] shit)
 {
     parent = p;
     bytes[0] = new MemoryStream(shit[0].data);
     bytes[1] = new MemoryStream(shit[2].data);
     bg = Image.FromStream(bytes[0]);
     fg = Image.FromStream(bytes[1]);
     parent.BackgroundImage = bg;
     parent.mainPanel.BackgroundImage = fg;
     flashHeader = new WebBrowser();
     parent.Controls.Add(flashHeader);
     flashHeader.Width = 950;
     flashHeader.Height = 24;
     parent.InitFlashMovie(flashHeader,shit[1]);
     FixAlign();
 }
Пример #9
0
 public abstract void WriteResource(Parser.Resource[] res, int page);
Пример #10
0
 protected void ParseTerezi()
 {
     if (!TereziParsed())
     {
         using (var parser = new Parser())
         {
             parser.GetTerezi();
             WriteResource(parser.GetResources(), (int)SpecialResources.TEREZI_PASSWORD);
         }
     }
 }
Пример #11
0
        public bool Initialize(System.ComponentModel.BackgroundWorker bgw)
        {
            if (ReadLastIndexedOrCreateDatabase(bgw))
            {
                using (var parser = new Parser())
                {
                    bgw.ReportProgress(0, "Checking MSPA for latest page...");
                    lastPage = parser.GetLatestPage();
                    if (lastPage == 0)
                    {
                        lastPage = archivedPages.FindHighestPage();
                        if (lastPage == 0)
                        {
                            MessageBox.Show("The database is empty. Cannot read MSPA.");
                            return false;
                        }
                    }
                    else if (lastPage != (int)StoryBoundaries.HS_END)
                    {
                        var pg = archivedPages.Prune();
                        if (pg != 0)
                        {
                            bgw.ReportProgress(0, "Reparsing last page... The may take a while if you stopped on a big page");
                            Prune(pg);
                            SavePage(pg);
                        }
                    }

                    if (!IconsAreParsed())
                    {
                        bgw.ReportProgress(0, "Downloading header icons...");
                        try
                        {
                            parser.LoadIcons();
                            WriteResource(parser.GetResources(), (int)SpecialResources.CANDYCORNS);
                        }
                        catch
                        {
                            MessageBox.Show("Unable to load icons above pages! Parsing failure!");
                            return false;
                        }
                    }
                }
                return true;
            }
            MessageBox.Show("Error creating the database!");
            return false;
        }
Пример #12
0
        static void Main()
        {
            if (mutex.WaitOne(TimeSpan.Zero, true)) //make sure we're the only instance
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);   //must be done before showing message boxes
                try
                {
                    string oldUpdatePath = Application.StartupPath + System.IO.Path.DirectorySeparatorChar + System.AppDomain.CurrentDomain.FriendlyName.Replace(" Update.exe", ".exe");

                    if (oldUpdatePath != Application.StartupPath + System.IO.Path.DirectorySeparatorChar + System.AppDomain.CurrentDomain.FriendlyName)
                        try
                        {
                            if (System.IO.File.Exists(oldUpdatePath))
                            {
                                MessageBox.Show("Update successful!");
                                System.IO.File.Delete(oldUpdatePath);   //delete the old version
                            }
                            else
                            {

                                oldUpdatePath = oldUpdatePath.Replace(".exe", "");
                                if (System.IO.File.Exists(oldUpdatePath))
                                {
                                    MessageBox.Show("Update successful!");
                                    System.IO.File.Delete(oldUpdatePath);
                                }
                            }
                        }
                        catch { }

                    try
                    {
                        var tmpParser = new Parser();
                        var res = tmpParser.CheckIfUpdateIsAvailable();
                        tmpParser.Dispose();
                        if (res != 0)
                        {
                            if (MessageBox.Show("Release version "+res+" available. Download now?",
                                             "Update Available",
                                             MessageBoxButtons.YesNo) == DialogResult.Yes)
                            {
                                try{
                                    string path = (Application.StartupPath + System.IO.Path.DirectorySeparatorChar + System.AppDomain.CurrentDomain.FriendlyName).Replace(".exe", " Update.exe");
                                    if (path == Application.StartupPath + System.IO.Path.DirectorySeparatorChar + System.AppDomain.CurrentDomain.FriendlyName)
                                        path += "Update.exe";
                                    System.IO.File.WriteAllBytes(path, Parser.DownloadFile(updateURL));
                                    System.Diagnostics.Process.Start(path);
                                    return;
                                }
                                catch {
                                    MessageBox.Show("Error downloading/saving the update! You can get it manually at https://github.com/cybnetsurfe3011/MSPA-Reader/releases.");
                                }
                            }
                        }

                    }
                    catch
                    {
                        MessageBox.Show("Unable to check for updates!");
                    }
                    try
                    {
                        DecryptSavedPassword();
                        var lastPage = Properties.Settings.Default.lastReadPage;
                        new DatabaseLogin().Show();
                        Application.Run();
                    }
                    catch
                    {
                        throw;
                    }
                    finally
                    {
                        EncryptSavedPassword();
                        Properties.Settings.Default.Save();
                    }
                }
                catch (Exception e){
                    MessageBox.Show("An unhandled exception occured. Please file a bug report at https://www.github.com/cybnetsurfe3011/MSPA-Reader containing the following: " + Environment.NewLine + Environment.NewLine + e.ToString(), "Critical Error!");
                }
                finally
                {
                    mutex.ReleaseMutex();
                }
        }
Пример #13
0
 //https://stackoverflow.com/questions/1874077/loading-a-flash-movie-from-a-memory-stream-or-a-byte-array
 //*
 private void InitFlashMovie(WebBrowser f, Parser.Resource swfFile, bool setDimensions = true)
 {
     if (setDimensions)
         SetFlashDimensions();
     var loc = WriteTempResource(ref swfFile);
     f.WebBrowserShortcutsEnabled = false;
     if (page.number == 8848 || page.number == 8850)
         f.DocumentText = "<style>html, body {{ padding: 0; margin: 0 }}</style><img src=\"" + loc + "\" border=\"0\"></img>";
     else
         f.Navigate(loc);
     f.Navigating += flash_Navigating;
 }
Пример #14
0
 public ScriptLine(Parser.Text.ScriptLine sl)
 {
     isImg = sl.isImg;
     hexColour = sl.hexColour;
     text = sl.text;
     precedingLineBreaks = sl.precedingLineBreaks;
     if (sl.subTexts != null)
     {
         subTexts = new List<SpecialSubText>();
         foreach (var sst in sl.subTexts)
             subTexts.Add(new SpecialSubText(sst));
     }
 }
Пример #15
0
 protected void Parsex2Header()
 {
     if (!x2HeaderParsed())
     {
         using (var parser = new Parser())
         {
             parser.GetX2Header();
             WriteResource(parser.GetResources(), (int)SpecialResources.X2_HEADER);
         }
     }
 }
Пример #16
0
 public SpecialSubText(Parser.Text.ScriptLine.SpecialSubText sst)
 {
     begin = sst.begin;
     length = sst.length;
     isImg = sst.isImg;
     isLink = sst.isLink;
     underlined = sst.underlined;
     colour = sst.colour;
 }
Пример #17
0
 string WriteTempResource(ref Parser.Resource res, bool findSburbScript = false)
 {
     string path = System.IO.Path.GetTempPath() + res.originalFileName;
     if(Parser.IsOpenBound(page.number))
         Directory.CreateDirectory(Path.GetDirectoryName(path));
     File.WriteAllBytes(path, res.data); //let the throw fall through and fail the page load (problems beyond our scope)
     res = null;
     GC.Collect();
     tempFiles.Add(path);
     if(!findSburbScript || Path.GetFileName(path) == "Sburb.min.js")
         return path;
     return null;
 }