Ejemplo n.º 1
0
	ReaderItem(StorageItem *Item)
	{
		Len = 0;
		Data = 0;
		Store = Item;
		Store->Object = this;

		GFile *f = Store->GotoObject(__FILE__, __LINE__);
		if (f)
		{
			Len = ((Storage1::StorageItemImpl*)Store)->StoreSize;
			if (Len <= 0)
			{
				Len = ((Storage1::StorageItemImpl*)Store)->StoreAllocatedSize;
			}

			LgiAssert(Len > 0);

			Data = new uchar[Len];
			if (Data)
			{
				f->Read(Data, Len);
			}
			
			DeleteObj(f);
		}
	}
Ejemplo n.º 2
0
GDocApp<OptionsFmt>::GDocApp(const char *appname, const TCHAR *icon, char *optsname)
{
	Options = 0;
	_LangOptsName = 0;
	d = new GDocAppPrivate(this, optsname);
	
	GRect r(0, 0, 800, 600);
	SetPos(r);
	MoveToCenter();
	_FileMenu = 0;
	d->AppName = NewStr(appname?appname:(char*)"Lgi.GDocApp");

	char p[MAX_PATH];
	if (LgiGetSystemPath(LSP_APP_INSTALL, p, sizeof(p)))
	{
		LgiMakePath(p, sizeof(p), p, "_write_test.txt");
		GFile f;
		if (!f.Open(p, O_WRITE))
		{
			d->Mode = InstallDesktop;
		}
		else
		{
			f.Close();
			FileDev->Delete(p, false);
		}
	}

	SetQuitOnClose(true);

	// Setup class
	if (icon)
	{
		#if defined WIN32
		GWin32Class *c = GWin32Class::Create(d->AppName);
		if (c)
		{
			#ifdef UNICODE
			GPointer p;
			p.w = (TCHAR*)icon;
			if (p.i < 0x10000)
			{
				c->Class.hIcon = LoadIcon(LgiProcessInst(), MAKEINTRESOURCE(icon));
			}
			else
			{
				GAutoWString wIcon(NewStrW(icon));
				c->Class.hIcon = LoadIcon(LgiProcessInst(), wIcon);
			}
			#else
			c->Class.hIcon = LoadIcon(LgiProcessInst(), ((NativeInt)icon&0xffff0000)?icon:MAKEINTRESOURCE(icon));
			#endif
		}
		#else
		if (icon)
			SetIcon(icon);
		#endif
	}
}
Ejemplo n.º 3
0
	bool Load(char *File)
	{
		bool Status = false;

		Langs.Empty();
		DeleteObj(Tree);
		Tree = new GXmlTag;
		if (Tree)
		{
			if (File)
			{
				GFile f;
				if (f.Open(File, O_READ))
				{
					GXmlTree t(GXT_NO_ENTITIES);
					if (t.Read(Tree, &f, 0))
					{
						CollectLangs(Tree);

						List<GLanguage> Lst;
						const char *Key = 0;
						for (bool p = Langs.First(&Key); p; p = Langs.Next(&Key))
						{
							Lst.Insert((GLanguage*)p);
						}
						Lst.Sort(Cmp, 0);

						for (GLanguage *l = Lst.First(); l; l = Lst.Next())
						{
							Inc->Insert(new LangInc(l));
						}

						Status = true;
					}
					else
					{
						LgiMsg(this, "Couldn't parse XML.", AppName);
					}
				}
				else
				{
					LgiMsg(this, "Couldn't open '%s'\n", AppName, MB_OK, File);
				}
			}
			else
			{
				LgiMsg(this, "No file.", AppName);
			}
		}

		return Status;
	}
Ejemplo n.º 4
0
	bool SerializeOpts(ObjProperties *p, bool Write)
	{
		bool Status = false;
		if (p)
		{
			GFile f;
			if (f.Open(OptionsFile, Write?O_WRITE:O_READ))
			{
				if (Write)
					f.SetSize(0);

				Status = p->Serialize(f, Write);
			}
		}
		return Status;
	}
Ejemplo n.º 5
0
	bool Serialize(GFile &f, bool Write)
	{
		if (Data && Write)
		{
			f.Write(Data->Data, Data->Len);
			return true;
		}

		return false;
	}
Ejemplo n.º 6
0
/*
====================
GLoad
====================
*/
const GData* GLoad(const CHAR* path)
{
	GFile file;
	CHECK(file.Open(path));
	U32 pos = file.Tell();
	file.Seek(0,2);
	U32 size = file.Tell();
	file.Seek(pos,0);
	GData* data = GNEW(GData(size+1,0)); CHECK(data);
	CHECK(file.Read(data->Ptr(),data->Size())==size);
	file.Close();
	return data;
}
Ejemplo n.º 7
0
	bool Save(char *File)
	{
		bool Status = false;

		if (Tree AND Inc)
		{
			if (Langs.Length())
			{
				// scan tree, removing the languages we don't want
				RemoveLangs(Tree);

				// write the remaining tree out to a file...
				GFile f;
				if (f.Open(File, O_WRITE))
				{
					f.SetSize(0);

					GXmlTree t(GXT_NO_ENTITIES | GXT_NO_PRETTY_WHITESPACE);
					if (t.Write(Tree, &f))
					{
						Status = true;
					}
					else
					{
						LgiMsg(this, "XML output failed.", AppName);
					}
				}
				else
				{
					LgiMsg(this, "Couldn't open '%s'.", AppName, MB_OK, File);
				}
			}
			else
			{
				LgiMsg(this, "No languages selected.", AppName);
			}
		}

		return Status;
	}
Ejemplo n.º 8
0
void MDeadMatch::CreateFileList()
{
	const char* maps_path = locate_file("deathmaps.txt");
	if ( maps_path == NULL) return;
	ifstream f(maps_path);

	string s;
	while (f && !f.bad() && !f.eof() && f >> s)
	{
		st_map map;
		GFile gfile;
		gfile.LoadMap(&map, s);
		if (map.deadmach && m_files < MAX_FILES) {
			m_filelist[m_files].file = s;
			m_filelist[m_files].pozadi = map.podklad;
			m_files++;
		}
	}
		
	
/*
   CFileFind finder;
	GFile     gfile;
	st_map    map;

   BOOL bWorking = finder.FindFile("*.ble");
   while (bWorking)
   {
      bWorking = finder.FindNextFile();
		gfile.LoadMap(&map, finder.GetFileName());
		if (map.deadmach) {
			m_filelist[m_files].file = finder.GetFileName();
			m_filelist[m_files].pozadi = map.podklad;
			m_files++;
		}
   }
   */
}
Ejemplo n.º 9
0
int
main (int argc, char * argv[])
{
    setbuf(stdout, NULL);   // Make stdout unbuffered.

    gameNumberT gNumber;

    bool option_ForceReplace = false;
    bool option_PreGameComments = true;

    uint pgnFileSize = 0;
    char *progname = argv[0];
    fileNameT fname;
    fileNameT baseName;
    uint argsleft = argc - 1;
    char ** nextArg = argv + 1;

    // Parse command-line argments:
    while (argsleft > 0  &&  nextArg[0][0] == '-') {
        if (! strCompare (*nextArg, "-f")) {
            option_ForceReplace = true;
        } else if (! strCompare (*nextArg, "-x")) {
            option_PreGameComments = false;
        } else {
            usage (progname);
        }
        argsleft--;
        nextArg++;
    }
    if (argsleft != 1  &&  argsleft != 2) {
        usage (progname);
    }

    char * pgnName = *nextArg;
    MFile pgnFile;

    pgnFileSize = fileSize (pgnName, "");

    // Ensure positive file size counter to avoid division by zero:
    if (pgnFileSize < 1) {
        pgnFileSize = 1;
    }

    // Make baseName from pgnName if baseName is not provided:
    if (argsleft == 1) {
        strCopy (baseName, pgnName);
        // If a gzip file, remove two suffixes, the first being ".gz":
        const char * lastSuffix = strFileSuffix (baseName);
        if (lastSuffix != NULL  &&  strEqual (lastSuffix, GZIP_SUFFIX)) {
            strTrimFileSuffix (baseName);
        }
        // Trim the ".pgn" suffix:
        strTrimFileSuffix (baseName);
    } else {
        strCopy (baseName, nextArg[1]);
    }

    // Check for existing database, avoid overwriting it:
    if (! option_ForceReplace) {
        if (fileSize (baseName, INDEX_SUFFIX) > 0) {
            // Scid index file already exists:
            fprintf (stderr, "%s: database already exists: %s\n", progname,
                     baseName);
            fprintf (stderr, "You can use:  %s -f %s   to overwrite"
                     " the existing database.\n", progname, pgnName);
            exit(1);
        }
    }

    if (pgnFile.Open (pgnName, FMODE_ReadOnly) != OK) {
        fprintf (stderr, "%s: could not open file %s\n", progname, pgnName);
        exit(1);
    }

    // Try opening the log file:
    strCopy (fname, baseName);
    strAppend (fname, ".err");
    FILE * logFile = fopen (fname, "w");
    if (logFile == NULL) {
        fprintf (stderr, "%s: could not open log file: %s\n", progname, fname);
        exit(1);
    }

    printf ("Converting file %s to Scid database %s:\n", pgnName, baseName);
    printf ("Errors/warnings will be written to %s.\n\n", fname);

    scid_Init();

    GFile * gameFile = new GFile;
    if ((gameFile->Create (baseName, FMODE_WriteOnly)) != OK) {
        fprintf (stderr, "%s: could not create the file %s%s\n",
                 progname, baseName, GFILE_SUFFIX);
        fprintf (stderr, "The file may already exist and be read-only, or\n");
        fprintf (stderr, "you may not have permission to create this file.\n");
        exit(1);
    }

    NameBase * nb = new NameBase;
    Index * idx = new Index;
    IndexEntry * ie = new IndexEntry;
    idx->SetFileName (baseName);
    idx->CreateIndexFile (FMODE_WriteOnly);

    Game * game = new Game;
    ProgBar progBar(stdout);
    progBar.Start();

    ByteBuffer *bbuf = new ByteBuffer;
    bbuf->SetBufferSize (BBUF_SIZE); // 32768

    PgnParser pgnParser (&pgnFile);
    pgnParser.SetErrorFile (logFile);
    pgnParser.SetPreGameText (option_PreGameComments);

    // TODO: Add command line option for ignored tags, rather than
    //       just hardcoding PlyCount as the only ignored tag.
    pgnParser.AddIgnoredTag ("PlyCount");

    // Add each game found to the database:
    while (pgnParser.ParseGame(game) != ERROR_NotFound) {
        ie->Init();

        if (idx->AddGame (&gNumber, ie) != OK) {
            fprintf (stderr, "\nLimit of %d games reached!\n", MAX_GAMES);
            exit(1);
        }

        // Add the names to the namebase:
        idNumberT id = 0;

        if (nb->AddName (NAME_PLAYER, game->GetWhiteStr(), &id) != OK) {
            fatalNameError (NAME_PLAYER);
        }
        nb->IncFrequency (NAME_PLAYER, id, 1);
        ie->SetWhite (id);

        if (nb->AddName (NAME_PLAYER, game->GetBlackStr(), &id) != OK) {
            fatalNameError (NAME_PLAYER);
        }
        nb->IncFrequency (NAME_PLAYER, id, 1);
        ie->SetBlack (id);

        if (nb->AddName (NAME_EVENT, game->GetEventStr(), &id) != OK) {
            fatalNameError (NAME_EVENT);
        }
        nb->IncFrequency (NAME_EVENT, id, 1);
        ie->SetEvent (id);

        if (nb->AddName (NAME_SITE, game->GetSiteStr(), &id) != OK) {
            fatalNameError (NAME_SITE);
        }
        nb->IncFrequency (NAME_SITE, id, 1);
        ie->SetSite (id);

        if (nb->AddName (NAME_ROUND, game->GetRoundStr(), &id) != OK) {
            fatalNameError (NAME_ROUND);
        }
        nb->IncFrequency (NAME_ROUND, id, 1);
        ie->SetRound (id);

        bbuf->Empty();
        if (game->Encode (bbuf, ie) != OK) {
            fprintf (stderr, "Fatal error encoding game!\n");
            abort();
        }
        uint offset = 0;
        if (gameFile->AddGame (bbuf, &offset) != OK) {
            fprintf (stderr, "Fatal error writing game file!\n");
            abort();
        }
        ie->SetOffset (offset);
        ie->SetLength (bbuf->GetByteCount());
        idx->WriteEntries (ie, gNumber, 1);

        // Update the progress bar:
        if (! (gNumber % 100)) {
            int bytesSeen = pgnParser.BytesUsed();
            int percentDone = 1 + ((bytesSeen) * 100 / pgnFileSize);
            progBar.Update (percentDone);
        }

    }

    uint t = 0;   // = time(0);
    nb->SetTimeStamp(t);
    nb->SetFileName (baseName);
    if (nb->WriteNameFile() != OK) {
        fprintf (stderr, "Fatal error writing name file!\n");
        exit(1);
    }
    progBar.Finish();

    printf ("\nDatabase `%s': %d games, %d players, %d events, %d sites.\n",
            baseName, idx->GetNumGames(), nb->GetNumNames (NAME_PLAYER),
            nb->GetNumNames (NAME_EVENT), nb->GetNumNames (NAME_SITE));
    fclose (logFile);
    if (pgnParser.ErrorCount() > 0) {
        printf ("There were %u errors or warnings; ", pgnParser.ErrorCount());
        printf ("examine the file \"%s.err\"\n", baseName);
    } else {
        printf ("There were no warnings or errors.\n");
        removeFile (baseName, ".err");
    }
    gameFile->Close();
    idx->CloseIndexFile();

    // If there is a tree cache file for this database, it is out of date:
    removeFile (baseName, TREEFILE_SUFFIX);
#ifdef ASSERTIONS
    printf("%d asserts were tested\n", numAsserts);
#endif
    return 0;
}
Ejemplo n.º 10
0
/*
====================
Save
====================
*/
VOID EChunk::Save(GFile& file)
{
	GUARD(EChunk::Save);

	// write the chunk header
	U32 header = MAKEFOURCC('G','C','H','K');
	file.Write(&header, sizeof(U32));

	// write the number of layers
	U32 num_layer = mLayers.size();
	file.Write(&num_layer, sizeof(U32));

	// write all of the layers
	if(mLayers.size() == 1)
	{
		Layer& layer = mLayers[0];

		// write the texture
		U32 name_len = layer.name.size();
		file.Write(&name_len, sizeof(U32));
		file.Write(layer.name.c_str(), name_len*sizeof(CHAR));
		file.Write(layer.st.ptr(), 2*sizeof(F32));

		// write the alpha
		U32 width = 1;
		file.Write(&width, sizeof(U32));
		U32 height = 1;
		file.Write(&height, sizeof(U32));
		U8 alpha = 127;
		file.Write(&alpha, sizeof(U8));
	}
	else
	{
		for(I32 k = 0; k < mLayers.size(); k++)
		{
			Layer& layer = mLayers[k];

			// write the texture
			U32 name_len = layer.name.size();
			file.Write(&name_len, sizeof(U32));
			file.Write(layer.name.c_str(), name_len*sizeof(CHAR));
			file.Write(layer.st.ptr(), 2*sizeof(F32));

			// write the alpha
			U32 width = U2P(ALPHA_STRIDE);
			file.Write(&width, sizeof(U32));
			U32 height = U2P(ALPHA_STRIDE);
			file.Write(&height, sizeof(U32));
			if(k==0)
			{
				std::vector<U8>data(width*height);
				for(U32 j = 0; j < height; j++)
				{
					for( U32 i = 0; i < width; i++)
					{
						U8& alpha = layer.alpha[i+j*width];
						U8& mask = mMask[i+j*width];
						if(mask == 0) data[i+j*width] = (U8)(((F32)alpha)/255.0f*127.0f);
						else data[i+j*width] = (U8)(((F32)alpha)/255.0f*127.0f)+128;
					}
				}
				file.Write(&data[0], width*height*sizeof(U8));
			}
			else
			{
				file.Write(&layer.alpha[0], width*height*sizeof(U8));
			}
		}
	}	

	UNGUARD;
}