Beispiel #1
0
        public static void Restore(ICollection <FileSystemInfo> collection)
        {
            try
            {
                if (collection.Count == 0 && collection == null)
                {
                    throw new Exception("Attempted to delete the same file  twice");
                }

                foreach (var fi in collection)
                {
                    if (collection.Count(e => e == fi) != 1)
                    {
                        throw new Exception("Attempted to delete the same file  twice");
                    }
                }

                if (ShellUtilities.RestoreFromRecycle(collection) == false)
                {
                    using (FileStream restoreFiles = new FileStream("restore_err.txt", FileMode.OpenOrCreate))
                    {
                        byte[] errorHeader = System.Text.Encoding.Default.GetBytes($"{DateTime.Now.ToString()}| Recycle restore " +
                                                                                   $"exception\nTry to restore the following file on your own\n->");
                        restoreFiles.Write(errorHeader, 0, errorHeader.Length);
                        foreach (var fi in collection)
                        {
                            byte[] note = System.Text.Encoding.Default.GetBytes($"{fi.FullName}\n");
                            restoreFiles.Write(note, 0, note.Length);
                        }

                        restoreFiles.Close();
                        throw new Exception($"Restore exception try\nSee info in {restoreFiles.Name}");
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "RESTORE ERROR", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }