While attempting to use the CopyFile() function I have encountered a strange error. It will write neither of the files to my destination.
Here is the code. The section when I send files has been commented. Keep in mind this code is a rough draft so ignore the function definitions.
/*
BrowserFind.c
Version 0.2
07/29/09
LogicKills
*/
#include <stdio.h>
#include <windows.h>
#include <dirent.h>
char* getPath();
char* combineStrings(char* profile, char* path);
char** findProfile(char* path);
void copyagain();
int main()
{
int fileIndex;
char* fileLocation = getPath();
char* whereAmI = _getcwd(NULL,0);
char **files = findProfile(fileLocation);
char* filesToExport[3] = {"\\formhistory.sqlite","\\cookies.sqlite", "\\downloads.sqlite"};
char* profileName = files[2];
char* partPath = strncat(fileLocation,"\\",3);
char* pathWoutFile = strncat(fileLocation,profileName,strlen(profileName) + 1);
char* fullPathWithFile;
char* fullSendPath;
char* downloads = "\\downloads.sqlite";
char* cookies = "\\cookies.sqlite";
char* history = "\\formhistory.sqlite";
char* from1 = strncat(fileLocation,filesToExport[0],100);
char* send1 = strncat(whereAmI,filesToExport[0],100);
char* from2 = strncat(fileLocation,filesToExport[1],100);
char* send2 = strncat(whereAmI,filesToExport[1],100);
// ***** This is where I try to send the files *****
CopyFile(from1,send1,TRUE);
//Fails when I add two calls to CopyFile();
CopyFile(from2,send2,TRUE);
return 0;
}
char* getPath()
{
char* appPath;
char* usrPath;
char* fullPath;
char* drive = getenv("SYSTEMDRIVE");
char* user = getenv("USERNAME");
OSVERSIONINFO info;
info.dwOSVersionInfoSize = sizeof(info);
GetVersionEx(&info);
if (info.dwMajorVersion >= 6)
{
appPath = "\\AppData\\Roaming\\Mozilla\\Firefox\\Profiles";
usrPath = "\\Users\\";
}
else
{
appPath = "\\Application Data\\Mozilla\\Firefox\\Profiles";
usrPath = "\\Documents and Settings\\";
}
strncat(drive,usrPath,strlen(usrPath) + 1);
strncat(drive,user,strlen(user) + 1);
strncat(drive,appPath,strlen(appPath) + 1);
fullPath = drive;
return (fullPath);
}
char** findProfile(char* path)
{
DIR *dir = opendir (path);
struct dirent *dp;
size_t filecount = 0;
size_t i = 0;
char **files;
if (dir == NULL) {
return NULL;
}
while ((dp = readdir (dir)) != NULL) {
filecount++;
}
files = (char **) malloc (filecount * sizeof (*files));
if (files == NULL) {
return NULL;
}
rewinddir (dir);
while ((dp = readdir (dir)) != NULL) {
files[i] = strdup (dp->d_name);
if (files[i] == NULL) {
while (i > 0) {
free (files[--i]);
}
free (files);
return NULL;
}
i++;
}
closedir (dir);
return files;
}