mirror of
https://github.com/rvtr/GodMode9i.git
synced 2025-11-02 00:11:07 -04:00
Fix deleting file when copying to same dir and add recursive copying (#13)
* Fix deleting file when copying to same dir and add recursive copying FIX: Deletes file when copying to same dir ADD: Recursive copying (copy files and dirs within dirs) (also undoes disabling copying folders) * Derp fix * Derp fix (with undoing disabling folder copying)
This commit is contained in:
parent
a97bfd5430
commit
9651648836
@ -1,5 +1,12 @@
|
||||
#include "fileOperations.h"
|
||||
#include <nds.h>
|
||||
#include <stdio.h>
|
||||
#include <dirent.h>
|
||||
#include <vector>
|
||||
|
||||
#include "file_browse.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
#define copyBufSize 0x8000
|
||||
|
||||
@ -26,8 +33,36 @@ off_t getFileSize(const char *fileName)
|
||||
return fsize;
|
||||
}
|
||||
|
||||
void dirCopy(DirEntry* entry, int i, const char *destinationPath, const char *sourcePath) {
|
||||
vector<DirEntry> dirContents;
|
||||
dirContents.clear();
|
||||
if (entry->isDirectory) chdir((sourcePath + ("/" + entry->name)).c_str());
|
||||
getDirectoryContents(dirContents);
|
||||
if (((int)dirContents.size()) == 1) mkdir((destinationPath + ("/" + entry->name)).c_str(), 0777);
|
||||
if (((int)dirContents.size()) != 1) fcopy((sourcePath + ("/" + entry->name)).c_str(), (destinationPath + ("/" + entry->name)).c_str());
|
||||
}
|
||||
|
||||
int fcopy(const char *sourcePath, const char *destinationPath)
|
||||
{
|
||||
DIR *isDir = opendir (sourcePath);
|
||||
|
||||
if (isDir != NULL) {
|
||||
chdir(sourcePath);
|
||||
vector<DirEntry> dirContents;
|
||||
getDirectoryContents(dirContents);
|
||||
DirEntry* entry = &dirContents.at(1);
|
||||
|
||||
mkdir(destinationPath, 0777);
|
||||
for (int i = 1; i < ((int)dirContents.size()); i++) {
|
||||
chdir(sourcePath);
|
||||
entry = &dirContents.at(i);
|
||||
dirCopy(entry, i, destinationPath, sourcePath);
|
||||
}
|
||||
|
||||
chdir (destinationPath);
|
||||
chdir ("..");
|
||||
return 1;
|
||||
} else {
|
||||
FILE* sourceFile = fopen(sourcePath, "rb");
|
||||
off_t fsize = 0;
|
||||
if (sourceFile) {
|
||||
@ -84,3 +119,5 @@ int fcopy(const char *sourcePath, const char *destinationPath)
|
||||
|
||||
return -1;
|
||||
}
|
||||
closedir(isDir);
|
||||
}
|
||||
|
||||
@ -1,3 +1,5 @@
|
||||
#include <nds.h>
|
||||
|
||||
#ifndef FILE_COPY
|
||||
#define FILE_COPY
|
||||
|
||||
|
||||
@ -49,13 +49,6 @@ using namespace std;
|
||||
|
||||
static char path[PATH_MAX];
|
||||
|
||||
struct DirEntry {
|
||||
string name;
|
||||
off_t size;
|
||||
bool isDirectory;
|
||||
bool isApp;
|
||||
} ;
|
||||
|
||||
bool nameEndsWith (const string& name) {
|
||||
|
||||
if (name.size() == 0) return false;
|
||||
@ -594,7 +587,7 @@ string browseForFile (void) {
|
||||
getDirectoryContents (dirContents);
|
||||
}
|
||||
}
|
||||
} else if ((strcmp(entry->name.c_str(), "..") != 0) && !entry->isDirectory) {
|
||||
} else if (strcmp(entry->name.c_str(), "..") != 0) {
|
||||
snprintf(clipboard, sizeof(clipboard), "%s%s", path, entry->name.c_str());
|
||||
snprintf(clipboardFilename, sizeof(clipboardFilename), "%s", entry->name.c_str());
|
||||
clipboardOn = true;
|
||||
|
||||
@ -25,7 +25,17 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
using namespace std;
|
||||
|
||||
struct DirEntry {
|
||||
string name;
|
||||
off_t size;
|
||||
bool isDirectory;
|
||||
bool isApp;
|
||||
} ;
|
||||
|
||||
std::string browseForFile (void);
|
||||
void getDirectoryContents (vector<DirEntry>& dirContents);
|
||||
|
||||
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user