public void AddDevice() { base.SetStatus("Adding device."); FolderBrowserDialog dlg = new FolderBrowserDialog(); dlg.ShowNewFolderButton = false; dlg.Description = "Please select a folder which contains a device to be installed."; string path = Program.ConfigMgt.Config.RecentDeviceSelectionFolder; path = ConfigHelper.GetFullPath(path); if (path != null && path.Length > 0) { dlg.SelectedPath = path; } if (dlg.ShowDialog(frmMain) == DialogResult.OK) { string folderName = dlg.SelectedPath; string path1 = ConfigHelper.GetFullPath(folderName); string path2 = ConfigHelper.EnsurePathSlash(ConfigHelper.GetFullPath(_deviceManager.DevicesFolder)); if (path1.IndexOf(path2) >= 0) { MessageBox.Show(frmMain, "Cannot install a new device from an existing folder in the Device folder. Please select another folder instead.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); goto exit; } frmMain.Cursor = Cursors.WaitCursor; GCDevice device = _deviceManager.AddDevice(folderName); frmMain.Cursor = Cursors.Default; if (device != null) { Program.Log.Write("{Device} Add device (" + device.ToString() + ") succeed : " + device.FolderPath); _deviceView.RefreshView(); _deviceView.SelectDevice(device); } else { Program.Log.Write(LogType.Warning, "{Device} Add device failed : " + GCError.LastErrorInfor); if (GCError.LastError != null) { Program.Log.Write(LogType.Error, GCError.LastError.ToString()); } MessageBox.Show(frmMain, "Add device failed.\r\n\r\n" + GCError.LastErrorInfor, "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } Program.ConfigMgt.Config.RecentDeviceSelectionFolder = dlg.SelectedPath; Program.ConfigMgt.Save(); exit: base.ClearStatus(); }