Inheritance: System.Runtime.Serialization.ISerializable
Ejemplo n.º 1
1
        protected AbstractHarddrive(ISmart smart, string name, 
      string firmwareRevision, int index, 
      IEnumerable<SmartAttribute> smartAttributes, ISettings settings)
            : base(name, new Identifier("hdd",
        index.ToString(CultureInfo.InvariantCulture)), settings)
        {
            this.firmwareRevision = firmwareRevision;
              this.smart = smart;
              handle = smart.OpenDrive(index);

              if (handle != smart.InvalidHandle)
            smart.EnableSmart(handle, index);

              this.index = index;
              this.count = 0;

              this.smartAttributes = new List<SmartAttribute>(smartAttributes);

              string[] logicalDrives = smart.GetLogicalDrives(index);
              List<DriveInfo> driveInfoList = new List<DriveInfo>(logicalDrives.Length);
              foreach (string logicalDrive in logicalDrives) {
            try {
              DriveInfo di = new DriveInfo(logicalDrive);
              if (di.TotalSize > 0)
            driveInfoList.Add(new DriveInfo(logicalDrive));
            } catch (ArgumentException) { } catch (IOException) { }
              }
              driveInfos = driveInfoList.ToArray();

              CreateSensors();
        }
Ejemplo n.º 2
0
		public static string GetUNCPath(DriveInfo drive)
		{
			var sb = new StringBuilder(512);
			var size = sb.Capacity;
			var error = WNetGetConnection(drive.Name.Substring(0, 2), sb, ref size);
			return sb.ToString().TrimEnd();
		}
Ejemplo n.º 3
0
        /// <summary>
        /// Constructor for NtfsUsnJournal class.  If no exception is thrown, _usnJournalRootHandle and
        /// _volumeSerialNumber can be assumed to be good. If an exception is thrown, the NtfsUsnJournal
        /// object is not usable.
        /// </summary>
        /// <param name="driveInfo">DriveInfo object that provides access to information about a volume</param>
        /// <remarks> 
        /// An exception thrown if the volume is not an 'NTFS' volume or
        /// if GetRootHandle() or GetVolumeSerialNumber() functions fail. 
        /// Each public method checks to see if the volume is NTFS and if the _usnJournalRootHandle is
        /// valid.  If these two conditions aren't met, then the public function will return a UsnJournalReturnCode
        /// error.
        /// </remarks>
        public UsnJournal(DriveInfo driveInfo)
        {
            _driveInfo = driveInfo;

            if (0 != string.Compare(_driveInfo.DriveFormat, "ntfs", true))
            {
                throw new Exception(string.Format("{0} is not an 'NTFS' volume.", _driveInfo.Name));
            }

            IsNtfsVolume = true;

            IntPtr rootHandle;

            var returnCode = GetRootHandle(out rootHandle);

            if (returnCode != UsnJournalReturnCode.USN_JOURNAL_SUCCESS)
            {
                throw new Win32Exception((int)returnCode);
            }

            _usnJournalRootHandle = rootHandle;

            returnCode = GetVolumeSerialNumber(_driveInfo, out _volumeSerialNumber);

            if (returnCode != UsnJournalReturnCode.USN_JOURNAL_SUCCESS)
            {
                throw new Win32Exception((int)returnCode);
            }
        }
 private string CheckDiskStatus(DriveInfo drive)
 {
     double spaceUsed = drive.TotalFreeSpace / drive.TotalSize;
     if (spaceUsed < 0.6) { return "OK"; }
     else if (spaceUsed < 0.8) { return "Warning"; }
     else { return "Error"; }
 }
Ejemplo n.º 5
0
        public DriveButton(DriveInfo drive)
        {
            InitializeComponent();

            this.currentDrive = drive;

            txtDriveName.Text = drive.Name[0].ToString();

            ShowDriveData(drive);

            //switch (drive.DriveType)
            //{
            //    case DriveType.CDRom:
            //        imgDriveType.Source = new BitmapImage(new Uri("/Icons/drive_cdrom.ico", UriKind.Relative));
            //        break;
            //    case DriveType.Fixed:
            //        imgDriveType.Source = new BitmapImage(new Uri("/Icons/drive_fixed.ico", UriKind.Relative));
            //        break;
            //    case DriveType.Network:
            //        imgDriveType.Source = new BitmapImage(new Uri("/Icons/drive_network.ico", UriKind.Relative));
            //        break;
            //    case DriveType.NoRootDirectory:
            //        break;
            //    case DriveType.Ram:
            //        break;
            //    case DriveType.Removable:
            //        imgDriveType.Source = new BitmapImage(new Uri("/Icons/drive_removable.ico", UriKind.Relative));
            //        break;
            //    case DriveType.Unknown:
            //        imgDriveType.Source = new BitmapImage(new Uri("/Icons/drive_unknown.ico", UriKind.Relative));
            //        break;
            //    default:
            //        break;
            //}
        }
 public Boolean IsCdRom()
 {
     DriveInfo monDriveInfo = new DriveInfo(this._path);
     if (monDriveInfo.DriveType == DriveType.CDRom)
         return (true);
     return (false);
 }
 public Boolean IsRemovableMedia()
 {
     DriveInfo monDriveInfo = new DriveInfo(this._path);
     if (monDriveInfo.DriveType == DriveType.Removable)
         return (true);
     return (false);
 }
        private static void Main()
        {
            // Start with drives if you have to search the entire computer.
            string[] drives = Environment.GetLogicalDrives();

            foreach (string dr in drives)
            {
                DriveInfo di = new DriveInfo(dr);

                // Here we skip the drive if it is not ready to be read. This
                // is not necessarily the appropriate action in all scenarios.
                if (!di.IsReady)
                {
                    Console.WriteLine("The drive {0} could not be read", di.Name);
                    continue;
                }

                DirectoryInfo rootDir = di.RootDirectory;
                WalkDirectoryTree(rootDir);
            }

            // Write out all the files that could not be processed.
            Console.WriteLine("Files with restricted access:");
            foreach (string s in log)
            {
                Console.WriteLine(s);
            }

            // Keep the console window open in debug mode.
            Console.WriteLine("Press any key");
            Console.ReadKey();
        }
 public override void Run()
 {
     DriveInfo d = new DriveInfo(Drive);
     long actual = d.AvailableFreeSpace / 1024;
     if (actual < RequiredMegabytes)
         throw new AssertionException<long>(RequiredMegabytes, actual, string.Format("Insufficient space on drive {0}",Drive));
 }
Ejemplo n.º 10
0
        void tvExplorer_AfterSelect(object sender, TreeViewEventArgs e)
        {
            btnOK.Enabled = false;
            btnNewFolder.Enabled = false;

            DirectoryInfo di = new DirectoryInfo(tvExplorer.SelectedNodePath);
            if (di.Exists)
            {
                btnOK.Enabled = (PerformPathValidation == null || PerformPathValidation(tvExplorer.SelectedNodePath));

                try
                {
                    DriveInfo drvInvo = new DriveInfo(di.Root.FullName);
                    btnNewFolder.Enabled = (drvInvo.AvailableFreeSpace > 0 && drvInvo.IsReady);
                }
                catch { }
            }

            if (btnOK.Enabled)
            {
                this.SelectedPath = tvExplorer.SelectedNodePath;
            }
            else
            {
                this.SelectedPath = string.Empty;
            }
        }
Ejemplo n.º 11
0
        public bool isDBSizeOk()
        {
            bool returnValue = true;

            try
            {
                conn.Open();
                DriveInfo diskInfo = new DriveInfo("C");
                if (diskInfo.IsReady == true)
                {
                    long diskFreeSpace = diskInfo.TotalFreeSpace;

                    long dbSize = GetDBSize();
                    double lowerThreshold = DB_SIZE_LOWER_THRESHOLD * maxDBSize;

                    CLogger.WriteLog(ELogLevel.DEBUG, "THe free space on disk is" + diskFreeSpace +
                        " dbSize: " + dbSize + " maxDBSize -dbSize : " + (maxDBSize - dbSize));

                    if (dbSize >= maxDBSize)
                    {
                        CLogger.WriteLog(ELogLevel.DEBUG, "Setting return val to false");
                        returnValue = false;
                    }
                }
                conn.Close();
            }
            catch (Exception exc)
            {
                CLogger.WriteLog(ELogLevel.DEBUG, "Exception while retreiving diskinfo " + exc.Message);
            }
            return returnValue;
        }
Ejemplo n.º 12
0
		private void DoBackup(DriveInfo info)
		{
			_checkForUsbKeyTimer.Enabled = false;
			_noteLabel.Visible = false;
			_topLabel.Text = "~Backing Up...";
			Refresh();
			try
			{
				string dest = Path.Combine(info.RootDirectory.FullName,
										   _projectInfo.Name + "_wesay.zip");
				BackupMaker.BackupToExternal(_projectInfo.PathToTopLevelDirectory,
											 dest,
											 _projectInfo.FilesBelongingToProject);
				_topLabel.Text = "~Backup Complete";
				_noteLabel.Visible = true;
				_noteLabel.Text = String.Format("~Files backed up to {0}", dest);
			}
			catch (Exception e)
			{
				ErrorReport.ReportNonFatalMessage(
						"WeSay could to perform the backup.  Reason: {0}", e.Message);
				_topLabel.Text = "~Files were not backed up.";
				_topLabel.ForeColor = Color.Red;
			}

			_cancelButton.Text = "&OK";
		}
Ejemplo n.º 13
0
 protected virtual void OnRemovableDrivePulled(DriveInfo d)
 {
     if (this.RemovableDrivePulled != null)
     {
         this.RemovableDrivePulled(this, new RemovableDriveEventArgs(d));
     }
 }
Ejemplo n.º 14
0
        /// <summary>
        /// Returns a response from the message received.
        /// The response comes from our AIML chat bot or from our own custom processing.
        /// </summary>
        /// <param name="message">string</param>
        /// <param name="user">User (for context)</param>
        /// <returns>string</returns>
        private static string HandleMessage(string message, User user)
        {
            string output = "";

            if (!string.IsNullOrEmpty(message))
            {
                // Provide custom commands for our chat bot, such as disk space, utility functions, typical IRC bot features, etc.
                if (message.ToUpper().IndexOf("DISK SPACE") != -1)
                {
                    DriveInfo driveInfo = new DriveInfo("C");
                    output = "Available disk space on " + driveInfo.Name + " is " + driveInfo.AvailableFreeSpace + ".";
                }
                else if (message.ToUpper().IndexOf("DISK SIZE") != -1)
                {
                    DriveInfo driveInfo = new DriveInfo("C");
                    output = "The current disk size on " + driveInfo.Name + " is " + driveInfo.TotalSize + ".";
                }
                else
                {
                    // No recognized command. Let our chat bot respond.
                    output = _bot.getOutput(message, user);
                }
            }

            return output;
        }
Ejemplo n.º 15
0
 /// <summary>
 /// 获取程序运行的磁盘的空闲容量
 /// </summary>
 /// <returns>空间空闲容量</returns>
 private long GetDriverFreeSpace(string strPath)
 {
     string strDriverName = Directory.GetDirectoryRoot(strPath);
     DriveInfo dInfo = new DriveInfo(strDriverName);
     long lSum = dInfo.AvailableFreeSpace;    //磁盘空闲容量
     return lSum;
 }
        private void Button2Click(object sender, RoutedEventArgs e)
        {
            if (textBox1.Text.Equals("")) return;
            var path = textBox1.Text;
            var key = Registry.CurrentUser.CreateSubKey("WoWCacheDelete");
            key.SetValue("Path",path);
            key.Close();
            try
            {
                var drive = new DriveInfo(textBox1.Text.Substring(0, 1));
                var freeSpaceInBytes = ((drive.TotalFreeSpace/1024)/1024);
                Directory.Delete(path + @"\Cache", true);
                Directory.Delete(path + @"\Data\Cache", true);
                var freeSpaceInBytesafter = ((drive.TotalFreeSpace/1024)/1024);
                var recovered = freeSpaceInBytesafter - freeSpaceInBytes;

                SetStatusGood("  Space Before: " + freeSpaceInBytes + "MB. Space After: " +
                              freeSpaceInBytesafter + "MB. Total Saving: " + recovered + "MB. All Done.  ");
            }
            catch (DirectoryNotFoundException direx)
            {
                SetStatusBad("  Cache Already Cleared!    No space to save.  ",null);
            }
            catch (Exception ex)
            {
             SetStatusBad(ex.Message,ex.StackTrace);
             return;
            }
        }
Ejemplo n.º 17
0
        public long GetFreeDiskSpaceInGb(string drive)
        {
            var driveInfo = new DriveInfo(drive);
            long freeSpace = driveInfo.AvailableFreeSpace / (1024 * 1024 * 1024);

            return freeSpace;
        }
        public void FindMediaOnComputer()
        {
            string[] drives = System.Environment.GetLogicalDrives();
            foreach (string dr in drives) {
                if (dr != "Y:\\") {
                    System.IO.DriveInfo di = new System.IO.DriveInfo(dr);
                    if (!di.IsReady) {
                        Console.WriteLine("The drive {0} could not be read", di.Name);
                        continue;
                    }

                    System.IO.DirectoryInfo rootDir = di.RootDirectory;
                    curHdd = rootDir.ToString();
                    statusUpt("Searching hdd: " + rootDir);
                    SearchInDirTree(rootDir);
                }
            }

            Environment.SpecialFolder[] specDirs = new Environment.SpecialFolder[] { Environment.SpecialFolder.MyDocuments, Environment.SpecialFolder.MyMusic, Environment.SpecialFolder.MyPictures, Environment.SpecialFolder.MyVideos, Environment.SpecialFolder.Favorites, Environment.SpecialFolder.Desktop };
            foreach (Environment.SpecialFolder sd in specDirs)
            {
                statusUpt("Searching special: " + sd.ToString());
                SearchInDirTree(new System.IO.DirectoryInfo(Environment.GetFolderPath(sd)));
            }

            foreach (string s in log)
            {
                //Alla filer som är restricted
            }
            statusUpt("Search is Done!");
            searchThread.Abort();
        }
 public Boolean IsHardDisk()
 {
     DriveInfo monDriveInfo = new DriveInfo(this._path);
     if (monDriveInfo.DriveType == DriveType.Fixed)
         return (true);
     return (false);
 }
Ejemplo n.º 20
0
 public static void AssemblyInitialize(TestContext context)
 {
     (mounterThread = new Thread(new ThreadStart(() => DokanOperationsFixture.Operations.Mount(DokanOperationsFixture.MOUNT_POINT.ToString(CultureInfo.InvariantCulture), DokanOptions.DebugMode | DokanOptions.NetworkDrive, 1)))).Start();
     var drive = new DriveInfo(DokanOperationsFixture.MOUNT_POINT.ToString(CultureInfo.InvariantCulture));
     while (!drive.IsReady)
         Thread.Sleep(50);
 }
Ejemplo n.º 21
0
        public static EsDriveInfo FromDirectory(string path, ILogger log)
        {
            try
            {
                string driveName;
                if (OS.IsUnix)
                {
                    driveName = GetDirectoryRootInUnix(path, log);
                    if (driveName == null)
                        return null;
                }
                else
                {
                    driveName = Directory.GetDirectoryRoot(path);
                }

                var drive = new DriveInfo(driveName);
                var esDrive = new EsDriveInfo(drive.Name, drive.TotalSize, drive.AvailableFreeSpace);
                return esDrive;
            }
            catch (Exception ex)
            {
                log.Debug("Error while reading drive info for path {0}. Message: {1}.", path, ex.Message);
                return null;
            }
        }
Ejemplo n.º 22
0
        private void ReportDiskUsage()
        {
            string drive = Path.GetPathRoot(AgentDirectory);
            DriveInfo driveInfo = new DriveInfo(drive);
            Console.WriteLine("Disk Usage Report");
            Console.WriteLine($"  Agent directory: {AgentDirectory}");
            Console.WriteLine($"  Drive letter: {drive}");
            Console.WriteLine($"  Total disk size: {string.Format("{0:N0}", driveInfo.TotalSize)} bytes");
            Console.WriteLine($"  Total disk free space: {string.Format("{0:N0}", driveInfo.TotalFreeSpace)} bytes");

            var workingDirectories = Directory.GetDirectories(Path.Combine(AgentDirectory, "_work"));
            var totalWorkingDirectories = workingDirectories != null ? workingDirectories.Length : 0;

            Console.WriteLine("  Agent info");
            Console.WriteLine($"    Total size of agent directory: {string.Format("{0:N0}", GetDirectoryAttributes(AgentDirectory).Item1)} bytes");
            Console.WriteLine($"    Total agent working directories: {totalWorkingDirectories}");

            if (totalWorkingDirectories > 0)
            {
                int nameLength = 0;
                foreach(string directoryName in workingDirectories)
                {
                    nameLength = directoryName.Length > nameLength ? directoryName.Length : nameLength;
                }
                int sizeLength = string.Format("{0:N0}", driveInfo.TotalSize).Length;
                string columnFormat = "      {0,-" + nameLength.ToString() + "}  {1," + sizeLength.ToString() + ":N0}  {2}";
                Console.WriteLine(string.Format(columnFormat, "Folder name", "Size (bytes)", "Last Modified DateTime"));
                foreach (var workingDirectory in workingDirectories)
                {
                    Tuple<long, DateTime> directoryAttributes = GetDirectoryAttributes(workingDirectory);
                    Console.WriteLine(string.Format(columnFormat, workingDirectory, directoryAttributes.Item1, directoryAttributes.Item2));
                }
            }
        }
 public bool GetQuota(out int totalBytes, out int availableBytes)
 {
     DriveInfo di = new DriveInfo(Path.GetPathRoot(Path.GetFullPath(basePath)));
     totalBytes = di.TotalSize > int.MaxValue ? int.MaxValue : (int)di.TotalSize;
     availableBytes = di.AvailableFreeSpace > int.MaxValue ? int.MaxValue : (int)di.AvailableFreeSpace;
     return true;
 }
        static void Main(string[] args)
        {
            Console.WriteLine("Enter the drive letter (a to z):"); 
     
            string driveletter = Console.ReadLine(); 
            DriveInfo d = new DriveInfo(driveletter);
            if (d.IsReady) 
            { 
                Console.WriteLine(d.Name); 
                Console.WriteLine(d.DriveType); 
                Console.WriteLine(d.VolumeLabel);
                Console.WriteLine(d.DriveFormat);
                Console.WriteLine(d.TotalSize + " bytes.");
                Console.WriteLine(d.TotalFreeSpace + " bytes.");

                Console.WriteLine(d.TotalSize/1024+ " kbytes.");
                Console.WriteLine(d.TotalFreeSpace/1024 + " Kbytes.");

                Console.WriteLine((d.TotalSize / 1024)/1024 + " MB.");
                Console.WriteLine((d.TotalFreeSpace / 1024)/1024 + " MB.");

                Console.WriteLine(((d.TotalSize / 1024)/1024)/1024 + " GB.");
                Console.WriteLine(((d.TotalFreeSpace / 1024)/1024)/1024 + " Gb.");


            }
            else Console.WriteLine(d.Name + " - " + " Not Ready."); 
            Console.Read(); 
        }
Ejemplo n.º 25
0
 public NtfsPartition(PartitionInfo info)
 {
     _info = info;
     _drive = new DriveInfo(info.Letter.ToString());
     info.FreeSpace = (int)(_drive.AvailableFreeSpace / 1024.0 / 1024.0);
     _currentDirectory = _drive.RootDirectory;
 }
Ejemplo n.º 26
0
 public bool ChangeDisk(string diskName)
 {
     List<Disk> disks = new List<Disk>();
     DriveInfo drive = new DriveInfo(diskName);
     disks.Add(new Disk(drive.Name, drive.Name, drive.DriveType, null));
     return SetDisk(disks);
 }
Ejemplo n.º 27
0
 public DriveItem(DriveInfo info)
 {
     Name = GetDriveInfoString(info);
     RootDirectory = info.RootDirectory.FullName;
     ShellObject = ShellObject.FromParsingName(RootDirectory);
     IsReady = info.IsReady;
 }
Ejemplo n.º 28
0
 /// <summary>
 /// Creates platform specific SystemDrive Instance
 /// </summary>
 /// <param name="drive"></param>
 /// <returns></returns>
 public static SystemDrive CreateSystemDrive(DriveInfo drive)
 {
     if(Environment.OSVersion.Platform == PlatformID.Win32NT)
         return new SystemDriveWindows(drive);
     else
         return new SystemDriveLinux(drive);
 }
Ejemplo n.º 29
0
		public DiskFullException(DriveInfo driveInfo, string filePath, long requestedFileSize)
			: base(
				string.Format("There is not enough space on {0} drive to set size of file {1} to {2} bytes", driveInfo.Name,
				              filePath, requestedFileSize))
		{
			DriveInfo = driveInfo;
		}
Ejemplo n.º 30
0
            // UNDONE: organise DriveProvider

            /// <summary>
            /// Creates platform specific SystemDrive Instance
            /// </summary>
            /// <param name="drive"></param>
            /// <returns></returns>
            public static Drive CreateDrive(DriveInfo drive)
            {
                if (Environment.OSVersion.Platform == PlatformID.Win32NT)
                    return new Windows.Drive(drive);
                else
                    return new Linux.Drive(drive);
            }