Ejemplo n.º 1
0
        public static bool RefreshLink(DownloadItemBase item, IRefreshLinkDialog dialog)
        {
            try
            {
                if (item.DownloadType != "Http" && item.DownloadType != "Dash")
                {
                    return(false);
                }
                string?referer = null;
                if (item.DownloadType == "Http")
                {
                    var state = DownloadStateIO.LoadSingleSourceHTTPDownloaderState(item.Id);
                    referer = GetReferer(state.Headers);
                }
                else if (item.DownloadType == "Dash")
                {
                    var state = DownloadStateIO.LoadDualSourceHTTPDownloaderState(item.Id);
                    referer = GetReferer(state.Headers1);
                }
                else
                {
                    return(false);
                }
                Log.Debug("Referer: " + referer);
                if (referer != null)
                {
                    dialog.WatchingStopped += (a, b) =>
                    {
                        ApplicationContext.LinkRefresher.ClearWatchList();
                    };

                    OpenBrowser(referer);
                    if (item.DownloadType == "Http")
                    {
                        var downloader = new SingleSourceHTTPDownloader(item.Id);
                        downloader.RestoreState();
                        ApplicationContext.LinkRefresher.RefreshedLinkReceived += (_, _) => dialog.LinkReceived();
                        ApplicationContext.LinkRefresher.AddToWatchList(downloader);
                    }
                    else if (item.DownloadType == "Dash")
                    {
                        var downloader = new DualSourceHTTPDownloader(item.Id);
                        downloader.RestoreState();
                        ApplicationContext.LinkRefresher.RefreshedLinkReceived += (_, _) => dialog.LinkReceived();
                        ApplicationContext.LinkRefresher.AddToWatchList(downloader);
                    }

                    dialog.ShowWindow();
                    return(true);
                }
            }
            catch (Exception e)
            {
                Log.Debug(e, e.Message);
            }
            return(false);
        }
Ejemplo n.º 2
0
 public void ShowPropertiesDialog(DownloadItemBase ent, ShortState?state)
 {
     using var propWin    = PropertiesDialog.CreateFromGladeFile(GetMainWindow(), GetWindowGroup());
     propWin.FileName     = ent.Name;
     propWin.Folder       = ent.TargetDir ?? FileHelper.GetDownloadFolderByFileName(ent.Name);
     propWin.Address      = ent.PrimaryUrl;
     propWin.FileSize     = FormattingHelper.FormatSize(ent.Size);
     propWin.DateAdded    = ent.DateAdded.ToLongDateString() + " " + ent.DateAdded.ToLongTimeString();
     propWin.DownloadType = ent.DownloadType;
     propWin.Referer      = ent.RefererUrl;
     propWin.Cookies      = state?.Cookies ?? state?.Cookies1 ?? new Dictionary <string, string>();
     propWin.Headers      = state?.Headers ?? state?.Headers1 ?? new Dictionary <string, List <string> >();
     propWin.Run();
     propWin.Destroy();
     propWin.Dispose();
 }
Ejemplo n.º 3
0
        public void ShowPropertiesDialog(DownloadItemBase ent, ShortState?state)
        {
            var propertiesWindow = new DownloadPropertiesWindow
            {
                FileName     = ent.Name,
                Folder       = ent.TargetDir ?? FileHelper.GetDownloadFolderByFileName(ent.Name),
                Address      = ent.PrimaryUrl,
                FileSize     = FormattingHelper.FormatSize(ent.Size),
                DateAdded    = ent.DateAdded.ToLongDateString() + " " + ent.DateAdded.ToLongTimeString(),
                DownloadType = ent.DownloadType,
                Referer      = ent.RefererUrl,
                Cookies      = state?.Cookies ?? state?.Cookies1 ?? new Dictionary <string, string>(),
                Headers      = state?.Headers ?? state?.Headers1 ?? new Dictionary <string, List <string> >(),
                Owner        = GetMainWindow()
            };

            propertiesWindow.ShowDialog(GetMainWindow());
        }
Ejemplo n.º 4
0
        public bool LoadDownloads(
            out List <InProgressDownloadItem> inProgressDownloads,
            out List <FinishedDownloadItem> finishedDownloads, QueryMode queryMode = QueryMode.All)
        {
            lock (db)
            {
                inProgressDownloads = new List <InProgressDownloadItem>();
                finishedDownloads   = new List <FinishedDownloadItem>();
                try
                {
                    SQLiteCommand sqlCommand;
                    if (queryMode == QueryMode.All)
                    {
                        if (cmdFetchAll == null)
                        {
                            cmdFetchAll = new SQLiteCommand("SELECT * FROM downloads", db);
                        }
                        sqlCommand = cmdFetchAll;
                    }
                    else
                    {
                        if (cmdFetchConditional == null)
                        {
                            cmdFetchConditional = new SQLiteCommand("SELECT * FROM downloads WHERE completed=@completed", db);
                        }
                        SetParam("@completed", queryMode == QueryMode.InProgress ? 0 : 1, cmdFetchConditional.Parameters);
                        sqlCommand = cmdFetchConditional;
                    }
                    using SQLiteDataReader r = sqlCommand.ExecuteReader();
                    while (r.Read())
                    {
                        var id                 = r.GetSafeString(0);
                        var inProgress         = r.GetInt32(1) == 0;
                        DownloadItemBase entry = r.GetInt32(1) == 0 ? new InProgressDownloadItem() : new FinishedDownloadItem();
                        entry.Id                 = id;
                        entry.Name               = r.GetSafeString(2);
                        entry.DateAdded          = DateTime.FromBinary(r.GetInt64(3));
                        entry.Size               = r.GetInt64(4);
                        entry.DownloadType       = r.GetSafeString(7);
                        entry.FileNameFetchMode  = (FileNameFetchMode)r.GetInt32(8);
                        entry.MaxSpeedLimitInKiB = r.GetInt32(9);
                        entry.TargetDir          = r.GetSafeString(10);
                        entry.PrimaryUrl         = r.GetSafeString(11);
                        entry.RefererUrl         = r.GetSafeString(12);
                        if (r.GetInt32(13) == 1)
                        {
                            var user = r.GetSafeString(14);
                            var pass = r.GetSafeString(15);
                            if (user != null)
                            {
                                entry.Authentication = new AuthenticationInfo
                                {
                                    UserName = user,
                                    Password = pass
                                };
                            }
                        }
                        var proxy = new ProxyInfo {
                        };
                        proxy.ProxyType = (ProxyType)r.GetInt32(16);
                        proxy.Host      = r.GetSafeString(17);
                        proxy.Port      = r.GetInt32(18);
                        proxy.UserName  = r.GetSafeString(19);
                        proxy.Password  = r.GetSafeString(20);
                        entry.Proxy     = proxy;

                        if (inProgress)
                        {
                            var inp = (InProgressDownloadItem)entry;
                            inp.Status   = DownloadStatus.Stopped;
                            inp.Progress = r.GetInt32(6);
                            inProgressDownloads.Add(inp);
                        }
                        else
                        {
                            finishedDownloads.Add((FinishedDownloadItem)entry);
                        }
                    }
                    return(true);
                }
                catch (Exception ex)
                {
                    Log.Debug(ex, ex.Message);
                }
                return(false);
            }
        }
Ejemplo n.º 5
0
        public DownloadItemBase?GetDownloadById(string id)
        {
            lock (db)
            {
                try
                {
                    if (cmdFetchOne == null)
                    {
                        cmdFetchOne = new SQLiteCommand("SELECT * FROM downloads WHERE id=@id", db);
                    }
                    SetParam("@id", id, cmdFetchOne.Parameters);
                    //cmdFetchOne.Parameters["@id"].Value = id;
                    using SQLiteDataReader r = cmdFetchOne.ExecuteReader();
                    if (r.Read())
                    {
                        var inProgress         = r.GetInt32(1) == 0;
                        DownloadItemBase entry = r.GetInt32(1) == 0 ? new InProgressDownloadItem() : new FinishedDownloadItem();
                        entry.Id                 = id;
                        entry.Name               = r.GetSafeString(2);
                        entry.DateAdded          = DateTime.FromBinary(r.GetInt64(3));
                        entry.Size               = r.GetInt64(4);
                        entry.DownloadType       = r.GetSafeString(7);
                        entry.FileNameFetchMode  = (FileNameFetchMode)r.GetInt32(8);
                        entry.MaxSpeedLimitInKiB = r.GetInt32(9);
                        entry.TargetDir          = r.GetSafeString(10);
                        entry.PrimaryUrl         = r.GetSafeString(11);
                        entry.RefererUrl         = r.GetSafeString(12);
                        if (r.GetInt32(13) == 1)
                        {
                            var user = r.GetSafeString(14);
                            var pass = r.GetSafeString(15);
                            if (user != null)
                            {
                                entry.Authentication = new AuthenticationInfo
                                {
                                    UserName = user,
                                    Password = pass
                                };
                            }
                        }
                        var proxy = new ProxyInfo {
                        };
                        proxy.ProxyType = (ProxyType)r.GetInt32(16);
                        proxy.Host      = r.GetSafeString(17);
                        proxy.Port      = r.GetInt32(18);
                        proxy.UserName  = r.GetSafeString(19);
                        proxy.Password  = r.GetSafeString(20);
                        entry.Proxy     = proxy;

                        if (inProgress)
                        {
                            var inp = (InProgressDownloadItem)entry;
                            inp.Status   = DownloadStatus.Stopped;
                            inp.Progress = r.GetInt32(6);
                        }
                        return(entry);
                    }
                }
                catch (Exception ex)
                {
                    Log.Debug(ex, ex.Message);
                }
                return(null);
            }
        }