⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fileio.cpp

📁 国外网络游戏 《The Kingdom of the Winds》 的服务端源码C+编写 有兴趣的可以
💻 CPP
字号:
// FileIO.cpp: implementation of the FileIO class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "Wox2Head.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

FileIO::FileIO()
{
	openings = 0;
}

FileIO::~FileIO()
{

}

//颇老捞 粮犁窍唱 眉农
int FileIO::checkok(char existfilename[])
{
	if(access(existfilename,0) == 0)
		return 1;
	else return NULL;
}

int FileIO::OpenFile(char filename[] , char mode[])
{
	if(checkok(filename) == NULL)
		return -1;
	else
	{
		t = fopen(filename,mode);
	}
	return 0;
}

int FileIO::CloseFile()
{
	if(ferror( t ) == NULL)
	{
		fclose(t);
	} else
	{
		return -1;
	}
	return 0;
}

void FileIO::ReadLine()
{
	int i=0;
	int c;
	char line_point[100];
	while ((c = fgetc(t)) != 10)
	{
		if (c!=13)
		{
			line_point[i]=c;
			i++;
		}
		if (feof(t))
		{
			printf("ERROR: readstring() unexpectedly reached EOF.\n");
			printf("There is an error at the end of you wox2.ini file.\n");
			exit(1);
		}
	}
	line_point[i]=0;

	memset(readed,0x00,sizeof(readed));
	memcpy(readed,line_point,i);
}

void FileIO::read2()
{
	int i;
	readscript();
	i=0;
	script1[0]=0;
	script2[0]=0;
	while(temp[i]!=0 && temp[i]!=' ' && temp[i]!='=')
	{
		i++;
	}
	strncpy(script1, temp, i);
	script1[i]=0;
	if (script1[0]!='}' && temp[i]!=0) strcpy(script2, temp+i+1);
	return;
}

void FileIO::read3()
{
	int i;
	readscript();
	i=0;
	memset(script1,0,sizeof(script1));
	memset(script2,0,sizeof(script2));
	memset(script3,0,sizeof(script3));
	script1[0]=0;
	script2[0]=0;
	script2[0]=0;
	while(temp[i]!=0 && temp[i]!=' ' && temp[i]!='=')
	{
		i++;
	}
	int k = i+1;
	while(temp[k]!=0 && temp[k]!=' ' && temp[k]!='=')
	{
		k++;
	}

	strncpy(script1, temp, i);
	script1[k]=0;
	if (script1[0]!='}' && temp[i]!=0) memcpy(script2, temp+i+1,k-i);
	if (script2[0]!='}' && temp[k]!=0) strcpy(script3, temp+k+1);
	return;
}


unsigned char FileIO::openscript(char *name)
{
	o=fopen(name,"r");
	if (o==NULL)
	{
		printf("ERROR: 颇老 '%s'阑 凯荐绝嚼聪促: %s\n", name, strerror(errno));
		Gv->ServerON=0;
		return 0xFF;
	}
	openings++;
	return 0;
}

void FileIO::closescript()
{
	if( o )
	{
		fclose(o);
		o = NULL;
	}
	openings--;
}

void FileIO::read1()
{
	readscript();
	strcpy(script1, temp);
}

void FileIO::readscript()
{
	if( o == NULL )
	{
		strcpy( temp, "EOF" );
		return;
	}
	int i, valid=0;
	char c;
	temp[0]=0;
	while(!valid)
	{
		i=0;
		if (feof(o))
		{
			strcpy( temp, "EOF" );
			return;
		}
		c=(char)fgetc(o);
		while (c!=10 && i < 1024)
		{
			if (c!=13)// && c!=0)
			{
				temp[i]=c;
				i++;
			}
			if (feof(o)) return;
			c=(char)fgetc(o);
			if( c == 9 ) c = 32;	// if we actually have a tab, then replace it with a space!
		}
		temp[i]=0;
		valid=1;
		if (temp[0]=='/' && temp[1]=='/') valid=0;
		if (temp[0]=='{') valid=0;
		if (temp[0]==0) valid=0;
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -