Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
illuna-minetest
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Illuna-Minetest
illuna-minetest
Commits
2f8fbdb9
Commit
2f8fbdb9
authored
10 years ago
by
SmallJoker
Committed by
Zeno-
10 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Rewrite fs:GetDirListing(file) by kahrl
parent
5229a229
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/filesys.cpp
+15
-47
15 additions, 47 deletions
src/filesys.cpp
with
15 additions
and
47 deletions
src/filesys.cpp
+
15
−
47
View file @
2f8fbdb9
...
...
@@ -34,11 +34,6 @@ namespace fs
#define _WIN32_WINNT 0x0501
#include
<windows.h>
#include
<malloc.h>
#include
<tchar.h>
#include
<wchar.h>
#define BUFSIZE MAX_PATH
std
::
vector
<
DirListNode
>
GetDirListing
(
std
::
string
pathstring
)
{
...
...
@@ -47,34 +42,18 @@ std::vector<DirListNode> GetDirListing(std::string pathstring)
WIN32_FIND_DATA
FindFileData
;
HANDLE
hFind
=
INVALID_HANDLE_VALUE
;
DWORD
dwError
;
LPTSTR
DirSpec
;
INT
retval
;
DirSpec
=
(
LPTSTR
)
malloc
(
BUFSIZE
);
if
(
DirSpec
==
NULL
)
{
errorstream
<<
"GetDirListing: Insufficient memory available"
<<
std
::
endl
;
retval
=
1
;
goto
Cleanup
;
}
// Check that the input is not larger than allowed.
if
(
pathstring
.
size
()
>
(
BUFSIZE
-
2
))
{
errorstream
<<
"GetDirListing: Input directory is too large."
<<
std
::
endl
;
retval
=
3
;
goto
Cleanup
;
}
//_tprintf (TEXT("Target directory is %s.\n"), pathstring.c_str());
sprintf
(
DirSpec
,
"%s"
,
(
pathstring
+
"
\\
*"
).
c_str
());
std
::
string
dirSpec
=
pathstring
+
"
\\
*"
;
// Find the first file in the directory.
hFind
=
FindFirstFile
(
D
irSpec
,
&
FindFileData
);
hFind
=
FindFirstFile
(
d
irSpec
.
c_str
()
,
&
FindFileData
);
if
(
hFind
==
INVALID_HANDLE_VALUE
)
{
retval
=
(
-
1
);
goto
Cleanup
;
dwError
=
GetLastError
();
if
(
dwError
!=
ERROR_FILE_NOT_FOUND
&&
dwError
!=
ERROR_PATH_NOT_FOUND
)
{
errorstream
<<
"GetDirListing: FindFirstFile error."
<<
" Error is "
<<
dwError
<<
std
::
endl
;
}
}
else
{
// NOTE:
// Be very sure to not include '..' in the results, it will
...
...
@@ -83,7 +62,7 @@ std::vector<DirListNode> GetDirListing(std::string pathstring)
DirListNode
node
;
node
.
name
=
FindFileData
.
cFileName
;
node
.
dir
=
FindFileData
.
dwFileAttributes
&
FILE_ATTRIBUTE_DIRECTORY
;
if
(
node
.
name
!=
"."
&&
node
.
name
!=
".."
)
if
(
node
.
name
!=
"."
&&
node
.
name
!=
".."
)
listing
.
push_back
(
node
);
// List all the other files in the directory.
...
...
@@ -98,23 +77,12 @@ std::vector<DirListNode> GetDirListing(std::string pathstring)
dwError
=
GetLastError
();
FindClose
(
hFind
);
if
(
dwError
!=
ERROR_NO_MORE_FILES
)
{
errorstream
<<
"GetDirListing: FindNextFile error.
Error is
"
<<
dwError
<<
std
::
endl
;
retval
=
(
-
1
);
goto
Cleanup
;
}
errorstream
<<
"GetDirListing: FindNextFile error."
<<
" Error is "
<<
dwError
<<
std
::
endl
;
listing
.
clear
(
);
return
listing
;
}
}
retval
=
0
;
Cleanup
:
free
(
DirSpec
);
if
(
retval
!=
0
)
listing
.
clear
();
//for(unsigned int i=0; i<listing.size(); i++){
// infostream<<listing[i].name<<(listing[i].dir?" (dir)":" (file)")<<std::endl;
//}
return
listing
;
}
...
...
@@ -246,7 +214,7 @@ std::vector<DirListNode> GetDirListing(std::string pathstring)
// NOTE:
// Be very sure to not include '..' in the results, it will
// result in an epic failure when deleting stuff.
if
(
dirp
->
d_name
==
"."
||
dirp
->
d_name
==
".."
)
if
(
strcmp
(
dirp
->
d_name
,
"."
)
==
0
||
strcmp
(
dirp
->
d_name
,
".."
)
==
0
)
continue
;
DirListNode
node
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment