Exemplo n.º 1
0
 /// <summary>
 /// Constructor
 /// 
 /// Create a StealthNetLink from a search result.
 /// Use this contructor to display this link with method 
 /// </summary>
 /// <param name="searchResult">searchResult object to construct the link from</param>
 /// <param name="htmlLink">true, if the string representation of this link should contain a html link</param>
 public StealthNetLink(Search.Result searchResult, bool htmlLink)
 {
     m_FileHash = searchResult.FileHash;
     m_FileName = searchResult.FileName;
     m_FileSize = searchResult.FileSize;
     m_htmlLink = htmlLink;
 }
        private Image GetRatingImage(Search.Result.Source source)
        {
            if (source == null)
                throw new ArgumentNullException("source");

            switch (source.Rating)
            {
                case 1:
                    return Properties.Resources.rating1_16x16;
                case 2:
                    return Properties.Resources.rating2_16x16;
                case 3:
                    return Properties.Resources.rating3_16x16;
                default:
                    return Properties.Resources.rating0_16x16;
            }
        }
 public SearchResultInformationControl(Search.Result result)
 {
     InitializeComponent();
     m_Result = result;
     iconPictureBox.Tag = m_Result.FileName;
     try
     {
         // 2008-10-21 Eroli: Mono-Fix
         if (!UtilitiesForMono.IsRunningOnMono)
             iconPictureBox.Image = ShellIcon.GetLargeSystemIcon((string)iconPictureBox.Tag);
     }
     catch
     {
     }
     fileNameTextBox.Text = m_Result.FileName;
     fileSizeTextBox.Text = m_Result.FileSizeString;
     fileHashTextBox.Text = m_Result.FileHashString;
 }
Exemplo n.º 4
0
        private static void GetRowColor(Search.Result result, DataGridViewRow resultRow)
        {
            if (result == null)
                throw new ArgumentNullException("result");
            if (resultRow == null)
                throw new ArgumentNullException("resultRow");

            bool known = Core.SharedFiles.ContainsKey(result.FileHashString);
            if (!known && Core.DownloadsAndQueue.ContainsKey(result.FileHashString, DownloadCollection.KeyAccess.FileHash))
                known = true;
            if (known)
            {
                resultRow.Cells["FileName"].Style.ForeColor = Color.Red;
                resultRow.Cells["FileName"].Style.SelectionForeColor = Color.Red;
                resultRow.Cells["FileSize"].Style.ForeColor = Color.Red;
                resultRow.Cells["FileSize"].Style.SelectionForeColor = Color.Red;
                resultRow.Cells["Sources"].Style.ForeColor = Color.Red;
                resultRow.Cells["Sources"].Style.SelectionForeColor = Color.Red;
                resultRow.Cells["Album"].Style.ForeColor = Color.Red;
                resultRow.Cells["Album"].Style.SelectionForeColor = Color.Red;
                resultRow.Cells["Artist"].Style.ForeColor = Color.Red;
                resultRow.Cells["Artist"].Style.SelectionForeColor = Color.Red;
                resultRow.Cells["Title"].Style.ForeColor = Color.Red;
                resultRow.Cells["Title"].Style.SelectionForeColor = Color.Red;
                resultRow.Cells["Age"].Style.ForeColor = Color.Red;
                resultRow.Cells["Age"].Style.SelectionForeColor = Color.Red;
            }
            else
            {
                Color color = Color.FromArgb(0, 0, (int)(((float)Color.Blue.B / 13) * Math.Max(result.Sources.Count * 2 - 1 > 13 ? 13 : result.Sources.Count * 2 - 1, 0)));
                resultRow.Cells["FileName"].Style.ForeColor = color;
                resultRow.Cells["FileName"].Style.SelectionForeColor = Color.White;
                resultRow.Cells["FileSize"].Style.ForeColor = color;
                resultRow.Cells["FileSize"].Style.SelectionForeColor = Color.White;
                resultRow.Cells["Sources"].Style.ForeColor = color;
                resultRow.Cells["Sources"].Style.SelectionForeColor = Color.White;
                resultRow.Cells["Album"].Style.ForeColor = color;
                resultRow.Cells["Album"].Style.SelectionForeColor = Color.White;
                resultRow.Cells["Artist"].Style.ForeColor = color;
                resultRow.Cells["Artist"].Style.SelectionForeColor = Color.White;
                resultRow.Cells["Title"].Style.ForeColor = color;
                resultRow.Cells["Title"].Style.SelectionForeColor = Color.White;
                resultRow.Cells["Age"].Style.ForeColor = color;
                resultRow.Cells["Age"].Style.SelectionForeColor = Color.White;
            }
        }
Exemplo n.º 5
0
        public Download(Search.Result result)
        {
            // Konstruktor für den Download eines Suchergebnisses
            if (result == null)
                throw new ArgumentNullException("result");

            Initialize(result.FileHash);
            m_FileSize = result.FileSize;
            m_FileSizeString = result.FileSizeString;
            m_Sectors = m_FileSize / 32768;
            m_SectorsMap = new byte[(m_Sectors / 8) + 1];
            for (long n = m_Sectors + 1; n < m_SectorsMap.Length * 8; n++)
                m_SectorsMap[n / 8] |= (byte)(1 << ((int)n % 8));
            m_TempFilePath = Path.Combine(m_Settings["TemporaryDirectory"], m_FileHashString);
            m_FileStream = new FileStream(m_TempFilePath, FileMode.Create, FileAccess.ReadWrite, FileShare.Read);
            if (result.IsSearchDBResult)
            {
                m_FileName = result.FileName;
            }
            else
                foreach (Search.Result.Source source in result.Sources.Values)
                    AddSource(source.ID, m_FileSize, source.FileName, source.MetaData, source.Comment, source.Rating, null);
            FillWithZeros();
        }
Exemplo n.º 6
0
        private static void StartSearch2(string command, Search.SearchType searchType)
        {
            if (command == null)
                throw new ArgumentNullException("command");

            Console.WriteLine();
            try
            {
                Core.Searches.Lock();
                string searchPattern;
                if (searchType == Search.SearchType.OnlyDatabase)
                {
                    searchPattern = Regex.Split(command, @"^start search only database (\S.{1,}\S)$", RegexOptions.IgnoreCase)[1];
                }
                else if (searchType == Search.SearchType.OnlyNetwork)
                {
                    searchPattern = Regex.Split(command, @"^start search only network (\S.{1,}\S)$", RegexOptions.IgnoreCase)[1];
                }
                else
                {
                    searchPattern = Regex.Split(command, @"^start search (\S.{1,}\S)$", RegexOptions.IgnoreCase)[1];
                }

                if (Core.Searches.Count < Constants.MaximumSearchesCount)
                {
                    Core.AddSearch(searchPattern, new AnyFileType(), searchType);
                    Console.WriteLine("The search of \"{0}\" has been started...", searchPattern);
                }
                else
                    Console.WriteLine("You have already {0} searches!", Core.Searches.Count);
            }
            catch (Exception ex)
            {
                string s = "An exception was thrown while starting the search!";
                Console.WriteLine(s);
                Logger.Instance.Log(ex, s);
            }
            finally
            {
                Core.Searches.Unlock();
            }
            Console.WriteLine();
        }
Exemplo n.º 7
0
        public static void AddSearch(string pattern, FileType fileTypeFilter, Search.SearchType searchType)
        {
            if (pattern == null)
                throw new ArgumentNullException("pattern");
            if (pattern.Trim().Length < 3)
                throw new ArgumentException();

            try
            {
                m_Searches.Lock();
                if (m_Searches.Count >= Constants.MaximumSearchesCount)
                    throw new InvalidOperationException();
                {
                    pattern = pattern.Trim().ToLower();
                    foreach (Search search in m_Searches.Values)
                        if (search.SearchPattern.Equals(pattern))
                            return;
                }
                {
                    // 2007-05-28
                    Search search = new Search(pattern, fileTypeFilter, searchType);
                    m_Searches.Add(search.SearchIDString, search);
                }
            }
            finally
            {
                m_Searches.Unlock();
            }
        }
Exemplo n.º 8
0
        public static void AddDownload(Search.Result result, string subFolder)
        {
            if (result == null)
                throw new ArgumentNullException("result");

            try
            {
                m_DownloadsAndQueue.Lock();
                if (m_DownloadsAndQueue.ContainsKey(ByteArrayToString(result.FileHash), DownloadCollection.KeyAccess.FileHash))
                    return;
                Download download = new Download(result);
                if (m_DownloadsAndQueue.Count >= Constants.MaximumDownloadsCount)
                {
                    download.SetSubFolderAndTime(subFolder, null);
                    download.RemoveSources();
                    if (bool.Parse(Settings.Instance["NewDownloadsToBeginngingOfQueue"]))
                        m_DownloadsAndQueue.Insert(Constants.MaximumDownloadsCount, download);
                    else
                        m_DownloadsAndQueue.Add(download);
                }
                else
                {
                    download.SetSubFolderAndTime(subFolder, DateTime.Now);
                    m_DownloadsAndQueue.Add(download);
                }
            }
            finally
            {
                m_DownloadsAndQueue.Unlock();
            }
            DownloadsXmlWriter.Write(m_DownloadsFilePath, m_DownloadsAndQueue);
        }
Exemplo n.º 9
0
        private void updateTimer_Tick(object sender, EventArgs e)
        {
            try
            {
                ((System.Windows.Forms.Timer)sender).Stop();
                updateTimer.Interval = Math.Max(Math.Max(1000, searchesDataGridView.Rows.Count * 10), Math.Max(1000, resultsDataGridView.Rows.Count * 10));
                if (m_MainForm.ActiveTab == this && !m_MainForm.IsInTray)
                {
                    Search selectedSearch = null;
                    try
                    {
                        Core.Searches.Lock();
                        searchesLabel.Text = string.Format(Properties.Resources.Searches, Core.Searches.Count, Constants.MaximumSearchesCount);
                        {
                            DataGridViewRow row;
                            for (int n = searchesDataGridView.Rows.Count - 1; n >= 0; n--)
                            {
                                row = searchesDataGridView.Rows[n];
                                if (!Core.Searches.ContainsKey(((RandomTag <string>)row.Tag).Tag))
                                {
                                    searchesDataGridView.Rows.RemoveAt(n);
                                }
                            }
                        }
                        DataGridViewRow  searchRow;
                        DataGridViewCell searchCell;
                        int a = 0;
                        foreach (Search search in Core.Searches.Values)
                        {
                            if (a % 50 == 0)
                            {
                                Application.DoEvents();
                            }
                            a++;
                            searchRow = null;
                            foreach (DataGridViewRow row in searchesDataGridView.Rows)
                            {
                                if (((RandomTag <string>)row.Tag).Tag.Equals(search.SearchIDString))
                                {
                                    searchRow = row;
                                    break;
                                }
                            }
                            if (searchRow == null)
                            {
                                searchRow        = new DataGridViewRow();
                                searchRow.Height = 17;
                                searchCell       = new DataGridViewTextBoxCell();
                                searchRow.Cells.Add(searchCell);
                                searchCell.Value = search.SearchPattern;
                                searchCell       = new DataGridViewTextBoxCell();
                                searchRow.Cells.Add(searchCell);
                                searchCell.Value = search.IsActive ? Properties.Resources.SearchState_Active : Properties.Resources.SearchState_Passive;
                                searchCell.Tag   = search.IsActive;
                                searchCell       = new DataGridViewTextBoxCell();
                                searchRow.Cells.Add(searchCell);
                                searchCell.Value = search.Results.Count.ToString();
                                searchCell.Tag   = search.Results.Count;
                                searchRow.Tag    = new RandomTag <string>(search.SearchIDString);
                                searchesDataGridView.Rows.Add(searchRow);
                                continue;
                            }
                            searchCell       = searchRow.Cells["IsActive"];
                            searchCell.Value = search.IsActive ? Properties.Resources.SearchState_Active : Properties.Resources.SearchState_Passive;
                            searchCell.Tag   = search.IsActive;
                            searchCell       = searchRow.Cells["Results"];
                            searchCell.Value = search.Results.Count.ToString();
                            searchCell.Tag   = search.Results.Count;
                        }
                        searchesDataGridView.Sort(searchesDataGridView.SortedColumn, searchesDataGridView.SortOrder == SortOrder.Descending ? ListSortDirection.Descending : ListSortDirection.Ascending);
                        if (searchesDataGridView.SelectedRows.Count == 1 && Core.Searches.ContainsKey(((RandomTag <string>)searchesDataGridView.SelectedRows[0].Tag).Tag))
                        {
                            selectedSearch = Core.Searches[((RandomTag <string>)searchesDataGridView.SelectedRows[0].Tag).Tag];
                        }
                    }
                    catch (Exception ex)
                    {
                        Logger.Instance.Log(ex, "An exception was thrown! (SearchControl - Searches)");
                    }
                    finally
                    {
                        Core.Searches.Unlock();
                    }
                    if (selectedSearch != null)
                    {
                        try
                        {
                            selectedSearch.Results.Lock();
                            //2009-01-31 Nochbaer
                            if (selectedSearch.TooManySearchDBResults)
                            {
                                searchesLabel.Text += string.Format(Properties.Resources.TooManySearchDBResults, m_Settings["MaxSearchDBResults"], selectedSearch.TotalSearchDBResults);
                            }

                            resultsDataGridView.Tag     = selectedSearch.SearchIDString;
                            resultsDataGridView.Enabled = true;
                            {
                                DataGridViewRow row;
                                for (int n = resultsDataGridView.Rows.Count - 1; n >= 0; n--)
                                {
                                    row = resultsDataGridView.Rows[n];
                                    if (!selectedSearch.Results.ContainsKey(((RandomTag <string>)row.Tag).Tag))
                                    {
                                        resultsDataGridView.Rows.RemoveAt(n);
                                    }
                                }
                            }
                            DataGridViewRow  resultRow;
                            DataGridViewCell resultCell;
                            int a = 0;
                            foreach (Search.Result result in selectedSearch.Results.Values)
                            {
                                if (a % 50 == 0)
                                {
                                    Application.DoEvents();
                                }
                                a++;

                                resultRow = null;
                                foreach (DataGridViewRow row in resultsDataGridView.Rows)
                                {
                                    if (((RandomTag <string>)row.Tag).Tag.Equals(result.FileHashString))
                                    {
                                        resultRow = row;
                                        break;
                                    }
                                }
                                if (resultRow == null)
                                {
                                    resultRow        = new DataGridViewRow();
                                    resultRow.Height = 17;
                                    resultCell       = new DataGridViewImageCell();
                                    resultCell.Tag   = result.FileName;
                                    resultRow.Cells.Add(resultCell);
                                    try
                                    {
                                        // 2008-10-21 Eroli: Mono-Fix
                                        if (!UtilitiesForMono.IsRunningOnMono)
                                        {
                                            resultCell.Value = ShellIcon.GetSmallSystemIcon((string)resultCell.Tag);
                                        }
                                    }
                                    catch
                                    {
                                    }
                                    resultCell = new DataGridViewImageCell();
                                    resultRow.Cells.Add(resultCell);
                                    resultCell.Value = GetRatingImage(result);
                                    resultCell.Tag   = result.Rating;
                                    resultCell       = new DataGridViewTextBoxCell();
                                    resultRow.Cells.Add(resultCell);
                                    resultCell.Value = result.FileName;
                                    resultCell       = new DataGridViewTextBoxCell();
                                    resultRow.Cells.Add(resultCell);
                                    resultCell.Value = result.FileSizeString;
                                    resultCell.Tag   = result.FileSize;
                                    resultCell       = new DataGridViewTextBoxCell();
                                    resultRow.Cells.Add(resultCell);
                                    string sourcesString;
                                    if (result.IsSearchDBResult)
                                    {
                                        sourcesString = "DB";
                                    }
                                    else
                                    {
                                        sourcesString = result.Sources.Count.ToString();
                                    }
                                    resultCell.Value = sourcesString;
                                    resultCell.Tag   = result.Sources.Count;
                                    resultCell       = new DataGridViewTextBoxCell();
                                    resultRow.Cells.Add(resultCell);
                                    resultCell.Value = result.Album;
                                    resultCell       = new DataGridViewTextBoxCell();
                                    resultRow.Cells.Add(resultCell);
                                    resultCell.Value = result.Artist;
                                    resultCell       = new DataGridViewTextBoxCell();
                                    resultRow.Cells.Add(resultCell);
                                    resultCell.Value = result.Title;
                                    resultCell       = new DataGridViewTextBoxCell();
                                    resultRow.Cells.Add(resultCell);
                                    if (result.IsSearchDBResult)
                                    {
                                        int days = ((TimeSpan)DateTime.Now.Subtract(result.Date)).Days;
                                        if (days == 0)
                                        {
                                            resultCell.Value = Properties.Resources.Today;
                                        }
                                        else
                                        {
                                            resultCell.Value = string.Format(Properties.Resources.Date_Diff_Only_Days, days);
                                        }
                                    }
                                    else
                                    {
                                        resultCell.Value = RShare.Properties.Resources.Today;
                                    }
                                    resultCell.Tag = result.Date;
                                    resultRow.Tag  = new RandomTag <string>(result.FileHashString);
                                    resultsDataGridView.Rows.Add(resultRow);
                                    GetRowColor(result, resultRow);
                                    continue;
                                }
                                resultCell = resultRow.Cells["Icon"];
                                if ((string)resultCell.Tag != result.FileName)
                                {
                                    resultCell.Tag = result.FileName;
                                    try
                                    {
                                        // 2008-10-21 Eroli: Mono-Fix
                                        if (!UtilitiesForMono.IsRunningOnMono)
                                        {
                                            resultCell.Value = ShellIcon.GetSmallSystemIcon((string)resultCell.Tag);
                                        }
                                    }
                                    catch
                                    {
                                    }
                                }
                                resultCell       = resultRow.Cells["RatingIcon"];
                                resultCell.Value = GetRatingImage(result);
                                resultCell.Tag   = result.Rating;
                                resultCell       = resultRow.Cells["FileName"];
                                resultCell.Value = result.FileName;
                                resultCell       = resultRow.Cells["Sources"];
                                string sourcesString2;
                                if (result.IsSearchDBResult)
                                {
                                    sourcesString2 = "DB";
                                }
                                else
                                {
                                    sourcesString2 = result.Sources.Count.ToString();
                                }
                                resultCell.Value = sourcesString2;
                                resultCell.Tag   = result.Sources.Count;
                                resultCell       = resultRow.Cells["Album"];
                                resultCell.Value = result.Album;
                                resultCell       = resultRow.Cells["Artist"];
                                resultCell.Value = result.Artist;
                                resultCell       = resultRow.Cells["Title"];
                                resultCell.Value = result.Title;
                                resultCell       = resultRow.Cells["Age"];
                                if (result.IsSearchDBResult)
                                {
                                    int days = ((TimeSpan)DateTime.Now.Subtract(result.Date)).Days;
                                    if (days == 0)
                                    {
                                        resultCell.Value = Properties.Resources.Today;
                                    }
                                    else
                                    {
                                        resultCell.Value = string.Format(Properties.Resources.Date_Diff_Only_Days, days);
                                    }
                                }
                                else
                                {
                                    resultCell.Value = RShare.Properties.Resources.Today;
                                }
                                resultCell.Tag = result.Date;

                                GetRowColor(result, resultRow);
                            }
                            resultsDataGridView.Sort(resultsDataGridView.SortedColumn, resultsDataGridView.SortOrder == SortOrder.Descending ? ListSortDirection.Descending : ListSortDirection.Ascending);
                        }
                        catch (Exception ex)
                        {
                            Logger.Instance.Log(ex, "An exception was thrown! (SearchControl - Results)");
                        }
                        finally
                        {
                            selectedSearch.Results.Unlock();
                        }
                    }
                    else
                    {
                        resultsDataGridView.Rows.Clear();
                        resultsDataGridView.Tag     = null;
                        resultsDataGridView.Enabled = false;
                    }
                }
            }
            finally
            {
                ((System.Windows.Forms.Timer)sender).Start();
            }
        }
 public SearchResultSourcesControl(Search.Result result)
 {
     InitializeComponent();
     sourcesDataGridView.Sort(sourcesDataGridView.Columns["FileName"], ListSortDirection.Ascending);
     m_Result = result;
 }