コード例 #1
0
        public bool InitFromLink(string sLink)
        {
            ED2KLink     pLink     = null;
            ED2KFileLink pFileLink = null;

            try
            {
                pLink = MuleApplication.Instance.ED2KObjectManager.CreateLinkFromUrl(sLink);
                if (pLink == null)
                {
                    throw new Exception("Not a Valid file link:" + sLink);
                }

                pFileLink = pLink.FileLink;
                if (pFileLink == null)
                {
                    throw new Exception("Not a Valid file link:" + sLink);
                }
            }
            catch (Exception)
            {
                //TODO:Log
                return(false);
            }

            tagList_.Add(MpdObjectManager.CreateTag(MuleConstants.FT_FILEHASH, pFileLink.HashKey));
            MpdUtilities.Md4Cpy(FileHash, pFileLink.HashKey);

            tagList_.Add(MpdObjectManager.CreateTag(MuleConstants.FT_FILESIZE, pFileLink.Size, true));
            FileSize = pFileLink.Size;

            tagList_.Add(MpdObjectManager.CreateTag(MuleConstants.FT_FILENAME, pFileLink.Name));
            SetFileName(pFileLink.Name, false, false, false);

            return(true);
        }
コード例 #2
0
        public ED2KLink CreateLinkFromUrl(string strURI)
        {
            strURI.Trim(); // This function is used for various sources, trim the string again.
            int iPos = 0;

            string[] tokens = strURI.Split('|');

            if (tokens.Length == 0)
            {
                throw new Exception("Not a valid ed2k link:" + strURI);
            }

            string strTok = GetNextToken(ref iPos, tokens);

            if (string.Compare(strTok, "ed2k://", true) == 0)
            {
                strTok = GetNextToken(ref iPos, tokens);
                if (string.Compare(strTok, "file") == 0)
                {
                    string strName = GetNextToken(ref iPos, tokens);
                    if (!string.IsNullOrEmpty(strName))
                    {
                        string strSize = GetNextToken(ref iPos, tokens);
                        if (!string.IsNullOrEmpty(strSize))
                        {
                            string strHash = GetNextToken(ref iPos, tokens);
                            if (!string.IsNullOrEmpty(strHash))
                            {
                                List <string> astrEd2kParams = new List <string>();
                                bool          bEmuleExt      = false;
                                string        strEmuleExt    = null;

                                string strLastTok = null;
                                strTok = GetNextToken(ref iPos, tokens);
                                while (!string.IsNullOrEmpty(strTok))
                                {
                                    strLastTok = strTok;
                                    if (string.Compare(strTok, "/") == 0)
                                    {
                                        if (bEmuleExt)
                                        {
                                            break;
                                        }
                                        bEmuleExt = true;
                                    }
                                    else
                                    {
                                        if (bEmuleExt)
                                        {
                                            if (!string.IsNullOrEmpty(strEmuleExt))
                                            {
                                                strEmuleExt += '|';
                                            }
                                            strEmuleExt += strTok;
                                        }
                                        else
                                        {
                                            astrEd2kParams.Add(strTok);
                                        }
                                    }
                                    strTok = GetNextToken(ref iPos, tokens);
                                }

                                if (string.Compare(strLastTok, "/") == 0)
                                {
                                    ED2KFileLink fileLink =
                                        CreateED2KFileLink(strName, strSize, strHash,
                                                           astrEd2kParams.ToArray(),
                                                           string.IsNullOrEmpty(strEmuleExt) ? null : strEmuleExt);

                                    return(fileLink);
                                }
                            }
                        }
                    }
                }
                else if (string.Compare(strTok, "serverlist") == 0)
                {
                    string strURL = GetNextToken(ref iPos, tokens);
                    if (!string.IsNullOrEmpty(strURL) &&
                        string.Compare(GetNextToken(ref iPos, tokens), "/") == 0)
                    {
                        return(CreateED2KServerListLink(strURL));
                    }
                }
                else if (string.Compare(strTok, "server") == 0)
                {
                    string strServer = GetNextToken(ref iPos, tokens);
                    if (!string.IsNullOrEmpty(strServer))
                    {
                        string strPort = GetNextToken(ref iPos, tokens);
                        if (!string.IsNullOrEmpty(strPort) &&
                            string.Compare(GetNextToken(ref iPos, tokens), "/") == 0)
                        {
                            return(CreateED2KServerLink(strServer, strPort));
                        }
                    }
                }
                else if (string.Compare(strTok, "nodeslist") == 0)
                {
                    string strURL = GetNextToken(ref iPos, tokens);
                    if (!string.IsNullOrEmpty(strURL) &&
                        string.Compare(GetNextToken(ref iPos, tokens), "/") == 0)
                    {
                        return(CreateED2KNodesListLink(strURL));
                    }
                }
            }

            throw new Exception("Not a ed2k link:" + strURI);
        }