summaryrefslogtreecommitdiff
path: root/src/file.cc
diff options
context:
space:
mode:
authordeva <deva>2005-10-18 14:04:41 +0000
committerdeva <deva>2005-10-18 14:04:41 +0000
commit9b2dd6e5ddd10e9beee061f3d1a25f047d80d290 (patch)
tree6dd302ebea1b40610fc7ebb9d3399e5ca360a153 /src/file.cc
parentc7ea90681bf4df1e8ba26e50bc065d26f24ce6b9 (diff)
*** empty log message ***
Diffstat (limited to 'src/file.cc')
-rw-r--r--src/file.cc135
1 files changed, 34 insertions, 101 deletions
diff --git a/src/file.cc b/src/file.cc
index f3c0cbc..3a59334 100644
--- a/src/file.cc
+++ b/src/file.cc
@@ -27,12 +27,16 @@
#include <config.h>
#include "file.h"
+#include "miav_config.h"
+
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
#include <unistd.h>
+#include <errno.h>
+
// For ntoh*
#include <netinet/in.h>
@@ -77,6 +81,9 @@ File::~File()
info->info("[%s]", filelist[cnt].c_str());
}
+ std::string *trash = config->readString("server_trash");
+ std::string *later = config->readString("server_later");
+
switch(savestate) {
case NO_CHANGE:
info->warn("File had no savestate!");
@@ -88,16 +95,12 @@ File::~File()
case DELETE:
info->info("Files in this session is to be deleted (moved to trash).");
- for(unsigned int cnt = 0; cnt < filelist.size(); cnt ++) {
- // TODO: Move file filelist[cnt] to trash
- }
+ Move((char*)trash->c_str());
break;
case LATER:
info->info("Files in this session is stored for later decisson.");
- for(unsigned int cnt = 0; cnt < filelist.size(); cnt ++) {
- // TODO: Move file filelist[cnt] to the later folder.
- }
+ Move((char*)later->c_str());
break;
}
@@ -105,6 +108,28 @@ File::~File()
delete extension;
}
+int File::Move(char *destination)
+{
+ char newfile[256];
+ char filename[256];
+
+ createPath(destination);
+ for(unsigned int cnt = 0; cnt < filelist.size(); cnt ++) {
+ // TODO: Check is the file exists... if not make som noise!
+
+
+ // TODO: Move file filelist[cnt] to the destination folder.
+ strcpy(filename, (char*)filelist[cnt].c_str());
+ sprintf(newfile, "%s%s", destination, strrchr(filename, '/'));
+ if(rename((char*)filelist[cnt].c_str(), newfile) == -1)
+ info->error("Error moving file %s to %s:",
+ (char*)filelist[cnt].c_str(),
+ newfile,
+ strerror(errno));
+ }
+ return 0;
+}
+
int File::Open()
{
char fname[256];
@@ -162,100 +187,7 @@ int File::Write(void* data, int size)
return w;
}
-/*
-int File::Write(char* data, int size)
-{
- return Write((void*)data, size);
-}
-
-int File::Write(unsigned long long int val)
-{
- int res;
- int written = 0;
- unsigned long int *h_u = (unsigned long int *)&val;
- unsigned long int *h_l = (unsigned long int *)(((char*)&val) + sizeof(unsigned long int));
-
- *h_u = htonl(*h_u);
- *h_l = htonl(*h_l);
-
- if((res = Write((void*)h_l, sizeof(*h_l))) < 0) {
- return res;
- }
- written += res;
-
- if((res = Write((void*)h_u, sizeof(*h_u))) < 0) {
- return res;
- }
- written += res;
-
- return written;
-}
-
-int File::Write(long long int val)
-{
- int res;
- int written = 0;
- unsigned long int *h_u = (unsigned long int *)&val;
- unsigned long int *h_l = (unsigned long int *)(((char*)&val) + sizeof(unsigned long int));
-
- *h_u = htonl(*h_u);
- *h_l = htonl(*h_l);
-
- if((res = Write((void*)h_l, sizeof(*h_l))) < 0) {
- return res;
- }
- written += res;
-
- if((res = Write((void*)h_u, sizeof(*h_u))) < 0) {
- return res;
- }
- written += res;
-
- return written;
-}
-
-int File::Write(long int val)
-{
- val = htonl(val);
-
- return Write((char*)&val, sizeof(val));
-}
-
-int File::Write(unsigned long int val)
-{
- val = htonl(val);
-
- return Write((char*)&val, sizeof(val));
-}
-
-int File::Write(int val)
-{
- val = htonl(val);
-
- return Write((char*)&val, sizeof(val));
-}
-
-int File::Write(unsigned int val)
-{
- val = htonl(val);
-
- return Write((char*)&val, sizeof(val));
-}
-int File::Write(short int val)
-{
- val = htons(val);
-
- return Write((char*)&val, sizeof(val));
-}
-
-int File::Write(unsigned short int val)
-{
- val = htons(val);
-
- return Write((char*)&val, sizeof(val));
-}
-*/
int File::createPath(char* path)
{
// struct stat stats;
@@ -281,9 +213,10 @@ int File::createPath(char* path)
return 0;
}
-void File::setSaveState(n_savestate savestate)
+void File::setSaveState(n_savestate s)
{
- this->savestate = savestate;
+ savestate = s;
+ info->info("SETTING SAVESTATE TO: %d", savestate);
}
#ifdef __TEST_FILE