/// <summary> /// Tests System.IO.DriveInfo plugs. /// </summary> public static void Execute(Debugger mDebugger) { string driveName = @"0:\"; var MyDrive = new DriveInfo(driveName); mDebugger.Send("START TEST: Get Name"); Assert.IsTrue(MyDrive.Name == driveName, "DriveInfo.Name failed drive has wrong name"); mDebugger.Send("END TEST"); mDebugger.Send("START TEST: Get TotalSize"); long MyDriveSize = MyDrive.TotalSize; mDebugger.Send($"Size is {MyDriveSize}"); Assert.IsTrue(MyDriveSize > 0, "DriveInfo.TotalSize failed: invalid size"); mDebugger.Send("END TEST"); mDebugger.Send("START TEST: Get AvailableFreeSpace"); long MyDriveAvailableFreeSpace = MyDrive.AvailableFreeSpace; mDebugger.Send($"AvailableFreeSpace {MyDriveAvailableFreeSpace}"); Assert.IsTrue(MyDriveAvailableFreeSpace >= 0, "DriveInfo.AvailableFreeSpace failed: invalid size"); Assert.IsFalse(MyDriveAvailableFreeSpace > MyDrive.TotalSize, "DriveInfo.AvailableFreeSpace failed: more than TotalSize"); mDebugger.Send("END TEST"); mDebugger.Send("START TEST: Get TotalFreeSpace"); long MyDriveTotalFreeSpace = MyDrive.TotalFreeSpace; mDebugger.Send($"TotalFreeSpace {MyDriveTotalFreeSpace}"); Assert.IsTrue(MyDriveTotalFreeSpace >= 0, "DriveInfo.TotalFreeSpace failed: invalid size"); Assert.IsFalse(MyDriveTotalFreeSpace > MyDrive.TotalSize, "DriveInfo.TotalFreeSpace failed: more than TotalSize"); /* * If disk quotas are enabled AvailableFreeSpace and TotalFreeSpace could be different numbers but TotalFreeSpace * should be always >= of AvailableFreeSpace */ Assert.IsTrue(MyDriveTotalFreeSpace >= MyDriveAvailableFreeSpace, "DriveInfo.MyDriveTotalFreeSpace failed: less than AvailableFreeSpace"); mDebugger.Send("END TEST"); mDebugger.Send("START TEST: Get RootDirectory"); var xDi = MyDrive.RootDirectory; Assert.IsTrue(xDi.Name == MyDrive.Name, "RootDirectory failed"); mDebugger.Send("END TEST"); mDebugger.Send("START TEST: Get DriveFormat"); Assert.IsTrue(MyDrive.DriveFormat == "FAT32", "DriveFormat failed"); mDebugger.Send("END TEST"); mDebugger.Send("START TEST: Get VolumeLabel"); string OriginalVolumeLabel = MyDrive.VolumeLabel; mDebugger.Send($"Volume Label of {MyDrive.Name} is {MyDrive.VolumeLabel}"); Assert.IsTrue(OriginalVolumeLabel == "COSMOS", "VolumeLabel Get failed not the expected value"); mDebugger.Send("END TEST"); mDebugger.Send("START TEST: Set VolumeLabel to <TEST>"); // Now try to change it... String NewVolumeLabel = "TEST"; mDebugger.Send($"Changing Volume Label to {NewVolumeLabel}..."); MyDrive.VolumeLabel = NewVolumeLabel; string SetVolumeLabel = MyDrive.VolumeLabel; mDebugger.Send($"Volume Label of {MyDrive.Name} is {SetVolumeLabel}"); Assert.IsTrue(SetVolumeLabel == NewVolumeLabel, "VolumeLabel Set failed: not the expected value"); mDebugger.Send("END TEST"); mDebugger.Send("START TEST: Set VolumeLabel (restoring original label)"); // Now try to change it... mDebugger.Send($"Changing Volume Label to {OriginalVolumeLabel}..."); MyDrive.VolumeLabel = OriginalVolumeLabel; SetVolumeLabel = MyDrive.VolumeLabel; mDebugger.Send($"Volume Label of {MyDrive.Name} is {SetVolumeLabel}"); Assert.IsTrue(SetVolumeLabel == OriginalVolumeLabel, "VolumeLabel Set failed: not the expected value"); mDebugger.Send("END TEST"); mDebugger.Send("START TEST: Testing isReady status of the Drive"); Assert.IsTrue(MyDrive.IsReady, "IsReady failed drive not ready"); mDebugger.Send("END TEST"); mDebugger.Send("START TEST: Testing DriveType"); Assert.IsTrue(MyDrive.DriveType == DriveType.Fixed, "DriveType failed drive not of Fixed type"); mDebugger.Send("END TEST"); mDebugger.Send("START TEST: Getting all drives info"); DriveInfo[] xDrives = DriveInfo.GetDrives(); Assert.IsFalse(xDrives == null, "GetDrives failed: null array returned"); // I suppose that at least a drive is recognized by Cosmos Assert.IsTrue(xDrives.Length > 0, "GetDrives failed: no drive recognized"); /* Check that only the Name property of the first one is the same of driveName */ Assert.IsTrue(xDrives[0].Name == driveName, "GetDrives failed: first drive is not the same of MyDrive (0:)"); mDebugger.Send("END TEST"); }
public static bool isDriveExists(string driveLetterWithColonAndSlash) { return(DriveInfo.GetDrives().Any(x => x.Name == driveLetterWithColonAndSlash)); }
/// <summary> /// Gets the root directories of the system /// </summary> /// <returns>Return the list of root directories</returns> public static IList <DriveInfo> GetRootDirectories() { return((from x in DriveInfo.GetDrives() select x).ToList()); }
public static string FBDialogFolderPath; //Select target path private void Particulars_Click(object sender, EventArgs e) { switch (((Button)sender).Tag.ToString()) { case "GPU": string strGPU = string.Empty; ManagementObjectSearcher mos = new ManagementObjectSearcher("Select * from Win32_VideoController"); foreach (ManagementObject mo in mos.Get()) { strGPU += mo["Name"].ToString() + " "; } rtxtContent.AppendText("GPU:" + strGPU + Environment.NewLine); break; case "HardDrive": DriveInfo[] drives = DriveInfo.GetDrives(); StringBuilder sr = new StringBuilder(); foreach (DriveInfo drive in drives) { if (drive.IsReady) { var val1 = (double)drive.TotalSize / 1024 / 1024; var val2 = (double)drive.TotalFreeSpace / 1024 / 1024; sr.AppendFormat("Name:{0}\t Format:{2}\tTotal:{3}MB\tLeft:{4}MB\tUsable Percent:{1}%\r\n", drive.Name, string.Format("{0:F2}", val2 / val1 * 100), drive.DriveFormat, (long)val1, (long)val2); } } rtxtContent.AppendText("HardDrive:\r\n" + sr.ToString() + Environment.NewLine); break; case "Processor": string strProcessor = ""; ManagementObjectSearcher driveID = new ManagementObjectSearcher("Select * from Win32_Processor"); foreach (ManagementObject mo in driveID.Get()) { strProcessor = mo["Name"].ToString(); } rtxtContent.AppendText("Processor:" + strProcessor + Environment.NewLine); break; case "OS": rtxtContent.AppendText("OS:" + Environment.OSVersion + Environment.NewLine); break; case "Printers": for (int i = 0; i < PrinterSettings.InstalledPrinters.Count; i++) { rtxtContent.AppendText("Printers:" + PrinterSettings.InstalledPrinters[i] + " " + Environment.NewLine); } rtxtContent.AppendText(Environment.NewLine); break; case "NetworkAdapters": NetworkInterface[] adapters = NetworkInterface.GetAllNetworkInterfaces(); StringBuilder sb = new StringBuilder(); foreach (NetworkInterface adapter in adapters) { sb.AppendFormat("Description:{0}\r\nId:{1}\r\nName:{2}\r\nNetworkInterfaceType:{3}\r\nSpeed:{4}\r\nOperationalStatus:{5}\r\nPhysicalAddress:{6}\r\n", adapter.Description, adapter.Id, adapter.Name, adapter.NetworkInterfaceType, adapter.Speed * 0.001 * 0.001 + "M", adapter.OperationalStatus, adapter.GetPhysicalAddress() ); sb.AppendFormat("\r\n"); } rtxtContent.AppendText("NetworkAdapters:" + Environment.NewLine + sb.ToString()); break; case "CacheMemory": string strCacheMemory = ""; ManagementObjectSearcher cacheMemory = new ManagementObjectSearcher("Select * from Win32_Processor"); var test = cacheMemory.Get(); foreach (ManagementObject mo in cacheMemory.Get()) { strCacheMemory = "L2CacheSize:" + mo["L2CacheSize"].ToString() + "KB\tL3CacheSize:" + mo["L3CacheSize"].ToString() + "KB"; } rtxtContent.AppendText("CacheMemory:" + strCacheMemory + Environment.NewLine); break; case "DeviceBus": string strDeviceBus = ""; ManagementObjectSearcher deviceBus = new ManagementObjectSearcher("Select * from Win32_Bus"); foreach (ManagementObject mo in deviceBus.Get()) { strDeviceBus += mo["DeviceID"].ToString() + "\r\n"; } rtxtContent.AppendText("DeviceBus:\r\n" + strDeviceBus + Environment.NewLine); break; case "DiskDrive": string strDiskDrive = ""; ManagementObjectSearcher diskDrive = new ManagementObjectSearcher("Select * from Win32_DiskDrive"); foreach (ManagementObject mo in diskDrive.Get()) { strDiskDrive += mo["Name"].ToString() + " "; } rtxtContent.AppendText("DiskDrive:" + strDiskDrive + Environment.NewLine); break; case "DiskPartition": DriveInfo[] diskPartition = DriveInfo.GetDrives(); StringBuilder sbDiskPartition = new StringBuilder(); foreach (DriveInfo di in diskPartition) { sbDiskPartition.Append(di + " "); } rtxtContent.AppendText("DiskPartition:" + sbDiskPartition.ToString().Trim() + Environment.NewLine); break; case "IDEController": string strIDEController = ""; ManagementObjectSearcher ideController = new ManagementObjectSearcher("Select * from Win32_IDEController"); var h = ideController.Get(); foreach (ManagementObject mo in ideController.Get()) { strIDEController += mo["Name"].ToString() + " "; } rtxtContent.AppendText("IDEController:" + strIDEController + Environment.NewLine); break; case "IRQResources": string strIRQResources = ""; ManagementObjectSearcher irqResources = new ManagementObjectSearcher("Select * from Win32_IRQResource"); foreach (ManagementObject mo in irqResources.Get()) { strIRQResources += mo["Name"].ToString() + " "; } rtxtContent.AppendText("IRQResources:" + strIRQResources + Environment.NewLine); break; case "VideoSettings": string strVideoSettings = ""; ManagementObjectSearcher videoSettings = new ManagementObjectSearcher("Select * from Win32_VideoController"); var h2 = videoSettings.Get(); foreach (ManagementObject mo in videoSettings.Get()) { strVideoSettings += mo["Name"].ToString() + " "; } rtxtContent.AppendText("VideoSettings:" + strVideoSettings + Environment.NewLine); break; } }
public override void Execute(string[] Args) { if (Args.Length == 1) { Program.Print("list"); Program.Print("list-update"); Program.Print("install"); Program.Print("installed"); Program.Print("scan"); Program.Print("start"); Program.Print("delete"); return; } switch (Args[1]) { case "list-update": Program.Print("Preuzimam linkove..."); using (WebClient wc = new WebClient()) { wc.DownloadFile("http://alantr7.uwebweb.com/alan/terminal/app-list.txt?_=" + DateTimeOffset.Now.ToUnixTimeMilliseconds(), Program.DIRECTORY + "app-list.txt"); } Program.Print("Linkovi uspjesno preuzeti."); return; case "list": { string[] lines = File.ReadAllLines(Program.DIRECTORY + "app-list.txt"); List <string> installed = new List <string>(); foreach (string l in File.ReadAllLines(Program.DIRECTORY + "app-installed.txt")) { JSONElement json = JSON.Parse(l); installed.Add(json.c["keyword"].ToString()); } Program.Print("\t§8NAZIV\t\t\tNAZIV PROGRAMA\t\tBIN\n", false); foreach (string line in lines) { JSONElement e = JSON.Parse(line); string output = $"\t{e.c["keyword"].ToString()}"; string tabs; if (e.c["keyword"].ToString().Length < 8) { tabs = "\t\t\t"; } else { tabs = "\t\t"; } output += tabs + e.c["name"].ToString(); if (e.c["name"].ToString().Length < 8) { tabs = "\t\t\t"; } else { tabs = "\t\t"; } output += tabs + e.c["bin"]; if (e.c["bin"].ToString().Length < 8) { tabs = "\t\t\t"; } else if (e.c["bin"].ToString().Length < 16) { tabs = "\t\t"; } else { tabs = "\t"; } output += tabs; Console.Write($"{output}"); if (installed.Contains(e.c["keyword"].ToString())) { Program.Print("§aInstalirano§f", false, false); } Console.WriteLine(); } return; } case "install": using (WebClient wc = new WebClient()) { string[] lines = File.ReadAllLines(Program.DIRECTORY + "app-list.txt"); foreach (string line in lines) { JSONElement e = JSON.Parse(line); if (e.c["keyword"].ToString().Equals(Args[2].ToLower())) { Stream stream = wc.OpenRead(e.c["url"].ToString()); int filesize = Convert.ToInt32(wc.ResponseHeaders["Content-Length"]); stream.Dispose(); wc.DownloadFileAsync(new Uri(e.c["url"].ToString()), Program.DIRECTORY + "downloads\\" + e.c["bin"].ToString()); bool done = false; Program.Print($"Ukupna velicina: {filesize / (1024 * 1024)}.{("" + filesize % (1024 * 1024)).Substring(0, 2)}MB"); int[] cp = Program.GetCursorPosition(); wc.DownloadFileCompleted += (o, s) => done = true; while (!done) { Program.SetCursorPosition(cp); Program.Print($"Preuzeto: {(int)(new FileInfo(Program.DIRECTORY + "downloads\\" + e.c["bin"].ToString()).Length / (double)filesize * 100)}%"); Thread.Sleep(500); } ; Console.WriteLine(); Program.Print("Cekam da se instalacija zavrsi..."); Process.Start(new ProcessStartInfo() { FileName = Program.DIRECTORY + "downloads\\" + e.c["bin"].ToString() }).WaitForExit(); Program.Print("Brisem setup"); Thread.Sleep(2000); File.Delete(Program.DIRECTORY + "downloads\\" + e.c["bin"].ToString()); Program.Print("Instalacija zavrsena"); break; } } } return; case "scan": { int searchlevel = Int32.Parse(Program.ArgValue(Args, "level", "3")); List <string> directories = new List <string>(); foreach (DriveInfo di in DriveInfo.GetDrives()) { if (di.IsReady) { directories.Add(di.Name); } } directories.Add(Environment.GetEnvironmentVariable("APPDATA")); directories.Add(Environment.GetEnvironmentVariable("LOCALAPPDATA")); directories.Add("C:\\Program Files (x86)\\Google\\Chrome\\Application"); Dictionary <string, string> apps = new Dictionary <string, string>(); foreach (string line in File.ReadAllLines(Program.DIRECTORY + "app-list.txt")) { JSONElement json = JSON.Parse(line); apps.Add(json.c["keyword"].ToString(), json.c["bin"].ToString().ToLower()); } int[] cp = Program.GetCursorPosition(); List <JSONElement> Found = new List <JSONElement>(); void SearchDirectory(string dir, int level) { if (level > searchlevel) { return; } if (level == 1) { Program.EmptyLine(cp); Program.SetCursorPosition(cp); Program.Print($"§7Provjeravam direktorij §8{dir}"); } try { foreach (string s in Directory.GetFiles(dir)) { if (Directory.Exists(s)) { SearchDirectory(s, level); } string[] split = s.Split('\\'); string name = split[split.Length - 1].ToLower(); foreach (string app in apps.Keys) { if (name.Equals(apps[app])) { JSONElement appf = new JSONElement(); JSONElement appf_n = new JSONElement(); appf_n.v = app; JSONElement appf_p = new JSONElement(); appf_p.v = s; JSONElement appf_b = new JSONElement(); appf_b.v = apps[app]; appf.c.Add("keyword", appf_n); appf.c.Add("path", appf_p); appf.c.Add("bin", appf_b); Found.Add(appf); break; } } } int newlevel = level + 1; foreach (string s in Directory.GetDirectories(dir)) { SearchDirectory(s, newlevel); } } catch { } } foreach (string dir in directories) { SearchDirectory(dir, 1); } Program.EmptyLine(cp); Program.SetCursorPosition(cp); Program.Print($"Pronadjeno §a{Found.Count} §finstaliranih aplikacija"); File.Delete(Program.DIRECTORY + "app-installed.txt"); string fline = ""; foreach (JSONElement el in Found) { fline += $"{JSON.Stringify(el)}\n"; } if (fline.EndsWith(",")) { fline = fline.Substring(0, fline.Length - 1); } File.WriteAllText(Program.DIRECTORY + "app-installed.txt", fline); return; } case "start": { string name = Args[2]; foreach (string l in File.ReadAllLines(Program.DIRECTORY + "app-installed.txt")) { JSONElement json = JSON.Parse(l); if (json.c["keyword"].ToString().ToLower().Equals(name.ToLower())) { Program.Print($"Aplikacija §7{name} §fpokrenuta"); Process.Start(new ProcessStartInfo() { FileName = json.c["path"].ToString() }); return; } } Program.Print($"Aplikacija §c{name} §fnije pronadjena"); break; } } }