From 2b3556b460665d9a4036b1623e7e7ff5ff6d37d8 Mon Sep 17 00:00:00 2001 From: Klaus Schmidinger Date: Sat, 26 Dec 2020 15:49:01 +0100 Subject: Implemented "Pattern Timers" --- recording.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 69 insertions(+), 1 deletion(-) (limited to 'recording.c') diff --git a/recording.c b/recording.c index 6bfbcff1..17467e36 100644 --- a/recording.c +++ b/recording.c @@ -4,7 +4,7 @@ * See the main source file 'vdr.c' for copyright information and * how to reach the author. * - * $Id: recording.c 4.29 2020/10/30 16:08:29 kls Exp $ + * $Id: recording.c 5.1 2020/12/26 15:49:01 kls Exp $ */ #include "recording.h" @@ -3050,6 +3050,74 @@ cUnbufferedFile *cFileName::NextFile(void) return SetOffset(fileNumber + 1); } +// --- cDoneRecordings ------------------------------------------------------- + +cDoneRecordings DoneRecordingsPattern; + +bool cDoneRecordings::Load(const char *FileName) +{ + fileName = FileName; + if (*fileName && access(fileName, F_OK) == 0) { + isyslog("loading %s", *fileName); + FILE *f = fopen(fileName, "r"); + if (f) { + char *s; + cReadLine ReadLine; + while ((s = ReadLine.Read(f)) != NULL) + Add(s); + fclose(f); + } + else { + LOG_ERROR_STR(*fileName); + return false; + } + } + return true; +} + +bool cDoneRecordings::Save(void) const +{ + bool result = true; + cSafeFile f(fileName); + if (f.Open()) { + for (int i = 0; i < doneRecordings.Size(); i++) { + if (fputs(doneRecordings[i], f) == EOF || fputc('\n', f) == EOF) { + result = false; + break; + } + } + if (!f.Close()) + result = false; + } + else + result = false; + return result; +} + +void cDoneRecordings::Add(const char *Title) +{ + doneRecordings.Append(strdup(Title)); +} + +void cDoneRecordings::Append(const char *Title) +{ + if (!Contains(Title)) { + Add(Title); + if (FILE *f = fopen(fileName, "a")) { + fputs(Title, f); + fputc('\n', f); + fclose(f); + } + else + esyslog("ERROR: can't open '%s' for appending '%s'", *fileName, Title); + } +} + +bool cDoneRecordings::Contains(const char *Title) const +{ + return doneRecordings.Find(Title) >= 0; +} + // --- Index stuff ----------------------------------------------------------- cString IndexToHMSF(int Index, bool WithFrame, double FramesPerSecond) -- cgit v1.2.3