Beispiel #1
0
        public static void SetVirtualMemoryOfDrive(Drive drive, int sizeMb)
        {
            List <VirtualMemory> list  = GetPagingFiles();
            VirtualMemory        exist = list.FirstOrDefault(a => a.DriveName == drive.Name);

            if (exist != null)
            {
                exist.MinSizeMb = sizeMb;
                exist.MaxSizeMb = sizeMb;
            }
            else
            {
                list.Add(new VirtualMemory()
                {
                    DriveName = drive.Name,
                    MinSizeMb = sizeMb,
                    MaxSizeMb = sizeMb
                });
            }
            string[] value = list.Select(a => a.ToString()).ToArray();

            Windows.Registry.SetValue(Microsoft.Win32.Registry.LocalMachine, MemoryManagementSubKey, "PagingFiles", value);
            DriveSet.Current.Refresh();
            DrivesViewModel.Current.IsNeedRestartWindows = VirtualMemory.IsStateChanged;
            drive.OptionalVirtualMemories.OnPropertyChanged(nameof(drive.OptionalVirtualMemories.List));
        }
 public OptionalVirtualMemory(Drive drive, int sizeG)
 {
     this.Set = new DelegateCommand(() => {
         VirtualMemory.SetVirtualMemoryOfDrive(Drive, SizeMb);
     });
     _drive = drive;
     _sizeG = sizeG;
 }
Beispiel #3
0
 public Drive(DriveInfo driveInfo)
 {
     _driveInfo = driveInfo;
     if (driveInfo.DriveType != DriveType.Fixed)
     {
         throw new InvalidProgramException();
     }
     this.ClearVirtualMemory = new DelegateCommand(() => {
         VirtualMemory.ClearVirtualMemory(this);
     });
 }
Beispiel #4
0
 public void Refresh()
 {
     VirtualMemory.RefreshVirtualMemories();
     foreach (var driveInfo in DriveInfo.GetDrives().Where(a => a.DriveType == DriveType.Fixed))
     {
         Drive drive = _drives.FirstOrDefault(a => a.Name == driveInfo.Name);
         drive?.Refresh(driveInfo);
     }
     OnPropertyChanged(nameof(Drives));
     OnPropertyChanged(nameof(TotalVirtualMemoryGb));
     OnPropertyChanged(nameof(TotalVirtualMemoryGbText));
 }
Beispiel #5
0
        public static void ClearVirtualMemory(Drive drive)
        {
            List <VirtualMemory> list  = GetPagingFiles();
            VirtualMemory        exist = list.FirstOrDefault(a => a.DriveName == drive.Name);

            if (exist == null)
            {
                return;
            }
            list.Remove(exist);
            string[] value = list.Select(a => a.ToString()).ToArray();

            Windows.Registry.SetValue(Microsoft.Win32.Registry.LocalMachine, MemoryManagementSubKey, "PagingFiles", value);
            DriveSet.Current.Refresh();
            DrivesViewModel.Current.IsNeedRestartWindows = VirtualMemory.IsStateChanged;
            drive.OptionalVirtualMemories.OnPropertyChanged(nameof(drive.OptionalVirtualMemories.List));
        }
Beispiel #6
0
        private static List <VirtualMemory> Parse(string[] vmReg)
        {
            List <VirtualMemory> list = new List <VirtualMemory>();

            try {
                foreach (string item in vmReg)
                {
                    VirtualMemory vm = Parse(item);
                    if (vm != null)
                    {
                        list.Add(vm);
                    }
                }
            }
            catch (Exception e) {
                Global.Logger.Error(e);
            }
            return(list);
        }
Beispiel #7
0
 public OptionalVirtualMemories(Drive drive, long awailableSpace, VirtualMemory vm)
 {
     _drive          = drive;
     _awailableSpace = awailableSpace;
     _vm             = vm;
 }