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
Hide 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) {
#include "../ocgcore/ocgapi.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>
using
namespace
irr
;
using
namespace
core
;
...
...
gframe/deck_manager.cpp
View file @
a8ccdbb1
...
...
@@ -263,15 +263,9 @@ void DeckManager::GetDeckFile(wchar_t* ret, irr::gui::IGUIComboBox* cbCategory,
}
}
FILE
*
DeckManager
::
OpenDeckFile
(
const
wchar_t
*
file
,
const
char
*
mode
)
{
#ifdef WIN32
wchar_t
wmode
[
20
]{};
BufferIO
::
CopyWStr
(
mode
,
wmode
,
sizeof
wmode
/
sizeof
wmode
[
0
]);
FILE
*
fp
=
_wfopen
(
file
,
wmode
);
#else
char
file2
[
256
];
BufferIO
::
EncodeUTF8
(
file
,
file2
);
FILE
*
fp
=
fopen
(
file2
,
mode
);
#endif
char
fullname
[
256
]{};
BufferIO
::
EncodeUTF8
(
file
,
fullname
);
FILE
*
fp
=
myfopen
(
fullname
,
mode
);
return
fp
;
}
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) {
const
wchar_t
*
name
=
mainGame
->
lstSinglePlayList
->
getListItem
(
sel
);
wchar_t
fname
[
256
];
myswprintf
(
fname
,
L"./single/%ls"
,
name
);
FILE
*
fp
;
#ifdef _WIN32
fp
=
_wfopen
(
fname
,
L"rb"
);
#else
char
filename
[
256
];
BufferIO
::
EncodeUTF8
(
fname
,
filename
);
fp
=
fopen
(
filename
,
"rb"
);
#endif
char
fullname
[
256
]{};
BufferIO
::
EncodeUTF8
(
fname
,
fullname
);
FILE
*
fp
=
myfopen
(
fullname
,
"rb"
);
if
(
!
fp
)
{
mainGame
->
stSinglePlayInfo
->
setText
(
L""
);
break
;
...
...
gframe/replay.cpp
View file @
a8ccdbb1
...
...
@@ -102,39 +102,26 @@ void Replay::SaveReplay(const wchar_t* name) {
return
;
wchar_t
fname
[
256
];
myswprintf
(
fname
,
L"./replay/%ls.yrp"
,
name
);
#ifdef WIN32
fp
=
_wfopen
(
fname
,
L"wb"
);
#else
char
fname2
[
256
];
BufferIO
::
EncodeUTF8
(
fname
,
fname2
);
fp
=
fopen
(
fname2
,
"wb"
);
#endif
if
(
!
fp
)
char
fullname
[
256
]{};
BufferIO
::
EncodeUTF8
(
fname
,
fullname
);
FILE
*
rfp
=
myfopen
(
fullname
,
"wb"
);
if
(
!
rfp
)
return
;
fwrite
(
&
pheader
,
sizeof
(
pheader
),
1
,
fp
);
fwrite
(
comp_data
,
comp_size
,
1
,
fp
);
fclose
(
fp
);
fwrite
(
&
pheader
,
sizeof
pheader
,
1
,
r
fp
);
fwrite
(
comp_data
,
comp_size
,
1
,
r
fp
);
fclose
(
r
fp
);
}
bool
Replay
::
OpenReplay
(
const
wchar_t
*
name
)
{
#ifdef WIN32
fp
=
_wfopen
(
name
,
L"rb"
);
#else
char
name2
[
256
];
BufferIO
::
EncodeUTF8
(
name
,
name2
);
fp
=
fopen
(
name2
,
"rb"
);
#endif
if
(
!
fp
)
{
char
fullname
[
256
]{};
BufferIO
::
EncodeUTF8
(
name
,
fullname
);
FILE
*
rfp
=
myfopen
(
fullname
,
"rb"
);
if
(
!
rfp
)
{
wchar_t
fname
[
256
];
myswprintf
(
fname
,
L"./replay/%ls"
,
name
);
#ifdef WIN32
fp
=
_wfopen
(
fname
,
L"rb"
);
#else
char
fname2
[
256
];
BufferIO
::
EncodeUTF8
(
fname
,
fname2
);
fp
=
fopen
(
fname2
,
"rb"
);
#endif
BufferIO
::
EncodeUTF8
(
fname
,
fullname
);
rfp
=
myfopen
(
fullname
,
"rb"
);
}
if
(
!
fp
)
if
(
!
r
fp
)
return
false
;
pdata
=
replay_data
;
...
...
@@ -142,13 +129,13 @@ bool Replay::OpenReplay(const wchar_t* name) {
is_replaying
=
false
;
replay_size
=
0
;
comp_size
=
0
;
if
(
fread
(
&
pheader
,
sizeof
(
pheader
),
1
,
fp
)
<
1
)
{
fclose
(
fp
);
if
(
fread
(
&
pheader
,
sizeof
pheader
,
1
,
r
fp
)
<
1
)
{
fclose
(
r
fp
);
return
false
;
}
if
(
pheader
.
flag
&
REPLAY_COMPRESSED
)
{
comp_size
=
fread
(
comp_data
,
1
,
MAX_COMP_SIZE
,
fp
);
fclose
(
fp
);
comp_size
=
fread
(
comp_data
,
1
,
MAX_COMP_SIZE
,
r
fp
);
fclose
(
r
fp
);
if
((
int
)
pheader
.
datasize
<
0
&&
(
int
)
pheader
.
datasize
>
MAX_REPLAY_SIZE
)
return
false
;
replay_size
=
pheader
.
datasize
;
...
...
@@ -159,8 +146,8 @@ bool Replay::OpenReplay(const wchar_t* name) {
return
false
;
}
}
else
{
replay_size
=
fread
(
replay_data
,
1
,
MAX_REPLAY_SIZE
,
fp
);
fclose
(
fp
);
replay_size
=
fread
(
replay_data
,
1
,
MAX_REPLAY_SIZE
,
r
fp
);
fclose
(
r
fp
);
comp_size
=
0
;
}
is_replaying
=
true
;
...
...
@@ -169,24 +156,20 @@ bool Replay::OpenReplay(const wchar_t* name) {
bool
Replay
::
CheckReplay
(
const
wchar_t
*
name
)
{
wchar_t
fname
[
256
];
myswprintf
(
fname
,
L"./replay/%ls"
,
name
);
#ifdef WIN32
FILE
*
rfp
=
_wfopen
(
fname
,
L"rb"
);
#else
char
fname2
[
256
];
BufferIO
::
EncodeUTF8
(
fname
,
fname2
);
FILE
*
rfp
=
fopen
(
fname2
,
"rb"
);
#endif
char
fullname
[
256
]{};
BufferIO
::
EncodeUTF8
(
fname
,
fullname
);
FILE
*
rfp
=
myfopen
(
fullname
,
"rb"
);
if
(
!
rfp
)
return
false
;
ReplayHeader
rheader
;
size_t
count
=
fread
(
&
rheader
,
sizeof
(
ReplayHeader
)
,
1
,
rfp
);
size_t
count
=
fread
(
&
rheader
,
sizeof
rheader
,
1
,
rfp
);
fclose
(
rfp
);
return
count
==
1
&&
rheader
.
id
==
0x31707279
&&
rheader
.
version
>=
0x12d0u
&&
(
rheader
.
version
<
0x1353u
||
(
rheader
.
flag
&
REPLAY_UNIFORM
));
}
bool
Replay
::
DeleteReplay
(
const
wchar_t
*
name
)
{
wchar_t
fname
[
256
];
myswprintf
(
fname
,
L"./replay/%ls"
,
name
);
#ifdef WIN32
#ifdef
_
WIN32
BOOL
result
=
DeleteFileW
(
fname
);
return
!!
result
;
#else
...
...
@@ -201,7 +184,7 @@ bool Replay::RenameReplay(const wchar_t* oldname, const wchar_t* newname) {
wchar_t
newfname
[
256
];
myswprintf
(
oldfname
,
L"./replay/%ls"
,
oldname
);
myswprintf
(
newfname
,
L"./replay/%ls"
,
newname
);
#ifdef WIN32
#ifdef
_
WIN32
BOOL
result
=
MoveFileW
(
oldfname
,
newfname
);
return
!!
result
;
#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