Raised This Month: $ Target: $400
 0% 

"Stats Backup", need help...


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
g4s
Junior Member
Join Date: May 2004
Location: Ca.
Old 05-12-2004 , 07:17   "Stats Backup", need help...
Reply With Quote #1

Hello
After several times of losing my stats data because of CS/Computer crash, I got an idea of making such a plugin that can make a backup of the csstats.dat. Here is the code:
Code:
#include <amxmodx>

new statsFile[] = "addons/amxx/custom/csstats.dat"
new backupFile[] = "addons/amxx/custom/csstats.bak"

public plugin_init() {
	register_plugin("Stats Backup", "0.1", "g4s")
	setBackup()
}

public backup() {
	if (file_size(statsFile, 0) > file_size(backupFile, 0)) {
		new statsdata[2048], statsline = 0, statssize = 0
		while((statsline = read_file(statsFile, statsline, statsdata, 2047, statssize)) != 0)
			write_file(backupFile, statsdata)
	}
}

setBackup()
	set_task(1200.0, "backup", 9128, "", 0, "b")
It simply checks the size of the two files every 20 minutes. If the size of csstats.dat gets bigger, then make a backup.

The problem here seems like that read_file and write_file do not work fine with those "square" characters. If the file contains only "abcd...1234...", this plugin works fine.

So is there any other way to copy those characters? Or is there another way to just make a copy of the file itself?

Any information would be greatly appreciated!
g4s is offline
Send a message via MSN to g4s
PM
hello, i am pm
Join Date: Jan 2004
Location: Canalization
Old 05-13-2004 , 07:18  
Reply With Quote #2

low-level file access. If there aren't C-like file access functions in the file.inc file, use the Low Level file access module... They should look like fopen, fclose, fread, ...
__________________
hello, i am pm
PM is offline
g4s
Junior Member
Join Date: May 2004
Location: Ca.
Old 05-13-2004 , 14:46  
Reply With Quote #3

Thanks for your reply, but I'm not so sure how to do that.

Do you mean that I should change read_file() and write_file() in both plugin script and file.inc to fread() and fwrite()?

If so, it does not work. It can be compiled, but I got "Function fread does not present" while loading.

Can you suggest a little bit more? Thanks.
g4s is offline
Send a message via MSN to g4s
BigBaller
Veteran Member
Join Date: Mar 2004
Location: Everett, WA
Old 05-13-2004 , 15:08  
Reply With Quote #4

What he is saying is go to the modules forum and get the "Low Level file access module" from the modules forum and use that for this plugin, meaning if people want to use your plugin they must also run this module.
__________________

BigBaller is offline
PM
hello, i am pm
Join Date: Jan 2004
Location: Canalization
Old 05-13-2004 , 15:44  
Reply With Quote #5

there will be low level file access routines integreted in AMXX core in 0.2.

Should work like this:
Code:
#define BUFSIZE 256 new file1 = fopen("filename", "rb");   // rb = read in binary mode new file2 = fopen("other_filename", "wb"); // wb = write in binary mode if (!file1 || !file2)     // error // get file size fseek(file1, 0, SEEK_END); new fileSize = ftell(file1); fseek(file1, 0, SEEK_SET); // copy new buffer[BUFSIZE]; new readSize = 0; for (i = 0; i < fileSize; i += BUFSIZE) {    readSize = fread(file1, buffer, BUFSIZE);    fwrite(file2, buffer, readSize); } if (file1)    fclose(file1); if (file2)    fclose(file2);

That could work (or maybe not )
__________________
hello, i am pm
PM is offline
g4s
Junior Member
Join Date: May 2004
Location: Ca.
Old 05-14-2004 , 07:18  
Reply With Quote #6

it does not work...

thank you anyways
g4s is offline
Send a message via MSN to g4s
SidLuke
Senior Member
Join Date: Mar 2004
Location: Poland, Chrzanow
Old 05-14-2004 , 08:05  
Reply With Quote #7

Quote:
there WILL BE low level file access routines integreted in AMXX core IN 0.2.
SidLuke is offline
Send a message via AIM to SidLuke Send a message via MSN to SidLuke
PM
hello, i am pm
Join Date: Jan 2004
Location: Canalization
Old 05-14-2004 , 08:25  
Reply With Quote #8

Make sure you have the Low Level File Access module if you don't have AMXX 0.2 (I doubt you do )
__________________
hello, i am pm
PM is offline
Reply


Thread Tools
Display Modes

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 07:40.


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