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.

FileHelper.cs

Description du code

FileHelper.cs est un fichier du projet BrolDev.
Ce fichier est situé dans /var/www/bin/sniplets/bibliobrol/broldev/src/.

Projet BrolDev : Librairie de composants réutilisables pour les applications BrolDev en CSharp.

Code source ou contenu du fichier

  1. using System;
  2. using System.ComponentModel;
  3. using System.IO;
  4. using System.Windows.Forms;
  5. using be.gaudry.model.win32;
  6.  
  7. namespace be.gaudry.model.file
  8. {
  9. public static class FileHelper
  10. {
  11. #region open file
  12. /// <summary>
  13. /// Open the "open with "dialog
  14. /// </summary>
  15. /// <param name="filename">(String) path of the file</param>
  16. /// <returns>(Process) </returns>
  17. public static System.Diagnostics.Process openWith(string filename)
  18. {
  19. return System.Diagnostics.Process.Start(
  20. "rundll32.exe",
  21. string.Format("shell32.dll,OpenAs_RunDLL {0}", filename)
  22. );
  23. }
  24. /// <summary>
  25. /// Open the "open with "dialog after testing if file exists.
  26. /// Display a messageBox if file doesn't exists.
  27. /// </summary>
  28. /// <param name="filename">(String) path of the file</param>
  29. /// <param name="appName">(String) name of the application</param>
  30. /// <returns>(Process) </returns>
  31. public static void openWith(string filename, string appName)
  32. {
  33. if (File.Exists(filename))
  34. {
  35. openWith(filename);
  36. }
  37. else
  38. {
  39. MessageBox.Show(
  40. String.Format(
  41. "Le fichier {0} semble inexistant. {1} ne peut donc l'ouvrir.",
  42. filename,
  43. appName
  44. ),
  45. "Erreur",
  46. MessageBoxButtons.OK,
  47. MessageBoxIcon.Exclamation
  48. );
  49. }
  50. }
  51. /// <summary>
  52. /// Open a file with the system default application
  53. /// </summary>
  54. /// <param name="filename">(String) path of the file</param>
  55. public static void open(string filename)
  56. {
  57. System.Diagnostics.Process process = new System.Diagnostics.Process();
  58. process.StartInfo.FileName = filename;
  59. // Start processus with the system default application
  60. process.Start();
  61. // Free the unused resources.
  62. // Rem : the close operation don't stop the process
  63. process.Close();
  64. }
  65. /// <summary>
  66. /// Open a file with the system default application after testing if file exists.
  67. /// Display a messageBox if file doesn't exists.
  68. /// </summary>
  69. /// <param name="filename">(String) path of the file</param>
  70. /// <param name="appName">(String) name of the application</param>
  71. public static void open(string filename, string appName)
  72. {
  73. if (File.Exists(filename))
  74. {
  75. open(filename);
  76. }
  77. else
  78. {
  79. MessageBox.Show(
  80. String.Format(
  81. "Le fichier {0} semble inexistant. {1} ne peut donc l'ouvrir.",
  82. filename,
  83. appName
  84. ),
  85. "Erreur",
  86. MessageBoxButtons.OK,
  87. MessageBoxIcon.Exclamation
  88. );
  89. }
  90. }
  91. #endregion
  92.  
  93. #region infos
  94.  
  95. public static void openFileProperties(string path)
  96. {
  97. Shell32Helper.ShowFileProperties(path);
  98. }
  99.  
  100. public static string getAttributeName(FileAttributes fa)
  101. {
  102. switch (fa)
  103. {
  104. case FileAttributes.Archive: return "archive";
  105. case FileAttributes.Compressed: return "compressé";
  106. case FileAttributes.Device: return "";
  107. case FileAttributes.Directory: return "répertoire";
  108. case FileAttributes.Encrypted: return "encrypté";
  109. case FileAttributes.Hidden: return "caché";
  110. case FileAttributes.Normal: return "normal";
  111. case FileAttributes.NotContentIndexed: return "contenu non indexé";
  112. case FileAttributes.Offline: return "hors ligne";
  113. case FileAttributes.ReadOnly: return "lecture seule";
  114. case FileAttributes.ReparsePoint: return "ReparsePoint";
  115. case FileAttributes.SparseFile: return "SparseFile";
  116. case FileAttributes.System: return "système";
  117. case FileAttributes.Temporary: return "temporaire";
  118. default: return "indéterminé";
  119. }
  120. }
  121.  
  122. /// <summary>
  123. /// Remove the last directory from the path
  124. /// </summary>
  125. /// <param name="dirPath"></param>
  126. /// <returns></returns>
  127. public static string getParentDir(string dirPath)
  128. {
  129. DirectoryInfo di = new DirectoryInfo(dirPath);
  130. return (di.Parent!=null)?di.Parent.FullName:dirPath;
  131. }
  132. /// <summary>
  133. /// Get the length of the directory in bytes (formated String)
  134. /// </summary>
  135. /// <param name="bgw">(BackgroundWorker) to cancel operation</param>
  136. /// <param name="e">(DoWorkEventArgs) to report progress</param>
  137. /// <param name="di">(DirectoryInfo) Start directoryinfo</param>
  138. /// <param name="includeSubFolders">(bool) add all subdirs infos (recursive method)</param>
  139. /// <returns>(String) length of the directory in bytes</returns>
  140. public static String getDirectoryLengthString(BackgroundWorker bgw, DoWorkEventArgs e, DirectoryInfo di, bool includeSubFolders)
  141. {
  142. return Units.getLengthString(getDirectoryLength(bgw, e, di, includeSubFolders));
  143. }
  144. /// <summary>
  145. /// Get the length of the directory in bytes (long)
  146. /// </summary>
  147. /// <param name="bgw">(BackgroundWorker) to cancel operation</param>
  148. /// <param name="e">(DoWorkEventArgs) to report progress</param>
  149. /// <param name="di">(DirectoryInfo) Start directoryinfo</param>
  150. /// <param name="includeSubFolders">(bool) add all subdirs infos (recursive method)</param>
  151. /// <returns>(long) length of the directory in bytes</returns>
  152. public static long getDirectoryLength(BackgroundWorker bgw, DoWorkEventArgs e, DirectoryInfo di, bool includeSubFolders)
  153. {
  154. long length = 0L;
  155. if (bgw.CancellationPending)
  156. {
  157. e.Cancel = true;
  158. }
  159. else
  160. {
  161. try
  162. {
  163. FileInfo[] filesInf = di.GetFiles();
  164. foreach (FileInfo fi in filesInf)
  165. {
  166. length += fi.Length;
  167. }
  168. }
  169. catch
  170. {
  171. }
  172. if (includeSubFolders)
  173. {
  174. try
  175. {
  176. foreach (DirectoryInfo dir in di.GetDirectories())
  177. {
  178. length += getDirectoryLength(bgw, e, dir, includeSubFolders);
  179. }
  180. }
  181. catch
  182. {
  183. }
  184. }
  185. }
  186. return length;
  187. }
  188. /// <summary>
  189. /// Get bitmap weight !!!!! this method is on test !!!!!! it doesn't return the correct weight, and i don't know why
  190. /// </summary>
  191. /// <param name="bmp">(Bitmap)</param>
  192. /// <returns>(long) size of the Bitmap</returns>
  193. public static long getWeight(System.Drawing.Image bmp)
  194. {
  195. if (bmp == null)
  196. return 0L;
  197. long w = bmp.Width * bmp.Height;
  198.  
  199. switch (bmp.PixelFormat)
  200. {
  201. case System.Drawing.Imaging.PixelFormat.Format24bppRgb: return w * 24;
  202. case System.Drawing.Imaging.PixelFormat.Format16bppArgb1555: return w * 16;
  203. case System.Drawing.Imaging.PixelFormat.Format16bppGrayScale: return w * 16;
  204. case System.Drawing.Imaging.PixelFormat.Format16bppRgb555: return w * 16;
  205. case System.Drawing.Imaging.PixelFormat.Format16bppRgb565: return w * 16;
  206. case System.Drawing.Imaging.PixelFormat.Format1bppIndexed: return w;
  207. case System.Drawing.Imaging.PixelFormat.Format32bppArgb: return w * 32;
  208. case System.Drawing.Imaging.PixelFormat.Format32bppPArgb: return w * 32;
  209. case System.Drawing.Imaging.PixelFormat.Format32bppRgb: return w * 32;
  210. case System.Drawing.Imaging.PixelFormat.Format48bppRgb: return w * 48;
  211. case System.Drawing.Imaging.PixelFormat.Format4bppIndexed: return w * 64;
  212. case System.Drawing.Imaging.PixelFormat.Format64bppArgb: return w * 64;
  213. case System.Drawing.Imaging.PixelFormat.Format64bppPArgb: return w * 64;
  214. case System.Drawing.Imaging.PixelFormat.Format8bppIndexed: return w * 8;
  215. default: return 0L;
  216. }
  217. }
  218. /// <summary>
  219. /// Get readable bitmap weight
  220. /// </summary>
  221. /// <param name="bmp">(Bitmap)</param>
  222. /// <returns>(String) size of the Bitmap</returns>
  223. public static String getWeightString(System.Drawing.Image bmp)
  224. {
  225. if (bmp == null)
  226. return "";
  227. return Units.getLengthString(getWeight(bmp));
  228. }
  229. #endregion
  230. }
  231. }

Structure et Fichiers du projet

Afficher/masquer...


Répertoires contenus dans /var/www/bin/sniplets/bibliobrol/broldev/src/model/file/ 
IcôneNomTailleModification
Pas de sous-répertoires.
IcôneNomTailleModification
| _ Répertoire parent0 octets1713865979 23/04/2024 11:52:59
Fichiers contenus dans /var/www/bin/sniplets/bibliobrol/broldev/src/model/file/ 
IcôneNomTailleModificationAction
IcôneNomTailleModificationAction
Afficher le fichier .cs|.csAbstractFileParser.cs9.32 Ko31/10/2018 18:33:10-refusé-
Afficher le fichier .cs|.csFileHelper.cs9.48 Ko31/10/2018 18:33:10-refusé-
Afficher le fichier .cs|.csAbstractFilesAndDirParser.cs2.97 Ko31/10/2018 18:33:10-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 16/10/2009 gemaakt, de laatste keer de 26/10/2018 gewijzigd
Bron van het afgedrukte document:https://www.gaudry.be/nl/cs-broldev-source-rf-model/file/FileHelper.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.