MediaBrowser.cs
Description du code
MediaBrowser.cs est un fichier du projet BrolExplorer.Ce fichier est situé dans /var/www/bin/sniplets/bibliobrol/brolexplorer/.
Projet BrolExplorer :
Explorateur de media en CSharp.
Code source ou contenu du fichier
Code c# (MediaBrowser.cs) (353 lignes)
using System; using System.Collections.Generic; using System.Text; using System.Data; using System.Windows.Forms; using System.IO; using System.ComponentModel; using be.gaudry.utils; using be.gaudry.config; namespace be.gaudry.explorer.model { public class MediaBrowser { #region constructors and declarations private List<String> extensions; private long minimumSize; float progressMax, progressToDo; private String startPath, searchText; private bool includeSubFolders, includeHidden, findDVD, findAllExtensions, preCalcProgress, validPreviousProgress; public MediaBrowser() { minimumSize = 0L; progressToDo = 0F; progressMax = 0F; validPreviousProgress = false; includeSubFolders = true; includeHidden = false; findDVD = false; findAllExtensions = false; preCalcProgress = true; "TargetInvocationException", "MediaBrowser", "http://www.thescripts.com/forum/thread519073.html", "TargetInvocationException et utilisation pour e.Results" ) ); } #endregion #region attributes public String SearchText { get { return this.searchText; } set { //ToUpper() not allowed on null objects this.searchText = (value!=null)?value.ToUpper():null; } } public long MinimumSize { get { return minimumSize; } set { minimumSize = value; } } /// <summary> /// True to search on the subfolders /// </summary> /// <remarks> /// Modifying this forces total size calculation if progress needed /// </remarks> public bool IncludeSubFolders { get { return includeSubFolders; } set { if (includeSubFolders != value) { //forces size calculation if progress needed validPreviousProgress = false; } includeSubFolders = value; } } /// <summary> /// True to search on the hidden files /// </summary> /// <remarks> /// Modifying this forces total size calculation if progress needed /// </remarks> public bool IncludeHiddenFiles { get { return includeHidden; } set { if (includeHidden != value) { //forces size calculation if progress needed validPreviousProgress = false; } includeHidden = value; } } public bool FindDVD { get { return findDVD; } set { findDVD = value; } } public bool FindAllExtensions { get { return findAllExtensions; } set { findAllExtensions = value; } } public bool PreCalcProgress { get { return preCalcProgress; } set { preCalcProgress = value; } } public List<String> Extensions { get { return this.extensions; } set { this.extensions.Clear(); for (int i = 0; i < value.Count;i++ ) { if (!value[i].StartsWith(".")) extensions.Add(String.Format(".{0}", value[i]).ToUpper()); else extensions.Add(value[i].ToUpper()); } } } /// <summary> /// Path of the root directory where to search /// </summary> /// <remarks> /// Modifying this forces total size calculation if progress needed /// </remarks> public String StartPath { get { return this.startPath; } set { if (startPath != value) { //forces size calculation if progress needed validPreviousProgress = false; } startPath = value; } } #endregion #region public methods public void addExtension(String extension) { if (!extension.StartsWith(".")) extensions.Add(String.Format(".{0}", extension).ToUpper()); else extensions.Add(extension.ToUpper()); } public long browse(BackgroundWorker bgw, DoWorkEventArgs e) { if (!validPreviousProgress) { // reset the progressMax if not valid because the searchMedia asynchroneous method will // add sizes along the search progressMax = 0F; if (preCalcProgress) { // Get progressMax before the first search, // or if a search parameter having a signification for the progressMax value has been modified bgw.ReportProgress((int)BrolFile.BGWORKER.currentInfo, "Lecture de la taille totale du répertoire"); progressMax = (float)BrolFile.getDirectoryLength(bgw, e, dirsInf, includeSubFolders); validPreviousProgress = true; } } //job may have been cancelled during the getDirectoryLength asynchroneous method if (!bgw.CancellationPending) { // Set the progressMax with the result of the search // the second search with the same basics search parameters // will able to display the progress //progressMax = browse(bgw, e, progressMax); progressToDo = progressMax; if (validPreviousProgress) { bgw.ReportProgress((int)BrolFile.BGWORKER.progressBarStyle_Block); } searchMedia(bgw, e, dirsInf); } //job may have been cancelled during the searchMedia asynchroneous method if (!bgw.CancellationPending) { validPreviousProgress = true; bgw.ReportProgress((int)BrolFile.BGWORKER.currentInfo, "Lecture de la taille totale du répertoire"); } return (long)progressMax; } /* public long browse(BackgroundWorker bgw, DoWorkEventArgs e, float progressMax) { DirectoryInfo dirsInf = new DirectoryInfo(startPath); if (progressMax > 0) { bgw.ReportProgress((int)BrolFile.BGWORKER.progressBarStyle_Block); } this.progressMax = progressMax; progressToDo = progressMax; searchMedia(bgw, e, dirsInf); Console.WriteLine("end of search, size = " + this.progressMax); return (long)this.progressMax; }*/ #endregion #region private methods /// <summary> /// /// </summary> /// <param name="bgw">BackgroundWorker to perform cancel if needed, and report progress</param> /// <param name="e">DoWorkEventArgs to perform cancel if needed, and report progress</param> /// <param name="dirsInf">DirectoryInfo to get size</param> private void searchMedia(BackgroundWorker bgw, DoWorkEventArgs e, DirectoryInfo dirsInf) { if (bgw.CancellationPending) { e.Cancel = true; } else { bgw.ReportProgress((int)BrolFile.BGWORKER.currentInfo, dirsInf.Name); try { FileInfo[] filesInf = dirsInf.GetFiles(); foreach (FileInfo fi in filesInf) { progressToDo -= fi.Length; // add length to avoid calculate progressMax each time if (!validPreviousProgress) { progressMax += fi.Length; } if (checkFileToAdd(bgw, e, fi)) { break; } } } catch (Exception) { } if (includeSubFolders) { try { foreach (DirectoryInfo dir in dirsInf.GetDirectories()) { searchMedia(bgw, e, dir); } } catch (Exception) { } } } } /// <summary> /// Test if a file may be in the results /// </summary> /// <param name="bgw">BackgroundWorker to perform cancel if needed, and report progress</param> /// <param name="e">DoWorkEventArgs to perform cancel if needed, and report progress</param> /// <param name="fi">FileInfo to check</param> /// <returns> /// true if we must leave this directory scan (ie. if we have a vob file, we don't check the other files in this directory) /// false otherwise ///</returns> private bool checkFileToAdd(BackgroundWorker bgw, DoWorkEventArgs e , FileInfo fi) { if(bgw.CancellationPending) { e.Cancel = true; return true; } else { int progressPercent = (validPreviousProgress)?((progressToDo <= progressMax) ? (int)((progressMax - progressToDo) / progressMax * 100) : 100):1; if(!includeHidden && ((fi.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden)) { bgw.ReportProgress(progressPercent, null); return false; } if (findDVD) { if (".VOB".Equals(fi.Extension.ToUpper())) { string dvdName = "VIDEO_TS".Equals(fi.Directory.Name.ToUpper()) ? fi.Directory.Parent.Name : fi.Directory.Name; if (!testName(dvdName))//search by part of name { bgw.ReportProgress(progressPercent, null); return true; } long dirSize = BrolFile.getDirectoryLength(bgw, e, fi.Directory, includeSubFolders); if ( minimumSize > 0 && minimumSize > dirSize ) { bgw.ReportProgress(progressPercent, null); return true; } { fi.FullName, "DVD", dvdName, fi.Directory.FullName, dirSize }); return true; } } if (!testName(fi.Name))//search by part of name { bgw.ReportProgress(progressPercent, null); return false; } if (findAllExtensions || extensions.Contains(fi.Extension.ToUpper())) { long fileLength; try { fileLength = fi.Length; } catch (Exception) { fileLength = 0L; } if (minimumSize == 0L || fileLength > minimumSize) { { fi.FullName, fi.Extension.ToUpper(), fi.Name, fi.Directory.FullName , fi.Length }); } else bgw.ReportProgress(progressPercent, null); } else bgw.ReportProgress(progressPercent, null); return false; } } private bool testName(string fileName) { return searchText == null || searchText.Equals(string.Empty) || fileName.ToUpper().Contains(searchText); } #endregion } }
Structure et Fichiers du projet
Afficher/masquer...Icône | Nom | Taille | Modification |
Pas de sous-répertoires. | |||
Icône | Nom | Taille | Modification |
| _ | Répertoire parent | 0 octets | 1732209228 21/11/2024 18:13:48 |
Utilisation de l'explorateur de code
- Navigation :
- Un clic sur une icône de répertoire ouvre ce répertoire pour en afficher les fichiers.
- Lorsque le répertoire en cours ne contient pas de sous-répertoires il est possible de remonter vers le répertoire parent.
- La structure de répertoires en treetable (tableau en forme d'arborescence) n'est plus possibledans cette version.
- Un clic sur une icône de fichier ouvre ce fichier pour en afficher le code avec la coloration syntaxique adaptée en fonction du langage principal utilisé dans le fichier.
- Affichage :
- Il est possible de trier les répertoires ou les fichiers selon certains critères (nom, taille, date).
- Actions :
- Les actions possible sur les fichiers dépendent de vos droits d'utilisateur sur le site. Veuillez activer le mode utilisateur pour activer les actions.
Version en cache
21/11/2024 18:13:48 Cette version de la page est en cache (à la date du 21/11/2024 18:13:48) afin d'accélérer le traitement. Vous pouvez activer le mode utilisateur dans le menu en haut pour afficher la dernère version de la page.Document créé le 30/10/2009, dernière modification le 26/10/2018
Source du document imprimé : https://www.gaudry.be/cs-brolexplorer-source-rf-model//MediaBrowser.cs.html
L'infobrol est un site personnel dont le contenu n'engage que moi. Le texte est mis à disposition sous licence CreativeCommons(BY-NC-SA). Plus d'info sur les conditions d'utilisation et sur l'auteur.