Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Y
ygopro-2pick
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-2pick
Commits
ead2ed3e
Commit
ead2ed3e
authored
Mar 26, 2019
by
mercury233
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'sort_files_fh' of
https://github.com/purerosefallen/ygopro
into test
parents
4166c835
dfa870a6
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
1 deletion
+23
-1
gframe/myfilesystem.h
gframe/myfilesystem.h
+23
-1
No files found.
gframe/myfilesystem.h
View file @
ead2ed3e
...
...
@@ -8,6 +8,8 @@
#ifndef _WIN32
#include <dirent.h>
#include <sys/stat.h>
#include <vector>
#include <algorithm>
#endif
#ifdef _WIN32
...
...
@@ -109,21 +111,41 @@ public:
return
MakeDir
(
dir
);
}
struct
file_unit
{
std
::
string
filename
;
bool
is_dir
;
};
static
void
TraversalDir
(
const
char
*
path
,
const
std
::
function
<
void
(
const
char
*
,
bool
)
>&
cb
)
{
DIR
*
dir
=
nullptr
;
struct
dirent
*
dirp
=
nullptr
;
if
((
dir
=
opendir
(
path
))
==
nullptr
)
return
;
struct
stat
fileStat
;
std
::
vector
<
file_unit
>
file_list
;
while
((
dirp
=
readdir
(
dir
))
!=
nullptr
)
{
file_unit
funit
;
char
fname
[
1024
];
strcpy
(
fname
,
path
);
strcat
(
fname
,
"/"
);
strcat
(
fname
,
dirp
->
d_name
);
stat
(
fname
,
&
fileStat
);
cb
(
dirp
->
d_name
,
S_ISDIR
(
fileStat
.
st_mode
));
funit
.
filename
=
std
::
string
(
dirp
->
d_name
);
funit
.
is_dir
=
S_ISDIR
(
fileStat
.
st_mode
);
file_list
.
push_back
(
funit
);
}
closedir
(
dir
);
std
::
sort
(
file_list
.
begin
(),
file_list
.
end
(),
TraversalDirSort
);
for
(
file_unit
funit
:
file_list
)
cb
(
funit
.
filename
.
c_str
(),
funit
.
is_dir
);
}
static
bool
TraversalDirSort
(
file_unit
file1
,
file_unit
file2
)
{
if
(
file1
.
is_dir
!=
file2
.
is_dir
)
{
return
file2
.
is_dir
;
}
else
{
return
file1
.
filename
<
file2
.
filename
;
}
}
static
void
TraversalDir
(
const
wchar_t
*
wpath
,
const
std
::
function
<
void
(
const
wchar_t
*
,
bool
)
>&
cb
)
{
...
...
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