From d81c884cea9b4451cdfa149bd67519df8f8df74e Mon Sep 17 00:00:00 2001 From: ac-stef Date: Mon, 19 May 2014 18:48:54 +0200 Subject: [PATCH] removed now redundant code and substituted "copy file and delete original" with "move file" --- source/src/client.cpp | 3 +-- source/src/stream.cpp | 32 -------------------------------- source/src/tools.h | 2 -- source/src/zip.cpp | 1 - 4 files changed, 1 insertion(+), 37 deletions(-) diff --git a/source/src/client.cpp b/source/src/client.cpp index af5267d4..05fb12df 100644 --- a/source/src/client.cpp +++ b/source/src/client.cpp @@ -1012,9 +1012,8 @@ int processdownload(package *pck) case PCK_TEXTURE: case PCK_AUDIO: { const char *pckname = findfile(path(pck->name, true), "w+"); - preparedir(pckname); // with textures/sounds, the image/audio file itself is sent. Just need to copy it from the temporary file - if(!copyfile(tmpname, pckname)) conoutf(_("\f3failed to install"), pckname); + if(rename(tmpname, pckname)) conoutf(_("\f3failed to install"), pckname); break; } diff --git a/source/src/stream.cpp b/source/src/stream.cpp index d05126a2..2e890a11 100644 --- a/source/src/stream.cpp +++ b/source/src/stream.cpp @@ -306,38 +306,6 @@ bool delfile(const char *path) return !remove(path); } -bool copyfile(const char *source, const char *destination) -{ - FILE *from = fopen(source, "rb"); - FILE *dest = fopen(destination, "wb"); - - if(!from || !dest) return false; - size_t len; - uchar buf[1024]; - while((len = fread(&buf, sizeof(uchar), 1024, from))) - { - fwrite(&buf, sizeof(uchar), len, dest); - } - fclose(from); - fclose(dest); - return true; -} - -bool preparedir(const char *destination) -{ - string dir; - copystring(dir, parentdir(destination)); - vector dirs; - while(*dir && !fileexists(dir, "r")) - { - dirs.add(newstring(dir)); - copystring(dir, parentdir(dir)); - } - - loopvrev(dirs) if(!createdir(dirs[i])) return false; - return true; -} - #ifndef STANDALONE static int rwopsseek(SDL_RWops *rw, int offset, int whence) { diff --git a/source/src/tools.h b/source/src/tools.h index e7186c15..35de88bf 100644 --- a/source/src/tools.h +++ b/source/src/tools.h @@ -949,8 +949,6 @@ extern bool listdir(const char *dir, const char *ext, vector &files); extern int listfiles(const char *dir, const char *ext, vector &files); extern int listzipfiles(const char *dir, const char *ext, vector &files); extern bool delfile(const char *path); -extern bool copyfile(const char *source, const char *destination); -extern bool preparedir(const char *destination); extern bool addzip(const char *name, const char *mount = NULL, const char *strip = NULL, bool extract = false, int type = -1); extern bool removezip(const char *name); extern struct mapstats *loadmapstats(const char *filename, bool getlayout); diff --git a/source/src/zip.cpp b/source/src/zip.cpp index 0b85cc57..76aacce5 100644 --- a/source/src/zip.cpp +++ b/source/src/zip.cpp @@ -552,7 +552,6 @@ bool extractzipfile(ziparchive *a, zipfile *f, const char *name) zipstream *s = new zipstream; FILE *target = NULL; defformatstring(fname)("%s", findfile(name, "wb")); - preparedir(fname); bool error = false; if(s->open(a, f) && (target = fopen(fname, "wb"))) {