static void Main(string[] args) { ConfigureSpeech(); Console.BufferWidth = 150; Console.WindowWidth = 150; _sourceFolder = new DirectoryInfo(args[0]); _initialDrives = DriveInfo.GetDrives(); Console.WriteLine($"Initial Drives: {_initialDrives.Select(d => d.Name).ToDelimitedString(", ")}"); Task.Run(() => MonitorDrives()); Console.WriteLine($"Started Monitorind Drives..."); Task.Run(() => MonitorReadyToCopyQueue()); Console.WriteLine($"Ready to copy data from {_sourceFolder} to your USB sticks, put them in these thiny wholes :P"); while (true) { if (_askForPositionQueue.TryDequeue(out var driveToProcess)) { Console.Write($"New USB Stick detected (Label: '{driveToProcess.VolumeLabel}', Name: '{driveToProcess.Name}') please enter location: "); var location = Console.ReadLine(); Console.WriteLine($"Start copy from '{_sourceFolder.FullName}' to '{driveToProcess.Name}', location: {location}"); _readyToCopyQueue.Enqueue(Tuple.Create(driveToProcess, location)); } if (_finishedQueue.TryDequeue(out var info)) { var x = info ?? null; Console.WriteLine($"Copy finished on '{ x.Item1.VolumeLabel}', Name: '{x.Item1.Name}') at location: '{x.Item2}'"); Console.Write("Please remove Drive and press any key to confirm."); _synth.Speak("Please confirm you fagot."); Console.ReadKey(intercept: true); _drivesInProgress.RemoveAll(d => string.Equals(d.Name, x.Item1.Name, StringComparison.CurrentCultureIgnoreCase)); Console.WriteLine("Tanks for your confirmation and see you soon :D"); } if (_errorQueue.TryDequeue(out var error)) { var x = error ?? null; Console.WriteLine($"Something happened to '{x.Item1.VolumeLabel}', Name: '{x.Item1.Name}' at location '{x.Item2}'"); Console.WriteLine(x.Item3); Console.Write("Please remove Drive and press any key to confirm."); _synth.Speak("Error! Error! Please confirm you fagot."); Console.Beep(); Console.ReadKey(intercept: true); _drivesInProgress.RemoveAll(d => string.Equals(d.Name, x.Item1.Name, StringComparison.CurrentCultureIgnoreCase)); Console.WriteLine("Tanks for your confirmation please fix drive on another PC and then try again."); } if (_progressQueue.TryDequeue(out var progress)) { var x = progress ?? null; Console.WriteLine($"Progress update: {progress.Item3}% '{x.Item1.VolumeLabel}', Name: '{x.Item1.Name}', Location '{x.Item2} "); } Thread.Sleep(100); } }
private static void MonitorDrives() { while (true) { foreach (var driveInfo in DriveInfo.GetDrives() .ExceptBy(_initialDrives, d => d.Name) .ExceptBy(_drivesInProgress, d => d.Name) .Where(d => d.IsReady && d.VolumeLabel == "USB DISK" && d.DriveType == DriveType.Removable)) { _drivesInProgress.Add(driveInfo); _askForPositionQueue.Enqueue(driveInfo); } Thread.Sleep(500); } }
private void DumpGetDriveFormat(bool isLocal) { Console.WriteLine("=== TEST {0} ===\n", isLocal ? "LOCAL" : "NETWORK"); var cnt = 0; // Get Logical Drives from Environment. foreach (var drv in Directory.GetLogicalDrives(false, true)) { UnitTestConstants.StopWatcher(true); try { // GetDriveType() can read an empty cdrom drive. // SetCurrentDirectory() wil fail on an empty cdrom drive. System.IO.Directory.SetCurrentDirectory(drv); } catch (Exception ex) { Console.WriteLine("\nCaught (unexpected) {0}: [{1}]", ex.GetType().FullName, ex.Message.Replace(Environment.NewLine, " ")); } var drive = isLocal ? drv : Path.LocalToUnc(drv); UnitTestConstants.StopWatcher(true); var driveInfo = new DriveInfo(drive); Console.WriteLine("#{0:000}\tInput Path : [{1}]", ++cnt, drive); Console.WriteLine("\tGetDriveFormat(): [{0}]", driveInfo.DriveFormat); Console.WriteLine("\tGetDriveType() : [{0}]", driveInfo.DriveType); Console.WriteLine("\tIsReady() : [{0}]", driveInfo.IsReady); Console.WriteLine("\tIsVolume() : [{0}]\n", driveInfo.IsVolume); if (isLocal) { Assert.AreEqual(new System.IO.DriveInfo(drive).IsReady, driveInfo.IsReady, "IsReady AlphaFS != System.IO"); } } Console.WriteLine("{0}\n\n", UnitTestConstants.Reporter(true)); if (cnt == 0) { Assert.Inconclusive("Nothing was enumerated, but it was expected."); } }
private void DumpGetDriveFormat(bool isLocal) { Console.WriteLine("=== TEST {0} ===\n", isLocal ? "LOCAL" : "NETWORK"); int cnt = 0; // Get Logical Drives from Environment. foreach (string drv in Directory.GetLogicalDrives()) { StopWatcher(true); try { // GetDriveType() can read an empty cdrom drive. // SetCurrentDirectory() wil fail on an empty cdrom drive. Directory.SetCurrentDirectory(drv); } catch (Exception ex) { Console.WriteLine("\tCaught Exception: [{0}]", ex.Message.Replace(Environment.NewLine, " ")); } string drive = isLocal ? drv : Path.LocalToUnc(drv); StopWatcher(true); DriveInfo driveInfo = new DriveInfo(drive); Console.WriteLine("#{0:000}\tInput Path : [{1}]", ++cnt, drive); Console.WriteLine("\tGetDriveFormat(): [{0}]", driveInfo.DriveFormat); Console.WriteLine("\tGetDriveType() : [{0}]", driveInfo.DriveType); Console.WriteLine("\tIsReady() : [{0}]", driveInfo.IsReady); Console.WriteLine("\tIsVolume() : [{0}]\n", driveInfo.IsVolume); if (isLocal) { Assert.AreEqual(new System.IO.DriveInfo(drive).IsReady, driveInfo.IsReady, "IsReady AlphaFS != System.IO"); } } Console.WriteLine("{0}\n\n", Reporter(true)); Assert.IsTrue(cnt > 0, "Nothing was enumerated."); }
public void DefineDosDevice() { Console.WriteLine("Volume.DefineDosDevice()"); if (!IsAdmin()) { Assert.Fail(); } #region Regular Drive Mapping string drive = string.Format(CultureInfo.CurrentCulture, "{0}{1}{2}", DriveInfo.GetFreeDriveLetter(), Path.VolumeSeparatorChar, Path.DirectorySeparatorChar); StopWatcher(true); // Create Regular drive mapping. bool actionIsTrue = false; try { Volume.DefineDosDevice(drive, TempFolder); actionIsTrue = true; } catch { } Console.WriteLine("\nCreated Regular drive mapping (Should be True): [{0}]\nDrive letter: [{1}] now points to: [{2}]\n\t{3}", actionIsTrue, drive, TempFolder, Reporter(true)); Assert.IsTrue(actionIsTrue, "Regular drive mapping should have been created."); DriveInfo di = new DriveInfo(drive); System.IO.DriveInfo diSysIo = new System.IO.DriveInfo(drive); try { Assert.IsTrue(Dump(di, -21)); // A Regular drive mapping that should be visible immediately in Explorer. // Seems to be invisible in Explorer on Windows 8, but visibile in an elevated cmd shell. //Assert.IsTrue(Directory.Exists(_driveLetter), "Drive letter not visible."); Console.WriteLine("\nDrive Letter: [{0}]\tGetVolumeDevice(): [{1}]", drive, Volume.GetVolumeDeviceName(drive)); Assert.AreEqual(diSysIo.IsReady, di.IsReady); } finally { StopWatcher(true); // Remove Regular drive mapping. actionIsTrue = false; try { Volume.DeleteDosDevice(drive); actionIsTrue = true; } catch { } Console.WriteLine("\n\nRemoved Regular drive mapping (Should be True): [{0}]\nDrive letter: [{1}] has been set free.\n\t{2}\n", actionIsTrue, drive, Reporter(true)); Assert.IsTrue(actionIsTrue, "Regular drive mapping should have been removed."); Assert.IsFalse(Directory.Exists(drive), "Drive letter should not be visible."); } #endregion // Regular Drive Mapping #region Symbolic Link Drive Mapping try { drive = string.Format(CultureInfo.CurrentCulture, "{0}{1}{2}", DriveInfo.GetFreeDriveLetter(true), Path.VolumeSeparatorChar, Path.DirectorySeparatorChar); StopWatcher(true); // Create Symbolic Link. bool createSymbolicLink = false; try { Volume.DefineDosDevice(drive, TempFolder, DosDeviceAttributes.RawTargetPath); createSymbolicLink = true; } catch { } Console.WriteLine("\n\nCreated Symbolic link mapping (Should be True): [{0}]\nDrive letter: [{1}] now points to: [{2}]\n\t{3}", createSymbolicLink, drive, TempFolder, Reporter(true)); Assert.IsTrue(createSymbolicLink); di = new DriveInfo(drive); Assert.IsTrue(Dump(di, -21)); // The link is created in the NT Device Name namespace and thus not visibile in Explorer. // Remove Symbolic Link, no exact match: fail. StopWatcher(true); bool removeSymbolicLink = false; try { Volume.DeleteDosDevice(drive, "NonExistingFolder", true); removeSymbolicLink = true; } catch { } Console.WriteLine("\n\nRemoved Symbolic link mapping (Should be False): [{0}]\nDrive letter: [{1}] has NOT been set free.\tNo exactMatch MS-DOS device name found.\n\t{2}", removeSymbolicLink, drive, Reporter(true)); Assert.IsFalse(removeSymbolicLink); } finally { StopWatcher(true); // Remove Symbolic Link, exact match: success. bool removeSymbolicLink = false; try { Volume.DeleteDosDevice(drive, TempFolder, true); removeSymbolicLink = true; } catch { } Console.WriteLine("\n\nRemoved Symbolic link mapping (Should be True): [{0}]\nDrive letter: [{1}] has been set free.\tFound exactMatch MS-DOS device name.\n\t{2}", removeSymbolicLink, drive, Reporter(true)); Assert.IsTrue(removeSymbolicLink); Assert.IsFalse(Directory.Exists(drive)); } #endregion // Symbolic Link Drive Mapping }
private static void DumpClassDriveInfo(bool isLocal, string drive) { Console.WriteLine("\n=== TEST {0} ===", isLocal ? Local : Network); string tempPath = drive; if (!isLocal) tempPath = Path.LocalToUnc(tempPath); StopWatcher(true); DriveInfo actual = new DriveInfo(tempPath); Console.WriteLine("\nInput Path: [{0}]{1}", tempPath, Reporter()); #region Local Drive if (isLocal) { // System.IO.DriveInfo() can not handle UNC paths. System.IO.DriveInfo expected = new System.IO.DriveInfo(tempPath); //Dump(expected, -21); // Even 1 byte more or less results in failure, so do these tests asap. Assert.AreEqual(expected.AvailableFreeSpace, actual.AvailableFreeSpace, "AvailableFreeSpace AlphaFS != System.IO"); Assert.AreEqual(expected.TotalFreeSpace, actual.TotalFreeSpace, "TotalFreeSpace AlphaFS != System.IO"); Assert.AreEqual(expected.TotalSize, actual.TotalSize, "TotalSize AlphaFS != System.IO"); Assert.AreEqual(expected.DriveFormat, actual.DriveFormat, "DriveFormat AlphaFS != System.IO"); Assert.AreEqual(expected.DriveType, actual.DriveType, "DriveType AlphaFS != System.IO"); Assert.AreEqual(expected.IsReady, actual.IsReady, "IsReady AlphaFS != System.IO"); Assert.AreEqual(expected.Name, actual.Name, "Name AlphaFS != System.IO"); Assert.AreEqual(expected.RootDirectory.ToString(), actual.RootDirectory.ToString(), "RootDirectory AlphaFS != System.IO"); Assert.AreEqual(expected.VolumeLabel, actual.VolumeLabel, "VolumeLabel AlphaFS != System.IO"); } #region Class Equality ////int getHashCode1 = actual.GetHashCode(); //DriveInfo driveInfo2 = new DriveInfo(tempPath); ////int getHashCode2 = driveInfo2.GetHashCode(); //DriveInfo clone = actual; ////int getHashCode3 = clone.GetHashCode(); //bool isTrue1 = clone.Equals(actual); //bool isTrue2 = clone == actual; //bool isTrue3 = !(clone != actual); //bool isTrue4 = actual == driveInfo2; //bool isTrue5 = !(actual != driveInfo2); ////Console.WriteLine("\n\t\t actual.GetHashCode() : [{0}]", getHashCode1); ////Console.WriteLine("\t\t clone.GetHashCode() : [{0}]", getHashCode3); ////Console.WriteLine("\t\tdriveInfo2.GetHashCode() : [{0}]\n", getHashCode2); ////Console.WriteLine("\t\t obj clone.ToString() == [{0}]", clone.ToString()); ////Console.WriteLine("\t\t obj clone.Equals() == [{0}] : {1}", TextTrue, isTrue1); ////Console.WriteLine("\t\t obj clone == == [{0}] : {1}", TextTrue, isTrue2); ////Console.WriteLine("\t\t obj clone != == [{0}]: {1}\n", TextFalse, isTrue3); ////Console.WriteLine("\t\tdriveInfo == driveInfo2 == [{0}] : {1}", TextTrue, isTrue4); ////Console.WriteLine("\t\tdriveInfo != driveInfo2 == [{0}] : {1}", TextFalse, isTrue5); //Assert.IsTrue(isTrue1, "clone.Equals(actual)"); //Assert.IsTrue(isTrue2, "clone == actual"); //Assert.IsTrue(isTrue3, "!(clone != actual)"); //Assert.IsTrue(isTrue4, "actual == driveInfo2"); //Assert.IsTrue(isTrue5, "!(actual != driveInfo2)"); #endregion // Class Equality #endregion // Local Drive StopWatcher(true); Dump(actual, -21); Dump(actual.DiskSpaceInfo, -26); //if (expected != null) Dump(expected.RootDirectory, -17); //Dump(actual.RootDirectory, -17); Dump(actual.VolumeInfo, -26); Console.WriteLine(Reporter()); Console.WriteLine(); }
public void DefineDosDevice() { Console.WriteLine("Volume.DefineDosDevice()"); if (!IsAdmin()) Assert.Fail(); #region Regular Drive Mapping string drive = string.Format(CultureInfo.CurrentCulture, "{0}{1}{2}", DriveInfo.GetFreeDriveLetter(), Path.VolumeSeparatorChar, Path.DirectorySeparatorChar); StopWatcher(true); // Create Regular drive mapping. bool actionIsTrue = false; try { Volume.DefineDosDevice(drive, TempFolder); actionIsTrue = true; } catch { } Console.WriteLine("\nCreated Regular drive mapping (Should be True): [{0}]\nDrive letter: [{1}] now points to: [{2}]\n\t{3}", actionIsTrue, drive, TempFolder, Reporter(true)); Assert.IsTrue(actionIsTrue, "Regular drive mapping should have been created."); DriveInfo di = new DriveInfo(drive); System.IO.DriveInfo diSysIo = new System.IO.DriveInfo(drive); try { Assert.IsTrue(Dump(di, -21)); // A Regular drive mapping that should be visible immediately in Explorer. // Seems to be invisible in Explorer on Windows 8, but visibile in an elevated cmd shell. //Assert.IsTrue(Directory.Exists(_driveLetter), "Drive letter not visible."); Console.WriteLine("\nDrive Letter: [{0}]\tGetVolumeDevice(): [{1}]", drive, Volume.GetVolumeDeviceName(drive)); Assert.AreEqual(diSysIo.IsReady, di.IsReady); } finally { StopWatcher(true); // Remove Regular drive mapping. actionIsTrue = false; try { Volume.DeleteDosDevice(drive); actionIsTrue = true; } catch { } Console.WriteLine("\n\nRemoved Regular drive mapping (Should be True): [{0}]\nDrive letter: [{1}] has been set free.\n\t{2}\n", actionIsTrue, drive, Reporter(true)); Assert.IsTrue(actionIsTrue, "Regular drive mapping should have been removed."); Assert.IsFalse(Directory.Exists(drive), "Drive letter should not be visible."); } #endregion // Regular Drive Mapping #region Symbolic Link Drive Mapping try { drive = string.Format(CultureInfo.CurrentCulture, "{0}{1}{2}", DriveInfo.GetFreeDriveLetter(true), Path.VolumeSeparatorChar, Path.DirectorySeparatorChar); StopWatcher(true); // Create Symbolic Link. bool createSymbolicLink = false; try { Volume.DefineDosDevice(drive, TempFolder, DosDeviceAttributes.RawTargetPath); createSymbolicLink = true; } catch { } Console.WriteLine("\n\nCreated Symbolic link mapping (Should be True): [{0}]\nDrive letter: [{1}] now points to: [{2}]\n\t{3}", createSymbolicLink, drive, TempFolder, Reporter(true)); Assert.IsTrue(createSymbolicLink); di = new DriveInfo(drive); Assert.IsTrue(Dump(di, -21)); // The link is created in the NT Device Name namespace and thus not visibile in Explorer. // Remove Symbolic Link, no exact match: fail. StopWatcher(true); bool removeSymbolicLink = false; try { Volume.DeleteDosDevice(drive, "NonExistingFolder", true); removeSymbolicLink = true; } catch { } Console.WriteLine("\n\nRemoved Symbolic link mapping (Should be False): [{0}]\nDrive letter: [{1}] has NOT been set free.\tNo exactMatch MS-DOS device name found.\n\t{2}", removeSymbolicLink, drive, Reporter(true)); Assert.IsFalse(removeSymbolicLink); } finally { StopWatcher(true); // Remove Symbolic Link, exact match: success. bool removeSymbolicLink = false; try { Volume.DeleteDosDevice(drive, TempFolder, true); removeSymbolicLink = true; } catch { } Console.WriteLine("\n\nRemoved Symbolic link mapping (Should be True): [{0}]\nDrive letter: [{1}] has been set free.\tFound exactMatch MS-DOS device name.\n\t{2}", removeSymbolicLink, drive, Reporter(true)); Assert.IsTrue(removeSymbolicLink); Assert.IsFalse(Directory.Exists(drive)); } #endregion // Symbolic Link Drive Mapping }
private void DumpGetDriveFormat(bool isLocal) { Console.WriteLine("=== TEST {0} ===\n", isLocal ? "LOCAL" : "NETWORK"); int cnt = 0; // Get Logical Drives from Environment. foreach (string drv in Directory.GetLogicalDrives()) { StopWatcher(true); try { // GetDriveType() can read an empty cdrom drive. // SetCurrentDirectory() wil fail on an empty cdrom drive. Directory.SetCurrentDirectory(drv); } catch (Exception ex) { Console.WriteLine("\tCaught Exception: [{0}]", ex.Message.Replace(Environment.NewLine, " ")); } string drive = isLocal ? drv : Path.LocalToUnc(drv); StopWatcher(true); DriveInfo driveInfo = new DriveInfo(drive); Console.WriteLine("#{0:000}\tInput Path : [{1}]", ++cnt, drive); Console.WriteLine("\tGetDriveFormat(): [{0}]", driveInfo.DriveFormat); Console.WriteLine("\tGetDriveType() : [{0}]", driveInfo.DriveType); Console.WriteLine("\tIsReady() : [{0}]", driveInfo.IsReady); Console.WriteLine("\tIsVolume() : [{0}]\n", driveInfo.IsVolume); if (isLocal) Assert.AreEqual(new System.IO.DriveInfo(drive).IsReady, driveInfo.IsReady, "IsReady AlphaFS != System.IO"); } Console.WriteLine("{0}\n\n", Reporter(true)); Assert.IsTrue(cnt > 0, "Nothing was enumerated."); }
private void DumpClassDriveInfo(bool isLocal, string drive) { Console.WriteLine("\n=== TEST {0} ===", isLocal ? UnitTestConstants.Local : UnitTestConstants.Network); var tempPath = drive; if (!isLocal) { tempPath = Path.LocalToUnc(tempPath); } UnitTestConstants.StopWatcher(true); var actual = new DriveInfo(tempPath); Console.WriteLine("\nInput Path: [{0}]{1}", tempPath, UnitTestConstants.Reporter()); #region UnitTestConstants.Local Drive if (isLocal) { // System.IO.DriveInfo() can not handle UNC paths. var expected = new System.IO.DriveInfo(tempPath); //Dump(expected, -21); // Even 1 byte more or less results in failure, so do these tests asap. Assert.AreEqual(expected.AvailableFreeSpace, actual.AvailableFreeSpace, "AvailableFreeSpace AlphaFS != System.IO"); Assert.AreEqual(expected.TotalFreeSpace, actual.TotalFreeSpace, "TotalFreeSpace AlphaFS != System.IO"); Assert.AreEqual(expected.TotalSize, actual.TotalSize, "TotalSize AlphaFS != System.IO"); Assert.AreEqual(expected.DriveFormat, actual.DriveFormat, "DriveFormat AlphaFS != System.IO"); Assert.AreEqual(expected.DriveType, actual.DriveType, "DriveType AlphaFS != System.IO"); Assert.AreEqual(expected.IsReady, actual.IsReady, "IsReady AlphaFS != System.IO"); Assert.AreEqual(expected.Name, actual.Name, "Name AlphaFS != System.IO"); Assert.AreEqual(expected.RootDirectory.ToString(), actual.RootDirectory.ToString(), "RootDirectory AlphaFS != System.IO"); Assert.AreEqual(expected.VolumeLabel, actual.VolumeLabel, "VolumeLabel AlphaFS != System.IO"); } #region Class Equality ////int getHashCode1 = actual.GetHashCode(); //DriveInfo driveInfo2 = new DriveInfo(tempPath); ////int getHashCode2 = driveInfo2.GetHashCode(); //DriveInfo clone = actual; ////int getHashCode3 = clone.GetHashCode(); //bool isTrue1 = clone.Equals(actual); //bool isTrue2 = clone == actual; //bool isTrue3 = !(clone != actual); //bool isTrue4 = actual == driveInfo2; //bool isTrue5 = !(actual != driveInfo2); ////Console.WriteLine("\n\t\t actual.GetHashCode() : [{0}]", getHashCode1); ////Console.WriteLine("\t\t clone.GetHashCode() : [{0}]", getHashCode3); ////Console.WriteLine("\t\tdriveInfo2.GetHashCode() : [{0}]\n", getHashCode2); ////Console.WriteLine("\t\t obj clone.ToString() == [{0}]", clone.ToString()); ////Console.WriteLine("\t\t obj clone.Equals() == [{0}] : {1}", TextTrue, isTrue1); ////Console.WriteLine("\t\t obj clone == == [{0}] : {1}", TextTrue, isTrue2); ////Console.WriteLine("\t\t obj clone != == [{0}]: {1}\n", TextFalse, isTrue3); ////Console.WriteLine("\t\tdriveInfo == driveInfo2 == [{0}] : {1}", TextTrue, isTrue4); ////Console.WriteLine("\t\tdriveInfo != driveInfo2 == [{0}] : {1}", TextFalse, isTrue5); //Assert.IsTrue(isTrue1, "clone.Equals(actual)"); //Assert.IsTrue(isTrue2, "clone == actual"); //Assert.IsTrue(isTrue3, "!(clone != actual)"); //Assert.IsTrue(isTrue4, "actual == driveInfo2"); //Assert.IsTrue(isTrue5, "!(actual != driveInfo2)"); #endregion // Class Equality #endregion // UnitTestConstants.Local Drive UnitTestConstants.StopWatcher(true); UnitTestConstants.Dump(actual, -21); UnitTestConstants.Dump(actual.DiskSpaceInfo, -26); //if (expected != null) Dump(expected.RootDirectory, -17); //Dump(actual.RootDirectory, -17); UnitTestConstants.Dump(actual.VolumeInfo, -26); Console.WriteLine(UnitTestConstants.Reporter()); Console.WriteLine(); }