コード例 #1
0
        public void OpenMemoryCard(string filePath)
        {
            try
            {
                _filePath = filePath;
                ParseFileData();

                if (_memoryCard != null)
                {
                    _view.UpdateOpenedFile(Path.GetFileName(filePath));
                    _view.UpdateBlockList(_memoryCard.Blocks.Select(x => FormatBlockTitle(x)).ToList(), 
                        _memoryCard.Blocks.Select(x => x.Icon != null ? ParseBitmap(x.Icon) : new Bitmap(16, 16)).ToList());
                }
            }
            catch (Exception ex)
            {
                // Undo memory card loading
                _memoryCard = null;
                _filePath = null;

                Trace.Write(ex.Message);
                Trace.Write(ex.StackTrace);

                _view.HandleError(ex);
            }
        }
コード例 #2
0
        private void ParseFileData()
        {
            byte[] _data;

            try
            {
                using (FileStream fs = File.Open(_filePath, FileMode.Open))
                {
                    _data = new byte[fs.Length];
                    fs.Read(_data, 0, (int)fs.Length);
                }

                if (DirectoryFrameParser.IsValidHeaderFrame(_data.SubArray(0, 128)))
                {
                    _memoryCard = new MemoryCard();
                    _memoryCard.FileName = Path.GetFileName(_filePath);

                    for (int i = 1; i < 16; ++i)
                    {
                        _memoryCard.DirectoryFrames.Add(DirectoryFrameParser.Parse(_data.SubArray(128 * i, 128)));
                        _memoryCard.Blocks.Add(BlockParser.Parse(_data.SubArray(8192 * i, 8192)));
                    }
                }
                else
                {
                    throw new InvalidDataException("Selected file is not a valid PSX memory card.");
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }