Beispiel #1
0
 public InvalidHfsCommandEvent(HostFileSystemCommands command) : base(
         $"Invalid Command: {command}",
         ErrorEventKeys.s_HfsInvalidCommand,
         false
         )
 {
 }
Beispiel #2
0
        public override void WriteData(uint address, uint data)
        {
            if (address == m_Settings.PinData)
            {
                if (m_Status == HostFileSystemStatus.HfsStatusFileOpen)
                {
                    m_CurrentFileStream.Write(BitConverter.GetBytes(data), 0, sizeof(uint));
                }
                else if (m_Status == HostFileSystemStatus.HfsStatusReady)
                {
                    char chr = ( char )data;
                    m_SbPath.Append(chr);
                }
            }

            if (address == m_Settings.PinCmd)
            {
                HostFileSystemCommands cmd = ( HostFileSystemCommands )data;

                switch (cmd)
                {
                case HostFileSystemCommands.HfsDeviceReset:
                    m_Status = HostFileSystemStatus.HfsStatusReady;
                    m_SbPath.Clear();
                    m_CurrentFileStream?.Close();
                    m_CurrentFileStream = null;
                    m_CurrentFile       = null;

                    break;

                case HostFileSystemCommands.HfsOpenRead:
                    m_Status = HostFileSystemStatus.HfsStatusFileOpen;
                    string pathR = GetPath(m_SbPath.ToString());

                    //Log( "Opening File(READ): " + pathR );

                    if (!File.Exists(pathR))
                    {
                        EventManager <ErrorEvent> .SendEvent(new FileNotFoundEvent( pathR, false ));
                    }
                    else
                    {
                        m_CurrentFileStream = File.OpenRead(pathR);
                        m_CurrentFile       = new FileInfo(pathR);
                    }

                    m_SbPath.Clear();

                    break;

                case HostFileSystemCommands.HfsOpenWrite:
                    m_Status = HostFileSystemStatus.HfsStatusFileOpen;
                    string pathW = GetPath(m_SbPath.ToString());

                    //Log( "Opening File(WRITE): " + pathW );

                    if (!File.Exists(m_SbPath.ToString()))
                    {
                        m_CurrentFileStream = File.Create(pathW);
                        m_CurrentFile       = new FileInfo(pathW);
                    }
                    else
                    {
                        m_CurrentFileStream = File.OpenWrite(pathW);
                        m_CurrentFile       = new FileInfo(pathW);
                    }

                    m_SbPath.Clear();

                    break;

                case HostFileSystemCommands.HfsClose:
                    //Log( "Closing File: " + m_CurrentFile.FullName );
                    m_Status = HostFileSystemStatus.HfsStatusReady;
                    m_SbPath.Clear();
                    m_CurrentFileStream?.Close();
                    m_CurrentFileStream = null;
                    m_CurrentFile       = null;

                    break;

                case HostFileSystemCommands.HfsFileSize:
                    string p = GetPath(m_SbPath.ToString());
                    m_CurrentFile = new FileInfo(p);
                    m_SbPath.Clear();
                    m_ReadFileSize = true;

                    break;

                case HostFileSystemCommands.HfsFileExist:
                    string testFile = GetPath(m_SbPath.ToString());

                    //Log( "[Test File Exists] {0}", testFile );
                    m_CurrentFile = new FileInfo(testFile);
                    m_SbPath.Clear();
                    m_ReadFileExists = true;

                    break;

                case HostFileSystemCommands.HfsChangeDir:
                    string dir = GetPath(m_SbPath.ToString());
                    Directory.SetCurrentDirectory(dir);
                    m_SbPath.Clear();

                    break;

                case HostFileSystemCommands.HfsMakeDir:
                    string newDir = GetPath(m_SbPath.ToString());
                    Directory.CreateDirectory(newDir);
                    m_SbPath.Clear();

                    break;

                case HostFileSystemCommands.HfsFileDelete:
                    string targetFile = GetPath(m_SbPath.ToString());
                    m_SbPath.Clear();

                    if (!m_Settings.EnableDeleteFiles)
                    {
                        break;
                    }

                    File.Delete(targetFile);

                    break;

                case HostFileSystemCommands.HfsLoadSymbols:
                    string target = GetPath(m_SbPath.ToString());
                    m_SbPath.Clear();
                    AttachedCpu.SymbolServer.LoadSymbols(target);

                    break;

                default:
                    EventManager <ErrorEvent> .SendEvent(new InvalidHfsCommandEvent( cmd ));

                    break;
                }
            }
        }