Raised This Month: $51 Target: $400
 12% 

Need help with file copy stock


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Potato Uno
Veteran Member
Join Date: Jan 2014
Location: Atlanta, Georgia
Old 09-25-2016 , 15:48   Need help with file copy stock
Reply With Quote #1

PHP Code:
stock bool CopyFile(const char[] Source, const char[] Destinationbool read_valve_fs=false)
{
    
Handle f OpenFile(Source"r"read_valve_fs);
    
Handle g OpenFile(Destination"w");
    
    
int Buffer[1024];
    while (!
IsEndOfFile(f))
    {
        
int Size ReadFile(fBuffersizeof(Buffer), 1);
        
WriteFile(gBufferSize1);
    }
    
    
delete f;
    
delete g;

Tried it with a bunch of MvM population files and the stock works correctly (use_valve_fs = false).

I tried it on a nav file from a VPK (read_valve_fs = true) and it didn't do the job properly, and I can't figure out why it doesn't work.

Test code: (don't criticize this code since it's a TEST.)

PHP Code:
public Action Trash(int iClientint nArgs)
{
    
char SrcPath[255], DstPath[255];
    
Format(SrcPathsizeof(SrcPath), "maps/cp_dustbowl.nav");
    
Format(DstPathsizeof(DstPath), "addons/sourcemod/configs/population/test/cp_dustbowl.nav");
    
CopyFile(SrcPathDstPathtrue);
    return 
Plugin_Handled;

File size of the nav in the vpk file: 1,170,989 bytes
File size of the copied nav file: 1,173,968 bytes

What's the deal with the 2979 byte discrepancy? What am I doing wrong?

If there is a better way to do this or a way to improve the stock, I am all ears for it. This has to work on all file types (including text files like .pop and binary files like .nav).

Last edited by Potato Uno; 09-25-2016 at 15:49.
Potato Uno is offline
Potato Uno
Veteran Member
Join Date: Jan 2014
Location: Atlanta, Georgia
Old 09-25-2016 , 16:25   Re: Need help with file copy stock
Reply With Quote #2

Oh, it's also causing the watchdog timer to kill it if I read from a VPK file. Is this a bug or an actual thing?
Potato Uno is offline
Impact123
Veteran Member
Join Date: Oct 2011
Location: Germany
Old 09-25-2016 , 16:42   Re: Need help with file copy stock
Reply With Quote #3

Try to open the files in binary mode like
PHP Code:
Handle f OpenFile(Source"rb"read_valve_fs); 
Here's some info about the watchdog in case that helps.
__________________

Last edited by Impact123; 09-25-2016 at 16:45.
Impact123 is offline
Potato Uno
Veteran Member
Join Date: Jan 2014
Location: Atlanta, Georgia
Old 09-25-2016 , 17:09   Re: Need help with file copy stock
Reply With Quote #4

That worked, thanks!

The watchdog timer is due to the fact that I read 1 byte at a time which caused the loop to run way too frequently. Changing it to 4 fixed the problem.

Last edited by Potato Uno; 09-25-2016 at 17:19.
Potato Uno is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 02:33.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode