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
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
MyCard
ygopro
Commits
a8ccdbb1
Commit
a8ccdbb1
authored
Sep 08, 2024
by
Chen Bill
Committed by
GitHub
Sep 08, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add wrapper function myfopen (#2582)
* add wrapper function myfopen * open file with myfopen
parent
0d282241
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
46 additions
and
60 deletions
+46
-60
gframe/config.h
gframe/config.h
+14
-0
gframe/deck_manager.cpp
gframe/deck_manager.cpp
+3
-9
gframe/menu_handler.cpp
gframe/menu_handler.cpp
+3
-8
gframe/replay.cpp
gframe/replay.cpp
+26
-43
No files found.
gframe/config.h
View file @
a8ccdbb1
...
@@ -58,6 +58,20 @@ inline int myswprintf(wchar_t(&buf)[N], const wchar_t* fmt, TR... args) {
...
@@ -58,6 +58,20 @@ inline int myswprintf(wchar_t(&buf)[N], const wchar_t* fmt, TR... args) {
#include "../ocgcore/ocgapi.h"
#include "../ocgcore/ocgapi.h"
#include "../ocgcore/common.h"
#include "../ocgcore/common.h"
inline
FILE
*
myfopen
(
const
char
*
filename
,
const
char
*
mode
)
{
FILE
*
fp
{};
#ifdef _WIN32
wchar_t
wname
[
256
]{};
wchar_t
wmode
[
20
]{};
BufferIO
::
DecodeUTF8
(
filename
,
wname
);
BufferIO
::
CopyWStr
(
mode
,
wmode
,
sizeof
wmode
/
sizeof
wmode
[
0
]);
fp
=
_wfopen
(
wname
,
wmode
);
#else
fp
=
fopen
(
filename
,
mode
);
#endif
return
fp
;
}
#include <irrlicht.h>
#include <irrlicht.h>
using
namespace
irr
;
using
namespace
irr
;
using
namespace
core
;
using
namespace
core
;
...
...
gframe/deck_manager.cpp
View file @
a8ccdbb1
...
@@ -263,15 +263,9 @@ void DeckManager::GetDeckFile(wchar_t* ret, irr::gui::IGUIComboBox* cbCategory,
...
@@ -263,15 +263,9 @@ void DeckManager::GetDeckFile(wchar_t* ret, irr::gui::IGUIComboBox* cbCategory,
}
}
}
}
FILE
*
DeckManager
::
OpenDeckFile
(
const
wchar_t
*
file
,
const
char
*
mode
)
{
FILE
*
DeckManager
::
OpenDeckFile
(
const
wchar_t
*
file
,
const
char
*
mode
)
{
#ifdef WIN32
char
fullname
[
256
]{};
wchar_t
wmode
[
20
]{};
BufferIO
::
EncodeUTF8
(
file
,
fullname
);
BufferIO
::
CopyWStr
(
mode
,
wmode
,
sizeof
wmode
/
sizeof
wmode
[
0
]);
FILE
*
fp
=
myfopen
(
fullname
,
mode
);
FILE
*
fp
=
_wfopen
(
file
,
wmode
);
#else
char
file2
[
256
];
BufferIO
::
EncodeUTF8
(
file
,
file2
);
FILE
*
fp
=
fopen
(
file2
,
mode
);
#endif
return
fp
;
return
fp
;
}
}
IReadFile
*
DeckManager
::
OpenDeckReader
(
const
wchar_t
*
file
)
{
IReadFile
*
DeckManager
::
OpenDeckReader
(
const
wchar_t
*
file
)
{
...
...
gframe/menu_handler.cpp
View file @
a8ccdbb1
...
@@ -570,14 +570,9 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
...
@@ -570,14 +570,9 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
const
wchar_t
*
name
=
mainGame
->
lstSinglePlayList
->
getListItem
(
sel
);
const
wchar_t
*
name
=
mainGame
->
lstSinglePlayList
->
getListItem
(
sel
);
wchar_t
fname
[
256
];
wchar_t
fname
[
256
];
myswprintf
(
fname
,
L"./single/%ls"
,
name
);
myswprintf
(
fname
,
L"./single/%ls"
,
name
);
FILE
*
fp
;
char
fullname
[
256
]{};
#ifdef _WIN32
BufferIO
::
EncodeUTF8
(
fname
,
fullname
);
fp
=
_wfopen
(
fname
,
L"rb"
);
FILE
*
fp
=
myfopen
(
fullname
,
"rb"
);
#else
char
filename
[
256
];
BufferIO
::
EncodeUTF8
(
fname
,
filename
);
fp
=
fopen
(
filename
,
"rb"
);
#endif
if
(
!
fp
)
{
if
(
!
fp
)
{
mainGame
->
stSinglePlayInfo
->
setText
(
L""
);
mainGame
->
stSinglePlayInfo
->
setText
(
L""
);
break
;
break
;
...
...
gframe/replay.cpp
View file @
a8ccdbb1
...
@@ -102,39 +102,26 @@ void Replay::SaveReplay(const wchar_t* name) {
...
@@ -102,39 +102,26 @@ void Replay::SaveReplay(const wchar_t* name) {
return
;
return
;
wchar_t
fname
[
256
];
wchar_t
fname
[
256
];
myswprintf
(
fname
,
L"./replay/%ls.yrp"
,
name
);
myswprintf
(
fname
,
L"./replay/%ls.yrp"
,
name
);
#ifdef WIN32
char
fullname
[
256
]{};
fp
=
_wfopen
(
fname
,
L"wb"
);
BufferIO
::
EncodeUTF8
(
fname
,
fullname
);
#else
FILE
*
rfp
=
myfopen
(
fullname
,
"wb"
);
char
fname2
[
256
];
if
(
!
rfp
)
BufferIO
::
EncodeUTF8
(
fname
,
fname2
);
fp
=
fopen
(
fname2
,
"wb"
);
#endif
if
(
!
fp
)
return
;
return
;
fwrite
(
&
pheader
,
sizeof
(
pheader
),
1
,
fp
);
fwrite
(
&
pheader
,
sizeof
pheader
,
1
,
r
fp
);
fwrite
(
comp_data
,
comp_size
,
1
,
fp
);
fwrite
(
comp_data
,
comp_size
,
1
,
r
fp
);
fclose
(
fp
);
fclose
(
r
fp
);
}
}
bool
Replay
::
OpenReplay
(
const
wchar_t
*
name
)
{
bool
Replay
::
OpenReplay
(
const
wchar_t
*
name
)
{
#ifdef WIN32
char
fullname
[
256
]{};
fp
=
_wfopen
(
name
,
L"rb"
);
BufferIO
::
EncodeUTF8
(
name
,
fullname
);
#else
FILE
*
rfp
=
myfopen
(
fullname
,
"rb"
);
char
name2
[
256
];
if
(
!
rfp
)
{
BufferIO
::
EncodeUTF8
(
name
,
name2
);
fp
=
fopen
(
name2
,
"rb"
);
#endif
if
(
!
fp
)
{
wchar_t
fname
[
256
];
wchar_t
fname
[
256
];
myswprintf
(
fname
,
L"./replay/%ls"
,
name
);
myswprintf
(
fname
,
L"./replay/%ls"
,
name
);
#ifdef WIN32
BufferIO
::
EncodeUTF8
(
fname
,
fullname
);
fp
=
_wfopen
(
fname
,
L"rb"
);
rfp
=
myfopen
(
fullname
,
"rb"
);
#else
char
fname2
[
256
];
BufferIO
::
EncodeUTF8
(
fname
,
fname2
);
fp
=
fopen
(
fname2
,
"rb"
);
#endif
}
}
if
(
!
fp
)
if
(
!
r
fp
)
return
false
;
return
false
;
pdata
=
replay_data
;
pdata
=
replay_data
;
...
@@ -142,13 +129,13 @@ bool Replay::OpenReplay(const wchar_t* name) {
...
@@ -142,13 +129,13 @@ bool Replay::OpenReplay(const wchar_t* name) {
is_replaying
=
false
;
is_replaying
=
false
;
replay_size
=
0
;
replay_size
=
0
;
comp_size
=
0
;
comp_size
=
0
;
if
(
fread
(
&
pheader
,
sizeof
(
pheader
),
1
,
fp
)
<
1
)
{
if
(
fread
(
&
pheader
,
sizeof
pheader
,
1
,
r
fp
)
<
1
)
{
fclose
(
fp
);
fclose
(
r
fp
);
return
false
;
return
false
;
}
}
if
(
pheader
.
flag
&
REPLAY_COMPRESSED
)
{
if
(
pheader
.
flag
&
REPLAY_COMPRESSED
)
{
comp_size
=
fread
(
comp_data
,
1
,
MAX_COMP_SIZE
,
fp
);
comp_size
=
fread
(
comp_data
,
1
,
MAX_COMP_SIZE
,
r
fp
);
fclose
(
fp
);
fclose
(
r
fp
);
if
((
int
)
pheader
.
datasize
<
0
&&
(
int
)
pheader
.
datasize
>
MAX_REPLAY_SIZE
)
if
((
int
)
pheader
.
datasize
<
0
&&
(
int
)
pheader
.
datasize
>
MAX_REPLAY_SIZE
)
return
false
;
return
false
;
replay_size
=
pheader
.
datasize
;
replay_size
=
pheader
.
datasize
;
...
@@ -159,8 +146,8 @@ bool Replay::OpenReplay(const wchar_t* name) {
...
@@ -159,8 +146,8 @@ bool Replay::OpenReplay(const wchar_t* name) {
return
false
;
return
false
;
}
}
}
else
{
}
else
{
replay_size
=
fread
(
replay_data
,
1
,
MAX_REPLAY_SIZE
,
fp
);
replay_size
=
fread
(
replay_data
,
1
,
MAX_REPLAY_SIZE
,
r
fp
);
fclose
(
fp
);
fclose
(
r
fp
);
comp_size
=
0
;
comp_size
=
0
;
}
}
is_replaying
=
true
;
is_replaying
=
true
;
...
@@ -169,24 +156,20 @@ bool Replay::OpenReplay(const wchar_t* name) {
...
@@ -169,24 +156,20 @@ bool Replay::OpenReplay(const wchar_t* name) {
bool
Replay
::
CheckReplay
(
const
wchar_t
*
name
)
{
bool
Replay
::
CheckReplay
(
const
wchar_t
*
name
)
{
wchar_t
fname
[
256
];
wchar_t
fname
[
256
];
myswprintf
(
fname
,
L"./replay/%ls"
,
name
);
myswprintf
(
fname
,
L"./replay/%ls"
,
name
);
#ifdef WIN32
char
fullname
[
256
]{};
FILE
*
rfp
=
_wfopen
(
fname
,
L"rb"
);
BufferIO
::
EncodeUTF8
(
fname
,
fullname
);
#else
FILE
*
rfp
=
myfopen
(
fullname
,
"rb"
);
char
fname2
[
256
];
BufferIO
::
EncodeUTF8
(
fname
,
fname2
);
FILE
*
rfp
=
fopen
(
fname2
,
"rb"
);
#endif
if
(
!
rfp
)
if
(
!
rfp
)
return
false
;
return
false
;
ReplayHeader
rheader
;
ReplayHeader
rheader
;
size_t
count
=
fread
(
&
rheader
,
sizeof
(
ReplayHeader
)
,
1
,
rfp
);
size_t
count
=
fread
(
&
rheader
,
sizeof
rheader
,
1
,
rfp
);
fclose
(
rfp
);
fclose
(
rfp
);
return
count
==
1
&&
rheader
.
id
==
0x31707279
&&
rheader
.
version
>=
0x12d0u
&&
(
rheader
.
version
<
0x1353u
||
(
rheader
.
flag
&
REPLAY_UNIFORM
));
return
count
==
1
&&
rheader
.
id
==
0x31707279
&&
rheader
.
version
>=
0x12d0u
&&
(
rheader
.
version
<
0x1353u
||
(
rheader
.
flag
&
REPLAY_UNIFORM
));
}
}
bool
Replay
::
DeleteReplay
(
const
wchar_t
*
name
)
{
bool
Replay
::
DeleteReplay
(
const
wchar_t
*
name
)
{
wchar_t
fname
[
256
];
wchar_t
fname
[
256
];
myswprintf
(
fname
,
L"./replay/%ls"
,
name
);
myswprintf
(
fname
,
L"./replay/%ls"
,
name
);
#ifdef WIN32
#ifdef
_
WIN32
BOOL
result
=
DeleteFileW
(
fname
);
BOOL
result
=
DeleteFileW
(
fname
);
return
!!
result
;
return
!!
result
;
#else
#else
...
@@ -201,7 +184,7 @@ bool Replay::RenameReplay(const wchar_t* oldname, const wchar_t* newname) {
...
@@ -201,7 +184,7 @@ bool Replay::RenameReplay(const wchar_t* oldname, const wchar_t* newname) {
wchar_t
newfname
[
256
];
wchar_t
newfname
[
256
];
myswprintf
(
oldfname
,
L"./replay/%ls"
,
oldname
);
myswprintf
(
oldfname
,
L"./replay/%ls"
,
oldname
);
myswprintf
(
newfname
,
L"./replay/%ls"
,
newname
);
myswprintf
(
newfname
,
L"./replay/%ls"
,
newname
);
#ifdef WIN32
#ifdef
_
WIN32
BOOL
result
=
MoveFileW
(
oldfname
,
newfname
);
BOOL
result
=
MoveFileW
(
oldfname
,
newfname
);
return
!!
result
;
return
!!
result
;
#else
#else
...
...
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