|
|
| Author |
Message |
|
|
Arlanthir
Joined: 14 Jan 2008 Posts: 4
|
Posted: Mon Jan 14, 2008 1:51 pm Post subject: [Solved] How to copy file with C and GTK+2.0? |
|
|
Hi.
I'm doing a little PSP managing utility (along the lines of qpspmanager, for those who know it) using GTK with C.
I'm in a part where I need to copy files from the PC to the PSP (not local, then) and, if possible, show a little progress bar.
Thing is, the only way I can copy the files is using a system call to exec cp. I've tried the copy char by char variant with no success, it works fine for files in the desktop but once you do that to a PSP with files over 1GB it's not *that* productive.
I was wondering if someone here knew a better way to do this, like nautilus does, exactly.
Another doubt I have is how can I see the total or free space (any, or both, will do) in a given dir/drive with a C function?
Thank you very very much!
Last edited by Arlanthir on Wed Feb 27, 2008 12:05 am; edited 1 time in total |
|
| Back to top |
|
 |
Basile S. Familiar Face
Joined: 04 Jan 2008 Posts: 10 Location: France (92340 Bourg La Reine)
|
Posted: Mon Jan 14, 2008 7:03 pm Post subject: |
|
|
To copy a file with visual feedback in a progress bar, you could perhaps use an idle routine which copies a chunk of it (perhaps 1Kbyte), and then update the progress bar and eventually is called again (by GTK loop) ....
To get the total or free space is probably OS specific.but I suggest using the g_stat wrapper to the stat (POSIX) function
I am not sure that asking for free space on a given drive makes any sense. I don't know Windows, but POSIX systems do not have any drive notion.
Maybe you want the statfs system call or an equivalent to ask about s filesystem. |
|
| Back to top |
|
 |
Arlanthir
Joined: 14 Jan 2008 Posts: 4
|
Posted: Mon Jan 14, 2008 8:15 pm Post subject: |
|
|
I tried the copy char by char method but it doesn't seem to work very efficiently. I'd really like to know how nautilus does it =/
Regarding the free space, maybe drive was a bad choice of word.
Partition size is better, I think. I think nautilus shows the free space in the current folder (read: free space in partition where folder is) in the bottom of the screen.
I'd like to point out I'm doing this in Linux (Ubuntu) and have no intention of porting it to Windows.
Again, Thank you! |
|
| Back to top |
|
 |
Basile S. Familiar Face
Joined: 04 Jan 2008 Posts: 10 Location: France (92340 Bourg La Reine)
|
Posted: Tue Jan 15, 2008 6:50 am Post subject: |
|
|
| Arlanthir wrote: | | I tried the copy char by char method but it doesn't seem to work very efficiently. |
char by char copy is really inefficient (just because of the overhead of every system call). You really should buffer it, and I suggested kilobytes by kilobytes copy. Maybe a 4Kb or 16Kb buffer is better than a 1Kb one but you really should avoid copying one byte per one byte.
| Arlanthir wrote: | | I think nautilus shows the free space in the current folder (read: free space in partition where folder is) in the bottom of the screen. |
You can get the information with the stat(2) and statfs(2) system calls. RTFM, so look at the output of | Code: (Plaintext) | 1 2
| man 2 stat
man 2 statfs | |
|
| Back to top |
|
 |
Arlanthir
Joined: 14 Jan 2008 Posts: 4
|
Posted: Tue Jan 15, 2008 10:45 am Post subject: |
|
|
I get it ;)
Will try, thank you once more! |
|
| Back to top |
|
 |
Arlanthir
Joined: 14 Jan 2008 Posts: 4
|
Posted: Wed Feb 27, 2008 12:04 am Post subject: |
|
|
Just summing up: All went good from there, everything working as it should now ;)
Thank you very much. |
|
| Back to top |
|
 |
|