상속: global::ProtoBuf.IExtensible
예제 #1
0
파일: RSRPC.cs 프로젝트: nolith/RSSSHClient
        public uint FilesControllDownload(RequestControlDownload.Action action, File file)
        {
            uint msgID = RSProtoBuf.ConstructMsgId(
                (byte)ExtensionId.CORE,
                (ushort)PackageId.FILES,
                (byte)rsctrl.files.RequestMsgIds.MsgId_RequestControlDownload,
                false
                );

            RequestControlDownload request = new RequestControlDownload();

            request.action = action;
            request.file   = file;
            return(Send <RequestControlDownload>(request, msgID));
        }
예제 #2
0
파일: RSRPC.cs 프로젝트: nolith/RSSSHClient
        public uint StreamRequestStartFileStream(File file, ulong startByte, ulong endByte, float rateKBs)
        {
            uint msgID = RSProtoBuf.ConstructMsgId(
                (byte)ExtensionId.CORE,
                (ushort)PackageId.STREAM,
                (byte)rsctrl.stream.RequestMsgIds.MsgId_RequestStartFileStream,
                false
                );

            RequestStartFileStream request = new RequestStartFileStream();

            request.end_byte   = endByte;
            request.file       = file;
            request.rate_kbs   = rateKBs;
            request.start_byte = startByte;
            return(Send <RequestStartFileStream>(request, msgID));
        }
예제 #3
0
        public static bool ReadCollection(string path, out List<File> fileList)
        {
            XmlTextReader tr = new XmlTextReader(path);
            bool foundCollectionTag = false;
            string currentPath = "";

            File tmpFile = new File();
            fileList = new List<File>();

            while (tr.Read())
            {
                if (tr.Name == "") continue;
                System.Diagnostics.Debug.WriteLineIf(DEBUG, "ReadCollection: node name " + tr.Name);
                System.Diagnostics.Debug.WriteLineIf(DEBUG, "ReadCollection: att count " + tr.AttributeCount);

                switch (tr.Name)
                {
                    case "RsCollection":
                        foundCollectionTag = true;
                        break;
                    case "Directory":
                        // save path
                        try
                        {
                            System.Diagnostics.Debug.WriteLineIf(DEBUG, "ReadCollection: getting file path");
                            currentPath = tr.GetAttribute("name");
                        }
                        catch (Exception e)
                        {
                            System.Diagnostics.Debug.WriteLineIf(DEBUG, "ReadCollection: error reading file path");
                            System.Diagnostics.Debug.WriteLineIf(DEBUG, "ReadCollection: " + e.Message);
                        }
                        break;
                    case "File":
                        // create a tmp file to add it to the list
                        tmpFile = new File();

                        // we need 3 attributes (name, size, hash)
                        if (tr.AttributeCount != 3)
                        {
                            System.Diagnostics.Debug.WriteLineIf(DEBUG, "ReadCollection: file att != 3");
                            break;
                        }

                        // try to add all 3 attributes
                        try
                        {
                            System.Diagnostics.Debug.WriteLineIf(DEBUG, "ReadCollection: adding file");
                            //tmpFile.size = System.Convert.ToUInt32(tr.GetAttribute(0));
                            //tmpFile.hash = tr.GetAttribute(1);
                            //tmpFile.name = tr.GetAttribute(2);
                            tmpFile.hash = tr.GetAttribute("sha1");
                            tmpFile.name = tr.GetAttribute("name");
                            tmpFile.size = System.Convert.ToUInt32(tr.GetAttribute("size"));
                            // TODO add file path
                        }
                        catch (Exception e)
                        {
                            System.Diagnostics.Debug.WriteLineIf(DEBUG, "ReadCollection: error adding file");
                            System.Diagnostics.Debug.WriteLineIf(DEBUG, "ReadCollection: " + e.Message);
                            break;
                        }

                        // the hash is the only thing we can ckeck
                        System.Diagnostics.Debug.WriteLineIf(DEBUG, "ReadCollection: checking file hash");
                        if (tmpFile.hash.Length != 40)
                        {
                            System.Diagnostics.Debug.WriteLineIf(DEBUG, "ReadCollection: error hash.length != 40");
                            break;
                        }

                        // add file to list
                        fileList.Add(tmpFile);
                        break;
                    default:
                        System.Diagnostics.Debug.WriteLineIf(DEBUG, "ReadCollection: unknown name " + tr.Name);
                        break;
                } // swicth
            }  // while

            if (!foundCollectionTag)
            {
                // shouldn't happen
                System.Diagnostics.Debug.WriteLineIf(DEBUG, "ReadCollection: no RsCollection tag!");
                fileList = null;
                return false;
            }
            return true;
        }