diff options
author | Kirill Volinsky <mataes2007@gmail.com> | 2012-06-29 05:38:03 +0000 |
---|---|---|
committer | Kirill Volinsky <mataes2007@gmail.com> | 2012-06-29 05:38:03 +0000 |
commit | af7e438cfe8ce85e1da234318ed1584e89d952cc (patch) | |
tree | 4cdb1379ef8d6c00389aa89cfb27a404ae2aba56 /plugins/FTPFileYM/dbentry.cpp | |
parent | 230623d50baff4e8bf13a8572e0b895bad7b7ed4 (diff) |
only add some plugins and protocols, not adapted
See please maybe not all need us
git-svn-id: http://svn.miranda-ng.org/main/trunk@678 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/FTPFileYM/dbentry.cpp')
-rw-r--r-- | plugins/FTPFileYM/dbentry.cpp | 169 |
1 files changed, 169 insertions, 0 deletions
diff --git a/plugins/FTPFileYM/dbentry.cpp b/plugins/FTPFileYM/dbentry.cpp new file mode 100644 index 0000000000..cb11af1944 --- /dev/null +++ b/plugins/FTPFileYM/dbentry.cpp @@ -0,0 +1,169 @@ +/*
+FTP File YM plugin
+Copyright (C) 2007-2010 Jan Holub
+
+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 version 2
+of the License.
+
+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, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "dbentry.h"
+#include "options.h"
+
+int DBEntry::entryID;
+Mutex DBEntry::mutexDB;
+
+DBEntry::DBEntry()
+{ }
+
+DBEntry::DBEntry(DBEntry *entry)
+{
+ this->fileID = entry->fileID;
+ this->iFtpNum = entry->iFtpNum;
+ strcpy(this->szFileName, entry->szFileName);
+}
+
+DBEntry *DBEntry::getFirts()
+{
+ entryID = 0;
+ DBEntry *entry = new DBEntry();
+ return getNext(entry);
+}
+
+DBEntry *DBEntry::getNext(DBEntry *entry)
+{
+ char szValue[256];
+ int count = DB::getDword(0, MODULE_FILES, "NextFileID", 0);
+
+ for (; entryID < count; entryID++)
+ {
+ int ftpNum = DB::getByteF(0, MODULE_FILES, "Ftp%d", entryID, -1);
+ if (ftpNum != -1)
+ {
+ if (!DB::getAStringF(0, MODULE_FILES, "Filename%d", entryID, szValue))
+ {
+ entry->fileID = entryID;
+ entry->iFtpNum = ftpNum;
+ strcpy(entry->szFileName, szValue);
+ entry->deleteTS = DB::getDwordF(0, MODULE_FILES, "DeleteTS%d", entryID, 0);
+ entryID++;
+ return entry;
+ }
+ }
+ }
+
+ delete entry;
+ return NULL;
+}
+
+void DBEntry::cleanupDB()
+{
+ int count = 0;
+
+ DBEntry *entry = getFirts();
+ while (entry != NULL)
+ {
+ DB::setByteF(0, MODULE_FILES, "Ftp%d", count, entry->iFtpNum);
+ DB::setAStringF(0, MODULE_FILES, "Filename%d", count, entry->szFileName);
+ if (entry->deleteTS != 0)
+ DB::setDwordF(0, MODULE_FILES, "DeleteTS%d", count, entry->deleteTS);
+
+ count++;
+ entry = getNext(entry);
+ }
+
+ DB::setDword(0, MODULE_FILES, "NextFileID", count);
+}
+
+DBEntry *DBEntry::get(int fileID)
+{
+ char szValue[256];
+ DBEntry *entry = new DBEntry();
+
+ int ftpNum = DB::getByteF(0, MODULE_FILES, "Ftp%d", fileID, -1);
+ if (ftpNum != -1)
+ {
+ if (!DB::getAStringF(0, MODULE_FILES, "Filename%d", fileID, szValue))
+ {
+ entry->fileID = fileID;
+ entry->iFtpNum = ftpNum;
+ strcpy(entry->szFileName, szValue);
+ entry->deleteTS = DB::getDwordF(0, MODULE_FILES, "DeleteTS%d", fileID, 0);
+ return entry;
+ }
+ }
+
+ return NULL;
+}
+
+void DBEntry::remove(int fileID)
+{
+ DB::deleteSettingF(0, MODULE_FILES, "Ftp%d", fileID);
+ DB::deleteSettingF(0, MODULE_FILES, "Filename%d", fileID);
+ DB::deleteSettingF(0, MODULE_FILES, "DeleteTS%d", fileID);
+}
+
+bool DBEntry::entryExists(GenericJob *job)
+{
+ Lock *lock = new Lock(mutexDB);
+
+ DBEntry *entry = getFirts();
+ while (entry != NULL)
+ {
+ if (entry->iFtpNum == job->iFtpNum && !strcmp(entry->szFileName, job->szSafeFileName))
+ {
+ delete lock;
+ return true;
+ }
+ entry = getNext(entry);
+ }
+
+ delete lock;
+ return false;
+}
+
+void DBEntry::add(GenericJob *job)
+{
+ if (entryExists(job))
+ return;
+
+ Lock *lock = new Lock(mutexDB);
+ int id = DB::getDword(0, MODULE_FILES, "NextFileID", 0);
+ DB::setByteF(0, MODULE_FILES, "Ftp%d", id, job->iFtpNum);
+ DB::setAStringF(0, MODULE_FILES, "Filename%d", id, job->szSafeFileName);
+
+ if (job->tab->iOptAutoDelete != -1)
+ {
+ time_t deleteTS = time(NULL);
+ deleteTS += (job->tab->iOptAutoDelete * 60);
+ DB::setDwordF(0, MODULE_FILES, "DeleteTS%d", id, deleteTS);
+ }
+
+ DB::setDword(0, MODULE_FILES, "NextFileID", id + 1);
+ job->fileID = id;
+
+ delete lock;
+}
+
+void DBEntry::setDeleteTS(GenericJob *job)
+{
+ if (job->tab->iOptAutoDelete != -1)
+ {
+ time_t deleteTS = time(NULL);
+ deleteTS += (job->tab->iOptAutoDelete * 60);
+ DB::setDwordF(0, MODULE_FILES, "DeleteTS%d", job->fileID, deleteTS);
+ }
+ else
+ {
+ DB::deleteSettingF(0, MODULE_FILES, "DeleteTS%d", job->fileID);
+ }
+}
\ No newline at end of file |