예제 #1
0
        private void ListBoxAudioDevices_MouseDoubleClick(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            AudioDevice SelectedDevice = (AudioDevice)ListBoxAudioDevices.SelectedItem;

            if (SelectedDevice != null)
            {
                ChangeDeviceName changeDeviceName = new ChangeDeviceName(SelectedDevice);
                changeDeviceName.labelControllerInformation.Content = SelectedDevice.ControllerInfo;
                changeDeviceName.textBoxDeviceName.Text             = SelectedDevice.Name;
                changeDeviceName.ShowDialog();

                PopulateDevices(ListBoxAudioDevices);
            }
        }
예제 #2
0
        private void ButtonCreate_Click(object sender, RoutedEventArgs e)
        {
            LabelStatus.Text = "";
            if (ListBoxAudioDevices.SelectedIndex == -1)
            {
                LabelStatus.Text = "Please select an Audio device";
                return;
            }

            AudioDevice SelectedDevice   = (AudioDevice)ListBoxAudioDevices.SelectedItem;
            int         SameDevicesNames = 0;

            foreach (Object temp in ListBoxAudioDevices.Items)
            {
                if (((AudioDevice)temp).Name.Equals(SelectedDevice.Name))
                {
                    SameDevicesNames++;
                }
            }

            if (SameDevicesNames > 1)
            {
                ChangeDeviceName changeDeviceName = new ChangeDeviceName(SelectedDevice);
                changeDeviceName.labelControllerInformation.Content = SelectedDevice.ControllerInfo;
                changeDeviceName.textBoxDeviceName.Text             = SelectedDevice.Name;
                changeDeviceName.ShowDialog();
                PopulateDevices(ListBoxAudioDevices);
                return;
            }


            String BatchFileName = SelectedDevice.Name.Replace(" ", "").Replace("-", "");

            LabelStatus.Text = BatchFileName;

            if (File.Exists($"{DirectoryPath}\\{BatchFileName}.bat"))
            {
                File.Delete($"{DirectoryPath}\\{BatchFileName}.bat");
            }

            using (StreamWriter sw = System.IO.File.CreateText($"{DirectoryPath}\\{BatchFileName}.bat"))
            {
                sw.WriteLine("@ECHO OFF");
                sw.WriteLine($"{DirectoryPath}\\NIRCMDC setdefaultsounddevice \"{SelectedDevice.Name}\" 1");
                sw.WriteLine($"{DirectoryPath}\\NIRCMDC setdefaultsounddevice \"{SelectedDevice.Name}\" 2");
            }

            object       shDesktop       = (object)"Desktop";
            WshShell     wsh             = new WshShell();
            string       shortcutAddress = (string)wsh.SpecialFolders.Item(ref shDesktop) + $@"\{BatchFileName}.lnk";
            IWshShortcut shortcut        = (IWshShortcut)wsh.CreateShortcut(shortcutAddress);

            shortcut.Description = $"Shortcut for {SelectedDevice.Name}";

            shortcut.TargetPath       = Environment.GetFolderPath(Environment.SpecialFolder.Windows) + @"\system32\cmd.exe";
            shortcut.Arguments        = $"/c \"{DirectoryPath}\\{BatchFileName}.bat\"";
            shortcut.WorkingDirectory = wsh.ExpandEnvironmentStrings(DirectoryPath);
            if (RadioButtonHeadset.IsChecked == true)
            {
                shortcut.IconLocation = @"%systemroot%\system32\ddores.dll,89";
            }
            else
            {
                shortcut.IconLocation = @"%systemroot%\system32\ddores.dll,88";
            }

            shortcut.Save();
        }