From 535e755278ef51b923a71299204ec86da4229d02 Mon Sep 17 00:00:00 2001 From: Klaus Schmidinger Date: Sun, 11 Feb 2001 11:04:41 +0100 Subject: Implemented 'Rewind' in the 'Recordings' menu --- recording.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 60 insertions(+), 2 deletions(-) (limited to 'recording.c') diff --git a/recording.c b/recording.c index dd364638..72b3135f 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 1.25 2001/02/04 12:36:32 kls Exp $ + * $Id: recording.c 1.26 2001/02/11 10:47:31 kls Exp $ */ #define _GNU_SOURCE @@ -15,7 +15,6 @@ #include #include #include -#include "dvbapi.h" #include "interface.h" #include "tools.h" #include "videodir.h" @@ -25,6 +24,7 @@ #define DATAFORMAT "%4d-%02d-%02d.%02d:%02d.%02d.%02d" RECEXT #define NAMEFORMAT "%s/%s/" DATAFORMAT +#define RESUMEFILESUFFIX "/resume.vdr" #define SUMMARYFILESUFFIX "/summary.vdr" #define MARKSFILESUFFIX "/marks.vdr" @@ -109,6 +109,64 @@ void AssertFreeDiskSpace(void) } } +// --- cResumeFile ------------------------------------------------------------ + +cResumeFile::cResumeFile(const char *FileName) +{ + fileName = new char[strlen(FileName) + strlen(RESUMEFILESUFFIX) + 1]; + if (fileName) { + strcpy(fileName, FileName); + strcat(fileName, RESUMEFILESUFFIX); + } + else + esyslog(LOG_ERR, "ERROR: can't allocate memory for resume file name"); +} + +cResumeFile::~cResumeFile() +{ + delete fileName; +} + +int cResumeFile::Read(void) +{ + int resume = -1; + if (fileName) { + int f = open(fileName, O_RDONLY); + if (f >= 0) { + if (read(f, &resume, sizeof(resume)) != sizeof(resume)) { + resume = -1; + LOG_ERROR_STR(fileName); + } + close(f); + } + else if (errno != ENOENT) + LOG_ERROR_STR(fileName); + } + return resume; +} + +bool cResumeFile::Save(int Index) +{ + if (fileName) { + int f = open(fileName, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP); + if (f >= 0) { + if (write(f, &Index, sizeof(Index)) != sizeof(Index)) + LOG_ERROR_STR(fileName); + close(f); + return true; + } + } + return false; +} + +void cResumeFile::Delete(void) +{ + if (fileName) { + if (remove(fileName) < 0 && errno != ENOENT) + LOG_ERROR_STR(fileName); + } +} + // --- cRecording ------------------------------------------------------------ cRecording::cRecording(cTimer *Timer) -- cgit v1.2.3