void Vector<C>::matlab_output (const char *file, const char *Vectorname) const { char Filename[200]; Filename[0] = '\x0'; strcat(Filename, file); strcat(Filename, ".m"); std::ofstream m_file(Filename); m_file << Vectorname << "=load('" << file << ".dat');" << std::endl; m_file.close(); Filename[0] = '\x0'; strcat(Filename, file); strcat(Filename, ".dat"); std::ofstream dat_file(Filename); dat_file.setf(std::ios::scientific, std::ios::fixed); dat_file.precision(15); for (typename Vector<C>::size_type i(0); i < size(); ++i) dat_file << this->operator () (i) << " "; dat_file << std::endl; dat_file.close(); }
bool ClientVersion::hasValidPaths() const { if(!client_path.DirExists()) { return false; } FileName dat_path = client_path.GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR) + "Tibia.dat"; FileName spr_path = client_path.GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR) + "Tibia.spr"; if(!dat_path.FileExists() || !spr_path.FileExists()) { return false; } if(!g_settings.getInteger(Config::CHECK_SIGNATURES)) { return true; } // Peek the version of the files FileReadHandle dat_file(static_cast<const char*>(dat_path.GetFullPath().mb_str())); if(!dat_file.isOk()) { wxLogError("Could not open Tibia.dat."); return false; } uint32_t datSignature; dat_file.getU32(datSignature); dat_file.close(); FileReadHandle spr_file(static_cast<const char*>(spr_path.GetFullPath().mb_str())); if(!spr_file.isOk()) { wxLogError("Could not open Tibia.spr."); return false; } uint32_t sprSignature; spr_file.getU32(sprSignature); spr_file.close(); for(const auto& clientData : data_versions) { if(clientData.sprSignature == sprSignature && clientData.datSignature == datSignature) { return true; } } wxString message = "Signatures are incorrect.\n"; message << "Dat signature: %X\n"; message << "Spr signature: %X"; wxLogError(wxString::Format(message, datSignature, sprSignature)); return false; }
void palm_installer::load_user_data() { wxUint32 string_length; wxUint8 count; bool found_user; wxUint8 empty_spaces; wxUint8 unused; wxUint8 single_character; wxString name_with_colons_replaced; wxLogDebug( "Attempting to load filestream" ); wxString dat_fullname = get_palm_desktop_path() + "/Palm Users"; wxLogDebug( "Looking for Palm Users dat file=" + dat_fullname ); // Make sure the file exists if ( ! wxFileExists( dat_fullname ) ) { // Note: a checkbox message dialog, casuses a crash when opening config dialog // if it was active. Therefore, no checkbox message dialog // Abort now. Can't read configuration from Registry. return; } // Create the object wxFile dat_file( dat_fullname ); // Make sure that file was opened properly. I am not going to make a checkbox removable // dialog since there is almost zero chance that it won't open. if ( ! dat_file.IsOpened() ) { wxLogError( "Error: unable to load file named " + dat_fullname ); // Need to return here or else will get in trouble later. return; } // Build an input stream from the file. Note we could have skipped right to // this function with the wxFileInputStream( wxString filename ) function, but // then it is harder to see what went wrong. wxFileInputStream userData( dat_file ); wxLogDebug( "Loaded filestream" ); // Seek to 7, which will be number of users. //! \todo Should this be reading 4,5,6,7 instead? if more than 128 users? userData.SeekI( 7 ); wxLogDebug( "SeekI to offset of 7" ); // Make a buffered input stream from file stream wxBufferedInputStream buf_input( userData ); wxLogDebug( "Loaded Bufferedinput stream from filestream" ); // Make a data input stream from the buffered input stream wxDataInputStream data_input( buf_input ); wxLogDebug( "Loaded DataInputStream from buffered filestream" ); // Set the Endian Order of the data stream. We want to read "0x00 0x00 0x00 0E" as // 14, not 234881024. data_input.BigEndianOrdered( TRUE ); wxLogDebug( "NOTE! Setting to Big Endian ordered data file for Palm Users file." ); // //! \todo See the 4,5,6,7 note above. // Read the number of users from the dat file. m_number_of_users = data_input.Read8(); wxLogDebug( wxT("Read m_number_of_users=%d"), (int)m_number_of_users ); if ( 0 < m_number_of_users ) { // Fast forward through 4 unneeded bytes by reading a UInt32 // This is since I don't care if NUser (user) or a CUser (profile). unused = data_input.Read32(); // Execute a loop enough times to query information about each user. for ( count = 0; count < m_number_of_users; count++ ) { // Add a new member to our array of users. // The "new" we create here, gets "delete"ed in the base class's destructor // as part of the WX_CLEAR_ARRAY macro palm_user_type* palm_user = new palm_user_type(); m_users_array.Add( palm_user ); wxLogDebug( "Added a new array element" ); // Reset value of string_length to 0, from last iteration of loop, as // a precaution. string_length = 0; // Read the user's Name // ReadString() might work because we have the correct Uint32 to tell how // long the string is. So could instead just do // m_users_array[ count ]->name = data_input.ReadString(); // However, I don't know how well it behaves with unicode. string_length = data_input.Read32(); wxLogDebug( "Read string_length=%u", string_length ); for ( int j = 0; j < string_length; j++ ) { single_character = data_input.Read8(); m_users_array[ count ]->name += (wxChar)single_character; } wxLogDebug( wxT( "Read user_name=%s" ), m_users_array[ count ]->name.c_str() ); // Make a dummy magic number of 0 m_users_array[ count ]->magic = 0; wxLogDebug( wxT("On OSX, just using a dummy magic number of %lu"), m_users_array[ count ]->magic ); // Read the user's subdirectory (I am assuming that all 4 bytes are for the // string length) name_with_colons_replaced = m_users_array[ count ]->name; name_with_colons_replaced.Replace( ":", "-" ); m_users_array[ count ]->subdirectory = name_with_colons_replaced; wxLogDebug( wxT( "user subdirectory calculated from username as=%s" ), m_users_array[ count ]->subdirectory.c_str() ); // Zip through rest of crap until find the next user entry if ( count < m_number_of_users - 1 ) { wxLogDebug( "Entering search for next user..." ); found_user = FALSE; // A signal for the next user/profile entry is either the sequence: // 0x4E 0x55 0x73 0x72 (78 85 115 114 which spells NUsr), or // 0x43 0x55 0x73 0x72 (67 85 115 114 which spells CUsr) while ( ! found_user ) { // Read the next character single_character = data_input.Read8(); // If the single character is 78 or 67.... if ( ( single_character == 78 ) || ( single_character == 67 ) ) { // Read the next character single_character = data_input.Read8(); // ...and it is followed by a 85... if ( single_character == 85 ) { // Read the next character single_character = data_input.Read8(); // ...and it is followed by a 85... if ( single_character == 115 ) { // Read the next character single_character = data_input.Read8(); // ...and it is followed by a 85... if ( single_character == 114 ) { wxLogDebug( "Found next user. Restarting loop to query info" ); // ...Got a user. break. found_user = TRUE; } } } } } } } } }