* src/DirectDiskAdaptor.h: New class.

* src/DirectDiskAdaptor.cc: New class.
	* src/MultiDiskAdaptor.h: New class.
	* src/MultiDiskAdaptor.cc: New class.
	* src/CopyDiskAdaptor.h: New class.
	* src/CopyDiskAdaptor.cc: New class.
	* src/DiskAdaptor.h: New class.
	* src/DiskAdaptor.cc: New class.
pull/1/head
Tatsuhiro Tsujikawa 2006-04-16 14:42:26 +00:00
parent 2a84b9de43
commit 28a82bfa4a
9 changed files with 451 additions and 2 deletions

View File

@ -60,11 +60,17 @@
* src/AbstractDiskWriter.cc (openFile): If file exists, call
openExistingFile, otherwise call initAndOpenFile.
(closeFile): fd > 0, not fd != 0.
* src/DirectDiskAdaptor.h: New class.
* src/DirectDiskAdaptor.cc: New class.
* src/MultiDiskAdaptor.h: New class.
* src/MultiDiskAdaptor.cc: New class.
* src/CopyDiskAdaptor.h: New class.
* src/CopyDiskAdaptor.cc: New class.
* src/DiskAdaptor.h: New class.
* src/DiskAdaptor.cc: New class.
* src/prefs.h (PREF_TORRENT_SHOW_FILES): Renamed as PREF_SHOW_FILES
(PREF_SHOW_FILES): New definition.
2006-04-12 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>

54
src/CopyDiskAdaptor.cc Normal file
View File

@ -0,0 +1,54 @@
/* <!-- copyright */
/*
* aria2 - a simple utility for downloading files faster
*
* Copyright (C) 2006 Tatsuhiro Tsujikawa
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/* copyright --> */
#include "CopyDiskAdaptor.h"
#include "Util.h"
CopyDiskAdaptor::CopyDiskAdaptor(DiskWriter* diskWriter):DiskAdaptor(diskWriter) {}
CopyDiskAdaptor::~CopyDiskAdaptor() {}
void CopyDiskAdaptor::onDownloadComplete() {
closeFile();
fixFilename();
openFile();
}
void CopyDiskAdaptor::fixFilename() {
if(topDir != NULL) {
topDir->createDir(storeDir, true);
}
long long int offset = 0;
for(FileEntries::iterator itr = fileEntries.begin();
itr != fileEntries.end(); itr++) {
if(!itr->extracted && itr->requested) {
string dest = storeDir+"/"+itr->path;
//logger->info("writing file %s", dest.c_str());
Util::rangedFileCopy(dest, getFilePath(), offset, itr->length);
itr->extracted = true;
}
offset += itr->length;
}
}
string CopyDiskAdaptor::getFilePath() const {
return storeDir+"/"+tempFilename;
}

47
src/CopyDiskAdaptor.h Normal file
View File

@ -0,0 +1,47 @@
/* <!-- copyright */
/*
* aria2 - a simple utility for downloading files faster
*
* Copyright (C) 2006 Tatsuhiro Tsujikawa
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/* copyright --> */
#ifndef _D_COPY_DISK_ADAPTOR_H_
#define _D_COPY_DISK_ADAPTOR_H_
#include "DiskAdaptor.h"
#include "DiskWriter.h"
class CopyDiskAdaptor : public DiskAdaptor {
private:
string tempFilename;
void fixFilename();
protected:
string getFilePath() const;
public:
CopyDiskAdaptor(DiskWriter* diskWriter);
~CopyDiskAdaptor();
virtual void onDownloadComplete();
// tempFilename is relative to storeDir
void setTempFilename(const string& tempFilename) {
this->tempFilename = tempFilename;
}
string getTempFile() const { return this->tempFilename; }
};
#endif // _D_COPY_DISK_ADAPTOR_H_

35
src/DirectDiskAdaptor.cc Normal file
View File

@ -0,0 +1,35 @@
/* <!-- copyright */
/*
* aria2 - a simple utility for downloading files faster
*
* Copyright (C) 2006 Tatsuhiro Tsujikawa
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/* copyright --> */
#include "DirectDiskAdaptor.h"
DirectDiskAdaptor::DirectDiskAdaptor(DiskWriter* diskWriter):DiskAdaptor(diskWriter) {}
DirectDiskAdaptor::~DirectDiskAdaptor() {}
string DirectDiskAdaptor::getFilePath() const {
return storeDir+"/"+fileEntries.front().path;
}
void DirectDiskAdaptor::onDownloadComplete() {
closeFile();
openFile();
}

37
src/DirectDiskAdaptor.h Normal file
View File

@ -0,0 +1,37 @@
/* <!-- copyright */
/*
* aria2 - a simple utility for downloading files faster
*
* Copyright (C) 2006 Tatsuhiro Tsujikawa
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/* copyright --> */
#ifndef _D_DIRECT_DISK_ADAPTOR_H_
#define _D_DIRECT_DISK_ADAPTOR_H_
#include "DiskAdaptor.h"
class DirectDiskAdaptor : public DiskAdaptor {
protected:
string getFilePath() const;
public:
DirectDiskAdaptor(DiskWriter* diskWriter);
virtual ~DirectDiskAdaptor();
virtual void onDownloadComplete();
};
#endif // _D_DIRECT_DISK_ADAPTOR_H_

94
src/DiskAdaptor.cc Normal file
View File

@ -0,0 +1,94 @@
/* <!-- copyright */
/*
* aria2 - a simple utility for downloading files faster
*
* Copyright (C) 2006 Tatsuhiro Tsujikawa
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/* copyright --> */
#include "DiskAdaptor.h"
#include "DlAbortEx.h"
void DiskAdaptor::openFile() {
diskWriter->openFile(getFilePath());
}
void DiskAdaptor::closeFile() {
diskWriter->closeFile();
}
void DiskAdaptor::openExistingFile() {
diskWriter->openExistingFile(getFilePath());
}
void DiskAdaptor::initAndOpenFile() {
diskWriter->initAndOpenFile(getFilePath());
}
void DiskAdaptor::writeData(const char* data, int len, long long int position) {
diskWriter->writeData(data, len, position);
}
int DiskAdaptor::readData(char* data, int len, long long int position) {
return diskWriter->readData(data, len, position);
}
string DiskAdaptor::sha1Sum(long long int offset, long long int length) {
return diskWriter->sha1Sum(offset, length);
}
FileEntry DiskAdaptor::getFileEntryFromPath(const string& fileEntryPath) const {
for(FileEntries::const_iterator itr = fileEntries.begin();
itr != fileEntries.end(); itr++) {
if(itr->path == fileEntryPath) {
return *itr;
}
}
throw new DlAbortEx("no such file entry <%s>", fileEntryPath.c_str());
}
bool DiskAdaptor::addDownloadEntry(const string& fileEntryPath) {
for(FileEntries::iterator itr = fileEntries.begin();
itr != fileEntries.end(); itr++) {
if(itr->path == fileEntryPath) {
itr->requested = true;
return true;
}
}
return false;
}
bool DiskAdaptor::addDownloadEntry(int index) {
if(fileEntries.size() <= (unsigned int)index) {
return false;
}
fileEntries.at(index).requested = true;
return true;
}
void DiskAdaptor::addAllDownloadEntry() {
for(FileEntries::iterator itr = fileEntries.begin();
itr != fileEntries.end(); itr++) {
itr->requested = true;
}
}
void DiskAdaptor::removeAllDownloadEntry() {
for(FileEntries::iterator itr = fileEntries.begin();
itr != fileEntries.end(); itr++) {
itr->requested = false;
}
}

77
src/DiskAdaptor.h Normal file
View File

@ -0,0 +1,77 @@
/* <!-- copyright */
/*
* aria2 - a simple utility for downloading files faster
*
* Copyright (C) 2006 Tatsuhiro Tsujikawa
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/* copyright --> */
#ifndef _D_DISK_ADAPTOR_H_
#define _D_DISK_ADAPTOR_H_
#include "common.h"
#include "FileEntry.h"
#include "Directory.h"
#include "DiskWriter.h"
class DiskAdaptor {
protected:
DiskWriter* diskWriter;
string storeDir;
FileEntries fileEntries;
const Directory* topDir;
virtual string getFilePath() const = 0;
public:
DiskAdaptor(DiskWriter* diskWriter):diskWriter(diskWriter), topDir(NULL) {}
virtual ~DiskAdaptor() {
delete diskWriter;
if(topDir != NULL) {
delete topDir;
}
}
virtual void openFile();
virtual void closeFile();
virtual void openExistingFile();
virtual void initAndOpenFile();
void writeData(const char* data, int len, long long int position);
int readData(char* data, int len, long long int position);
string sha1Sum(long long int offset, long long int length);
virtual void onDownloadComplete() = 0;
void setFileEntries(const FileEntries& fileEntries) {
this->fileEntries = fileEntries;
}
FileEntry getFileEntryFromPath(const string& fileEntryPath) const;
bool addDownloadEntry(const string& fileEntryPath);
bool addDownloadEntry(int index);
void addAllDownloadEntry();
void removeAllDownloadEntry();
void setStoreDir(const string& storeDir) { this->storeDir = storeDir; }
string getStoreDir() const { return this->storeDir; }
void setTopDir(const Directory* dirctory) {
if(this->topDir != NULL) {
delete topDir;
}
this->topDir = dirctory;
}
const Directory* getTopDir() const { return this->topDir; }
};
#endif // _D_DISK_ADAPTOR_H_

56
src/MultiDiskAdaptor.cc Normal file
View File

@ -0,0 +1,56 @@
/* <!-- copyright */
/*
* aria2 - a simple utility for downloading files faster
*
* Copyright (C) 2006 Tatsuhiro Tsujikawa
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/* copyright --> */
#include "MultiDiskAdaptor.h"
MultiDiskAdaptor::MultiDiskAdaptor(MultiDiskWriter* diskWriter):DiskAdaptor(diskWriter) {}
MultiDiskAdaptor::~MultiDiskAdaptor() {}
void MultiDiskAdaptor::setDiskWriterFileEntries() {
((MultiDiskWriter*)diskWriter)->setFileEntries(fileEntries);
}
string MultiDiskAdaptor::getFilePath() const {
return storeDir;
}
void MultiDiskAdaptor::openFile() {
topDir->createDir(storeDir, true);
setDiskWriterFileEntries();
DiskAdaptor::openFile();
}
void MultiDiskAdaptor::initAndOpenFile() {
topDir->createDir(storeDir, true);
setDiskWriterFileEntries();
DiskAdaptor::initAndOpenFile();
}
void MultiDiskAdaptor::openExistingFile() {
setDiskWriterFileEntries();
DiskAdaptor::openExistingFile();
}
void MultiDiskAdaptor::onDownloadComplete() {
closeFile();
openFile();
}

43
src/MultiDiskAdaptor.h Normal file
View File

@ -0,0 +1,43 @@
/* <!-- copyright */
/*
* aria2 - a simple utility for downloading files faster
*
* Copyright (C) 2006 Tatsuhiro Tsujikawa
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/* copyright --> */
#ifndef _D_MULTI_DISK_ADAPTOR_H_
#define _D_MULTI_DISK_ADAPTOR_H_
#include "DiskAdaptor.h"
#include "MultiDiskWriter.h"
class MultiDiskAdaptor : public DiskAdaptor {
private:
void setDiskWriterFileEntries();
protected:
virtual string getFilePath() const;
public:
MultiDiskAdaptor(MultiDiskWriter* diskWriter);
virtual ~MultiDiskAdaptor();
virtual void openFile();
virtual void initAndOpenFile();
virtual void openExistingFile();
virtual void onDownloadComplete();
};
#endif // _D_MULTI_DISK_ADAPTOR_H_