// Update is called once per frame
 void Update()
 {
     if (Input.GetMouseButtonDown(0))
     {
         m_DownloadManager.AddDownload(path, url, DefaultPriority);
     }
 }
Exemple #2
0
 private void AddDownload(Download download)
 {
     if (!downloadManager.AddDownload(download))
     {
         MessageBox.Show(this, Localization.GetString("msg.url_already_added", "The video URL is already added to the download list!"), Localization.GetString("msg.url_already_added.title", "Failed to queue download!"), MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
     }
 }
 void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
 {
     if (hub != null && !hub.IsDisposed && hub.RegMode >= 0 && !sentRequest)
     {
         if (last > System.DateTime.Now.Subtract(new System.TimeSpan(0, 0, 30)).Ticks)
         {
             SortedList <string, User> usrs = new SortedList <string, User>(hub.Userlist);
             foreach (var item in usrs)
             {
                 if (item.Value.ID == hub.Me.ID || item.Value.ID == "-YnHub-")
                 {
                     continue;
                 }
                 User usr = item.Value;
                 new Thread(
                     delegate()
                 {
                     // Adding filelist of unknown type to download manager.
                     ContentInfo info = new ContentInfo(ContentInfo.FILELIST, BaseFilelist.UNKNOWN);
                     info.Set(ContentInfo.ID, usr.StoreID);
                     info.Set(ContentInfo.STORAGEPATH, currentDir + "Filelists\\" + usr.StoreID + ".filelist");
                     downloadManager.AddDownload(new DownloadItem(info), new Source(hub.RemoteAddress.ToString(), usr.StoreID));
                     // Start transfer to user
                     UpdateBase(this, new FmdcEventArgs(Actions.StartTransfer, usr));
                 }).Start();
             }
             sentRequest = true;
         }
     }
 }
Exemple #4
0
    public void Click()
    {
        DownloadManager downloadManager = DownloadManagerHelper.GetDonwloadManager();
        int             id = downloadManager.AddDownload(UrlText.text, PathText.text, true, HttpVerbType.kHttpVerbGET, completed);

        msgs[id] = Instantiate(msgPrefabs, content.transform);
        msgs[id].transform.Find("StartOrPause").GetComponent <ButtonEvent>().id = id;
    }
        public void GetFileList(User usr, string func)
        {
            ContentInfo info = new ContentInfo(ContentInfo.FILELIST, BaseFilelist.UNKNOWN);
            string      id   = FlowLib.Utils.Convert.Base32.Encode(System.Text.Encoding.UTF8.GetBytes(usr.StoreID.ToLower().Trim()));

            info.Set(ContentInfo.STORAGEPATH, "filelists" + System.IO.Path.DirectorySeparatorChar + id + ".filelist");
            info.Set("USR", usr.ID);
            info.Set("FUNC", func);
            downloadManager.AddDownload(new DownloadItem(info), new Source(hubConnection.HubSetting.Address + hubConnection.HubSetting.Port, usr.StoreID));

            UpdateBase(this, new FmdcEventArgs(Actions.StartTransfer, usr));
        }
        void hubConnection_Update(object sender, FmdcEventArgs e)
        {
            Hub hub = (Hub)sender;

            switch (e.Action)
            {
            case Actions.TransferRequest:
                if (e.Data is TransferRequest)
                {
                    TransferRequest req = (TransferRequest)e.Data;
                    if (transferManager.GetTransferReq(req.Key) == null)
                    {
                        transferManager.AddTransferReq(req);
                    }
                }
                break;

            case Actions.TransferStarted:
                Transfer trans = e.Data as Transfer;
                if (trans != null)
                {
#if !COMPACT_FRAMEWORK
                    // Security, Windows Mobile doesnt support SSLStream so we disable this feature for it.
                    trans.SecureUpdate += new FmdcEventHandler(trans_SecureUpdate);
#endif
                    transferManager.StartTransfer(trans);
                    trans.Protocol.ChangeDownloadItem += new FmdcEventHandler(Protocol_ChangeDownloadItem);
                    trans.Protocol.RequestTransfer    += new FmdcEventHandler(Protocol_RequestTransfer);
                }
                break;

            case Actions.UserOnline:
                bool hasMe = (hub.GetUserById(hub.Me.ID) != null);
                if (!sentRequest && hasMe)
                {
                    User usr = null;
                    if ((usr = hub.GetUserByNick("FlowLibActiveTLS")) != null)
                    {
                        // Adding filelist of unknown type to download manager.
                        // to the user FlowLibActiveTLS
                        ContentInfo info = new ContentInfo(ContentInfo.FILELIST, BaseFilelist.UNKNOWN);
                        info.Set(ContentInfo.STORAGEPATH, currentDir + "Filelists\\" + usr.StoreID + ".filelist");
                        downloadManager.AddDownload(new DownloadItem(info), new Source(hub.RemoteAddress.ToString(), usr.StoreID));
                        // Start transfer to user
                        UpdateBase(this, new FmdcEventArgs(Actions.StartTransfer, usr));
                        sentRequest = true;
                    }
                }
                break;
            }
        }
Exemple #7
0
        void hubConnection_Update(object sender, FmdcEventArgs e)
        {
            Hub hub = (Hub)sender;

            switch (e.Action)
            {
            case Actions.TransferRequest:
                if (e.Data is TransferRequest)
                {
                    TransferRequest req = (TransferRequest)e.Data;
                    if (transferManager.GetTransferReq(req.Key) == null)
                    {
                        transferManager.AddTransferReq(req);
                    }
                }
                break;

            case Actions.TransferStarted:
                Transfer trans = e.Data as Transfer;
                if (trans != null)
                {
                    // Here we bind transfer to our data collector
                    stats = new GeneralProtocolDataCollector(trans);
                    transferManager.StartTransfer(trans);
                    trans.Protocol.ChangeDownloadItem += new FmdcEventHandler(Protocol_ChangeDownloadItem);
                    trans.Protocol.RequestTransfer    += new FmdcEventHandler(Protocol_RequestTransfer);
                }
                break;

            case Actions.UserOnline:
                bool hasMe = (hub.GetUserById(hub.Me.ID) != null);
                if (!sentRequest && hasMe)
                {
                    User usr = null;
                    if ((usr = hub.GetUserByNick("DCpp706")) != null)
                    {
                        // Adding filelist of unknown type to download manager.
                        // to the user DCpp706
                        ContentInfo info = new ContentInfo(ContentInfo.FILELIST, BaseFilelist.UNKNOWN);
                        info.Set(ContentInfo.STORAGEPATH, currentDir + "Filelists\\" + usr.StoreID + ".filelist");
                        downloadManager.AddDownload(new DownloadItem(info), new Source(hub.RemoteAddress.ToString(), usr.StoreID));
                        // Start transfer to user
                        UpdateBase(this, new FmdcEventArgs(Actions.StartTransfer, usr));
                        sentRequest = true;
                    }
                }
                break;
            }
        }
Exemple #8
0
        private void downloadEpisode_Click(object sender, RoutedEventArgs e)
        {
            MenuItem mnu = sender as MenuItem;
            ListView lv  = ((ContextMenu)mnu.Parent).PlacementTarget as ListView;

            List <Episode> episodes = lv.SelectedItems.OfType <Episode>().ToList();

            episodes.Reverse();

            foreach (Episode episode in episodes)
            {
                AnimeDownload dl = new AnimeDownload();
                dl.Title   = episode.EpisodeName;
                dl.Episode = episode;

                DownloadManager.AddDownload(dl);
            }
        }
 private void ButtonDownloadAll_OnClick(object sender, RoutedEventArgs e)
 {
     DownloadManager.AddDownload(songs);
 }
Exemple #10
0
 private void BtnDownload_OnClick(object sender, RoutedEventArgs e)
 {
     DownloadManager.AddDownload(ncsong);
 }
Exemple #11
0
        void downloadManager_DownloadCompleted(object sender, FmdcEventArgs e)
        {
            DownloadItem dwnItem = sender as DownloadItem;

            if (dwnItem == null)
            {
                return;
            }

            if (dwnItem.ContentInfo.IsFilelist)
            {
                _gotFilelist = true;
                // Read filelist
                byte[]       data     = System.IO.File.ReadAllBytes(dwnItem.ContentInfo.Get(ContentInfo.STORAGEPATH));
                BaseFilelist filelist = null;
                switch (dwnItem.ContentInfo.Get(ContentInfo.FILELIST))
                {
                case BaseFilelist.XMLBZ:
                    filelist = new FilelistXmlBz2(data, true);
                    break;

                case BaseFilelist.XML:
                    filelist = new FilelistXmlBz2(data, false);
                    break;
                }
                _testTimeoutLength += 10;
                filelist.CreateShare();
                IShare share = filelist.Share;

                // Select one file that is more then 500 MiB of size
                var bigContentItem = share.Where(f => f.Value.Size > BIGSIZE).Select(k => k.Value).FirstOrDefault();
                // Select one file that is less then 100 MiB of size
                var smallContentItem = share.Where(f => f.Value.Size < SMALLSIZE).Select(k => k.Value).FirstOrDefault();

                if (bigContentItem == null)
                {
                    return;
                }
                // Add BIG file for a user
                bigContentItem.Set(ContentInfo.STORAGEPATH, currentDir + "Download" + System.IO.Path.DirectorySeparatorChar + "big" + ".file");
                downloadManager.AddDownload(new DownloadItem(bigContentItem), new Source(dwnItem.ContentInfo.Get("HubStoreId"), dwnItem.ContentInfo.Get(UserInfo.STOREID)));
                _hasBigContent = true;

                if (smallContentItem == null)
                {
                    return;
                }
                // Add SMALL file for a user
                smallContentItem.Set(ContentInfo.STORAGEPATH, currentDir + "Download" + System.IO.Path.DirectorySeparatorChar + "small" + ".file");
                downloadManager.AddDownload(new DownloadItem(smallContentItem), new Source(dwnItem.ContentInfo.Get("HubStoreId"), dwnItem.ContentInfo.Get(UserInfo.STOREID)));
                _hasSmallContent = true;

                _testTimeoutLength += 30;
            }
            else
            {
                // Handle file
                if (dwnItem.ContentInfo.Size > BIGSIZE)
                {
                    _gotBigContent = true;
                }
                else if (dwnItem.ContentInfo.Size < SMALLSIZE)
                {
                    _gotSmallContent = true;
                }
            }

            if (_gotFilelist && _gotBigContent && _gotSmallContent)
            {
                _isFinished = true;
            }
        }
Exemple #12
0
        /// <summary>
        /// </summary>
        public static void OnStart()
        {
            Statistic.Instantiate();

            ScmManager = new ScmManager();
            IOQueue    = new AsyncIOQueue();
            ManifestDownloadManager = new ManifestDownloadManager();

            DownloadManager = new DownloadManager();
            DownloadManager.OnRequestReplicatedBuilds += (List <Guid> SelectTags, List <Guid> IgnoreTags, DateTime NewerThan) =>
            {
                NetClient.RequestFilteredBuilds(SelectTags, IgnoreTags, NewerThan);

                Settings.ReplicationNewerThanTime = DownloadManager.ReplicationNewerThanTime;
                SaveSettings();
            };

            Logger.Log(LogLevel.Info, LogCategory.Main, "OnStart: Initializing settings");
            InitSettings();

            NetClient          = new Core.Client.Client();
            RemoteActionClient = new RemoteActionClient(NetClient, ManifestDownloadManager);

            TagRegistry   = new TagRegistry();
            RouteRegistry = new RouteRegistry(null, TagRegistry);
            BuildRegistry = new BuildManifestRegistry(TagRegistry);

            StorageManager = new StorageManager(Settings.StorageLocations, ManifestDownloadManager, BuildRegistry, IOQueue, Settings.StorageHeuristic, Settings.PrioritizeKeepingBuildTagIds, Settings.PrioritizeDeletingBuildTagIds);

            Logger.Log(LogLevel.Info, LogCategory.Main, "OnStart: Setting up network client");
            BuildRegistry.Open(Path.Combine(AppDataDir, "Manifests"), int.MaxValue);

            Logger.Log(LogLevel.Info, LogCategory.Main, "OnStart: Setting up network client");
            NetClient.Start(
                Settings.ServerHostname,
                Settings.ServerPort,
                Settings.ClientPortRangeMin,
                Settings.ClientPortRangeMax,
                Settings.AllowRemoteActions,
                Settings.TagIds,
                BuildRegistry,
                StorageManager,
                ManifestDownloadManager,
                TagRegistry,
                RouteRegistry
                );
            NetClient.TagIds = new List <Guid>(Settings.TagIds);

            // Setup the virtual file system we will store our available builds in.
            Logger.Log(LogLevel.Info, LogCategory.Main, "OnStart: Setting up build file system");

            BuildFileSystem = new VirtualFileSystem();
            NetClient.OnClientTagsUpdatedByServer += () =>
            {
                Settings.TagIds = NetClient.TagIds;

                NetClient.RestartConnections();
                SaveSettings();
            };
            NetClient.OnTagListRecieved += (List <Tag> InTags) =>
            {
                TagRenderer.InvalidateResources();
            };
            NetClient.OnPermissionsUpdated += () =>
            {
                BuildFileSystem.ForceRefresh();
                DownloadManager.ForceRefresh();
            };
            NetClient.OnBuildPublished += (string Path, Guid Id) =>
            {
                BuildFileSystem.ForceRefresh();
                DownloadManager.ForceRefresh();
            };
            NetClient.OnBuildUpdated += (string Path, Guid Id) =>
            {
                BuildFileSystem.ForceRefresh();
                DownloadManager.ForceRefresh();
            };
            NetClient.OnConnectedToServer      += () => { BuildFileSystem.ForceRefresh(); };
            NetClient.OnFilteredBuildsRecieved += (Builds) =>
            {
                DownloadManager.RecieveReplicatedBuilds(Builds);
            };
            NetClient.OnBuildsRecieved += (RootPath, Builds) =>
            {
                List <VirtualFileSystemInsertChild> NewChildren = new List <VirtualFileSystemInsertChild>();
                foreach (NetMessage_GetBuildsResponse.BuildInfo Build in Builds)
                {
                    NewChildren.Add(
                        new VirtualFileSystemInsertChild
                    {
                        VirtualPath = Build.VirtualPath,
                        CreateTime  = Build.Guid == Guid.Empty ? DateTime.UtcNow : Build.CreateTime,
                        Metadata    = Build
                    }
                        );
                }

                BuildFileSystem.ReconcileChildren(RootPath, NewChildren);
            };
            BuildFileSystem.OnRequestChildren += (FileSystem, Path) =>
            {
                if (NetClient.IsConnected)
                {
                    NetClient.RequestBuilds(Path);
                }
            };
            BuildFileSystem.Init();

            // Setup download managers for the manifest and app level.
            Logger.Log(LogLevel.Info, LogCategory.Main, "OnStart: Setting up manifest download manager");

            ManifestDownloadManager.Start(
                StorageManager,
                Settings.ManifestDownloadStates,
                BuildRegistry,
                IOQueue
                );

            Logger.Log(LogLevel.Info, LogCategory.Main, "OnStart: Setting up download manager");

            DownloadManager.Start(
                ManifestDownloadManager,
                Settings.DownloadStates,
                BuildFileSystem,
                ScmManager,
                Settings.ReplicationNewerThanTime
                );

            Logger.Log(LogLevel.Info, LogCategory.Main, "OnStart: Setting up update download");

            // Ensure we are downloading the latest update.
            string UpdateDownloadName = "$ Buildsync Update $";

            foreach (DownloadState State in DownloadManager.States.States)
            {
                if (State.Name == UpdateDownloadName)
                {
                    InternalUpdateDownload = State;
                    break;
                }
            }

            if (InternalUpdateDownload == null)
            {
                InternalUpdateDownload = DownloadManager.AddDownload(UpdateDownloadName, "$Internal$/Updates", 2, BuildSelectionRule.Newest, BuildSelectionFilter.None, "", "", true, false, "", "", new List <Guid>(), new List <Guid>());
            }

            // Make sure we have to get the latest manifest id before updating.
            InternalUpdateDownload.ActiveManifestId = Guid.Empty;

            // Clean up any orphan builds.
            StorageManager.CleanUpOrphanBuilds();

            Logger.Log(LogLevel.Info, LogCategory.Main, "OnStart: Complete");
        }
Exemple #13
0
 private void Btn_Down_OnClick(object sender, RoutedEventArgs e)
 {
     DownloadManager.AddDownload(HyPlayList.NowPlayingItem.ToNCSong());
 }
Exemple #14
0
        /// <summary>
        /// Allows to start a file download easily
        /// </summary>
        /// <param name="magnet">Magnet-link to search file</param>
        /// <param name="fullSystemPath">optional complete file path to be saved</param>
        /// <param name="sources">optional set of sources to use</param>
        public DownloadItem DownloadFile(Magnet magnet, string fullSystemPath = null, IEnumerable <Source> sources = null)
        {
            if (string.IsNullOrEmpty(fullSystemPath))
            {
                fullSystemPath = Path.Combine(Settings.PathDownload, magnet.FileName);
            }
            else
            {
                if (Directory.Exists(fullSystemPath))
                {
                    throw new ArgumentException("Provide full system path to the file, not the directory", fullSystemPath);
                }
            }


            if (!FileHelper.IsValidFilePath(fullSystemPath))
            {
                throw new InvalidFileNameException("Storage path of the file is invalid")
                      {
                          FileName = fullSystemPath
                      }
            }
            ;

            if (!FileHelper.IsValidFileName(Path.GetFileName(fullSystemPath)))
            {
                throw new InvalidFileNameException("Storage path of the file is invalid")
                      {
                          FileName = fullSystemPath
                      }
            }
            ;

            if (!string.IsNullOrEmpty(magnet.FileName))
            {
                if (!FileHelper.IsValidFileName(magnet.FileName))
                {
                    throw new InvalidFileNameException("Name of the file is invalid")
                          {
                              FileName = magnet.FileName
                          }
                }
                ;
            }

            var di = new DownloadItem(magnet)
            {
                SaveTargets = new List <string> {
                    fullSystemPath
                }
            };



            if (sources != null)
            {
                di.Sources.AddRange(sources);
            }

            var result = SearchManager.GetHubResultByTTH(di.Magnet.TTH);

            if (result != null)
            {
                di.Sources.AddRange(result.Sources);
            }

            if (DownloadManager.AddDownload(di) && Active)
            {
                if (di.Sources.Count == 0)
                {
                    lock (DownloadManager.SyncRoot)
                        SearchManager.Search(di);
                }
                else
                {
                    TransferManager.RequestTransfers(di);
                }
            }

            return(di);
        }
Exemple #15
0
        public void Hub_Update(object sender, FlowLib.Events.FmdcEventArgs e)
        {
            Hub hub = (Hub)sender;

            this.hub = hub;
            string str = string.Empty;

            switch (e.Action)
            {
            case Actions.TransferStarted:
                if (e.Data is ITransfer)
                {
                    ITransfer trans = (ITransfer)e.Data;
                    transferManager.StartTransfer(trans);
                }
                break;

            case Actions.TransferRequest:
                if (e.Data is TransferRequest)
                {
                    TransferRequest req = (TransferRequest)e.Data;
                    transferManager.AddTransferReq(req);
                }
                break;

                #region MainMessage
            case Actions.MainMessage:
                if (e.Data is MainMessage)
                {
                    MainMessage mainchat = (MainMessage)e.Data;
                    if (mainchat.From == null)
                    {
                        str = mainchat.Content;
                    }
                    else
                    {
                        User u = hub.GetUserById(mainchat.From);
                        if (u == null)
                        {
                            str = "<" + mainchat.From + "> " + mainchat.Content;
                        }
                        else
                        {
                            str = "<" + u.DisplayName + "> " + mainchat.Content;
                        }
                    }
                    // Test : Start
                    user = hub.GetUserById("DC++0.699");
                    //User user = hub.GetUserById("DCDM++0.0495");
                    if (user != null && hub.Share != null)
                    {
                        ContentInfo ci = new ContentInfo(ContentInfo.FILELIST, FlowLib.Utils.FileLists.BaseFilelist.UNKNOWN);
                        ci.Set(ContentInfo.STORAGEPATH, @"C:\Private\FMDC\PiP\FlowLibDemo\ConsoleDemo\bin\Debug\FileLists\" + user.ID + ".xml.bz2");
                        DownloadItem di = new DownloadItem(ci);
                        downloadManager.AddDownload(di, new Source(null, user.ID));
                        downloadManager.DownloadCompleted += new FmdcEventHandler(DownloadManager_DownloadCompleted);
                        this.Hub_Update(null, new FmdcEventArgs(Actions.TransferRequest, new TransferRequest(user.ID, hub, user.UserInfo)));
                        //TransferManager.AddTransferReq(user.ID, hub, user.UserInfo);
                        hub.Send(new FlowLib.Protocols.HubNmdc.ConnectToMe(user.ID, hub.Share.Port, hub));
                    }
                    // Test : End
                }
                else
                {
                    str = e.Data.ToString();
                }
                Console.WriteLine(str);
                break;

                #endregion
                #region PrivateMessage
            case Actions.PrivateMessage:
                PrivateMessage to = (PrivateMessage)e.Data;
                Console.WriteLine("*** PM From: " + to.From + ", To: " + to.To + " " + to.Content);
                break;

                #endregion
                #region RegMode
            case Actions.RegMode:
                break;

                #endregion
                #region Status
            case Actions.StatusChange:
                HubStatus status = (HubStatus)e.Data;
                switch (status.Code)
                {
                case HubStatus.Codes.Disconnected:
                    Console.WriteLine("*** Hub Disconnected");
                    if (status.Exception != null)
                    {
#if DEBUG
                        if (status.Exception is System.Net.Sockets.SocketException)
                        {
                            System.Net.Sockets.SocketException se = (System.Net.Sockets.SocketException)status.Exception;
                            StringBuilder sb = new StringBuilder();
                            sb.Append("\r\n");
                            sb.Append("\tErrorCode: " + se.ErrorCode + "\r\n");
                            sb.Append("\tMessage: " + se.Message + "\r\n");
                            sb.Append("\tStackTrace: " + se.StackTrace);
                            Console.WriteLine(sb.ToString());
                        }
#else
                        Console.WriteLine(" : " + status.Exception.Message);
                        //richTextBox1.AppendText(status.Exception.StackTrace);
#endif
                    }
                    Console.WriteLine("\r\n");
                    break;

                case HubStatus.Codes.Connected:
                    Console.WriteLine("*** Hub Connected");
                    break;

                case HubStatus.Codes.Connecting:
                    Console.WriteLine("*** Hub Connecting");
                    break;
                }
                break;

                #endregion
            default:
                Console.WriteLine(e.Data);
                break;
            }
        }