Exemple #1
0
        private string GetCurrentSubstituteDriveVersion()
        {
            string currentVersion = "";

            DriveInfo[] allDrives;
            //string CurrentDrive;
            string label    = null;
            string realPath = null;
            bool   isSubst  = false;
            string pathRoot = Path.GetPathRoot(Environment.CurrentDirectory);

            allDrives = DriveInfo.GetDrives();
            foreach (DriveInfo d in allDrives)
            {
                System.IO.DriveType driveType = d.DriveType;
                //CurrentDrive = "";
                //if (d.Name == pathRoot)
                //{
                //    CurrentDrive = " <Current Drive> ";

                //}

                label = d.IsReady ? String.Format("{0}", d.VolumeLabel) : null;

                isSubst = IsSubstedPath(d.Name, out realPath);

                if (isSubst)
                {
                    currentVersion = DetermineCurrentVersion(realPath);
                    break;
                }
            }

            return(currentVersion);
        }
Exemple #2
0
        private void UpdateAvailableDrives(object s = null, EventArgs e = null)
        {
            //Clear drives list
            drives.RemoveRange(0, drives.Count);

            //Detect drives
            System.IO.DriveInfo[] drivesListing = System.IO.DriveInfo.GetDrives();
            foreach (var drive in drivesListing)
            {
                System.IO.DriveType driveType = drive.DriveType;
                string driveName = drive.Name;                 // C:\, E:\, etc:\
                switch (driveType)
                {
                case System.IO.DriveType.Removable:
                    // Usually a USB Drive
                    drives.Add(drive.Name);
                    break;
                }
            }

            comboBox1.Items.Clear();
            comboBox1.Text = "";

            //Add drives to combobox
            foreach (string d in drives)
            {
                comboBox1.Items.Add(d);
            }
        }
Exemple #3
0
        private void LoadTree()
        {
            TreeNode node         = null;
            TreeNode sysnode      = null;
            string   pathRoot     = Path.GetPathRoot(Environment.CurrentDirectory);
            string   CurrentDrive = "";
            string   label        = null;
            string   realPath     = null;
            bool     isSubst      = false;
            string   stringSubst;

            treeView1.UseWaitCursor = true;
            treeView1.Nodes.Clear();
            allDrives = DriveInfo.GetDrives();
            sysnode   = treeView1.Nodes.Add("<System>", "<System>");
            foreach (DriveInfo d in allDrives)
            {
                System.IO.DriveType driveType = d.DriveType;
                CurrentDrive = "";
                if (d.Name == pathRoot)
                {
                    CurrentDrive = " <Current Drive> ";
                }

                label = d.IsReady ? String.Format("{0}", d.VolumeLabel) : null;

                isSubst     = IsSubstedPath(d.Name, out realPath);
                stringSubst = "";
                if (isSubst)
                {
                    if (selectedVersion == null)
                    {
                        selectedVersion             = DetermineCurrentVersion(realPath);
                        toolStripPlatformCombo.Text = selectedVersion;
                    }

                    stringSubst = " - <Substituted drive>";
                }

                node = sysnode.Nodes.Add(d.Name, d.Name + CurrentDrive + stringSubst);
                if (node != null)
                {
                    DirectoryInfo dir = d.RootDirectory;

                    stringSubst = "";

                    if (isSubst)
                    {
                        stringSubst = "<Substituted Path = " + realPath + ">";
                        node.Nodes.Add(stringSubst);
                    }

                    if (label == null)
                    {
                        node.Nodes.Add("Drive Type: " + driveType.ToString());
                    }
                    else
                    {
                        node.Nodes.Add("Drive Type: " + driveType.ToString() + " [ " + label + " ] ");
                    }

                    //if (isSubst == false)
                    //{
                    //    node.Nodes.Add("Total Available Space:" + d.AvailableFreeSpace.ToString());
                    //    node.Nodes.Add("Total Total Space:" + d.TotalSize.ToString());
                    //}
                }
            }

            treeView1.ExpandAll();
            treeView1.UseWaitCursor = false;
        }
Exemple #4
0
 /// <summary>Create entry with custom option</summary>
 public AndOption(IFileSystem filesystem, string path, string name, DateTimeOffset lastModified, DateTimeOffset lastAccess, System.IO.DriveType driveType, long driveFreeSpace, long driveSize, string driveLabel, string driveFormat, bool isDirectory, IOption options, string physicalPath) : base(filesystem, path, name, lastModified, lastAccess, driveType, driveFreeSpace, driveSize, driveLabel, driveFormat, isDirectory, physicalPath)
 {
     this.Options = options;
 }
Exemple #5
0
 /// <summary>
 /// Create entry
 /// </summary>
 /// <param name="filesystem"></param>
 /// <param name="path"></param>
 /// <param name="name"></param>
 /// <param name="lastModified"></param>
 /// <param name="lastAccess"></param>
 /// <param name="driveType"></param>
 /// <param name="driveFreeSpace"></param>
 /// <param name="driveSize"></param>
 /// <param name="driveLabel"></param>
 /// <param name="driveFormat"></param>
 /// <param name="isDirectory">Does entry represent a directory (is entry ready, mounted and readable)</param>
 /// <param name="physicalPath"></param>
 public DriveEntry(IFileSystem filesystem, string path, string name, DateTimeOffset lastModified, DateTimeOffset lastAccess, System.IO.DriveType driveType, long driveFreeSpace, long driveSize, string driveLabel, string driveFormat, bool isDirectory, string physicalPath) : base(filesystem, path, name, lastModified, lastAccess)
 {
     this.DriveType      = driveType;
     this.DriveFreeSpace = driveFreeSpace;
     this.DriveSize      = driveSize;
     this.DriveLabel     = driveLabel;
     this.DriveFormat    = driveFormat;
     this.IsDirectory    = isDirectory;
     this.PhysicalPath   = physicalPath;
 }
Exemple #6
0
        public static DriveInformation GetDriveInfo()
        {
            //try
            //{
            //    StringBuilder volname = new StringBuilder(261);
            //    StringBuilder fsname = new StringBuilder(261);
            //    uint sernum, maxlen;
            //    FileSystemFeature flags;
            //    if (!GetVolumeInformation("c:\\", volname, volname.Capacity, out sernum, out maxlen, out flags, fsname, fsname.Capacity))
            //        Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error());
            //    string volnamestr = volname.ToString();
            //    string fsnamestr = fsname.ToString();

            //    Console.WriteLine(" >>>> volnamestr : " + volnamestr);
            //    Console.WriteLine(" >>>> fsnamestr : " + fsnamestr);
            //}
            //catch (Exception ex)
            //{
            //    MessageBox.Show(ex.Message);
            //}

            string           start_path = AppDomain.CurrentDomain.BaseDirectory;
            DriveInformation drive      = new DriveInformation();

            // In case running app from \\comp_name\dir\exe_file.exe
            if (start_path.StartsWith("\\\\"))
            {
                //int first_sep = start_path.IndexOf("\\", 2);
                drive.isNetworkDrive = true;
                drive.compName       = Licensing.GetServerCompName(); //start_path.Substring(2, first_sep - 2);
                if (Licensing.IsLAN() && Licensing.IsServer())
                {
                    drive.correctMachine  = true;
                    drive.hddSerialNumber = Licensing.GetHDDSerialNumber(Licensing.GetLocalDriveLetterFromUnc(Licensing.GetUncPath(new FileInfo(@"CL.DLL"))));
                }
                return(drive);
            }

            // In case running app from drive(Local, Network)
            string drive_letter = start_path.Substring(0, 3);

            DriveInfo[] drives = DriveInfo.GetDrives();
            foreach (var drv in drives)
            {
                string driveName = drv.Name; // C:\, E:\, etc:\
                if (drv.Name == drive_letter)
                {
                    System.IO.DriveType driveType = drv.DriveType;
                    switch (driveType)
                    {
                    case System.IO.DriveType.CDRom:
                        // CD Rom
                        drive.isCdRomDrive = true;
                        break;

                    case System.IO.DriveType.Fixed:
                        // Local Drive
                        drive.isLocalDrive    = true;
                        drive.hddSerialNumber = Licensing.GetHDDSerialNumber(drv.Name.Substring(0, 1));
                        drive.correctMachine  = true;
                        break;

                    case System.IO.DriveType.Network:
                        // Mapped Drive
                        string unc_path = Licensing.GetUncPath(new FileInfo(@"CL.DLL"));
                        drive.isNetworkDrive = true;
                        drive.compName       = Licensing.GetServerCompName();
                        if (Licensing.IsLAN() && Licensing.IsServer())
                        {
                            drive.correctMachine  = true;
                            drive.hddSerialNumber = Licensing.GetHDDSerialNumber(Licensing.GetLocalDriveLetterFromUnc(Licensing.GetUncPath(new FileInfo(@"CL.DLL"))));
                        }
                        else if (Licensing.IsLAN() && !Licensing.IsServer())
                        {
                            drive.correctMachine  = false;
                            drive.hddSerialNumber = (Licensing.GetLocalRegData() != null ? Licensing.GetLocalRegData().machine_code : "");
                        }
                        //ManagementScope scope = new ManagementScope("\\\\.\\ROOT\\cimv2");
                        //ObjectQuery query = new ObjectQuery("SELECT * From Win32_LogicalDisk Where DeviceID=\"" + drive_letter.Replace("\\", "") + "\"");
                        //ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query);
                        //foreach (ManagementObject obj in searcher.Get())
                        //{
                        //    if (obj["ProviderName"] != null)
                        //    {
                        //        string path = obj["ProviderName"].ToString();
                        //        int first_sep = path.IndexOf("\\", 2);
                        //        drive.compName = path.Substring(2, first_sep - 2);
                        //    }
                        //}
                        //drive.isNetworkDrive = true;
                        break;

                    case System.IO.DriveType.NoRootDirectory:
                        drive.isNoRootDirectory = true;
                        break;

                    case System.IO.DriveType.Ram:
                        drive.isRamDrive = true;
                        break;

                    case System.IO.DriveType.Removable:
                        // Usually a USB Drive
                        drive.isRemovableDrive = true;
                        break;

                    case System.IO.DriveType.Unknown:
                        drive.isUnknowDrive = true;
                        break;
                    }
                }
            }

            return(drive);
        }