private void Initialize() { var phisicalDrives = DriveInfo.GetDrives() .Where(drive => drive.DriveType == DriveType.Fixed) .Select(drive => drive.Name) .ToArray(); foreach (var drive in phisicalDrives) { Drives.Add(drive); } var helpPairs = new[] { new { Desr = FolderTypes.CommonFolder.GetDescription(), FolderType = FolderTypes.CommonFolder }, new { Desr = FolderTypes.ClickOnceApplication.GetDescription(), FolderType = FolderTypes.ClickOnceApplication }, new { Desr = FolderTypes.CanBeAnApplication.GetDescription(), FolderType = FolderTypes.CanBeAnApplication }, new { Desr = FolderTypes.UnknownClickOnceApplication.GetDescription(), FolderType = FolderTypes.UnknownClickOnceApplication }, new { Desr = FolderTypes.HaveProblems.GetDescription(), FolderType = FolderTypes.HaveProblems } }; foreach (var pair in helpPairs) { HistoryHelpItems.Add(new HistoryHelp(pair.Desr, pair.FolderType)); } }
private async void DeviceAdded(DeviceWatcher sender, DeviceInformation args) { var deviceId = args.Id; var root = StorageDevice.FromId(deviceId); // If drive already in list, skip. if (Drives.Any(x => x.tag == root.Name)) { return; } DriveType type = DriveType.Removable; var driveItem = new DriveItem( root, Visibility.Visible, type); // Update the collection on the ui-thread. try { CoreApplication.MainView.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () => { Drives.Add(driveItem); }); } catch (Exception e) { // Ui-Thread not yet created. Drives.Add(driveItem); } }
private void Window_Loaded(object sender, RoutedEventArgs e) { Drives.Add(new DriveInfo { Name = "aa", Icon = "/CUERipper.WPF;component/musicbrainz.ico" }); Drives.Add(new DriveInfo { Name = "cc", Icon = "/CUERipper.WPF;component/freedb16.png" }); Drives.Add(new DriveInfo { Name = "ee", Icon = "ff" }); SelectedDrive = Drives[0]; CDImageLayout toc = new CDImageLayout(2, 2, 1, "0 10000 20000"); Releases.Add(new CUEMetadataEntry(toc, "/CUERipper.WPF;component/musicbrainz.ico")); Releases[0].metadata.Artist = "Mike Oldfield"; Releases[0].metadata.Title = "Amarok"; Releases[0].metadata.Tracks[0].Artist = "Mike Oldfield"; Releases[0].metadata.Tracks[0].Title = "Amarok 01"; Releases[0].metadata.Tracks[1].Artist = "Mike Oldfield"; Releases[0].metadata.Tracks[1].Title = "Amarok 02"; Releases.Add(new CUEMetadataEntry(toc, "/CUERipper.WPF;component/freedb16.png")); SelectedRelease = Releases[0]; }
public List <string> getLogicalDrives() { Drives.Clear(); string[] tmp = Directory.GetLogicalDrives(); foreach (var i in tmp) { Drives.Add(i); } return(Drives); }
private void AddDrive(DriveInfo driveInfo) { if (dispatcher.CheckAccess()) { Drives.Add(driveInfo); } else { dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() => AddDrive(driveInfo))); } }
internal WarehouseRobotEngine(WarehouseRobot robot) : base() { Robot = robot; DriveX = new RobotDimensionalDrive(Dimension.X); DriveY = new RobotDimensionalDrive(Dimension.Y); Drives.Add(DriveX); Drives.Add(DriveY); engineTaskControllingEvent = new ManualResetEvent(false); }
public MachineStatusResult(SystemStatus status) { Cpu = new CpuResult(status.CpuInfo); Drives = status.DrivesInfo.ToDictionary(x => x.VolumeName.Replace(":", string.Empty), x => new DriveResult(x)); if (Drives.ContainsKey("total") == false && status.DrivesInfo.Any()) { var totalSpace = status.DrivesInfo.Sum(x => x.TotalSpace); var freeSpace = status.DrivesInfo.Sum(x => x.FreeSpace); var total = new DriveInfo("total", totalSpace, freeSpace); Drives.Add(total.VolumeName, new DriveResult(total)); } Ram = new MemoryResult(status.MemoryInfo); Environment = new EnvResult(status.EnvInfo); }
private void ProcessDrives() { ColorGenerator colorGen = new ColorGenerator(6); foreach (var drive in DriveInfo.GetDrives()) { Drives.Add(new DiskModel { Name = drive.Name.TrimEnd(new[] { ':', '\\' }), Background = colorGen.NextColor(), SizeText = $"{(drive.TotalSize - drive.TotalFreeSpace).FormatDataSize()} / {drive.TotalSize.FormatDataSize()}" }); } }
private async void DeviceAdded(DeviceWatcher sender, DeviceInformation args) { var deviceId = args.Id; StorageFolder root = null; try { root = StorageDevice.FromId(deviceId); } catch (UnauthorizedAccessException) { Logger.Warn($"UnauthorizedAccessException: Attemting to add the device, {args.Name}, failed at the StorageFolder initialization step. This device will be ignored. Device ID: {args.Id}"); return; } // If drive already in list, skip. if (Drives.Any(x => x.tag == root.Name)) { return; } DriveType type = DriveType.Removable; var driveItem = new DriveItem( root, Visibility.Visible, type); Logger.Info($"Drive added: {driveItem.tag}, {driveItem.Type}"); // Update the collection on the ui-thread. try { CoreApplication.MainView.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () => { Drives.Add(driveItem); DeviceWatcher_EnumerationCompleted(null, null); }); } catch (Exception e) { // Ui-Thread not yet created. Drives.Add(driveItem); } }
public void Load() { IEnumerable <DriveDto> lookup; if (CanShowHidden) { itemsCount = _lookupDataService .GetDrivesCountByCondition(x => x.Title.Contains(FilterText), x => x.DriveCode , false, 1, int.MaxValue); lookup = _lookupDataService.GetDrivesByCondition(x => x.Title.Contains(FilterText), x => x.DriveCode , false, CurrentPage, PageLength); } else { itemsCount = _lookupDataService .GetDrivesCountByCondition(x => x.Title.Contains(FilterText) && x.IsSecret == false, x => x.DriveCode , false, 1, int.MaxValue); lookup = _lookupDataService.GetDrivesByCondition(x => x.Title.Contains(FilterText) && x.IsSecret == false, x => x.DriveCode , false, CurrentPage, PageLength); } Drives.Clear(); foreach (var item in lookup) { Drives.Add(new NavigationDriveItemViewModel( item.DriveId, string.Format("{0}", item.Title.TrimEnd(' ') ), nameof(DriveDetailViewModel), _eventAggregator, item.DriveCode.TrimEnd(' '), item.IsSecret)); } //var categoryLookup = _categoryLookupDataService.GetCategoryLookup(); //Categories.Clear(); //foreach (var item in categoryLookup) //{ // //Categories.Add(new NavigationItemViewModel(item.Id, // //item.DisplayMember, nameof(CategoryDetailViewModel), _eventAggregator)); //} }
public void ImportOld(string path) { if (File.Exists(path)) { OldConfig oldConfig = new OldConfig(path); ParityDir = oldConfig.ParityDir; TempDir = oldConfig.TempDir; MaxTempRAM = oldConfig.MaxTempRAM; IgnoreHidden = oldConfig.IgnoreHidden; for (int i = 0; i < oldConfig.BackupDirs.Length; i++) { Drives.Add(new Drive(oldConfig.BackupDirs[i], String.Format("files{0}.dat", i))); } foreach (string i in oldConfig.Ignores) { Ignores.Add(i); } UpdateIgnoresRegex(); Save(); } }
public void AddDriveExpressionUNC(string Drive, string Expression, string UNC) { string driveLetterContainingUNC = DrivesContainUNC(UNC); if (!string.IsNullOrEmpty(driveLetterContainingUNC)) { log.Warn($"Skip: \"{UNC}\" - already in \"{driveLetterContainingUNC}\" drive mapping"); return; } if (Drives.ContainsKey(Drive)) { Drives[Drive].Add(new Tuple <string, string>(Expression, UNC)); } else { Drives.Add(Drive, new List <Tuple <string, string> >() { new Tuple <string, string>(Expression, UNC) }); } }
public void MoveFirstUNCConflict(string FromDrive, string ToDrive) { if (!Drives.ContainsKey(FromDrive)) { log.Error($"{FromDrive} doesn't exist!"); return; } if (Drives.ContainsKey(ToDrive)) { log.Error($"{ToDrive} is already in use!"); return; } List <Tuple <string, string> > uncs = Drives[FromDrive]; Tuple <string, string> unc = uncs[1]; Drives.Add(ToDrive, new List <Tuple <string, string> >() { unc }); uncs.RemoveAt(1); log.Debug($"Moved \"{FromDrive}\" [{unc.Item1} = {unc.Item2}] to \"{ToDrive}\""); }
//public ReturnBox DownloadFile(string src, string dst) //{ // ReturnBox r = new ReturnBox(); // if (Connected) // { // try // { // using (Stream fs = File.Create(dst)) // { // Sftp.DownloadFile(src, fs); // } // r.Success = true; // } // catch (Exception ex) // { // r.Error = ex.Message; // } // } // return r; //} //public ReturnBox UploadFile(string src, string dir, string filename) //{ // ReturnBox r = new ReturnBox(); // if (Connected) // { // try // { // using (var fs = new FileStream(src, FileMode.Open)) // { // Sftp.BufferSize = 4 * 1024; // bypass Payload error large files // Sftp.ChangeDirectory(dir); // Sftp.UploadFile(fs, filename, true); // } // r.Success = true; // } // catch (Exception ex) // { // r.Error = ex.Message; // } // } // return r; //} #endregion #region Local Drive Management public void UpdateDrives(Settings settings) { string GOLDLETTERS = "GHIJKLMNOPQRSTUVWXYZ"; List <char> letters = GOLDLETTERS.ToCharArray().ToList(); DriveInfo[] drives = DriveInfo.GetDrives(); Drives.Clear(); var settingsDrives = settings.Drives.Values.ToList(); var netUseDrives = GetUsedDrives(); foreach (char c in letters) { //if (c == 'W') // c.ToString(); bool used = false; Drive d = new Drive { Letter = c.ToString() }; for (int i = 0; i < drives.Length; i++) { try { DriveInfo dinfo = drives[i]; if (dinfo.Name[0] == c) { d.Status = DriveStatus.UNKNOWN; // this triggers IOException when drive is unavailable d.IsGoldDrive = dinfo.DriveFormat == "FUSE-Golddrive"; used = true; if (d.IsGoldDrive == true) { d.MountPoint = dinfo.VolumeLabel.Replace("/", "\\"); d.Label = GetExplorerDriveLabel(d); if (dinfo.IsReady) { d.Status = DriveStatus.CONNECTED; } else { d.Status = DriveStatus.BROKEN; } var d1 = settingsDrives.Find(x => x.Letter == d.Letter); if (d1 != null) { //d.MountPoint = d1.MountPoint; d.Args = d1.Args; d.Label = d1.Label; } } Drives.Add(d); break; } } catch (IOException e) { } catch (Exception ex) { } } if (!used) { var d0 = netUseDrives.Find(x => x.Letter == d.Letter); if (d0 != null) { d.IsGoldDrive = d0.IsGoldDrive; d.Status = d0.Status; if (d.IsGoldDrive == true) { d.Status = DriveStatus.BROKEN; d.MountPoint = d0.MountPoint; d.Label = d0.Label; var d1 = settingsDrives.Find(x1 => x1.Letter == d.Letter); if (d1 != null) { d.Args = d1.Args; d.Label = d1.Label; } } else { d.Status = DriveStatus.UNKNOWN; } } else { var d1 = settingsDrives.Find(x1 => x1.Letter == d.Letter); if (d1 != null) { d.Status = DriveStatus.DISCONNECTED; d.MountPoint = d1.MountPoint; d.Args = d1.Args; d.Label = d1.Label; d.IsGoldDrive = true; } else { d.Status = DriveStatus.FREE; } } Drives.Add(d); } } }
public async Task RefreshAsync() { using (await RefreshAsyncLock.LockAsync()) { Drives.Clear(); DriveInfo[] drives; try { drives = DriveInfo.GetDrives(); } catch (Exception ex) { Logger.Error(ex, "Getting drives"); await Services.MessageUI.DisplayMessageAsync(Resources.DriveSelection_RefreshError, MessageType.Error); return; } foreach (var drive in drives) { if (BrowseVM.AllowedTypes != null && !BrowseVM.AllowedTypes.Contains(drive.DriveType)) { continue; } ImageSource icon = null; string label = null; string path; string format = null; ByteSize? freeSpace = null; ByteSize? totalSize = null; DriveType? type = null; bool? ready = null; try { label = drive.VolumeLabel; } catch (Exception ex) { Logger.Debug(ex, "Getting drive label"); } try { path = drive.Name; try { using var shellObj = ShellObject.FromParsingName(path); var thumb = shellObj.Thumbnail; thumb.CurrentSize = new System.Windows.Size(16, 16); icon = thumb.GetTransparentBitmap()?.ToImageSource(); } catch (Exception ex) { Logger.Debug(ex, "Getting drive icon"); } } catch (Exception ex) { Logger.Debug(ex, "Getting drive name"); continue; } try { format = drive.DriveFormat; } catch (Exception ex) { Logger.Debug(ex, "Getting drive format"); } try { freeSpace = ByteSize.FromBytes(drive.TotalFreeSpace); } catch (Exception ex) { Logger.Debug(ex, "Getting drive freeSpace"); } try { totalSize = ByteSize.FromBytes(drive.TotalSize); } catch (Exception ex) { Logger.Debug(ex, "Getting drive totalSize"); } try { type = drive.DriveType; } catch (Exception ex) { Logger.Debug(ex, "Getting drive type"); } try { ready = drive.IsReady; if (!drive.IsReady && !BrowseVM.AllowNonReadyDrives) { continue; } } catch (Exception ex) { Logger.Debug(ex, "Getting drive ready"); if (!BrowseVM.AllowNonReadyDrives) { continue; } } // Create the view model var vm = new DriveViewModel() { Path = path, Icon = icon, Format = format, Label = label, Type = type, FreeSpace = freeSpace, TotalSize = totalSize, IsReady = ready }; Drives.Add(vm); } } }
public void UpdateDrives() { Drives.Clear(); Directory.GetLogicalDrives().ToList().ForEach(x => Drives.Add(x)); }
public void Load() { if (!File.Exists(filename)) { return; } using (XmlReader reader = XmlReader.Create(new StreamReader(filename))) { for (; ;) { reader.Read(); if (reader.EOF) { break; } if (reader.NodeType == XmlNodeType.Whitespace) { continue; } if (reader.Name == "Options" && reader.IsStartElement()) { for (; ;) { if (!reader.Read() || reader.EOF) { break; } if (reader.NodeType == XmlNodeType.Whitespace) { continue; } else if (reader.NodeType == XmlNodeType.EndElement) { break; } if (reader.Name == "TempDir") { reader.Read(); TempDir = reader.Value; reader.Read(); } else if (reader.Name == "MaxTempRAM") { reader.Read(); MaxTempRAM = Convert.ToUInt32(reader.Value); reader.Read(); } else if (reader.Name == "IgnoreHidden") { reader.Read(); IgnoreHidden = (reader.Value == "true") ? true : false; reader.Read(); } else if (reader.Name == "MonitorDrives") { reader.Read(); MonitorDrives = (reader.Value == "true") ? true : false; reader.Read(); } else if (reader.Name == "UpdateDelay") { reader.Read(); UpdateDelay = Convert.ToUInt32(reader.Value); reader.Read(); } else if (reader.Name == "UpdateMode") { reader.Read(); int mode = Convert.ToInt32(reader.Value); reader.Read(); if (mode == 1) { UpdateMode = UpdateMode.NoAction; } else if (mode == 2) { UpdateMode = UpdateMode.ScanOnly; } else if (mode == 3) { UpdateMode = UpdateMode.ScanAndUpdate; } } else if (reader.Name == "Ignores") { for (; ;) { if (!reader.Read() || reader.EOF) { break; } if (reader.NodeType == XmlNodeType.Whitespace) { continue; } else if (reader.NodeType == XmlNodeType.EndElement) { break; } if (reader.Name == "Ignore" && reader.IsStartElement()) { reader.Read(); Ignores.Add(reader.Value); reader.Read(); // skip end element } } } } } else if (reader.Name == "Parity") { ParityDir = reader.GetAttribute("Path"); } else if (reader.Name == "Layout" && reader.IsStartElement()) { for (; ;) { if (!reader.Read() || reader.EOF) { break; } if (reader.NodeType == XmlNodeType.Whitespace) { continue; } else if (reader.NodeType == XmlNodeType.EndElement) { break; } else if (reader.Name == "MainWindowX") { reader.Read(); MainWindowX = Convert.ToInt32(reader.Value); reader.Read(); } else if (reader.Name == "MainWindowY") { reader.Read(); MainWindowY = Convert.ToInt32(reader.Value); reader.Read(); } else if (reader.Name == "MainWindowWidth") { reader.Read(); MainWindowWidth = Convert.ToInt32(reader.Value); reader.Read(); } else if (reader.Name == "MainWindowHeight") { reader.Read(); MainWindowHeight = Convert.ToInt32(reader.Value); reader.Read(); } } } else if (reader.Name == "Drives" && reader.IsStartElement()) { for (; ;) { if (!reader.Read() || reader.EOF) { break; } if (reader.NodeType == XmlNodeType.Whitespace) { continue; } else if (reader.NodeType == XmlNodeType.EndElement) { break; } if (reader.Name == "Drive") { Drives.Add(new Drive(reader.GetAttribute("Path"), reader.GetAttribute("Meta"))); } } } } } UpdateIgnoresRegex(); }
public override void Initialize() { if (!String.IsNullOrEmpty(Environment.GetEnvironmentVariable("ProgramW6432"))) { this.AddPath(EnvironmentVariable.ProgramFiles, Environment.GetEnvironmentVariable("ProgramW6432")); this.AddPath(EnvironmentVariable.ProgramFilesX86, Environment.GetEnvironmentVariable("PROGRAMFILES(X86)")); } else { this.AddPath(EnvironmentVariable.ProgramFiles, Environment.GetEnvironmentVariable("PROGRAMFILES")); //this.AddPath(EnvironmentVariable.ProgramFilesX86,Environment.GetEnvironmentVariable("PROGRAMFILES")); } if (!String.IsNullOrEmpty(Environment.GetEnvironmentVariable("LOCALAPPDATA"))) { Version = WindowsVersion.WindowsVista; } else { Version = WindowsVersion.WindowsXP; } this.AddPath(EnvironmentVariable.StartMenu, Environment.GetFolderPath(Environment.SpecialFolder.CommonStartMenu)); // Not really used //common_program_files = Environment.GetEnvironmentVariable("COMMONPROGRAMFILES"); foreach (DriveInfo look_here in DriveInfo.GetDrives()) { if (look_here.IsReady && (look_here.DriveType == DriveType.Fixed || look_here.DriveType == DriveType.Removable)) { Drives.Add(look_here.Name); } } //host_name = Environment.GetEnvironmentVariable("COMPUTERNAME"); this.AddPath(EnvironmentVariable.AllUsersProfile, Environment.GetEnvironmentVariable("ALLUSERSPROFILE")); if (Version == WindowsVersion.WindowsVista) { this.AddPath(EnvironmentVariable.Public, Environment.GetEnvironmentVariable("PUBLIC")); } this.AddPath(EnvironmentVariable.CommonApplicationData, Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData)); if (Version != WindowsVersion.WindowsXP) { RegistryHandler uac_status = new RegistryHandler("local_machine", @"SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System", false); if (uac_status.getValue("EnableLUA") == "1") { UACEnabled = true; } } string[] split = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData).Split(Path.DirectorySeparatorChar); StringBuilder user_root = new StringBuilder(split[0]); if (Version == WindowsVersion.WindowsXP) { for (int i = 1; i < split.Length - 2; i++) { user_root.Append(Path.DirectorySeparatorChar + split[i]); } } else { for (int i = 1; i < split.Length - 3; i++) { user_root.Append(Path.DirectorySeparatorChar + split[i]); } } //Per-user variables loadUsersData("current_user", null); if (Core.AllUsersModes) { // All this crap lets me get data from other user's registries IntPtr token = new IntPtr(0); int retval = 0; TOKEN_PRIVILEGES TP = new TOKEN_PRIVILEGES(); TOKEN_PRIVILEGES TP2 = new TOKEN_PRIVILEGES(); LUID RestoreLuid = new LUID(); LUID BackupLuid = new LUID(); int return_length = 0; TOKEN_PRIVILEGES oldPriveleges = new TOKEN_PRIVILEGES(); System.Diagnostics.Process process = System.Diagnostics.Process.GetCurrentProcess(); //IntPtr hndle = GetModuleHandle(null); //retval = OpenProcessToken(hndle, TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, ref token); retval = OpenProcessToken(process.Handle, TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, ref token); retval = LookupPrivilegeValue(null, SE_RESTORE_NAME, ref RestoreLuid); TP.PrivilegeCount = 1; TP.Privileges.attributes = SE_PRIVILEGE_ENABLED; TP.Privileges.luid = RestoreLuid; retval = AdjustTokenPrivileges(token, 0, ref TP, TP.Size(), ref oldPriveleges, ref return_length); if (retval == 0) { throw new Exception(Core.Translator["ProcessRestorePermissionError", retval.ToString()]); } retval = LookupPrivilegeValue(null, SE_BACKUP_NAME, ref BackupLuid); TP2.PrivilegeCount = 1; TP2.Privileges.attributes = SE_PRIVILEGE_ENABLED; TP2.Privileges.luid = BackupLuid; retval = AdjustTokenPrivileges(token, 0, ref TP2, TP2.Size(), ref oldPriveleges, ref return_length); if (retval == 0) { throw new Exception(Core.Translator["ProcessBackupPermissionError", retval.ToString()]); } Console.WriteLine(retval); foreach (DirectoryInfo user_folder in new DirectoryInfo(user_root.ToString()).GetDirectories()) { if (user_folder.Name.ToLower() == "default user") { continue; } if (user_folder.Name.ToLower() == "default") { continue; } if (user_folder.Name.ToLower() == "all users") { continue; } string hive_file = Path.Combine(user_folder.FullName, "NTUSER.DAT"); if (!File.Exists(hive_file)) { continue; } int h = RegLoadKey(HKEY_USERS, user_folder.Name, hive_file); //int h = RegLoadAppKey(hive_file,out hKey, RegSAM.AllAccess,REG_PROCESS_APPKEY,0); if (h == 32) { continue; } if (h != 0) { throw new Exception(Core.Translator["UserRegistryLoadError", user_folder.Name, h.ToString()]); } //sub_key = new RegistryHandler(hKey); //sub_key = new RegistryHandler(RegRoot.users,user_folder.Name,false); loadUsersData("users", user_folder.Name); string result = RegUnLoadKey(HKEY_USERS, user_folder.Name).ToString(); } } }