| 0: | // FSTypeUtility.cs | |
| 1: | // Copyright (C) 2001 Mike Krueger | |
| 2: | // with contributions from : | |
| 3: | // Patrick Steele (pj_steele@yahoo.com) | |
| 4: | // This program is free software; you can redistribute it and/or modify | |
| 5: | // it under the terms of the GNU General Public License as published by | |
| 6: | // the Free Software Foundation; either version 2 of the License, or | |
| 7: | // (at your option) any later version. | |
| 8: | // | |
| 9: | // This program is distributed in the hope that it will be useful, | |
| 10: | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 11: | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 12: | // GNU General Public License for more details. | |
| 13: | // | |
| 14: | // You should have received a copy of the GNU General Public License | |
| 15: | // along with this program; if not, write to the Free Software | |
| 16: | // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| 17: | ||
| 18: | using System.IO; | |
| 19: | using System.Text; | |
| 20: | using System.Runtime.InteropServices; | |
| 21: | using System.Diagnostics; | |
| 22: | using System.Windows.Forms; | |
| 23: | ||
| 24: | namespace SharpDevelop.Tool.Function { | |
| 25: | ||
| 26: | public enum FileType { | |
| 27: | Unknown, | |
| 28: | Resource, | |
| 29: | Text, | |
| 30: | Help, | |
| 31: | Icon, | |
| 32: | Xml, | |
| 33: | Html, | |
| 34: | Batch, | |
| 35: | SharpDevelopProject, | |
| 36: | SharpDevelopCombine, | |
| 37: | Exe, | |
| 38: | Dll, | |
| 39: | }; | |
| 40: | ||
| 41: | public enum DriveType | |
| 42: | { | |
| 43: | Unknown = 0, | |
| 44: | NoRoot = 1, | |
| 45: | Removeable = 2, | |
| 46: | Fixed = 3, | |
| 47: | Remote = 4, | |
| 48: | Cdrom = 5, | |
| 49: | Ramdisk = 6 | |
| 50: | } | |
| 51: | ||
| 52: | ||
| 53: | public class FSTypeUtility | |
| 54: | { | |
| 55: | public static bool IsDirectory(string filename) | |
| 56: | { | |
| 57: | FileAttributes attr = File.GetAttributes(filename); | |
| 58: | return (attr & FileAttributes.Directory) != 0; | |
| 59: | } | |
| 60: | ||
| 61: | public static FileType GetFileType(string filename) | |
| 62: | { | |
| 63: | Debug.Assert(filename != null, "SharpDevelop.Tool.Function.FSTypeUtility : string filename == null"); | |
| 64: | ||
| 65: | switch (Path.GetExtension(filename).ToUpper()) { | |
| 66: | case ".DLL": | |
| 67: | return FileType.Dll; | |
| 68: | case ".EXE": | |
| 69: | return FileType.Exe; | |
| 70: | case ".RESX": | |
| 71: | case ".RESOURCES": | |
| 72: | return FileType.Resource; | |
| 73: | case ".TXT": | |
| 74: | return FileType.Text; | |
| 75: | case ".CHM": | |
| 76: | return FileType.Help; | |
| 77: | case ".ICO": | |
| 78: | return FileType.Icon; | |
| 79: | case ".XML": | |
| 80: | return FileType.Xml; | |
| 81: | case ".HTM": | |
| 82: | case ".HTML": | |
| 83: | return FileType.Html; | |
| 84: | case ".BAT": | |
| 85: | return FileType.Batch; | |
| 86: | case ".PRJX": | |
| 87: | return FileType.SharpDevelopProject; | |
| 88: | case ".CMBX": | |
| 89: | return FileType.SharpDevelopCombine; | |
| 90: | default: | |
| 91: | return FileType.Unknown; | |
| 92: | } | |
| 93: | } | |
| 94: | ||
| 95: | /* contributed from Patrick Steele | |
| 96: | * pj_steele@yahoo.com | |
| 97: | */ | |
| 98: | [DllImport("kernel32.dll", SetLastError=true)] | |
| 99: | public static extern int GetVolumeInformation(string RootPath, StringBuilder VolumeNameBuffer, int VolNameBuffSize, ref int VolumeSerNo, ref int MaxComponentLength, ref int FileSystemFlags, StringBuilder FileSystemNameBuffer, int FileSysBuffSize); | |
| 100: | ||
| 101: | public static string VolumeLabel(string RootPath) | |
| 102: | { | |
| 103: | StringBuilder VolName = new StringBuilder(128); | |
| 104: | StringBuilder NameBuff = new StringBuilder(128); | |
| 105: | int SerialNo = 0; | |
| 106: | int MaxCompLength = 0; | |
| 107: | int FSFlags = 0; | |
| 108: | ||
| 109: | try { | |
| 110: | GetVolumeInformation(RootPath, VolName, 128, ref SerialNo, ref MaxCompLength, ref FSFlags, NameBuff, 128); | |
| 111: | return VolName.ToString(); | |
| 112: | } catch(System.Exception) { | |
| 113: | return ""; | |
| 114: | } | |
| 115: | } | |
| 116: | /***** EOC *****/ | |
| 117: | ||
| 118: | ||
| 119: | [DllImport("kernel32.dll")] | |
| 120: | public static extern DriveType GetDriveType(string drivename); | |
| 121: | ||
| 122: | public static bool TestFileExists(string filename) | |
| 123: | { | |
| 124: | if (!File.Exists(filename)) { | |
| 125: | MessageBox.Show("can't load " + filename, "File not found", | |
| 126: | MessageBoxButtons.OK, MessageBoxIcon.Warning); | |
| 127: | return false; | |
| 128: | } | |
| 129: | return true; | |
| 130: | } | |
| 131: | } | |
| 132: | } |
This page was automatically generated by SharpDevelop.