Skip to content

Commit

Permalink
Working code
Browse files Browse the repository at this point in the history
  • Loading branch information
Ben1028 committed Apr 22, 2019
1 parent 1100f60 commit a4e0b60
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 41 deletions.
16 changes: 8 additions & 8 deletions AxisDBCreator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ bool LoadTable(string &sPath)
sPath.erase(sPath.rfind("\\") + 1); //trim end

string sLine;
while (getline(file, sLine))
while (getline(file, sLine))
{
string sUpper = MakeUpper(sLine);

Expand All @@ -164,7 +164,7 @@ bool LoadTable(string &sPath)
else if (bProcess)
{
StripStr(sLine);

if (!sLine.empty())
{

Expand Down Expand Up @@ -199,7 +199,7 @@ bool LoadTable(string &sPath)
return true;
}

void LoadSingleDirectory(string &sPath)
void LoadSingleDirectory(const string &sPath)
{
for (const auto & p : fs::directory_iterator(sPath))
{
Expand All @@ -213,7 +213,7 @@ void LoadSingleDirectory(string &sPath)
}


bool LoadFile(string &sPath)
bool LoadFile(const string &sPath)
{
ifstream file(sPath);
if (!file.is_open())
Expand Down Expand Up @@ -774,7 +774,7 @@ void ReadList(ifstream &file, CObject *cObject, vector<CObject*> &vList)
vList.push_back(cObject);
}

void ReadTypes(ifstream &file, string &sPath)
void ReadTypes(ifstream &file, const string &sPath)
{
string sKey;

Expand Down Expand Up @@ -804,7 +804,7 @@ void ReadTypes(ifstream &file, string &sPath)
}
}

void ReadDef(ifstream &file, string &sPath)
void ReadDef(ifstream &file, const string &sPath)
{
string sKey, sValue;

Expand Down Expand Up @@ -833,7 +833,7 @@ void ReadDef(ifstream &file, string &sPath)
}
}

void ReadMsg(ifstream &file, string &sPath)
void ReadMsg(ifstream &file, const string &sPath)
{
string sKey, sValue;

Expand Down Expand Up @@ -1084,4 +1084,4 @@ bool SortDB()
}
DBCreateData.CommitTransaction();
return true;
}
}
31 changes: 16 additions & 15 deletions AxisDBCreator.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
#include <iostream>
#include <fstream>
#include <string>
#include <filesystem>
#include <experimental/filesystem>
#include <algorithm>
#include <sstream>
#include <map>
using namespace std;
Expand Down Expand Up @@ -49,24 +50,24 @@ namespace fs = std::experimental::filesystem;
ofstream logFile;
bool SortDB();
void InsertDB();
void LoadSingleDirectory(string &sPath);
void LoadSingleDirectory(const string &sPath);
bool LoadTable(string &sPath);
bool LoadFile(string &sPath);
bool LoadFile(const string &sPath);
void ReadItem(ifstream &file, CItem *cObject);
void ReadChar(ifstream &file, CChar *cObject);
void ReadMap(ifstream &file, CMap *cObject);
void ReadSpawn(ifstream &file, CChar *cObject);
void ReadTemplate(ifstream &file, CItem *cObject);
void ReadList(ifstream &file, CObject *cObject, vector<CObject*> &vList);
void ReadTypes(ifstream &file, string &sPath);
void ReadDef(ifstream &file, string &sPath);
void ReadMsg(ifstream &file, string &sPath);
void ReadTypes(ifstream &file, const string &sPath);
void ReadDef(ifstream &file, const string &sPath);
void ReadMsg(ifstream &file, const string &sPath);

//Replace all instances of 'from' by 'to' in 'str'
void ReplaceAll(string &str, const string& from, const string& to)
{
size_t start_pos = 0;
while ((start_pos = str.find(from, start_pos)) != string::npos)
while ((start_pos = str.find(from, start_pos)) != string::npos)
{
str.replace(start_pos, from.length(), to);
start_pos += to.length();
Expand Down Expand Up @@ -96,8 +97,8 @@ string MakeUpper(string s)

string GetFilename(string s)
{
//remove all before the last '\'
size_t pos = s.find_last_of("\\");
//remove all before the last '\' or '/'
size_t pos = s.find_last_of("\\/");
if (pos != string::npos)
{
s.erase(0, pos + 1);
Expand All @@ -108,13 +109,13 @@ string GetFilename(string s)
string GetLastPath(string s)
{
//remove all after the last '\'
size_t pos = s.find_last_of("\\");
size_t pos = s.find_last_of("\\/");
if (pos != string::npos)
{
s.erase(pos);
}
//remove all before the last directory
pos = s.find_last_of("\\");
pos = s.find_last_of("\\/");
if (pos != string::npos)
{
s.erase(0, pos + 1);
Expand All @@ -125,13 +126,13 @@ string GetLastPath(string s)
string GetFirstPath(string s)
{
//remove all after the first directory '\'
size_t pos = s.find_first_of("\\", 1);
size_t pos = s.find_first_of("\\/", 1);
if (pos != string::npos)
{
s.erase(pos);
}
//remove all before the first '\' (if path starts with '\')
pos = s.find_first_of("\\");
pos = s.find_first_of("\\/");
if (pos != string::npos)
{
s.erase(0, pos + 1);
Expand Down Expand Up @@ -252,7 +253,7 @@ void logData(string data)
//0 = string
//1 = hex number
//2 = decimal number
UINT IsStrType(string s)
unsigned int IsStrType(string s)
{
//hex or string
if (s.find("0") == 0)
Expand All @@ -265,7 +266,7 @@ UINT IsStrType(string s)
{
return 0;
}

}
//decimal
else if (s.find_first_not_of("0123456789") == string::npos)
Expand Down
8 changes: 4 additions & 4 deletions AxisDBCreator.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<ProjectGuid>{36B600FD-FA70-4210-815E-DFCEF3C20518}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>AxisDBCreator</RootNamespace>
<WindowsTargetPlatformVersion>10.0.17134.0</WindowsTargetPlatformVersion>
<WindowsTargetPlatformVersion>10.0.17763.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
Expand Down Expand Up @@ -80,15 +80,13 @@
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>false</LinkIncremental>
<OutDir>C:\Users\bcrou\source\repos\Source-experimental\win64\bin64\Debug\</OutDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
<OutDir>C:\Users\bcrou\source\repos\Source-experimental\win64\bin64\Debug\</OutDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
<OutDir>C:\Users\bcrou\source\repos\Source-experimental\win64\bin64\Debug\</OutDir>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
Expand All @@ -114,7 +112,7 @@
<ClCompile>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Full</Optimization>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
<StringPooling>true</StringPooling>
Expand All @@ -123,6 +121,7 @@
<FunctionLevelLinking>true</FunctionLevelLinking>
<PrecompiledHeaderFile />
<PrecompiledHeaderOutputFile />
<WholeProgramOptimization>false</WholeProgramOptimization>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
Expand Down Expand Up @@ -164,6 +163,7 @@
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<PrecompiledHeaderFile />
<PrecompiledHeaderOutputFile />
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
Expand Down
15 changes: 15 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
project(AxisDBCreator)

set(SOURCE_FILES AxisDBCreator.cpp AxisDBCreator.h Objects.h SQLite.cpp SQLite.h sqlite3.c sqlite3.h)
add_executable(AxisDBCreator ${SOURCE_FILES})

if (MSVC)
set (CMAKE_C_FLAGS "/O2")
set (CMAKE_CXX_FLAGS "/O2 /std:c++17")
else (MSVC)
if (UNIX)
set(CMAKE_C_FLAGS "-s -O3")
set(CMAKE_CXX_FLAGS "-s -O3 -std=c++17 -pthread")
target_link_libraries(AxisDBCreator stdc++fs pthread dl)
endif (UNIX)
endif(MSVC)
36 changes: 23 additions & 13 deletions SQLite.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
#include "SQLite.h"
#include <cstring>

#ifdef _WIN32
#define strcmpi _strcmpi
#else
#define strcmpi strcasecmp
#endif

namespace SQLite
{
Expand Down Expand Up @@ -100,16 +107,19 @@ namespace SQLite

void Database::ConvertUTF8ToString(char * strInUTF8MB, stdvstring & strOut)
{
int len = (int)strlen(strInUTF8MB) + 1;
strOut.resize(len, 0);


WCHAR * wChar = new WCHAR[len];
wChar[0] = 0;
MultiByteToWideChar(CP_UTF8, 0, strInUTF8MB, len, wChar, len);
WideCharToMultiByte(CP_ACP, 0, wChar, len, &strOut[0], len, 0, 0);
delete[] wChar;

int len=(int)strlen(strInUTF8MB)+1;
strOut.resize(len, 0);
wchar_t * wChar = new wchar_t[len];
wChar[0]=0;
#ifdef _WIN32
size_t aux = 0;
mbstowcs_s(&aux, wChar, len*sizeof(wchar_t), strInUTF8MB,len);
wcstombs_s(&aux, &strOut[0], len*sizeof(char), wChar, len);
#else
mbstowcs(wChar,strInUTF8MB,len);
wcstombs(&strOut[0],wChar,len);
#endif
delete [] wChar;
}

int Database::ExecuteSQL(std::string strSQL)
Expand Down Expand Up @@ -247,7 +257,7 @@ namespace SQLite
if (m_iPos < 0) return 0;
for (int i = 0; i < m_iCols; i++)
{
if (!_stricmp(&m_strlstCols[i][0], lpColName.c_str()))
if (!strcmpi(&m_strlstCols[i][0], lpColName.c_str()))
{
return &m_lstRows[m_iPos][i][0];
}
Expand All @@ -268,7 +278,7 @@ namespace SQLite
if (m_iPos < 0) return 0;
for (int i = 0; i < m_iCols; i++)
{
if (!_stricmp(&m_strlstCols[i][0], lpColName.c_str()))
if (!strcmpi(&m_strlstCols[i][0], lpColName.c_str()))
{
return &m_lstRows[m_iPos][i][0];
}
Expand Down Expand Up @@ -302,4 +312,4 @@ namespace SQLite
}
}
}
}
}
1 change: 0 additions & 1 deletion SQLite.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#include "sqlite3.h"
#include <string>
#include <vector>
#include <windows.h>

namespace SQLite
{
Expand Down

0 comments on commit a4e0b60

Please sign in to comment.