DarkflameServer/dCommon/FdbToSqlite.h

154 lines
3.6 KiB
C
Raw Normal View History

2022-12-05 08:57:58 +00:00
#ifndef __FDBTOSQLITE__H__
#define __FDBTOSQLITE__H__
#pragma once
#include <cstdint>
#include <iosfwd>
#include <map>
enum class eSqliteDataType : int32_t;
namespace FdbToSqlite {
class Convert {
public:
/**
* Create a new convert object with an input .fdb file and an output binary path.
*
* @param inputFile The file which ends in .fdb to be converted
* @param binaryPath The base path where the file will be saved
*/
Convert(std::string inputFile, std::string binaryOutPath);
/**
* Destroy the convert object and close the fdb file.
*/
~Convert();
/**
* Converts the input file to sqlite. Calling multiple times is safe.
*
* @return true if the database was converted properly, false otherwise.
*/
2022-12-05 08:57:58 +00:00
bool ConvertDatabase();
/**
* @brief Reads a 32 bit int from the fdb file.
*
* @return The read value
*/
2022-12-05 08:57:58 +00:00
int32_t ReadInt32();
/**
* @brief Reads a 64 bit integer from the fdb file.
*
* @return The read value
*/
2022-12-05 08:57:58 +00:00
int64_t ReadInt64();
/**
* @brief Reads a string from the fdb file.
*
* @return The read string
*
* TODO This needs to be translated to latin-1!
*/
2022-12-05 08:57:58 +00:00
std::string ReadString();
/**
* @brief Seeks to a pointer position.
*
* @return The previous position before the seek
*/
2022-12-05 08:57:58 +00:00
int32_t SeekPointer();
/**
* @brief Reads a column header from the fdb file and creates the table in the database
*
* @return The table name
*/
2022-12-05 08:57:58 +00:00
std::string ReadColumnHeader();
/**
* @brief Read the tables from the fdb file.
*
* @param numberOfTables The number of tables to read
*/
2022-12-05 08:57:58 +00:00
void ReadTables(int32_t& numberOfTables);
/**
* @brief Reads the columns from the fdb file.
*
* @param numberOfColumns The number of columns to read
* @return All columns of the table formatted for a sql query
*/
2022-12-05 08:57:58 +00:00
std::string ReadColumns(int32_t& numberOfColumns);
/**
* @brief Reads the row header from the fdb file.
*
* @param tableName The tables name
*/
2022-12-05 08:57:58 +00:00
void ReadRowHeader(std::string& tableName);
/**
* @brief Read the rows from the fdb file.,
*
* @param numberOfAllocatedRows The number of rows that were allocated. Always a power of 2!
* @param tableName The tables name.
*/
2022-12-05 08:57:58 +00:00
void ReadRows(int32_t& numberOfAllocatedRows, std::string& tableName);
/**
* @brief Reads a row from the fdb file.
*
* @param position The position to seek in the fdb to
* @param tableName The tables name
*/
void ReadRow(int32_t& position, std::string& tableName);
/**
* @brief Reads the row info from the fdb file.
*
* @param tableName The tables name
*/
2022-12-05 08:57:58 +00:00
void ReadRowInfo(std::string& tableName);
/**
* @brief Reads each row and its values from the fdb file and inserts them into the database
*
* @param numberOfColumns The number of columns to read in
* @param tableName The tables name
*/
2022-12-05 08:57:58 +00:00
void ReadRowValues(int32_t& numberOfColumns, std::string& tableName);
private:
/**
* Maps each sqlite data type to its string equivalent.
*/
static std::map<eSqliteDataType, std::string> m_SqliteType;
/**
* Base path of the folder containing the fdb file
*/
std::string m_BasePath{};
/**
* ifstream containing the fdb file
*/
std::ifstream m_Fdb{};
/**
* Whether or not a conversion was started. If one was started, do not attempt to convert the file again.
*/
bool m_ConversionStarted{};
/**
* The path where the CDServer will be stored
*/
std::string m_BinaryOutPath{};
}; //! class FdbToSqlite
2022-12-05 08:57:58 +00:00
}; //! namespace FdbToSqlite
#endif //!__FDBTOSQLITE__H__