Geen cache-versie.

Caching uitgeschakeld. Standaardinstelling voor deze pagina:ingeschakeld (code LNG204)
Als het scherm te langzaam is, kunt u de gebruikersmodus uitschakelen om de cacheversie te bekijken.

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

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Data;
  5. using System.Windows.Forms;
  6. using System.IO;
  7. using System.ComponentModel;
  8. using be.gaudry.utils;
  9. using be.gaudry.config;
  10.  
  11. namespace be.gaudry.explorer.model
  12. {
  13. public class MediaBrowser
  14. {
  15. #region constructors and declarations
  16.  
  17. private List<String> extensions;
  18. private long minimumSize;
  19. float progressMax, progressToDo;
  20. private String startPath, searchText;
  21. private bool includeSubFolders, includeHidden, findDVD, findAllExtensions, preCalcProgress, validPreviousProgress;
  22.  
  23. public MediaBrowser()
  24. {
  25. extensions = new List<String>();
  26. minimumSize = 0L;
  27. progressToDo = 0F;
  28. progressMax = 0F;
  29. validPreviousProgress = false;
  30. includeSubFolders = true;
  31. includeHidden = false;
  32. findDVD = false;
  33. findAllExtensions = false;
  34. preCalcProgress = true;
  35. SourcesManager.addSource(new Source(
  36. "TargetInvocationException",
  37. "MediaBrowser",
  38. "http://www.thescripts.com/forum/thread519073.html",
  39. "TargetInvocationException et utilisation pour e.Results"
  40. )
  41. );
  42. }
  43. #endregion
  44.  
  45. #region attributes
  46. public String SearchText
  47. {
  48. get { return this.searchText; }
  49. set
  50. {
  51. //ToUpper() not allowed on null objects
  52. this.searchText = (value!=null)?value.ToUpper():null;
  53. }
  54. }
  55. public long MinimumSize
  56. {
  57. get { return minimumSize; }
  58. set { minimumSize = value; }
  59. }
  60. /// <summary>
  61. /// True to search on the subfolders
  62. /// </summary>
  63. /// <remarks>
  64. /// Modifying this forces total size calculation if progress needed
  65. /// </remarks>
  66. public bool IncludeSubFolders
  67. {
  68. get { return includeSubFolders; }
  69. set
  70. {
  71. if (includeSubFolders != value)
  72. {
  73. //forces size calculation if progress needed
  74. validPreviousProgress = false;
  75. }
  76. includeSubFolders = value;
  77. }
  78. }
  79. /// <summary>
  80. /// True to search on the hidden files
  81. /// </summary>
  82. /// <remarks>
  83. /// Modifying this forces total size calculation if progress needed
  84. /// </remarks>
  85. public bool IncludeHiddenFiles
  86. {
  87. get { return includeHidden; }
  88. set
  89. {
  90. if (includeHidden != value)
  91. {
  92. //forces size calculation if progress needed
  93. validPreviousProgress = false;
  94. }
  95. includeHidden = value;
  96. }
  97. }
  98. public bool FindDVD
  99. {
  100. get { return findDVD; }
  101. set { findDVD = value; }
  102. }
  103. public bool FindAllExtensions
  104. {
  105. get { return findAllExtensions; }
  106. set { findAllExtensions = value; }
  107. }
  108. public bool PreCalcProgress
  109. {
  110. get { return preCalcProgress; }
  111. set { preCalcProgress = value; }
  112. }
  113. public List<String> Extensions
  114. {
  115. get { return this.extensions; }
  116. set
  117. {
  118. this.extensions.Clear();
  119. for (int i = 0; i < value.Count;i++ )
  120. {
  121. if (!value[i].StartsWith("."))
  122. extensions.Add(String.Format(".{0}", value[i]).ToUpper());
  123. else
  124. extensions.Add(value[i].ToUpper());
  125. }
  126. }
  127. }
  128. /// <summary>
  129. /// Path of the root directory where to search
  130. /// </summary>
  131. /// <remarks>
  132. /// Modifying this forces total size calculation if progress needed
  133. /// </remarks>
  134. public String StartPath
  135. {
  136. get { return this.startPath; }
  137. set
  138. {
  139. if (startPath != value)
  140. {
  141. //forces size calculation if progress needed
  142. validPreviousProgress = false;
  143. }
  144. startPath = value;
  145. }
  146. }
  147. #endregion
  148.  
  149. #region public methods
  150. public void addExtension(String extension)
  151. {
  152. if (!extension.StartsWith("."))
  153. extensions.Add(String.Format(".{0}", extension).ToUpper());
  154. else
  155. extensions.Add(extension.ToUpper());
  156. }
  157. public long browse(BackgroundWorker bgw, DoWorkEventArgs e)
  158. {
  159. DirectoryInfo dirsInf = new DirectoryInfo(startPath);
  160. if (!validPreviousProgress)
  161. {
  162. // reset the progressMax if not valid because the searchMedia asynchroneous method will
  163. // add sizes along the search
  164. progressMax = 0F;
  165. if (preCalcProgress)
  166. {
  167. // Get progressMax before the first search,
  168. // or if a search parameter having a signification for the progressMax value has been modified
  169. bgw.ReportProgress((int)BrolFile.BGWORKER.currentInfo, "Lecture de la taille totale du répertoire");
  170. progressMax = (float)BrolFile.getDirectoryLength(bgw, e, dirsInf, includeSubFolders);
  171. validPreviousProgress = true;
  172. }
  173. }
  174. //job may have been cancelled during the getDirectoryLength asynchroneous method
  175. if (!bgw.CancellationPending)
  176. {
  177. // Set the progressMax with the result of the search
  178. // the second search with the same basics search parameters
  179. // will able to display the progress
  180. //progressMax = browse(bgw, e, progressMax);
  181. progressToDo = progressMax;
  182. if (validPreviousProgress)
  183. {
  184. bgw.ReportProgress((int)BrolFile.BGWORKER.progressBarStyle_Block);
  185. }
  186. searchMedia(bgw, e, dirsInf);
  187. }
  188. //job may have been cancelled during the searchMedia asynchroneous method
  189. if (!bgw.CancellationPending)
  190. {
  191. validPreviousProgress = true;
  192. bgw.ReportProgress((int)BrolFile.BGWORKER.currentInfo, "Lecture de la taille totale du répertoire");
  193. }
  194. return (long)progressMax;
  195. }
  196. /*
  197.   public long browse(BackgroundWorker bgw, DoWorkEventArgs e, float progressMax)
  198.   {
  199.   DirectoryInfo dirsInf = new DirectoryInfo(startPath);
  200.   if (progressMax > 0)
  201.   {
  202.   bgw.ReportProgress((int)BrolFile.BGWORKER.progressBarStyle_Block);
  203.   }
  204.   this.progressMax = progressMax;
  205.   progressToDo = progressMax;
  206.   searchMedia(bgw, e, dirsInf);
  207.   Console.WriteLine("end of search, size = " + this.progressMax);
  208.   return (long)this.progressMax;
  209.   }*/
  210. #endregion
  211.  
  212. #region private methods
  213.  
  214.  
  215. /// <summary>
  216. ///
  217. /// </summary>
  218. /// <param name="bgw">BackgroundWorker to perform cancel if needed, and report progress</param>
  219. /// <param name="e">DoWorkEventArgs to perform cancel if needed, and report progress</param>
  220. /// <param name="dirsInf">DirectoryInfo to get size</param>
  221. private void searchMedia(BackgroundWorker bgw, DoWorkEventArgs e, DirectoryInfo dirsInf)
  222. {
  223. if (bgw.CancellationPending)
  224. {
  225. e.Cancel = true;
  226. }
  227. else
  228. {
  229. bgw.ReportProgress((int)BrolFile.BGWORKER.currentInfo, dirsInf.Name);
  230. try
  231. {
  232. FileInfo[] filesInf = dirsInf.GetFiles();
  233. foreach (FileInfo fi in filesInf)
  234. {
  235. progressToDo -= fi.Length;
  236. // add length to avoid calculate progressMax each time
  237. if (!validPreviousProgress)
  238. {
  239. progressMax += fi.Length;
  240. }
  241. if (checkFileToAdd(bgw, e, fi))
  242. {
  243. break;
  244. }
  245. }
  246. }
  247. catch (Exception) { }
  248. if (includeSubFolders)
  249. {
  250. try
  251. {
  252. foreach (DirectoryInfo dir in dirsInf.GetDirectories())
  253. {
  254. searchMedia(bgw, e, dir);
  255. }
  256. }
  257. catch (Exception) { }
  258. }
  259. }
  260. }
  261. /// <summary>
  262. /// Test if a file may be in the results
  263. /// </summary>
  264. /// <param name="bgw">BackgroundWorker to perform cancel if needed, and report progress</param>
  265. /// <param name="e">DoWorkEventArgs to perform cancel if needed, and report progress</param>
  266. /// <param name="fi">FileInfo to check</param>
  267. /// <returns>
  268. /// 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)
  269. /// false otherwise
  270. ///</returns>
  271. private bool checkFileToAdd(BackgroundWorker bgw, DoWorkEventArgs e , FileInfo fi)
  272. {
  273. if(bgw.CancellationPending)
  274. {
  275. e.Cancel = true;
  276. return true;
  277. }
  278. else
  279. {
  280. int progressPercent = (validPreviousProgress)?((progressToDo <= progressMax) ? (int)((progressMax - progressToDo) / progressMax * 100) : 100):1;
  281.  
  282. if(!includeHidden && ((fi.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden))
  283. {
  284. bgw.ReportProgress(progressPercent, null);
  285. return false;
  286. }
  287. if (findDVD)
  288. {
  289. if (".VOB".Equals(fi.Extension.ToUpper()))
  290. {
  291. string dvdName = "VIDEO_TS".Equals(fi.Directory.Name.ToUpper()) ? fi.Directory.Parent.Name : fi.Directory.Name;
  292. if (!testName(dvdName))//search by part of name
  293. {
  294. bgw.ReportProgress(progressPercent, null);
  295. return true;
  296. }
  297. long dirSize = BrolFile.getDirectoryLength(bgw, e, fi.Directory, includeSubFolders);
  298. if (
  299. minimumSize > 0
  300. && minimumSize > dirSize
  301. )
  302. {
  303. bgw.ReportProgress(progressPercent, null);
  304. return true;
  305. }
  306. bgw.ReportProgress(progressPercent, new object[]
  307. {
  308. fi.FullName,
  309. "DVD",
  310. dvdName,
  311. fi.Directory.FullName,
  312. dirSize
  313. });
  314. return true;
  315. }
  316. }
  317. if (!testName(fi.Name))//search by part of name
  318. {
  319. bgw.ReportProgress(progressPercent, null);
  320. return false;
  321. }
  322. if (findAllExtensions || extensions.Contains(fi.Extension.ToUpper()))
  323. {
  324. long fileLength;
  325. try { fileLength = fi.Length; }
  326. catch (Exception) { fileLength = 0L; }
  327. if (minimumSize == 0L || fileLength > minimumSize)
  328. {
  329. bgw.ReportProgress(progressPercent, new object[]
  330. {
  331. fi.FullName,
  332. fi.Extension.ToUpper(),
  333. fi.Name,
  334. fi.Directory.FullName ,
  335. fi.Length
  336. });
  337. }
  338. else bgw.ReportProgress(progressPercent, null);
  339. }
  340. else bgw.ReportProgress(progressPercent, null);
  341. return false;
  342. }
  343. }
  344.  
  345. private bool testName(string fileName)
  346. {
  347. return searchText == null
  348. || searchText.Equals(string.Empty)
  349. || fileName.ToUpper().Contains(searchText);
  350. }
  351. #endregion
  352. }
  353. }

Structure et Fichiers du projet

Afficher/masquer...


Répertoires contenus dans /var/www/bin/sniplets/bibliobrol/brolexplorer/model/ 
IcôneNomTailleModification
Pas de sous-répertoires.
IcôneNomTailleModification
| _ Répertoire parent0 octets1714238709 27/04/2024 19:25:09
Fichiers contenus dans /var/www/bin/sniplets/bibliobrol/brolexplorer/model/ 
IcôneNomTailleModificationAction
IcôneNomTailleModificationAction
Afficher le fichier .cs|.csDrive.cs6.66 Ko31/10/2018 18:32:21-refusé-
Afficher le fichier .cs|.csDirectoryTreeNode.cs2.79 Ko31/10/2018 18:32:21-refusé-
Afficher le fichier .cs|.csMediaBrowser.cs13.11 Ko31/10/2018 18:32:21-refusé-
Afficher le fichier .cs|.csMediaParser.cs5.71 Ko31/10/2018 18:32:21-refusé-

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.

Nederlandse vertaling

U hebt gevraagd om deze site in het Nederlands te bezoeken. Voor nu wordt alleen de interface vertaald, maar nog niet alle inhoud.

Als je me wilt helpen met vertalingen, is je bijdrage welkom. Het enige dat u hoeft te doen, is u op de site registreren en mij een bericht sturen waarin u wordt gevraagd om u toe te voegen aan de groep vertalers, zodat u de gewenste pagina's kunt vertalen. Een link onderaan elke vertaalde pagina geeft aan dat u de vertaler bent en heeft een link naar uw profiel.

Bij voorbaat dank.

Document heeft de 30/10/2009 gemaakt, de laatste keer de 26/10/2018 gewijzigd
Bron van het afgedrukte document:https://www.gaudry.be/nl/cs-brolexplorer-source-rf-model/MediaBrowser.cs.html

De infobrol is een persoonlijke site waarvan de inhoud uitsluitend mijn verantwoordelijkheid is. De tekst is beschikbaar onder CreativeCommons-licentie (BY-NC-SA). Meer info op de gebruiksvoorwaarden en de auteur.