Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
ziqian zhang
Grasscutter
Commits
512021b2
Commit
512021b2
authored
May 19, 2022
by
Melledy
Browse files
Fix dataloader with eclipse
parent
bad85357
Changes
2
Show whitespace changes
Inline
Side-by-side
src/main/java/emu/grasscutter/data/DataLoader.java
View file @
512021b2
...
...
@@ -7,8 +7,10 @@ import emu.grasscutter.utils.FileUtils;
import
emu.grasscutter.utils.Utils
;
import
java.io.*
;
import
java.nio.file.FileSystems
;
import
java.nio.file.Path
;
import
java.util.List
;
import
java.util.regex.Pattern
;
import
static
emu
.
grasscutter
.
Configuration
.
DATA
;
...
...
@@ -46,17 +48,18 @@ public class DataLoader {
}
public
static
void
CheckAllFiles
()
{
String
pathSplitter
=
"defaults"
+
Pattern
.
quote
(
FileSystems
.
getDefault
().
getSeparator
())
+
"data"
+
Pattern
.
quote
(
FileSystems
.
getDefault
().
getSeparator
());
try
{
List
<
Path
>
filenames
=
FileUtils
.
getPathsFromResource
(
"/defaults/data/"
);
for
(
Path
file
:
filenames
)
{
String
relativePath
=
String
.
valueOf
(
file
).
split
(
"/defaults/data/"
)[
1
];
String
relativePath
=
String
.
valueOf
(
file
).
split
(
pathSplitter
)[
1
];
CheckAndCopyData
(
relativePath
);
}
}
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
();
...
...
src/main/java/emu/grasscutter/utils/FileUtils.java
View file @
512021b2
...
...
@@ -9,6 +9,7 @@ import java.net.URI;
import
java.net.URISyntaxException
;
import
java.nio.charset.StandardCharsets
;
import
java.nio.file.*
;
import
java.util.Arrays
;
import
java.util.Collections
;
import
java.util.List
;
import
java.util.stream.Collectors
;
...
...
@@ -76,15 +77,16 @@ public final class FileUtils {
// From https://mkyong.com/java/java-read-a-file-from-resources-folder/
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
()
.
getCodeSource
()
.
getLocation
()
.
toURI
()
.
getPath
();
try
{
// file walks JAR
URI
uri
=
URI
.
create
(
"jar:file:"
+
jarPath
);
try
(
FileSystem
fs
=
FileSystems
.
newFileSystem
(
uri
,
Collections
.
emptyMap
()))
{
...
...
@@ -92,6 +94,11 @@ public final class FileUtils {
.
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
;
}
...
...
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