Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
G
Grasscutter
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Operate
Environments
Terraform modules
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
ziqian zhang
Grasscutter
Commits
a088ea9b
Commit
a088ea9b
authored
3 years ago
by
Melledy
Browse files
Options
Downloads
Patches
Plain Diff
Fix dataloader with eclipse
parent
a5007a43
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/main/java/emu/grasscutter/data/DataLoader.java
+6
-3
6 additions, 3 deletions
src/main/java/emu/grasscutter/data/DataLoader.java
src/main/java/emu/grasscutter/utils/FileUtils.java
+17
-10
17 additions, 10 deletions
src/main/java/emu/grasscutter/utils/FileUtils.java
with
23 additions
and
13 deletions
src/main/java/emu/grasscutter/data/DataLoader.java
+
6
−
3
View file @
a088ea9b
...
@@ -7,8 +7,10 @@ import emu.grasscutter.utils.FileUtils;
...
@@ -7,8 +7,10 @@ import emu.grasscutter.utils.FileUtils;
import
emu.grasscutter.utils.Utils
;
import
emu.grasscutter.utils.Utils
;
import
java.io.*
;
import
java.io.*
;
import
java.nio.file.FileSystems
;
import
java.nio.file.Path
;
import
java.nio.file.Path
;
import
java.util.List
;
import
java.util.List
;
import
java.util.regex.Pattern
;
import
static
emu
.
grasscutter
.
Configuration
.
DATA
;
import
static
emu
.
grasscutter
.
Configuration
.
DATA
;
...
@@ -46,17 +48,18 @@ public class DataLoader {
...
@@ -46,17 +48,18 @@ public class DataLoader {
}
}
public
static
void
CheckAllFiles
()
{
public
static
void
CheckAllFiles
()
{
String
pathSplitter
=
"defaults"
+
Pattern
.
quote
(
FileSystems
.
getDefault
().
getSeparator
())
+
"data"
+
Pattern
.
quote
(
FileSystems
.
getDefault
().
getSeparator
());
try
{
try
{
List
<
Path
>
filenames
=
FileUtils
.
getPathsFromResource
(
"/defaults/data/"
);
List
<
Path
>
filenames
=
FileUtils
.
getPathsFromResource
(
"/defaults/data/"
);
for
(
Path
file
:
filenames
)
{
for
(
Path
file
:
filenames
)
{
String
relativePath
=
String
.
valueOf
(
file
).
split
(
"/defaults/data/"
)[
1
];
String
relativePath
=
String
.
valueOf
(
file
).
split
(
pathSplitter
)[
1
];
CheckAndCopyData
(
relativePath
);
CheckAndCopyData
(
relativePath
);
}
}
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
Grasscutter
.
getLogger
().
error
(
"An error occurred while trying to check the data folder. \n"
+
e
);
Grasscutter
.
getLogger
().
error
(
"An error occurred while trying to check the data folder. \n"
,
e
);
}
}
GenerateGachaMappings
();
GenerateGachaMappings
();
...
...
This diff is collapsed.
Click to expand it.
src/main/java/emu/grasscutter/utils/FileUtils.java
+
17
−
10
View file @
a088ea9b
...
@@ -9,6 +9,7 @@ import java.net.URI;
...
@@ -9,6 +9,7 @@ import java.net.URI;
import
java.net.URISyntaxException
;
import
java.net.URISyntaxException
;
import
java.nio.charset.StandardCharsets
;
import
java.nio.charset.StandardCharsets
;
import
java.nio.file.*
;
import
java.nio.file.*
;
import
java.util.Arrays
;
import
java.util.Collections
;
import
java.util.Collections
;
import
java.util.List
;
import
java.util.List
;
import
java.util.stream.Collectors
;
import
java.util.stream.Collectors
;
...
@@ -76,23 +77,29 @@ public final class FileUtils {
...
@@ -76,23 +77,29 @@ public final class FileUtils {
// From https://mkyong.com/java/java-read-a-file-from-resources-folder/
// From https://mkyong.com/java/java-read-a-file-from-resources-folder/
public
static
List
<
Path
>
getPathsFromResource
(
String
folder
)
throws
URISyntaxException
,
IOException
{
public
static
List
<
Path
>
getPathsFromResource
(
String
folder
)
throws
URISyntaxException
,
IOException
{
List
<
Path
>
result
;
List
<
Path
>
result
=
null
;
//
g
et path of the current running JAR
//
G
et path of the current running JAR
String
jarPath
=
Grasscutter
.
class
.
getProtectionDomain
()
String
jarPath
=
Grasscutter
.
class
.
getProtectionDomain
()
.
getCodeSource
()
.
getCodeSource
()
.
getLocation
()
.
getLocation
()
.
toURI
()
.
toURI
()
.
getPath
();
.
getPath
();
// file walks JAR
try
{
URI
uri
=
URI
.
create
(
"jar:file:"
+
jarPath
);
// file walks JAR
try
(
FileSystem
fs
=
FileSystems
.
newFileSystem
(
uri
,
Collections
.
emptyMap
()))
{
URI
uri
=
URI
.
create
(
"jar:file:"
+
jarPath
);
result
=
Files
.
walk
(
fs
.
getPath
(
folder
))
try
(
FileSystem
fs
=
FileSystems
.
newFileSystem
(
uri
,
Collections
.
emptyMap
()))
{
.
filter
(
Files:
:
isRegularFile
)
result
=
Files
.
walk
(
fs
.
getPath
(
folder
))
.
collect
(
Collectors
.
toList
());
.
filter
(
Files:
:
isRegularFile
)
.
collect
(
Collectors
.
toList
());
}
}
catch
(
Exception
e
)
{
// Eclipse puts resources in its bin folder
File
f
=
new
File
(
jarPath
+
"defaults/data/"
);
result
=
Arrays
.
stream
(
f
.
listFiles
()).
map
(
File:
:
toPath
).
toList
();
}
}
return
result
;
return
result
;
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
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