Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Y
ygopro
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nanahira
ygopro
Commits
24e5ca92
Commit
24e5ca92
authored
Dec 08, 2018
by
mercury233
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update loadDB
parent
ae3da991
Changes
5
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
640 additions
and
11 deletions
+640
-11
gframe/data_manager.cpp
gframe/data_manager.cpp
+24
-9
gframe/data_manager.h
gframe/data_manager.h
+3
-2
gframe/game.cpp
gframe/game.cpp
+1
-0
gframe/spmemvfs.c
gframe/spmemvfs.c
+548
-0
gframe/spmemvfs.h
gframe/spmemvfs.h
+64
-0
No files found.
gframe/data_manager.cpp
View file @
24e5ca92
...
...
@@ -9,20 +9,33 @@ byte DataManager::scriptBuffer[0x20000];
DataManager
dataManager
;
bool
DataManager
::
LoadDB
(
const
char
*
file
)
{
sqlite3
*
pDB
;
if
(
sqlite3_open_v2
(
file
,
&
pDB
,
SQLITE_OPEN_READONLY
,
0
)
!=
SQLITE_OK
)
return
Error
(
pDB
);
wchar_t
wfile
[
256
];
BufferIO
::
DecodeUTF8
(
file
,
wfile
);
IReadFile
*
reader
=
FileSystem
->
createAndOpenFile
(
wfile
);
if
(
reader
==
NULL
)
return
false
;
spmemvfs_db_t
db
;
spmembuffer_t
*
mem
=
(
spmembuffer_t
*
)
calloc
(
sizeof
(
spmembuffer_t
),
1
);
spmemvfs_env_init
();
mem
->
total
=
mem
->
used
=
reader
->
getSize
();
mem
->
data
=
(
char
*
)
malloc
(
mem
->
total
+
1
);
reader
->
read
(
mem
->
data
,
mem
->
total
);
reader
->
drop
();
(
mem
->
data
)[
mem
->
total
]
=
'\0'
;
if
(
spmemvfs_open_db
(
&
db
,
file
,
mem
)
!=
SQLITE_OK
)
return
Error
(
&
db
);
sqlite3
*
pDB
=
db
.
handle
;
sqlite3_stmt
*
pStmt
;
const
char
*
sql
=
"select * from datas,texts where datas.id=texts.id"
;
if
(
sqlite3_prepare_v2
(
pDB
,
sql
,
-
1
,
&
pStmt
,
0
)
!=
SQLITE_OK
)
return
Error
(
pDB
);
return
Error
(
&
db
);
CardDataC
cd
;
CardString
cs
;
int
step
=
0
;
do
{
step
=
sqlite3_step
(
pStmt
);
if
(
step
==
SQLITE_BUSY
||
step
==
SQLITE_ERROR
||
step
==
SQLITE_MISUSE
)
return
Error
(
pDB
,
pStmt
);
return
Error
(
&
db
,
pStmt
);
else
if
(
step
==
SQLITE_ROW
)
{
cd
.
code
=
sqlite3_column_int
(
pStmt
,
0
);
cd
.
ot
=
sqlite3_column_int
(
pStmt
,
1
);
...
...
@@ -62,7 +75,8 @@ bool DataManager::LoadDB(const char* file) {
}
}
while
(
step
!=
SQLITE_DONE
);
sqlite3_finalize
(
pStmt
);
sqlite3_close
(
pDB
);
spmemvfs_close_db
(
&
db
);
spmemvfs_env_fini
();
return
true
;
}
bool
DataManager
::
LoadStrings
(
const
char
*
file
)
{
...
...
@@ -99,11 +113,12 @@ bool DataManager::LoadStrings(const char* file) {
myswprintf
(
numStrings
[
i
],
L"%d"
,
i
);
return
true
;
}
bool
DataManager
::
Error
(
s
qlite3
*
pDB
,
sqlite3_stmt
*
pStmt
)
{
BufferIO
::
DecodeUTF8
(
sqlite3_errmsg
(
pDB
),
strBuffer
);
bool
DataManager
::
Error
(
s
pmemvfs_db_t
*
pDB
,
sqlite3_stmt
*
pStmt
)
{
BufferIO
::
DecodeUTF8
(
sqlite3_errmsg
(
pDB
->
handle
),
strBuffer
);
if
(
pStmt
)
sqlite3_finalize
(
pStmt
);
sqlite3_close
(
pDB
);
spmemvfs_close_db
(
pDB
);
spmemvfs_env_fini
();
return
false
;
}
bool
DataManager
::
GetData
(
int
code
,
CardData
*
pData
)
{
...
...
gframe/data_manager.h
View file @
24e5ca92
...
...
@@ -3,6 +3,7 @@
#include "config.h"
#include "sqlite3.h"
#include "spmemvfs.h"
#include "client_card.h"
#include <unordered_map>
...
...
@@ -13,7 +14,7 @@ public:
DataManager
()
:
_datas
(
8192
),
_strings
(
8192
)
{}
bool
LoadDB
(
const
char
*
file
);
bool
LoadStrings
(
const
char
*
file
);
bool
Error
(
s
qlite3
*
pDB
,
sqlite3_stmt
*
pStmt
=
0
);
bool
Error
(
s
pmemvfs_db_t
*
pDB
,
sqlite3_stmt
*
pStmt
=
0
);
bool
GetData
(
int
code
,
CardData
*
pData
);
code_pointer
GetCodePointer
(
int
code
);
bool
GetString
(
int
code
,
CardString
*
pStr
);
...
...
@@ -54,7 +55,7 @@ public:
static
int
CardReader
(
int
,
void
*
);
static
byte
*
ScriptReaderEx
(
const
char
*
script_name
,
int
*
slen
);
static
byte
*
ScriptReader
(
const
char
*
script_name
,
int
*
slen
);
IFileSystem
*
FileSystem
;
};
extern
DataManager
dataManager
;
...
...
gframe/game.cpp
View file @
24e5ca92
...
...
@@ -56,6 +56,7 @@ bool Game::Initialize() {
ErrorLog
(
"Failed to load textures!"
);
return
false
;
}
dataManager
.
FileSystem
=
device
->
getFileSystem
();
LoadExpansionDB
();
if
(
!
dataManager
.
LoadDB
(
"cards.cdb"
))
{
ErrorLog
(
"Failed to load card database (cards.cdb)!"
);
...
...
gframe/spmemvfs.c
0 → 100644
View file @
24e5ca92
This diff is collapsed.
Click to expand it.
gframe/spmemvfs.h
0 → 100644
View file @
24e5ca92
/*
* BSD 2-Clause License
*
* Copyright 2009 Stephen Liu
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __spmemvfs_h__
#define __spmemvfs_h__
#ifdef __cplusplus
extern
"C"
{
#endif
#include "sqlite3.h"
#define SPMEMVFS_NAME "spmemvfs"
typedef
struct
spmembuffer_t
{
char
*
data
;
int
used
;
int
total
;
}
spmembuffer_t
;
typedef
struct
spmemvfs_db_t
{
sqlite3
*
handle
;
spmembuffer_t
*
mem
;
}
spmemvfs_db_t
;
int
spmemvfs_env_init
();
void
spmemvfs_env_fini
();
int
spmemvfs_open_db
(
spmemvfs_db_t
*
db
,
const
char
*
path
,
spmembuffer_t
*
mem
);
int
spmemvfs_close_db
(
spmemvfs_db_t
*
db
);
#ifdef __cplusplus
}
#endif
#endif
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment