Beispiel #1
0
    ///////////////////////////////////////////////////////////////////////
    // Function: CopyFile
    //
    //   Author: $author$
    //     Date: 2/21/2012
    ///////////////////////////////////////////////////////////////////////
    virtual EvError CopyFile
    (const char* chars,
     const char* chars2) 
    {
        EvError error = EV_ERROR_FAILED;
        int type;

        DBT("(const char* chars=\"%s\", const chars2=\"%s\")...\n", chars, chars2);

        if (EvFileSystemEntry::EV_TYPE_NONE
            < (type = m_targetEntry.Exists(chars2)))
        switch(type)
        {
        case EvFileSystemEntry::EV_TYPE_FILE:
            error = CopyFile2File(chars, chars2);
            break;
        case EvFileSystemEntry::EV_TYPE_DIRECTORY:
            break;
        }
        else error = CopyFile2File(chars, chars2);
        return error;
    }
Beispiel #2
0
void WriteUserData(char* said)
{
	if (!topicNumber)  return; //   no topics ever loaded or we are not responding

	char ptr[MAX_WORD_SIZE];
    sprintf(ptr,"USERS/topic_%s_%s.txt",loginID,computerID);
	char name[MAX_WORD_SIZE];
	sprintf(name,"USERS/fact_%s.txt",loginID);

	// Backup allows one to ":revert" for debugging - if you see a bad answer and revert, you can reenter your data while tracing...
	if (!server)
	{
		CopyFile2File("TMP/topics.tmp",ptr,false);	// make backup of current topic in single user mode- aids in debugging
		CopyFile2File("TMP/facts.tmp",name,false);	// make backup of current topic facts in single user mode- aids in debugging
	}
    FILE* out = fopen(ptr,"wb");

	if (!out) 
	{
#ifdef WIN32
		system("mkdir USERS");
#endif
		out = fopen(ptr,"wb");
		if (!out)
		{
			ReportBug("cannot open user state file %s to write\r\n",ptr);
			return;
		}
	}
	fprintf(out,"%s\n",saveVersion); // format validation stamp

    //   turn off  uservars and dump user vars values
    WriteTopicData(out);

    //   recently used messages
    unsigned int i;
	int start = humanSaidIndex - 20;
	if (start < 0) start = 0;
    for (i = start; i < humanSaidIndex; ++i)   fprintf(out,"%s\n",NLSafe(humanSaid[i]));    //   what he said indented 3
	fprintf(out,"#end usr\n");

 	start = chatbotSaidIndex - 20;
	if (start < 0) start = 0;
    for (i = start; i < chatbotSaidIndex; ++i) fprintf(out,"%s\n",NLSafe(chatbotSaid[i]));    //   what we replied indented 1
	fprintf(out,"#end bot\n");

    //   write out fact sets
	fprintf(out,"%x #sets flags\n",(unsigned int) setControl);
    for (i = 1; i < MAX_FIND_SETS; ++i) 
    {
		if (!(setControl & (uint64) (1 << i))) continue; // purely transient stuff

		//   remove dead references
		FACT** set = factSet[i];
        unsigned int count = (ulong_t) set[0];
		unsigned int j;
        for (j = 1; j <= count; ++j)
		{
			FACT* F = set[j];
			if (!F || F->properties & (TRANSIENTFACT | DEADFACT))
			{
				memcpy(&set[j],&set[j+1],sizeof(FACT*) * (count - j));
				--count;
				--j;
			}
		}
        if (!count) continue;
        fprintf(out,"Fact %d %d \r\n",i,count); //   set and count
        for (j = 1; j <= count; ++j)
		{
			char word[MAX_WORD_SIZE];
			fprintf(out,"%s\n",WriteFact(factSet[i][j],false,word));
		}
    }
    fclose(out);

	//   now write user facts, if any have changed. Otherwise file is valid as it stands.
	bool written = (factFree == userFactBase); 
 	while (factFree > topicFacts) 
	{
		// see if any facts are actually important and "new"
		if (!written && !(factFree->properties & (TRANSIENTFACT|DEADFACT))) 
		{
			WriteFacts(fopen(name,"wb"),topicFacts); // write facts from here on down
			written = true;
		}
		FreeFact(factFree--); //   erase new facts
	}

}