示例#1
0
        private void LoadInternal(eOpenType xiOpenType, string xiFilename)
        {
            Chunk  lNewRootChunk  = null;
            string lExceptionWhen = "opening file";

            try
            {
                using (FileStream fs = File.OpenRead(xiFilename))
                {
                    lExceptionWhen = "deserialising the file";
                    switch (xiOpenType)
                    {
                    case eOpenType.LevelBinary:
                        lNewRootChunk = new Level(fs);
                        break;

                    case eOpenType.UnknownBinary:
                        lNewRootChunk = new FileChunk(fs);
                        break;

                    case eOpenType.Mmv:
                        lNewRootChunk = new VersionList(fs);
                        break;

                    case eOpenType.Xml:
                        XmlSerializer xs = new XmlSerializer(typeof(Chunk));
                        lNewRootChunk = (Chunk)xs.Deserialize(fs);
                        break;

                    default: throw new Exception("unreachable case");
                    }

                    if (fs.Length != fs.Position)
                    {
                        //check the whole file has been read
                        throw new DeserialisationException(string.Format("Deserialisation terminated early at byte {0} of {1}", fs.Position, fs.Length));
                    }
                }
            }
            catch (Exception err)
            {
                Trace.WriteLine(err);
                MessageBox.Show(string.Format("Exception occurred while {0}: {1}", lExceptionWhen, err.Message), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            // level loaded OK, now fill tree:
            RootChunk = lNewRootChunk;
            mLocalSettings.LastOpenedFile = xiFilename;
            mLocalSettings.LastOpenedType = xiOpenType;
            mCurrentFile     = xiFilename;
            mCurrentFileMode = xiOpenType == eOpenType.Mmv ? eSaveMode.Mmv : xiOpenType == eOpenType.Xml ? eSaveMode.Xml : eSaveMode.Binary;
        }
示例#2
0
        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //=======================================================================
            // Prompt for file
            //=======================================================================
            OpenFileDialog.FileName    = mLocalSettings.LastOpenedFile;
            OpenFileDialog.Filter      = OPEN_FILTER;
            OpenFileDialog.FilterIndex = (int)mLocalSettings.LastOpenedType;

            if (OpenFileDialog.ShowDialog(this) == DialogResult.OK)
            {
                //=====================================================================
                // Open the file
                //=====================================================================
                string    lFileToOpen = OpenFileDialog.FileName;
                eOpenType lOpenType   = (eOpenType)OpenFileDialog.FilterIndex;
                LoadInternal(lOpenType, lFileToOpen);
            }
        }
示例#3
0
        private void LoadInternal(eOpenType xiOpenType, string xiFilename)
        {
            Chunk lNewRootChunk = null;
              string lExceptionWhen = "opening file";
              try
              {
            using (FileStream fs = File.OpenRead(xiFilename))
            {
              lExceptionWhen = "deserialising the file";
              switch (xiOpenType)
              {
            case eOpenType.LevelBinary:
              lNewRootChunk = new Level(fs);
              break;
            case eOpenType.UnknownBinary:
              lNewRootChunk = new FileChunk(fs);
              break;
            case eOpenType.Mmv:
              lNewRootChunk = new VersionList(fs);
              break;
            case eOpenType.Xml:
              XmlSerializer xs = new XmlSerializer(typeof(Chunk));
              lNewRootChunk = (Chunk)xs.Deserialize(fs);
              break;
            default: throw new Exception("unreachable case");
              }

              if (fs.Length != fs.Position)
              {
            //check the whole file has been read
            throw new DeserialisationException(string.Format("Deserialisation terminated early at byte {0} of {1}", fs.Position, fs.Length));
              }
            }
              }
              catch (Exception err)
              {
            Trace.WriteLine(err);
            MessageBox.Show(string.Format("Exception occurred while {0}: {1}", lExceptionWhen, err.Message), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            return;
              }
              // level loaded OK, now fill tree:
              RootChunk = lNewRootChunk;
              mLocalSettings.LastOpenedFile = xiFilename;
              mLocalSettings.LastOpenedType = xiOpenType;
              mCurrentFile = xiFilename;
              mCurrentFileMode = xiOpenType == eOpenType.Mmv ? eSaveMode.Mmv : xiOpenType == eOpenType.Xml ? eSaveMode.Xml : eSaveMode.Binary;
        }