2 Copyright 2006 Chris Tallon
4 This file is part of VOMP.
6 VOMP is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 VOMP is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with VOMP. If not, see <https://www.gnu.org/licenses/>.
27 rootDir = new Directory("/");
36 void RecMan::setStats(ULONG ttotalSpace, ULONG tfreeSpace, ULONG tusedPercent)
38 totalSpace = ttotalSpace;
39 freeSpace = tfreeSpace;
40 usedPercent = tusedPercent;
43 void RecMan::addEntry(bool isNew, ULONG startTime, char* name, char* fileName)
45 Recording* rec = new Recording();
47 rec->setStartTime(startTime);
48 rec->setFileName(fileName);
50 // And now for the directory structure & prog name
54 std::stack<char*> dirNamesStack;
56 bool gotProgName = false;
57 for(c = (name + strlen(name) - 1); c >= name; c--)
59 if ((*c == '~') || (c == name))
61 // Make d point to the start of the string (i.e. move on 1 from ~ if necessary)
62 if (c == name) d = name;
67 rec->setProgName(d); // will copy from d to end of string
74 oneDirName = new char[strlen(d) + 1];
75 strcpy(oneDirName, d);
76 dirNamesStack.push(oneDirName);
82 Directory* targetDirectory = rootDir;
85 while(!dirNamesStack.empty())
87 oneDirName = dirNamesStack.top();
88 if (!oneDirName) break;
90 getDir = targetDirectory->getDirByName(oneDirName);
93 targetDirectory = getDir;
97 getDir = new Directory(oneDirName); // Make a new directory
98 getDir->parent = targetDirectory;
99 targetDirectory->dirList.push_back(getDir); // Put the new directory in the tree
100 targetDirectory = getDir; // Make the new dir the target
107 targetDirectory->recList.push_back(rec);
110 ULONG RecMan::getTotalSpace()
115 ULONG RecMan::getFreeSpace()
120 ULONG RecMan::getUsedPercent()
125 int RecMan::deleteRecording(Recording* rec)
129 for(RecordingList::iterator i = currentDir->recList.begin(); i != currentDir->recList.end(); i++)
133 success = VDR::getInstance()->deleteRecording(rec->getFileName());
136 currentDir->recList.erase(i);
146 void RecMan::constructPath(char* target, Directory* dir)
150 constructPath(target, dir->parent);
151 strcat(target, dir->name);
156 int RecMan::moveRecording(Recording* toMove, Directory* toDir)
158 char newPath[PATH_MAX];
159 strcpy(newPath, "~");
160 constructPath(&newPath[1], toDir);
163 for(RecordingList::iterator i = currentDir->recList.begin(); i != currentDir->recList.end(); i++)
167 char* newFileName = VDR::getInstance()->moveRecording(toMove->getFileName(), newPath);
172 toMove->setFileName(newFileName);
173 delete[] newFileName;
175 currentDir->recList.erase(i);
176 toDir->recList.push_back(toMove);
177 toDir->sort(chronoSortOrder);
187 bool RecMan::isSubDir()
189 return (currentDir != rootDir);
192 bool RecMan::down(Directory* downDir)
194 // Check dir is in currentDir
195 for(DirectoryList::iterator i = currentDir->dirList.begin(); i != currentDir->dirList.end(); i++)
199 currentDir = downDir;
208 if (!isSubDir()) return false;
210 Directory* oldDir = currentDir;
211 currentDir = currentDir->parent;
213 if (oldDir->getNumRecordings() == 0)
217 for (DirectoryList::iterator i = currentDir->dirList.begin(); i != currentDir->dirList.end(); i++)
220 if (tempdir == oldDir)
222 currentDir->dirList.erase(i);
232 char* RecMan::getCurDirName()
234 return currentDir->name;
237 DirectoryList* RecMan::getDirectories()
239 return ¤tDir->dirList;
242 RecordingList* RecMan::getRecordings()
244 return ¤tDir->recList;
247 Directory* RecMan::getRootDir()
252 void RecMan::setSortOrderChron()
254 chronoSortOrder = true;
257 void RecMan::toggleSortOrder()
259 chronoSortOrder = !chronoSortOrder;
264 Log::getInstance()->log("RecMan", Log::DEBUG, "Sort");
265 rootDir->sort(chronoSortOrder);