Ejemplo n.º 1
0
        private void doc_FormClosed(object sender, FormClosedEventArgs e)
        {
            var doc = (frmCR2WDocument) sender;
            OpenDocuments.Remove(doc);

            if (doc == ActiveDocument)
            {
                ActiveDocument = null;
            }
        }
Ejemplo n.º 2
0
 private void saveFile(frmCR2WDocument d)
 {
     d.SaveFile();
 }
Ejemplo n.º 3
0
 private void doc_Activated(object sender, EventArgs e)
 {
     ActiveDocument = (frmCR2WDocument)sender;
 }
Ejemplo n.º 4
0
        public frmCR2WDocument LoadDocument(string filename, MemoryStream memoryStream = null, bool suppressErrors = false)
        {
            if (memoryStream == null && !File.Exists(filename))
            {
                return(null);
            }

            foreach (var t in OpenDocuments.Where(t => t.FileName == filename))
            {
                t.Activate();
                return(null);
            }

            var doc = new frmCR2WDocument();

            OpenDocuments.Add(doc);

            try
            {
                if (memoryStream != null)
                {
                    doc.LoadFile(filename, memoryStream);
                }
                else
                {
                    doc.LoadFile(filename);
                }
            }
            catch (InvalidFileTypeException ex)
            {
                if (!suppressErrors)
                {
                    MessageBox.Show(this, ex.Message, @"Error opening file.");
                }

                OpenDocuments.Remove(doc);
                doc.Dispose();
                return(null);
            }
            catch (MissingTypeException ex)
            {
                if (!suppressErrors)
                {
                    MessageBox.Show(this, ex.Message, @"Error opening file.");
                }

                OpenDocuments.Remove(doc);
                doc.Dispose();
                return(null);
            }
            switch (Path.GetExtension(filename))
            {
            case ".w2scene":
            {
                doc.flowDiagram = new frmChunkFlowDiagram
                {
                    File      = doc.File,
                    DockAreas = DockAreas.Document
                };
                doc.flowDiagram.OnSelectChunk += doc.frmCR2WDocument_OnSelectChunk;
                doc.flowDiagram.Show(doc.FormPanel, DockState.Document);
                break;
            }

            default:
            {
                break;
            }
            }
            if (doc.File.block7.Count > 0)
            {
                doc.embeddedFiles = new frmEmbeddedFiles
                {
                    File      = doc.File,
                    DockAreas = DockAreas.Document
                };
                doc.embeddedFiles.Show(doc.FormPanel, DockState.Document);
            }
            doc.Activated += doc_Activated;
            doc.Show(dockPanel, DockState.Document);
            doc.FormClosed += doc_FormClosed;

            var output = new StringBuilder();

            if (doc.File.UnknownTypes.Any())
            {
                ShowOutput();

                output.Append(doc.FileName + ": contains " + doc.File.UnknownTypes.Count + " unknown type(s):\n");
                foreach (var unk in doc.File.UnknownTypes)
                {
                    output.Append("\"" + unk + "\", \n");
                }

                output.Append("-------\n\n");
            }

            var hasUnknownBytes = false;

            foreach (var t in doc.File.chunks.Where(t => t.unknownBytes?.Bytes != null && t.unknownBytes.Bytes.Length > 0))
            {
                output.Append(t.Name + " contains " + t.unknownBytes.Bytes.Length + " unknown bytes. \n");
                hasUnknownBytes = true;
            }

            if (hasUnknownBytes)
            {
                output.Append("-------\n\n");
            }

            AddOutput(output.ToString());
            return(doc);
        }