public static void FillWithDeskopItems(this ListView listView, Desktop currentDesktop,Desktop savedDesktop)
        {
            var colors = GetColors(currentDesktop,savedDesktop);
            for (int index = 0; index < currentDesktop.Files.Count; index++)
            {
                var path = currentDesktop.Files[index];

                if (File.Exists(path))
                {
                    listView.Items.Add(FromFile(path, colors[index]));
                }
                else if (Directory.Exists(path))
                {
                    listView.Items.Add(FromDirectory(path, colors[index]));
                }
            }
        }
        public async void Restore(string destination)
        {
            var currentDesktop = new Desktop();
            var filesToMove = currentDesktop.Files.Except(Files);
            var sizesOfItemsInPercents = GetSizesOfItemsInPercents(filesToMove);
            var destinationFolder = $@"{destination}\{DateTime.Now.Date.ToShortDateString().Replace('/', '.')}";
            CreateFolderIfNonExistent(destinationFolder);

            var tasks =
                filesToMove.Select(item => new Task<FileMoveResult>(() => new ItemMover(item, destinationFolder).Start())).ToList();
            tasks.ForEach(t => t.Start());

            while (tasks.Count > 0)
            {
                var firstFinishedTask = await Task.WhenAny(tasks);
                tasks.Remove(firstFinishedTask);
                var result = await firstFinishedTask;
                result.fileSizeInPercents = sizesOfItemsInPercents[result.SourcePath];
                OnResultReady(result);
            }

            Task.WaitAll(tasks.ToArray());
            OnResultReady(null);
        }
 private static Color[] GetColors(Desktop currentDesktop, Desktop savedDesktop)
 {
     return currentDesktop.Files.Select(path => savedDesktop.Files.Contains(path) ? Color.DarkGreen : Color.DarkRed).ToArray();
 }
 private void UpdateLbItems()
 {
     currentDesktop = new Desktop();
     lbItems.BeginUpdate();
     lbItems.Clear();
     lbItems.SmallImageList = FileListViewManager.GetIcons(currentDesktop.Files.Where(File.Exists));
     lbItems.FillWithDeskopItems(currentDesktop, savedDesktop);
     lbItems.EndUpdate();
 }
 private void DesktopMaid_Shown(object sender, EventArgs e)
 {
     if (savedDesktop == null)
     {
         savedDesktop = new Desktop(new string[] {});
         MessageBox.Show("Now you have to add files that you want to preserve on your desktop.");
         tabControl1.SelectedIndex = 0;
         BlinkControl(butPreserve);
     }
     if (string.IsNullOrWhiteSpace(tbPath.Text))
     {
         MessageBox.Show("You also have to select path to copy files to."); //todo rewrite
         tabControl1.SelectedIndex = 1;
         BlinkControl(butBrowse);
     }
     UpdateLbItems();
 }
        private void DesktopMaid_Load(object sender, EventArgs e)
        {
            savedDesktop = Desktop.Load();
            settings = Settings.Load();

            if (settings != null)
            {
                tbPath.Text = settings.Path;
                cbRunAtStartup.Checked = settings.RunAtStartup;
                chbAutoRestore.Checked = settings.AutoRestore;
                numInterval.Value = settings.Interval;
                if (settings.StartMinimalized)
                {
                    ChangeWindowState(FormWindowState.Minimized);
                }
            }
            else
            {
                settings = new Settings();
            }
        }
Exemple #7
0
 private static Color[] GetColors(Desktop currentDesktop, Desktop savedDesktop)
 {
     return(currentDesktop.Files.Select(path => savedDesktop.Files.Contains(path) ? Color.DarkGreen : Color.DarkRed).ToArray());
 }
Exemple #8
0
        public static void FillWithDesktopItems(this ListView listView, Desktop currentDesktop, Desktop savedDesktop)
        {
            var colors = GetColors(currentDesktop, savedDesktop);

            for (int index = 0; index < currentDesktop.Files.Count; index++)
            {
                var path = currentDesktop.Files[index];

                if (File.Exists(path))
                {
                    listView.Items.Add(FromFile(path, colors[index]));
                }
                else if (Directory.Exists(path))
                {
                    listView.Items.Add(FromDirectory(path, colors[index]));
                }
            }
        }