[SOLVED]Percentage when copy a file...

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
ne0h
Posts: 386
Joined: Thu Feb 21, 2008 2:15 am

[SOLVED]Percentage when copy a file...

Post by ne0h »

I will show the percentage when a file is copying in this function:

int fileCopy(char* inSrc , char* inDest) {
SceUID tempSrc = sceIoOpen(inSrc, PSP_O_RDONLY, 0777);
if(!tempSrc){
printf("Error...\n");
}
SceUID tempDest = sceIoOpen(inDest, PSP_O_WRONLY | PSP_O_CREAT, 0777);
if(!tempDest) {
sceIoClose(tempSrc);
printf("Error...\n");
}

char tempData[1024];
int tempRead = sceIoRead(tempSrc, tempData, 1024);
int tempWritten;

while(tempRead > 0) {
tempWritten = sceIoWrite(tempDest, tempData, tempRead);
if(tempWritten != tempRead) {
sceIoClose(tempDest);
sceIoClose(tempSrc);
sceIoRemove(inDest);
printf("Error...\n");
}
tempRead = sceIoRead(tempSrc, tempData, 1024);

}

sceIoClose(tempDest);
sceIoClose(tempSrc);
return 1;
}

Have someone a solution?
Or how to get the file lenght?
I'll make a comparison between the read file and the file in writing to get
the current progress, it's possible?
Last edited by ne0h on Mon Mar 17, 2008 3:18 am, edited 1 time in total.
sakya
Posts: 190
Joined: Fri Apr 28, 2006 5:48 pm
Contact:

Re: Percentage when copy a file...

Post by sakya »

Hi! :)
ne0h wrote:Or how to get the file lenght?
You can use stat:

Code: Select all

#include <sys/stat.h>
struct stat stbuf;
if&#40;stat&#40;fileName, &stbuf&#41; == -1&#41;
   return -1;
fileSize = stbuf.st_size;
or move to 0 bytes from the end of the file:

Code: Select all

fd = sceIoOpen&#40;filename, PSP_O_RDONLY, 0777&#41;;
if &#40;fd < 0&#41;
   return -1;
fileSize = sceIoLseek32&#40;fd, 0, PSP_SEEK_END&#41;;
sceIoLseek32&#40;fd, 0, PSP_SEEK_SET&#41;;
Ciaooo
Sakya
Post Reply