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
Code c# (FileHelper.cs) (231 lignes)
using System; using System.ComponentModel; using System.IO; using System.Windows.Forms; using be.gaudry.model.win32; namespace be.gaudry.model.file { public static class FileHelper { #region open file /// <summary> /// Open the "open with "dialog /// </summary> /// <param name="filename">(String) path of the file</param> /// <returns>(Process) </returns> public static System.Diagnostics.Process openWith(string filename) { return System.Diagnostics.Process.Start( "rundll32.exe", string.Format("shell32.dll,OpenAs_RunDLL {0}", filename) ); } /// <summary> /// Open the "open with "dialog after testing if file exists. /// Display a messageBox if file doesn't exists. /// </summary> /// <param name="filename">(String) path of the file</param> /// <param name="appName">(String) name of the application</param> /// <returns>(Process) </returns> public static void openWith(string filename, string appName) { if (File.Exists(filename)) { openWith(filename); } else { MessageBox.Show( String.Format( "Le fichier {0} semble inexistant. {1} ne peut donc l'ouvrir.", filename, appName ), "Erreur", MessageBoxButtons.OK, MessageBoxIcon.Exclamation ); } } /// <summary> /// Open a file with the system default application /// </summary> /// <param name="filename">(String) path of the file</param> public static void open(string filename) { process.StartInfo.FileName = filename; // Start processus with the system default application process.Start(); // Free the unused resources. // Rem : the close operation don't stop the process process.Close(); } /// <summary> /// Open a file with the system default application after testing if file exists. /// Display a messageBox if file doesn't exists. /// </summary> /// <param name="filename">(String) path of the file</param> /// <param name="appName">(String) name of the application</param> public static void open(string filename, string appName) { if (File.Exists(filename)) { open(filename); } else { MessageBox.Show( String.Format( "Le fichier {0} semble inexistant. {1} ne peut donc l'ouvrir.", filename, appName ), "Erreur", MessageBoxButtons.OK, MessageBoxIcon.Exclamation ); } } #endregion #region infos public static void openFileProperties(string path) { Shell32Helper.ShowFileProperties(path); } public static string getAttributeName(FileAttributes fa) { switch (fa) { case FileAttributes.Archive: return "archive"; case FileAttributes.Compressed: return "compressé"; case FileAttributes.Device: return ""; case FileAttributes.Directory: return "répertoire"; case FileAttributes.Encrypted: return "encrypté"; case FileAttributes.Hidden: return "caché"; case FileAttributes.Normal: return "normal"; case FileAttributes.NotContentIndexed: return "contenu non indexé"; case FileAttributes.Offline: return "hors ligne"; case FileAttributes.ReadOnly: return "lecture seule"; case FileAttributes.ReparsePoint: return "ReparsePoint"; case FileAttributes.SparseFile: return "SparseFile"; case FileAttributes.System: return "système"; case FileAttributes.Temporary: return "temporaire"; default: return "indéterminé"; } } /// <summary> /// Remove the last directory from the path /// </summary> /// <param name="dirPath"></param> /// <returns></returns> public static string getParentDir(string dirPath) { return (di.Parent!=null)?di.Parent.FullName:dirPath; } /// <summary> /// Get the length of the directory in bytes (formated String) /// </summary> /// <param name="bgw">(BackgroundWorker) to cancel operation</param> /// <param name="e">(DoWorkEventArgs) to report progress</param> /// <param name="di">(DirectoryInfo) Start directoryinfo</param> /// <param name="includeSubFolders">(bool) add all subdirs infos (recursive method)</param> /// <returns>(String) length of the directory in bytes</returns> public static String getDirectoryLengthString(BackgroundWorker bgw, DoWorkEventArgs e, DirectoryInfo di, bool includeSubFolders) { return Units.getLengthString(getDirectoryLength(bgw, e, di, includeSubFolders)); } /// <summary> /// Get the length of the directory in bytes (long) /// </summary> /// <param name="bgw">(BackgroundWorker) to cancel operation</param> /// <param name="e">(DoWorkEventArgs) to report progress</param> /// <param name="di">(DirectoryInfo) Start directoryinfo</param> /// <param name="includeSubFolders">(bool) add all subdirs infos (recursive method)</param> /// <returns>(long) length of the directory in bytes</returns> public static long getDirectoryLength(BackgroundWorker bgw, DoWorkEventArgs e, DirectoryInfo di, bool includeSubFolders) { long length = 0L; if (bgw.CancellationPending) { e.Cancel = true; } else { try { FileInfo[] filesInf = di.GetFiles(); foreach (FileInfo fi in filesInf) { length += fi.Length; } } catch { } if (includeSubFolders) { try { foreach (DirectoryInfo dir in di.GetDirectories()) { length += getDirectoryLength(bgw, e, dir, includeSubFolders); } } catch { } } } return length; } /// <summary> /// Get bitmap weight !!!!! this method is on test !!!!!! it doesn't return the correct weight, and i don't know why /// </summary> /// <param name="bmp">(Bitmap)</param> /// <returns>(long) size of the Bitmap</returns> public static long getWeight(System.Drawing.Image bmp) { if (bmp == null) return 0L; long w = bmp.Width * bmp.Height; switch (bmp.PixelFormat) { case System.Drawing.Imaging.PixelFormat.Format24bppRgb: return w * 24; case System.Drawing.Imaging.PixelFormat.Format16bppArgb1555: return w * 16; case System.Drawing.Imaging.PixelFormat.Format16bppGrayScale: return w * 16; case System.Drawing.Imaging.PixelFormat.Format16bppRgb555: return w * 16; case System.Drawing.Imaging.PixelFormat.Format16bppRgb565: return w * 16; case System.Drawing.Imaging.PixelFormat.Format1bppIndexed: return w; case System.Drawing.Imaging.PixelFormat.Format32bppArgb: return w * 32; case System.Drawing.Imaging.PixelFormat.Format32bppPArgb: return w * 32; case System.Drawing.Imaging.PixelFormat.Format32bppRgb: return w * 32; case System.Drawing.Imaging.PixelFormat.Format48bppRgb: return w * 48; case System.Drawing.Imaging.PixelFormat.Format4bppIndexed: return w * 64; case System.Drawing.Imaging.PixelFormat.Format64bppArgb: return w * 64; case System.Drawing.Imaging.PixelFormat.Format64bppPArgb: return w * 64; case System.Drawing.Imaging.PixelFormat.Format8bppIndexed: return w * 8; default: return 0L; } } /// <summary> /// Get readable bitmap weight /// </summary> /// <param name="bmp">(Bitmap)</param> /// <returns>(String) size of the Bitmap</returns> public static String getWeightString(System.Drawing.Image bmp) { if (bmp == null) return ""; return Units.getLengthString(getWeight(bmp)); } #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 | 1732359989 23/11/2024 12:06:29 |
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.
English translation
You have asked to visit this site in English. For now, only the interface is translated, but not all the content yet.If you want to help me in translations, your contribution is welcome. All you need to do is register on the site, and send me a message asking me to add you to the group of translators, which will give you the opportunity to translate the pages you want. A link at the bottom of each translated page indicates that you are the translator, and has a link to your profile.
Thank you in advance.
Document created the 16/10/2009, last modified the 26/10/2018
Source of the printed document:https://www.gaudry.be/en/cs-broldev-source-rf-model/file//FileHelper.cs.html
The infobrol is a personal site whose content is my sole responsibility. The text is available under CreativeCommons license (BY-NC-SA). More info on the terms of use and the author.