Exemplo n.º 1
0
        public static void Close(this MiraConnection p_Connection, int p_Handle)
        {
            if (p_Connection == null)
            {
                return;
            }

            if (p_Handle < 0)
            {
                return;
            }

            var s_Transport = new RpcTransport
            {
                Header = new RpcHeader()
                {
                    Category  = RpcCategory.File,
                    Error     = 0,
                    IsRequest = true,
                    Magic     = c_Magic,
                    Type      = (uint)FileExplorerCommands.FileExplorer_Close
                },
                Data = ByteString.CopyFrom
                       (
                    new FmCloseRequest
                {
                    Handle = p_Handle
                }.ToByteArray()
                       )
            };

            // We don't care about the response
            p_Connection.SendMessageWithResponse(s_Transport);
        }
Exemplo n.º 2
0
        public static byte[] Read(this MiraConnection p_Connection, int p_Handle, ulong p_Offset, int p_Count)
        {
            if (p_Connection == null)
            {
                return(null);
            }

            if (p_Handle < 0)
            {
                return(null);
            }

            var s_Transport = new RpcTransport
            {
                Header = new RpcHeader()
                {
                    Category  = RpcCategory.File,
                    Error     = 0,
                    IsRequest = true,
                    Magic     = c_Magic,
                    Type      = (uint)FileExplorerCommands.FileExplorer_Read
                },
                Data = ByteString.CopyFrom
                       (
                    // TODO: Add offset
                    new FmReadRequest
                {
                    Handle = p_Handle,
                    Size   = (uint)p_Count
                }.ToByteArray()
                       )
            };

            var s_ResponseData = p_Connection.SendMessageWithResponse(s_Transport);

            if (s_ResponseData == null)
            {
                return(null);
            }

            var s_Response = FmReadResponse.Parser.ParseFrom(s_ResponseData.Data);

            if (s_Response == null)
            {
                return(null);
            }

            return(s_Response.Data.ToArray());
        }
Exemplo n.º 3
0
        public static List <FmDent> GetDents(this MiraConnection p_Connection, string p_Path)
        {
            if (p_Connection == null)
            {
                return(new List <FmDent>());
            }

            if (string.IsNullOrWhiteSpace(p_Path))
            {
                return(new List <FmDent>());
            }

            var s_Transport = new RpcTransport
            {
                Header = new RpcHeader()
                {
                    Category  = RpcCategory.File,
                    Error     = 0,
                    IsRequest = true,
                    Magic     = c_Magic,
                    Type      = (uint)FileExplorerCommands.FileExplorer_GetDents
                },
                Data = ByteString.CopyFrom
                       (
                    new FmGetDentsRequest
                {
                    Path = p_Path
                }.ToByteArray()
                       )
            };

            var s_ResponseTransport = p_Connection.SendMessageWithResponse(s_Transport);

            if (s_ResponseTransport == null)
            {
                return(new List <FmDent>());
            }

            var s_Response = FmGetDentsResponse.Parser.ParseFrom(s_ResponseTransport.Data);

            if (s_Response == null)
            {
                return(new List <FmDent>());
            }

            return(s_Response.Dents.ToList());
        }
Exemplo n.º 4
0
        public static int Open(this MiraConnection p_Connection, string p_Path, int p_Flags, int p_Mode)
        {
            if (p_Connection == null)
            {
                return(-1);
            }

            if (string.IsNullOrWhiteSpace(p_Path))
            {
                return(-1);
            }

            var s_Transport = new RpcTransport
            {
                Header = new RpcHeader()
                {
                    Category  = RpcCategory.File,
                    Error     = 0,
                    IsRequest = true,
                    Magic     = c_Magic,
                    Type      = (uint)FileExplorerCommands.FileExplorer_Open
                },
                Data = ByteString.CopyFrom
                       (
                    new FmOpenRequest
                {
                    Path  = p_Path,
                    Flags = p_Flags,
                    Mode  = p_Mode
                }.ToByteArray()
                       )
            };

            var s_Response = p_Connection.SendMessageWithResponse(s_Transport);

            if (s_Response == null)
            {
                return(-1);
            }

            return((int)s_Response.Header.Error);
        }
Exemplo n.º 5
0
        public static bool Write(this MiraConnection p_Connection, int p_Handle, byte[] p_Data)
        {
            if (p_Connection == null)
            {
                return(false);
            }

            if (p_Handle < 0)
            {
                return(false);
            }

            var s_Transport = new RpcTransport
            {
                Header = new RpcHeader()
                {
                    Category  = RpcCategory.File,
                    Error     = 0,
                    IsRequest = true,
                    Magic     = c_Magic,
                    Type      = (uint)FileExplorerCommands.FileExplorer_Write
                },
                Data = ByteString.CopyFrom
                       (
                    // TODO: Add offset
                    new FmWriteRequest
                {
                    Handle = p_Handle,
                    Data   = ByteString.CopyFrom(p_Data)
                }.ToByteArray()
                       )
            };

            var s_ResponseTransport = p_Connection.SendMessageWithResponse(s_Transport);

            if (s_ResponseTransport == null)
            {
                return(false);
            }

            return(s_ResponseTransport.Header.Error >= 0);
        }
Exemplo n.º 6
0
        public static FmStatResponse Stat(this MiraConnection p_Connection, int p_Handle)
        {
            if (p_Connection == null)
            {
                return(null);
            }

            if (p_Handle < 0)
            {
                return(null);
            }

            var s_Transport = new RpcTransport
            {
                Header = new RpcHeader()
                {
                    Category  = RpcCategory.File,
                    Error     = 0,
                    IsRequest = true,
                    Magic     = c_Magic,
                    Type      = (uint)FileExplorerCommands.FileExplorer_Stat
                },
                Data = ByteString.CopyFrom
                       (
                    new FmStatRequest
                {
                    Handle = p_Handle,
                }.ToByteArray()
                       )
            };

            var s_ResponseTransport = p_Connection.SendMessageWithResponse(s_Transport);

            if (s_ResponseTransport == null)
            {
                return(null);
            }

            return(FmStatResponse.Parser.ParseFrom(s_ResponseTransport.Data));
        }