Example #1
0
        void DownloadManager_DownloadCompleted(object sender, FmdcEventArgs e)
        {
            DownloadItem di = sender as DownloadItem;
            if (di == null)
                return;
            if (di.ContentInfo.IsFilelist)
            {
                byte[] data = System.IO.File.ReadAllBytes(di.ContentInfo.Get(ContentInfo.STORAGEPATH));
                BaseFilelist filelist = null;
                switch (di.ContentInfo.Get(ContentInfo.FILELIST))
                {
                    case BaseFilelist.XMLBZ:
                        filelist = new FilelistXmlBz2(data, true);
                        break;
                    case BaseFilelist.BZ:
                        filelist = new FilelistMyList(data, true);
                        break;
                }

                if (filelist != null)
                {
                    filelist.CreateShare();
                    Share userShare = filelist.Share;

                    if (user != null)
                    {
                        foreach (System.Collections.Generic.KeyValuePair<string, ContentInfo> var in userShare)
                        {
                            var.Value.Set(ContentInfo.STORAGEPATH, @"C:\Private\FMDC\PiP\FlowLibDemo\ConsoleDemo\bin\Debug\Download\" + var.Value.Get(ContentInfo.NAME));
                            DownloadItem di2 = new DownloadItem(var.Value);
                            // Uncomment below if you want to disable segment downloading.
                            //di2.SegmentSize = di2.ContentInfo.Size;
                            downloadManager.AddDownload(di2, new Source(null, user.ID));
                        }
                    }
                }
            }
        }
Example #2
0
        public static bool TryHandleDownload(DcBot connection, DownloadItem item, Source source)
        {
            if (item != null && source != null)
            {
                string fileType = item.ContentInfo.Get(ContentInfo.FILELIST);
                string func = item.ContentInfo.Get("FUNC");
                string path = item.ContentInfo.Get(ContentInfo.STORAGEPATH);
                string usrId = item.ContentInfo.Get("USR");

                byte[] data = null;

                BaseFilelist filelist = null;

                int i = 0;
                while (i < 10)
                {
                    try
                    {
                        data = File.ReadAllBytes(path);
                        break;
                    }
                    catch (Exception)
                    {
                        System.Threading.Thread.Sleep(100);
                    }
                    finally
                    {
                        i++;
                    }

                }

                if (data == null)
                    return false;

                switch (fileType)
                {
                    case BaseFilelist.XMLBZ:
                        filelist = new FilelistXmlBz2(data, true);
                        break;
                    case BaseFilelist.XML:
                        filelist = new FilelistXmlBz2(data, false);
                        break;
                    case BaseFilelist.BZ:
                        filelist = new FilelistMyList(data, true);
                        break;
                    default:
                        connection.SendMessage(Actions.PrivateMessage, usrId, "Unrecognized filelist.");
                        return false;
                }

                LogMsg("CreateShare");
                filelist.CreateShare();
                LogMsg("/CreateShare");
                Share share = filelist.Share as Share;

                File.Delete(path);

                if (share != null)
                {
                    switch (func)
                    {
                        case "new":
                            FuncListShare(connection, share, usrId, FunctionTypes.ListNewEpisodes); break;
                        case "list":
                            FuncListShare(connection, share, usrId, FunctionTypes.ListAllEpisodes); break;
                        case "debug":
                            FuncListShare(connection, share, usrId, FunctionTypes.ListDebugInfoOnEpisodes); break;
                        case "countdown":
                        case "cd":
                            FuncCountDownShare(connection, share, usrId); break;
                    }
                }
            }

            return false;
        }