Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
R
rd-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
苍蓝
rd-ygopro
Commits
66749df5
Commit
66749df5
authored
Jan 21, 2019
by
nanahira
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'sort_files_fh'
parents
3e942cf2
b33eb644
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
2 deletions
+25
-2
gframe/myfilesystem.h
gframe/myfilesystem.h
+25
-2
No files found.
gframe/myfilesystem.h
View file @
66749df5
...
@@ -8,6 +8,8 @@
...
@@ -8,6 +8,8 @@
#ifndef _WIN32
#ifndef _WIN32
#include <dirent.h>
#include <dirent.h>
#include <sys/stat.h>
#include <sys/stat.h>
#include <vector>
#include <algorithm>
#endif
#endif
#ifdef _WIN32
#ifdef _WIN32
...
@@ -109,21 +111,42 @@ public:
...
@@ -109,21 +111,42 @@ public:
return
MakeDir
(
dir
);
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
)
{
static
void
TraversalDir
(
const
char
*
path
,
const
std
::
function
<
void
(
const
char
*
,
bool
)
>&
cb
)
{
DIR
*
dir
=
nullptr
;
DIR
*
dir
=
nullptr
;
struct
dirent
*
dirp
=
nullptr
;
struct
dirent
*
dirp
=
nullptr
;
if
((
dir
=
opendir
(
path
))
==
nullptr
)
if
((
dir
=
opendir
(
path
))
==
nullptr
)
return
;
return
;
struct
stat
fileStat
;
struct
stat
fileStat
;
while
((
dirp
=
readdir
(
dir
))
!=
nullptr
)
{
std
::
vector
<
file_unit
>
file_list
;
while
((
dirp
=
readdir
(
dir
))
!=
nullptr
)
{
file_unit
funit
;
char
fname
[
1024
];
char
fname
[
1024
];
strcpy
(
fname
,
path
);
strcpy
(
fname
,
path
);
strcat
(
fname
,
"/"
);
strcat
(
fname
,
"/"
);
strcat
(
fname
,
dirp
->
d_name
);
strcat
(
fname
,
dirp
->
d_name
);
stat
(
fname
,
&
fileStat
);
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
);
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
file1
.
is_dir
;
}
else
{
return
file1
.
filename
<
file2
.
filename
;
}
}
}
static
void
TraversalDir
(
const
wchar_t
*
wpath
,
const
std
::
function
<
void
(
const
wchar_t
*
,
bool
)
>&
cb
)
{
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