Exemple #1
0
/**
 *
 *  @author OLiver
 */
bool Savegame::Load(BinaryFile& file, const bool load_players, const bool load_sgd)
{
    // Signatur und Version einlesen
    if(!ValidateFile(file, 8, SAVE_SIGNATURE, SAVE_VERSION))
    {
        LOG.lprintf("Savegame::Load: ERROR: File is not a valid RTTR savegame!\n");
        return false;
    }

    // Zeitstempel
    file.ReadRawData(&save_time, 8);

    // Map-Name
    file.ReadShortString(map_name);

    // Anzahl Spieler
    player_count = file.ReadUnsignedChar();

    // Spielerzeug
    if(load_players)
    {
        // Größe des Spielerblocks überspringen
        file.Seek(4, SEEK_CUR);

        ReadPlayerData(file);
    }
    else
    {
        // Überspringen
        players = 0;
        unsigned player_size = file.ReadUnsignedInt();
        file.Seek(player_size, SEEK_CUR);
    }

    // GGS
    ReadGGS(file);

    // Start-GF
    start_gf = file.ReadUnsignedInt();

    if(load_sgd)
    {
        // Serialisiertes Spielzeug lesen
        sgd.ReadFromFile(file);
    }

    return true;
}
/**
 *
 *  @author OLiver
 */
bool Savegame::Load(BinaryFile& file, const bool load_players, const bool load_sgd)
{
    // Signatur und Version einlesen
    if(!ValidateFile(file, sizeof(SAVE_SIGNATURE), SAVE_SIGNATURE, SAVE_VERSION))
        return false;

    // Zeitstempel
    file.ReadRawData(&save_time, 8);
    save_time = libendian::ConvertEndianess<false>::toNative(save_time);

    // Map-Name
    map_name = file.ReadShortString();

    // Anzahl Spieler
    SetPlayerCount(file.ReadUnsignedChar());

    // Spielerzeug
    if(load_players)
    {
        // Größe des Spielerblocks überspringen
        file.Seek(4, SEEK_CUR);

        ReadPlayerData(file);
    }
    else
    {
        // Überspringen
        unsigned player_size = file.ReadUnsignedInt();
        file.Seek(player_size, SEEK_CUR);
    }

    // GGS
    ReadGGS(file);

    // Start-GF
    start_gf = file.ReadUnsignedInt();

    if(load_sgd)
    {
        // Serialisiertes Spielzeug lesen
        sgd.ReadFromFile(file);
    }

    return true;
}
Exemple #3
0
int main(int argc, char **argv) {
  int index, initial_index = 1, repeat_count = 1;
  if (argc == 1) {
    printf("%s: no input files\n", argv[0]);
  }
  if (!strcmp(argv[1],"--repeat"))
    repeat_count = atoi(argv[2]),
    initial_index += 2;
  for (index = initial_index; index < argc; ++index) {
    const char *filename = argv[index];
    int rc = ValidateFile(filename, repeat_count);
    if (rc != 0) {
      printf("file '%s' can not be fully validated\n", filename);
      return 1;
    }
  }
  return 0;
}
Exemple #4
0
//*-----------------------------------------------------------------------
//| fReadHeader
//|
//| PURPOSE:    Open a file and return the handle to that file if it is a
//|             valid WCT dialog file, or NULL if not.
//|
//| ENTRY:      FileName        - Name of file to check
//|             oMode           - File access mode
//|             action          - TRUE if version if WCT file is pertinent
//|             failflag        - Pointer to success/failure flag
//|
//| EXIT:       File handle of open file if valid WCT file, or NULL if not
//*-----------------------------------------------------------------------
FD PRIVATE fReadHeader (LPSTR FileName, BYTE oMode, BOOL action,
                        INT FAR *failflag)
{
        FD      fd = fdNull;

        // Open file for mode oMode
        //-------------------------------------------------------------
        if ( (fd = M_lopen (FileName,oMode)) == fdNull )
                *failflag = WCT_DLGFILEERR;
        else
                // See if it's a valid WCT file; close it if not
                //-----------------------------------------------------
                if ((*failflag = ValidateFile(fd, action)) != WCT_NOERR)
                    {
                        M_lclose(fd);
                        fd = fdNull;
                    }
        return (fd);
}
Exemple #5
0
bool PerformDedicatedInstallationSanityCheck()
{
	char tmpLineBuffer[TMP_CONFIG_LINE_BUFFER];
	string checksumPath = PathUtil::GetGameFolder() + "/Scripts/DedicatedConfigs/" + "check.txt";
	bool bOk=true;
	
	FILE *checksumFile = fopen(checksumPath.c_str(),"r");

	if (!checksumFile)
	{
		CryLogAlways("Failed to open validation configuration - Please check your install!");
		return false;
	}
	else
	{
		while (fgets(tmpLineBuffer,TMP_CONFIG_LINE_BUFFER-1,checksumFile))
		{
			string temp = tmpLineBuffer;
				
			string::size_type posEq = temp.find( "*", 0 );
			
			if (string::npos!=posEq)
			{
					string md5( temp, 0, posEq );
					string path( temp,posEq+1,temp.length());

					path.TrimRight(" \r\n");
					md5.TrimRight(" \r\n");

					if (!ValidateFile(path,md5))
					{
						CryLogAlways(path + " failed validation check - Please check your install! ("+md5+")");
						bOk=false;
					}
			}
		}

		fclose(checksumFile);
	}

	return bOk;
}
Exemple #6
0
AskDataBase::AskDataBase(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::AskDataBase)
{
    ui->setupUi(this);
    connect(ui->pushButton_3,SIGNAL(clicked()),this,SLOT(close()));
    connect(ui->pushButton_2,SIGNAL(clicked()),this,SLOT(ValidateFile()));
    connect(ui->pushButton,SIGNAL(clicked()),this,SLOT(CreateFile()));
    connect(ui->pushButton_4,SIGNAL(clicked()),this,SLOT(SelectFile()));
    QString MyAppDirPath =  QCoreApplication::applicationDirPath();
    QStringList listFilter;
    listFilter << "*.db";
    QDir *DirA = new QDir(MyAppDirPath);
    QStringList FIL = DirA->entryList(listFilter);
    int i = 0;
    for(i=0;i<FIL.count();i++)
    {
        ui->comboBox->addItem(FIL[i]);
    }
    free(DirA);
}
/**
 *
 *  @author OLiver
 */
bool Replay::LoadHeader(const std::string& filename, const bool load_extended_header)
{
	this->filename = filename;
	// Datei öffnen
	if(!file.Open(filename.c_str(),OFM_READ))
		return false;

	// Version überprüfen
	// Signatur und Version einlesen
	if(!ValidateFile(file,6,REPLAY_SIGNATURE,REPLAY_VERSION))
	{
		LOG.lprintf("Replay::Load: ERROR: File \"%s\" is not a valid RTTR replay!\n", filename.c_str());
		return false;
	}

	// Zeitstempel
	file.ReadRawData(&save_time,8);
	// NWF-Länge
	nwf_length = file.ReadUnsignedShort();
	// Zufallsgeneratorinitialisierung
	random_init = file.ReadUnsignedInt();
	/// Pathfinding-Results hier drin?
	pathfinding_results = (file.ReadUnsignedChar()==1);
	/// End-GF
	last_gf = file.ReadUnsignedInt();
	// Spieleranzahl
	player_count = file.ReadUnsignedChar();

	// Spielerdaten
	ReadPlayerData(file);
	// GGS
	ReadGGS(file);

	// Map-Type
	map_type = static_cast<MapType>(file.ReadUnsignedShort());

	if(load_extended_header)
	{
		switch(map_type)
		{
		default:
			break;
		case MAPTYPE_OLDMAP:
			{
				// Map-Daten
				map_length = file.ReadUnsignedInt();
				map_zip_length = file.ReadUnsignedInt();
				map_data = new unsigned char[map_zip_length];
				file.ReadRawData(map_data,map_zip_length);
			} break;
		case MAPTYPE_SAVEGAME:
			{
				// Savegame speichern
				if(!savegame->Load(file,true,true))
					return false;
			} break;
		}

		file.ReadShortString(map_name);

		// bei ungerader 4er position aufrunden
		//while(file.Tell() % 4)
		//	file.Seek(1, SEEK_CUR);
	}

	if(load_extended_header)
	{
		// Try to open precalculated pathfinding results
		pathfinding_results = pf_file.Open((filename + "_res").c_str(),OFM_READ);

		if(!pathfinding_results)
			pf_file.Open((filename + "_res").c_str(),OFM_WRITE);
	}


	return true;
}
Exemple #8
0
bool DlgController::OnCommand (int ctrlid, int code)
{
	int	i =	0;
	switch (ctrlid)
	{
	case IDC_BUTTON_ABOUT:
		::DialogBox	(_hInst, MAKEINTRESOURCE (DLG_ABOUT), _hWnd, DLGPROC (AboutDlgProc));
		return true;
	case IDC_BUTTON_START:
		if (_isStopped)
		{
			_isStopped = !_painter.Start();
			if (_isStopped)
			{
				_buttonStart.SetText ("Start");
			}
			else
			{
				_buttonStart.SetText ("Stop");
			}
		}
		else
		{
			Stop ();
			_buttonStart.SetText ("Start");
			_isStopped = true;
		}
		return true;
	case IDC_RADIO_8_BITS:
		if (_radio8.IsClicked (code))
		{
			_bitsPerSample = 8;
			ReInit ();
		}
		return true;
	case IDC_RADIO_16_BITS:
		if (_radio16.IsClicked (code))
		{
			_bitsPerSample = 16;
			ReInit ();
		}
		return true;
	case IDC_RADIO_MIKE:
		if (_mike.IsClicked (code))
		{
			_painter.SetSource (SRC_MIKE);
			ReInit ();
			return true;
		}
		break;
	case IDC_RADIO_FILE:
		if (_wave.IsClicked (code))
		{
			SelectFile (SRC_WAVE);
			return true;
		}
		break;
	case IDC_RADIO_IMAGE:
		if (_image.IsClicked (code))
		{
			SelectFile (SRC_IMAGE);
			return true;
		}
		break;
	case IDC_EDIT_FILE:
		if (_editFile.IsChanged (code))
			::PostMessage (_hWnd, WM_COMMAND, MAKEWPARAM (IDC_BUTTON_FILE, 0), 0);
		break;
	case IDC_BUTTON_FILE:
		{
			std::string name = _editFile.GetString ();
			SourceType type = ValidateFile (name, SRC_ANY);
			if (type == SRC_WAVE)
			{
				_mike.UnCheck ();
				_image.UnCheck ();
				_wave.Check ();
				_painter.SetSource (SRC_WAVE, name.c_str ());
			}
			else if (type == SRC_IMAGE)
			{
				_mike.UnCheck ();
				_wave.UnCheck ();
				_image.Check ();
				_painter.SetSource (SRC_IMAGE, name.c_str ());
			}
			else
			{
				_wave.UnCheck ();
				_image.UnCheck ();
				_mike.Check ();
				_painter.SetSource (SRC_MIKE);
			}
			InitScrollPositions	();
			ReInit ();
		}
		return true;
	case IDC_COMBO_SAMPLING:
		if (_comboFreq.IsChanged (code))
		{
			_samplesPerSecond =	_comboFreq.GetValue	();
			InitScrollPositions	();
			ReInit ();
			return true;
		}	 
		break;
	case IDC_COMBO_POINTS:
		if (_comboPoints.IsChanged(code))
		{
			_fftPoints = _comboPoints.GetValue ();
			InitScrollPositions	();
			ReInit ();
			return true;
		}
	}
	return false;
}
Exemple #9
0
void Permutator::InitPermutator(char* fileName)
{
// Open file for IO operations
	try
	{
		hInputFile.open(fileName, std::ios::in | std::ios::binary);
	}
	catch (std::fstream::failure e)
	{
		std::cerr << "InitPermutator: Error while opening input file: " 
					<< e.what() << std::endl;
		exit(-1);
	}

// Determine whether ELF or PE
	char sig[4];
	try {
		hInputFile.read(sig, 4);
	}
	catch (std::fstream::failure e) {
		std::cerr << "InitPermutator: Error while reading input file: " 
					<< e.what() << std::endl;
		exit(-1);
	}

	if (sig[0]=='M'&&sig[1]=='Z')
		elfMode = 0;
	else if (sig[0]==0x7f && sig[1]=='E' && sig[2]=='L' && sig[3]=='F')
		elfMode = 1;
	else {
		std::cerr << "InitPermutator: Error, file corrupted" << std::endl;
		exit(-1);
	}

	if (elfMode) {

		// Read the ELF header
		pElfHeader = (Elf32_Ehdr *)
						ReadHeader(hInputFile, sizeof(Elf32_Ehdr), 0);
		if (!pElfHeader) {
			std::cerr << "InitPermutator: cannot read ELF header" << std::endl;
			exit(-1);
		}

		// Check if it's valid/supported
		if (!elf_supported(pElfHeader)) {
			std::cerr << "InitPermutator: invalid or unsupported format" 
						<< std::endl;
			exit(-1);
		}

	}
	else {
		if (!ValidateFile(hInputFile))
		{
			std::cerr << "InitPermutator: Not a valid PE file (MZ signature)" 
						<< std::endl;
			exit(-1);
		}
		// Read the DOS header
		pDosHeader = (PIMAGE_DOS_HEADER)
						ReadHeader(hInputFile, sizeof(IMAGE_DOS_HEADER), 0);
		if (pDosHeader == nullptr)
		{
			std::cerr << "InitPermutator: Invalid DOS header" << std::endl;
			exit(-1);
		}

		// Read the PE Header
		pNtHeader = (PIMAGE_NT_HEADERS)
						ReadHeader(hInputFile, sizeof(IMAGE_NT_HEADERS), 
									pDosHeader->e_lfanew);
		if (pNtHeader == nullptr)
		{
			std::cerr << "InitPermutator: Invalid NT header" << std::endl;
			exit(-1);
		}

		// Find the file offset to the first section header
		dwFstSctHdrOffset = pDosHeader->e_lfanew + 4 
							+ IMAGE_SIZEOF_FILE_HEADER 
							+ pNtHeader->FileHeader.SizeOfOptionalHeader;			
	}

}
Exemple #10
0
void iwMusicPlayer::Msg_Input(const unsigned int win_id, const std::string& msg)
{
    switch(win_id)
    {
            // Add Track - Window
        case 0:
        {
            bool valid = false;

            // Existiert diese Datei nicht?
            if(ValidateFile(msg))
                valid = true;
            else
            {
                // Evtl ein Siedlerstück ("sNN")?
                if(msg.length() == 3)
                {
                    if(atoi(msg.substr(1).c_str()) <= 14)
                        valid = true;
                }
            }

            // Gültiges Siedlerstück?
            if(valid)
            {
                // Hinzufügen
                GetCtrl<ctrlList>(0)->AddString(msg);
                changed = true;
            }
            else
                WINDOWMANAGER.Show(new iwMsgbox(_("Error"), _("The specified file couldn't be opened!"), this, MSB_OK, MSB_EXCLAMATIONRED));

        } break;
        // Add Playlist
        case 1:
        {
            bool valid = true;

            // Ungültige Namen ausschließen
            if(msg.length() == 0) valid = false;
            else if(!((msg[0] >= 'a' && msg[0] <= 'z') || (msg[0] >= 'A' && msg[0] <= 'Z'))) valid = false;

            Playlist pl;
            if(!pl.SaveAs(GetFullPlaylistPath(msg), true))
                valid = false;

            if(valid)
            {
                // Combobox updaten
                UpdatePlaylistCombo(msg);
                changed = true;
            }
            else
            {
                // Fehler, konnte nicht gespeichert werden
                WINDOWMANAGER.Show(new iwMsgbox(_("Error"), _("The specified file couldn't be saved!"), this, MSB_OK, MSB_EXCLAMATIONRED));
            }
        } break;
        // Add Track directory of tracks - Window
        case 2:
        {
            std::list<std::string> lst;
            ListDir(msg + "/*.ogg", false, NULL, NULL, &lst);

            for(std::list<std::string>::iterator it = lst.begin(); it != lst.end(); ++it)
                GetCtrl<ctrlList>(0)->AddString(*it);

            changed = true;

        } break;

    }
}