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
c470682b
Commit
c470682b
authored
Sep 08, 2025
by
Chen Bill
Committed by
GitHub
Sep 08, 2025
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor SaveReplay, Check file path (#2917)
parent
47ccc4af
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
35 additions
and
17 deletions
+35
-17
gframe/duelclient.cpp
gframe/duelclient.cpp
+5
-2
gframe/replay.cpp
gframe/replay.cpp
+29
-14
gframe/replay.h
gframe/replay.h
+1
-1
No files found.
gframe/duelclient.cpp
View file @
c470682b
...
@@ -762,8 +762,11 @@ void DuelClient::HandleSTOCPacketLan(unsigned char* data, int len) {
...
@@ -762,8 +762,11 @@ void DuelClient::HandleSTOCPacketLan(unsigned char* data, int len) {
prep
+=
sizeof
new_replay
.
pheader
;
prep
+=
sizeof
new_replay
.
pheader
;
std
::
memcpy
(
new_replay
.
comp_data
,
prep
,
len
-
sizeof
new_replay
.
pheader
-
1
);
std
::
memcpy
(
new_replay
.
comp_data
,
prep
,
len
-
sizeof
new_replay
.
pheader
-
1
);
new_replay
.
comp_size
=
len
-
sizeof
new_replay
.
pheader
-
1
;
new_replay
.
comp_size
=
len
-
sizeof
new_replay
.
pheader
-
1
;
if
(
mainGame
->
actionParam
)
if
(
mainGame
->
actionParam
)
{
new_replay
.
SaveReplay
(
mainGame
->
ebRSName
->
getText
());
bool
save_result
=
new_replay
.
SaveReplay
(
mainGame
->
ebRSName
->
getText
());
if
(
!
save_result
)
new_replay
.
SaveReplay
(
L"_LastReplay"
);
}
else
else
new_replay
.
SaveReplay
(
L"_LastReplay"
);
new_replay
.
SaveReplay
(
L"_LastReplay"
);
}
}
...
...
gframe/replay.cpp
View file @
c470682b
...
@@ -63,23 +63,29 @@ void Replay::EndRecord() {
...
@@ -63,23 +63,29 @@ void Replay::EndRecord() {
}
}
is_recording
=
false
;
is_recording
=
false
;
}
}
void
Replay
::
SaveReplay
(
const
wchar_t
*
name
)
{
bool
Replay
::
SaveReplay
(
const
wchar_t
*
base_
name
)
{
if
(
!
FileSystem
::
IsDirExists
(
L"./replay"
)
&&
!
FileSystem
::
MakeDir
(
L"./replay"
))
if
(
!
FileSystem
::
IsDirExists
(
L"./replay"
)
&&
!
FileSystem
::
MakeDir
(
L"./replay"
))
return
;
return
false
;
wchar_t
fname
[
256
];
wchar_t
filename
[
256
]{};
myswprintf
(
fname
,
L"./replay/%ls.yrp"
,
name
);
wchar_t
path
[
256
]{};
FILE
*
rfp
=
mywfopen
(
fname
,
"wb"
);
BufferIO
::
CopyWideString
(
base_name
,
filename
);
FileSystem
::
SafeFileName
(
filename
);
if
(
myswprintf
(
path
,
L"./replay/%ls.yrp"
,
filename
)
<=
0
)
return
false
;
FILE
*
rfp
=
mywfopen
(
path
,
"wb"
);
if
(
!
rfp
)
if
(
!
rfp
)
return
;
return
false
;
std
::
fwrite
(
&
pheader
,
sizeof
pheader
,
1
,
rfp
);
std
::
fwrite
(
&
pheader
,
sizeof
pheader
,
1
,
rfp
);
std
::
fwrite
(
comp_data
,
comp_size
,
1
,
rfp
);
std
::
fwrite
(
comp_data
,
comp_size
,
1
,
rfp
);
std
::
fclose
(
rfp
);
std
::
fclose
(
rfp
);
return
true
;
}
}
bool
Replay
::
OpenReplay
(
const
wchar_t
*
name
)
{
bool
Replay
::
OpenReplay
(
const
wchar_t
*
name
)
{
FILE
*
rfp
=
mywfopen
(
name
,
"rb"
);
FILE
*
rfp
=
mywfopen
(
name
,
"rb"
);
if
(
!
rfp
)
{
if
(
!
rfp
)
{
wchar_t
fname
[
256
];
wchar_t
fname
[
256
];
myswprintf
(
fname
,
L"./replay/%ls"
,
name
);
if
(
myswprintf
(
fname
,
L"./replay/%ls"
,
name
)
<=
0
)
return
false
;
rfp
=
mywfopen
(
fname
,
"rb"
);
rfp
=
mywfopen
(
fname
,
"rb"
);
}
}
if
(
!
rfp
)
if
(
!
rfp
)
...
@@ -131,19 +137,28 @@ bool Replay::OpenReplay(const wchar_t* name) {
...
@@ -131,19 +137,28 @@ bool Replay::OpenReplay(const wchar_t* name) {
return
true
;
return
true
;
}
}
bool
Replay
::
DeleteReplay
(
const
wchar_t
*
name
)
{
bool
Replay
::
DeleteReplay
(
const
wchar_t
*
name
)
{
if
(
std
::
wcschr
(
name
,
L'/'
)
||
std
::
wcschr
(
name
,
L'\\'
))
return
false
;
wchar_t
fname
[
256
];
wchar_t
fname
[
256
];
myswprintf
(
fname
,
L"./replay/%ls"
,
name
);
if
(
myswprintf
(
fname
,
L"./replay/%ls"
,
name
)
<=
0
)
return
false
;
return
FileSystem
::
RemoveFile
(
fname
);
return
FileSystem
::
RemoveFile
(
fname
);
}
}
bool
Replay
::
RenameReplay
(
const
wchar_t
*
oldname
,
const
wchar_t
*
newname
)
{
bool
Replay
::
RenameReplay
(
const
wchar_t
*
oldname
,
const
wchar_t
*
newname
)
{
wchar_t
oldfname
[
256
];
wchar_t
old_path
[
256
];
wchar_t
newfname
[
256
];
wchar_t
new_path
[
256
];
myswprintf
(
oldfname
,
L"./replay/%ls"
,
oldname
);
if
(
std
::
wcschr
(
oldname
,
L'/'
)
||
std
::
wcschr
(
oldname
,
L'\\'
))
myswprintf
(
newfname
,
L"./replay/%ls"
,
newname
);
return
false
;
if
(
std
::
wcschr
(
newname
,
L'/'
)
||
std
::
wcschr
(
newname
,
L'\\'
))
return
false
;
if
(
myswprintf
(
old_path
,
L"./replay/%ls"
,
oldname
)
<=
0
)
return
false
;
if
(
myswprintf
(
new_path
,
L"./replay/%ls"
,
newname
)
<=
0
)
return
false
;
char
oldfilefn
[
1024
];
char
oldfilefn
[
1024
];
char
newfilefn
[
1024
];
char
newfilefn
[
1024
];
BufferIO
::
EncodeUTF8
(
old
fname
,
oldfilefn
);
BufferIO
::
EncodeUTF8
(
old
_path
,
oldfilefn
);
BufferIO
::
EncodeUTF8
(
new
fname
,
newfilefn
);
BufferIO
::
EncodeUTF8
(
new
_path
,
newfilefn
);
int
result
=
std
::
rename
(
oldfilefn
,
newfilefn
);
int
result
=
std
::
rename
(
oldfilefn
,
newfilefn
);
return
result
==
0
;
return
result
==
0
;
}
}
...
...
gframe/replay.h
View file @
c470682b
...
@@ -65,7 +65,7 @@ public:
...
@@ -65,7 +65,7 @@ public:
void
WriteInt32
(
int32_t
data
,
bool
flush
=
true
);
void
WriteInt32
(
int32_t
data
,
bool
flush
=
true
);
void
Flush
();
void
Flush
();
void
EndRecord
();
void
EndRecord
();
void
SaveReplay
(
const
wchar_t
*
name
);
bool
SaveReplay
(
const
wchar_t
*
base_
name
);
// play
// play
static
bool
DeleteReplay
(
const
wchar_t
*
name
);
static
bool
DeleteReplay
(
const
wchar_t
*
name
);
...
...
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