Esempio n. 1
0
        private static List <RecordingFileInfo> GetRecordingsOnDrive(string drive)
        {
            List <RecordingFileInfo> recordings      = new List <RecordingFileInfo>();
            IList <Recording>        recordedTvShows = Recording.ListAll();

            foreach (Recording recorded in recordedTvShows)
            {
                if (recorded.FileName.ToUpperInvariant()[0] != drive.ToUpperInvariant()[0])
                {
                    continue;
                }

                bool add = true;
                foreach (RecordingFileInfo fi in recordings)
                {
                    if (String.Compare(fi.filename, recorded.FileName, true) == 0)
                    {
                        add = false;
                    }
                }
                if (add)
                {
                    try
                    {
                        FileInfo          info = new FileInfo(recorded.FileName);
                        RecordingFileInfo fi   = new RecordingFileInfo();
                        fi.info     = info;
                        fi.filename = recorded.FileName;
                        fi.record   = recorded;
                        recordings.Add(fi);
                    }
                    catch (Exception e)
                    {
                        Log.Error("DiskManagement: Exception at building FileInfo ({0})", recorded.FileName);
                        Log.Write(e);
                    }
                }
            }
            return(recordings);
        }
Esempio n. 2
0
        private static void CheckDriveFreeDiskSpace(string drive)
        {
            //get disk quota to use
            if (!OutOfDiskSpace(drive))
            {
                return;
            }

            Log.Write("DiskManagement: not enough free space on drive: {0}", drive);

            List <RecordingFileInfo> recordings = GetRecordingsOnDrive(drive);

            if (recordings.Count == 0)
            {
                Log.Write("DiskManagement: no recordings to delete");
                return;
            }

            Log.Write("DiskManagement: found {0} recordings", recordings.Count);

            // Not enough free diskspace
            // start deleting recordings (oldest ones first)
            // until we have enough free disk space again
            recordings.Sort();
            while (OutOfDiskSpace(drive) && recordings.Count > 0)
            {
                RecordingFileInfo fi = recordings[0];
                if (fi.record.KeepUntil == (int)KeepMethodType.UntilSpaceNeeded)
                {
                    // Delete the file from disk and the recording entry from the database.
                    bool result = RecordingFileHandler.DeleteRecordingOnDisk(fi.record.FileName);
                    if (result)
                    {
                        fi.record.Delete();
                    }
                }
                recordings.RemoveAt(0);
            }
        }