Esempio n. 1
0
        public void AttemptDeletions()
        {
            lock (PendingDelete) {
                int oldCount = PendingDelete.Count;
                for (int i = PendingDelete.Count - 1; i >= 0; i--)
                {
                    string path = System.IO.Path.Combine(Sys.Settings.LibraryLocation, PendingDelete[i]);
                    try {
                        if (System.IO.File.Exists(path))
                        {
                            System.IO.File.Delete(path);
                        }
                        else if (System.IO.Directory.Exists(path))
                        {
                            System.IO.Directory.Delete(path, true);
                        }
                    } catch (System.IO.IOException) {
                        System.Diagnostics.Debug.Write(String.Format("File {0} could not be accessed - in use? Leaving in list.", path));
                        continue;
                    }
                    System.Diagnostics.Debug.Write(String.Format("File {0} successfully deleted.", path));
                    PendingDelete.RemoveAt(i);
                }

                if (oldCount != PendingDelete.Count)
                {
                    Sys.Save();
                }
            }
        }
Esempio n. 2
0
        public void AttemptDeletions()
        {
            lock (_pendingLock)
            {
                int oldCount = PendingDelete.Count;
                for (int i = PendingDelete.Count - 1; i >= 0; i--)
                {
                    string path = Path.Combine(Sys.Settings.LibraryLocation, PendingDelete[i]);
                    try
                    {
                        if (File.Exists(path))
                        {
                            File.Delete(path);
                        }
                        else if (Directory.Exists(path))
                        {
                            Directory.Delete(path, true);
                        }
                    }
                    catch (IOException ioex)
                    {
                        Sys.Message(new WMessage($"File {path} could not be accessed - in use? Leaving in list.", WMessageLogLevel.LogOnly, ioex));
                        continue;
                    }
                    catch (Exception ex)
                    {
                        Sys.Message(new WMessage($"Unknown exception deleting {path} - Leaving in list.", WMessageLogLevel.LogOnly, ex));
                        continue;
                    }

                    Sys.Message(new WMessage($"File {path} successfully deleted.", WMessageLogLevel.LogOnly));
                    PendingDelete.RemoveAt(i);
                }

                if (oldCount != PendingDelete.Count)
                {
                    Sys.SaveLibrary();
                }
            }
        }