diff options
Diffstat (limited to 'recording.c')
-rw-r--r-- | recording.c | 81 |
1 files changed, 67 insertions, 14 deletions
diff --git a/recording.c b/recording.c index 2eba90b..e37ccd8 100644 --- a/recording.c +++ b/recording.c @@ -4,14 +4,16 @@ * See the main source file 'vdr.c' for copyright information and * how to reach the author. * - * $Id: recording.c 1.8 2000/05/13 16:16:56 kls Exp $ + * $Id: recording.c 1.12 2000/07/24 16:31:07 kls Exp $ */ #define _GNU_SOURCE #include "recording.h" #include <errno.h> +#include <fcntl.h> #include <stdio.h> #include <string.h> +#include <unistd.h> #include "interface.h" #include "tools.h" @@ -20,7 +22,9 @@ #define DATAFORMAT "%4d-%02d-%02d.%02d:%02d.%02d.%02d" RECEXT #define NAMEFORMAT "%s/%s/" DATAFORMAT -#define FINDCMD "find %s -type d -name '%s'" +#define SUMMARYFILESUFFIX "/summary.vdr" + +#define FINDCMD "find %s -type d -name '%s' | sort -df" #define DFCMD "df -m %s" #define MINDISKSPACE 1024 // MB @@ -102,21 +106,14 @@ void AssertFreeDiskSpace(void) // --- cRecording ------------------------------------------------------------ -cRecording::cRecording(const char *Name, time_t Start, int Priority, int LifeTime) -{ - titleBuffer = NULL; - fileName = NULL; - name = strdup(Name); - start = Start; - priority = Priority; - lifetime = LifeTime; -} - cRecording::cRecording(cTimer *Timer) { titleBuffer = NULL; fileName = NULL; name = strdup(Timer->file); + summary = Timer->summary ? strdup(Timer->summary) : NULL; + if (summary) + strreplace(summary, '|', '\n'); start = Timer->StartTime(); priority = Timer->priority; lifetime = Timer->lifetime; @@ -130,6 +127,7 @@ cRecording::cRecording(const char *FileName) char *p = strrchr(FileName, '/'); name = NULL; + summary = NULL; if (p) { time_t now = time(NULL); struct tm t = *localtime(&now); // this initializes the time zone in 't' @@ -141,7 +139,41 @@ cRecording::cRecording(const char *FileName) name = new char[p - FileName + 1]; strncpy(name, FileName, p - FileName); name[p - FileName] = 0; + strreplace(name, '_', ' '); } + // read an optional summary file: + char *SummaryFileName = NULL; + asprintf(&SummaryFileName, "%s%s", fileName, SUMMARYFILESUFFIX); + int f = open(SummaryFileName, O_RDONLY); + if (f >= 0) { + struct stat buf; + if (fstat(f, &buf) == 0) { + int size = buf.st_size; + summary = new char[size + 1]; // +1 for terminating 0 + if (summary) { + int rbytes = read(f, summary, size); + if (rbytes >= 0) { + summary[rbytes] = 0; + if (rbytes != size) + esyslog(LOG_ERR, "%s: expected %d bytes but read %d", SummaryFileName, size, rbytes); + } + else { + LOG_ERROR_STR(SummaryFileName); + delete summary; + summary = NULL; + } + + } + else + esyslog(LOG_ERR, "can't allocate %d byte of memory for summary file '%s'", size + 1, SummaryFileName); + close(f); + } + else + LOG_ERROR_STR(SummaryFileName); + } + else if (errno != ENOENT) + LOG_ERROR_STR(SummaryFileName); + delete SummaryFileName; } } @@ -150,6 +182,7 @@ cRecording::~cRecording() delete titleBuffer; delete fileName; delete name; + delete summary; } const char *cRecording::FileName(void) @@ -157,6 +190,8 @@ const char *cRecording::FileName(void) if (!fileName) { struct tm *t = localtime(&start); asprintf(&fileName, NAMEFORMAT, BaseDir, name, t->tm_year + 1900, t->tm_mon + 1, t->tm_mday, t->tm_hour, t->tm_min, priority, lifetime); + if (fileName) + strreplace(fileName, ' ', '_'); } return fileName; } @@ -166,10 +201,10 @@ const char *cRecording::Title(char Delimiter) delete titleBuffer; titleBuffer = NULL; struct tm *t = localtime(&start); - asprintf(&titleBuffer, "%02d.%02d.%04d%c%02d:%02d%c%s", + asprintf(&titleBuffer, "%02d.%02d.%02d%c%02d:%02d%c%s", t->tm_mday, t->tm_mon + 1, - t->tm_year + 1900, + t->tm_year % 100, Delimiter, t->tm_hour, t->tm_min, @@ -178,6 +213,24 @@ const char *cRecording::Title(char Delimiter) return titleBuffer; } +bool cRecording::WriteSummary(void) +{ + if (summary) { + char *SummaryFileName = NULL; + asprintf(&SummaryFileName, "%s%s", fileName, SUMMARYFILESUFFIX); + FILE *f = fopen(SummaryFileName, "w"); + if (f) { + if (fputs(summary, f) < 0) + LOG_ERROR_STR(SummaryFileName); + fclose(f); + } + else + LOG_ERROR_STR(SummaryFileName); + delete SummaryFileName; + } + return true; +} + bool cRecording::Delete(void) { bool result = true; |