public static void ApplyResults(object sender, DoWorkEventArgs args)
        {
            MarioKart64ReaderResults results = (MarioKart64ReaderResults)args.Argument;

            //To-do: add an error report for any sort of exceptions during saving?
            ProgressService.SetMessage("Splicing data elements into Rom object");
            foreach (N64DataElement element in results.NewElements)
            {
                RomProject.Instance.Files[0].AddElement(element);
            }

            if (results.KartResults != null)
            {
                ProgressService.SetMessage("Splicing kart data into Rom object");
                KartReader.ApplyResults(results.KartResults);
            }

            //  if (results.TrackResults != null)
            //  {
            //      ProgressService.SetMessage("Splicing track data into Rom object");
            //TrackReader.ApplyResults(results.TrackResults);
            //    }

            if (results.TextBank != null)
            {
                ProgressService.SetMessage("Splicing text data into Rom object");
                MarioKart64ElementHub.Instance.TextBank = results.TextBank;
            }

            if (results.TextureResults != null)
            {
                ProgressService.SetMessage("Splicing texture data into Rom object");
                TextureReader.ApplyResults(results.TextureResults);
            }

            //Does this really belong here?
            if (!RomProject.Instance.Items.Contains(MarioKart64ElementHub.Instance))
            {
                RomProject.Instance.AddRomItem(MarioKart64ElementHub.Instance);
            }

            ProgressService.SetMessage("Finished!");
        }
        private static void ReadRomPayload(object sender, DoWorkEventArgs args)
        {
            BackgroundWorker worker = sender as BackgroundWorker;

            MarioKart64ReaderResults results = new MarioKart64ReaderResults();

            //The rom should be loaded as the first file in the rom project
            byte[] rawData = RomProject.Instance.Files[0].GetAsBytes();

            //NOTE: THIS IS HOW YOU DO A CANCELLATION
            //if ((worker.CancellationPending == true))
            //{
            //    args.Cancel = true;
            //    return;
            //}

            /*ProgressService.SetMessage("Reading TKMK00 Textures");
             *
             * N64DataElement preExistingElement;
             *
             * //Now read the different data bits here, if they haven't been read in yet
             * for (int i = 0; i < MarioKartRomInfo.TKMK00TextureLocations.Length; i++)
             * {
             *  preExistingElement = RomProject.Instance.Files[0].GetElementAt(MarioKartRomInfo.TKMK00TextureLocations[i].RomOffset);
             *  if (preExistingElement != null && preExistingElement.GetType() == typeof(UnknownData))
             *  {
             *      ushort alpha = MarioKartRomInfo.TKMK00TextureLocations[i].AlphaColor;
             *      int offset = MarioKartRomInfo.TKMK00TextureLocations[i].RomOffset;
             *      int length = MarioKartRomInfo.TKMK00TextureLocations[i].Length;
             *
             *      TKMK00Block tkmk;
             *
             *      byte[] bytes = new byte[length];
             *      Array.Copy(rawData, offset, bytes, 0, length);
             *
             *      tkmk = new TKMK00Block(offset, bytes, alpha);
             *
             *      if (MarioKart64ElementHub.Instance.OriginalTKMK00Blocks.SingleOrDefault(t => t.FileOffset == tkmk.FileOffset) == null)
             *      {
             *          results.NewElements.Add(tkmk);
             *          results.OriginalTKMK00Blocks.Add(tkmk);
             *      }
             *  }
             *  else if (preExistingElement is TKMK00Block &&
             *      MarioKart64ElementHub.Instance.OriginalTKMK00Blocks.SingleOrDefault(t => t.FileOffset == preExistingElement.FileOffset) == null)
             *  {
             *      results.OriginalTKMK00Blocks.Add((TKMK00Block)preExistingElement);
             *  }
             * }
             */
            //Text bank!
            TextBankBlock      textBankBlock      = null;
            TextReferenceBlock textReferenceBlock = null;
            bool previouslyLoadedText             = false;

            //To do: add a function to automate this pre-existing check, like
            //        bool hasExistingElement<T:N64DataElement> (offset, out T)
            N64DataElement preExistingElement;

            if (RomProject.Instance.Files[0].HasElementAt(TextBankBlock.TEXT_BLOCK_START, out preExistingElement) &&
                preExistingElement.GetType() == typeof(UnknownData))
            {
                byte[] bytes = new byte[TextBankBlock.TEXT_BLOCK_LENGTH];
                Array.Copy(rawData, TextBankBlock.TEXT_BLOCK_START, bytes, 0, bytes.Length);

                textBankBlock = new TextBankBlock(TextBankBlock.TEXT_BLOCK_START, bytes);
                results.NewElements.Add(textBankBlock);
            }
            else if (preExistingElement.GetType() == typeof(TextBankBlock))
            {
                previouslyLoadedText = true;
                textBankBlock        = (TextBankBlock)preExistingElement;
            }

            if (RomProject.Instance.Files[0].HasElementAt(TextReferenceBlock.TEXT_REFERENCE_SECTION_1, out preExistingElement) &&
                preExistingElement.GetType() == typeof(UnknownData))
            {
                byte[] bytes = new byte[TextReferenceBlock.TEXT_REFERENCE_END - TextReferenceBlock.TEXT_REFERENCE_SECTION_1];
                Array.Copy(rawData, TextReferenceBlock.TEXT_REFERENCE_SECTION_1, bytes, 0, bytes.Length);

                textReferenceBlock = new TextReferenceBlock(TextReferenceBlock.TEXT_REFERENCE_SECTION_1, bytes);
                results.NewElements.Add(textReferenceBlock);
            }
            else if (preExistingElement.GetType() == typeof(TextReferenceBlock))
            {
                previouslyLoadedText = true;
                textReferenceBlock   = (TextReferenceBlock)preExistingElement;
            }

            if (textBankBlock != null && textReferenceBlock != null)
            {
                TextBank textBank = new TextBank(textBankBlock, textReferenceBlock, !previouslyLoadedText);
                results.TextBank = textBank;
            }

            TextureReader.ReadRom(worker, rawData, results);

            KartReader.ReadRom(worker, rawData, results);

            args.Result = results;
        }