public double CumulativeDistance(string start = null) // optional first system to measure from { ISystem last = null; double distance = 0; int i = 0; if (start != null) { i = Systems.FindIndex(x => x.Equals(start, StringComparison.InvariantCultureIgnoreCase)); if (i == -1) { return(-1); } } for (; i < Systems.Count; i++) { ISystem s = SystemCache.FindSystem(Systems[i]); if (s != null) { if (last != null) { //System.Diagnostics.Debug.WriteLine("Cum dist " + s.Name + " " + last.Name + " " + distance + " " + s.Distance(last)); distance += s.Distance(last); } last = s; } } return(distance); }
/// <summary> /// Get a complete list of active disc drives and fill the combo box /// </summary> /// <remarks>TODO: Find a way for this to periodically run, or have it hook to a "drive change" event</remarks> private void PopulateDrives() { ViewModels.LoggerViewModel.VerboseLogLn("Scanning for drives.."); // Always enable the media scan MediaScanButton.IsEnabled = true; // Populate the list of drives and add it to the combo box Drives = Validators.CreateListOfDrives(UIOptions.Options.IgnoreFixedDrives); DriveLetterComboBox.ItemsSource = Drives; if (DriveLetterComboBox.Items.Count > 0) { // Check for active optical drives first int index = Drives.FindIndex(d => d.MarkedActive && d.InternalDriveType == InternalDriveType.Optical); // Then we check for floppy drives if (index == -1) { index = Drives.FindIndex(d => d.MarkedActive && d.InternalDriveType == InternalDriveType.Floppy); } // Then we try all other drive types if (index == -1) { index = Drives.FindIndex(d => d.MarkedActive); } // Set the selected index DriveLetterComboBox.SelectedIndex = (index != -1 ? index : 0); StatusLabel.Content = "Valid drive found! Choose your Media Type"; CopyProtectScanButton.IsEnabled = true; // Get the current media type if (!UIOptions.Options.SkipSystemDetection && index != -1) { ViewModels.LoggerViewModel.VerboseLog("Trying to detect system for drive {0}.. ", Drives[index].Letter); var currentSystem = Validators.GetKnownSystem(Drives[index]); ViewModels.LoggerViewModel.VerboseLogLn(currentSystem == null || currentSystem == KnownSystem.NONE ? "unable to detect." : ("detected " + currentSystem.LongName() + ".")); if (currentSystem != null && currentSystem != KnownSystem.NONE) { int sysIndex = Systems.FindIndex(s => s == currentSystem); SystemTypeComboBox.SelectedIndex = sysIndex; } } // Only enable the start/stop if we don't have the default selected StartStopButton.IsEnabled = (SystemTypeComboBox.SelectedItem as KnownSystemComboBoxItem) != KnownSystem.NONE; ViewModels.LoggerViewModel.VerboseLogLn("Found {0} drives: {1}", Drives.Count, string.Join(", ", Drives.Select(d => d.Letter))); } else { DriveLetterComboBox.SelectedIndex = -1; StatusLabel.Content = "No valid drive found!"; StartStopButton.IsEnabled = false; CopyProtectScanButton.IsEnabled = false; ViewModels.LoggerViewModel.VerboseLogLn("Found no drives"); } }
/// <summary> /// Load any options-related elements /// </summary> private void Load() { InternalProgramComboBox.SelectedIndex = InternalPrograms.FindIndex(r => r == Options.InternalProgram); DefaultSystemComboBox.SelectedIndex = Systems.FindIndex(r => r == Options.DefaultSystem); RedumpPasswordBox.Password = Options.RedumpPassword; }