Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
M
Mirai
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
MyCard
Mirai
Commits
4b96bf0e
Commit
4b96bf0e
authored
Sep 15, 2019
by
Him188moe
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
updated
parent
ad89a176
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
14 deletions
+15
-14
mirai-core/src/main/java/net/mamoe/mirai/utils/setting/MiraiSettings.java
...ain/java/net/mamoe/mirai/utils/setting/MiraiSettings.java
+15
-14
No files found.
mirai-core/src/main/java/net/mamoe/mirai/utils/setting/MiraiSettings.java
View file @
4b96bf0e
...
@@ -3,12 +3,14 @@ package net.mamoe.mirai.utils.setting;
...
@@ -3,12 +3,14 @@ package net.mamoe.mirai.utils.setting;
import
net.mamoe.mirai.plugin.MiraiPluginBase
;
import
net.mamoe.mirai.plugin.MiraiPluginBase
;
import
org.ini4j.Config
;
import
org.ini4j.Config
;
import
org.ini4j.Ini
;
import
org.ini4j.Ini
;
import
org.jetbrains.annotations.NotNull
;
import
java.io.File
;
import
java.io.File
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
import
java.util.Objects
;
import
java.util.concurrent.ConcurrentHashMap
;
import
java.util.concurrent.ConcurrentHashMap
;
/**
/**
...
@@ -31,16 +33,15 @@ public class MiraiSettings {
...
@@ -31,16 +33,15 @@ public class MiraiSettings {
this
(
new
File
(
filename
));
this
(
new
File
(
filename
));
}
}
public
MiraiSettings
(
File
file
)
{
public
MiraiSettings
(
@NotNull
File
file
)
{
if
(!
file
.
getName
().
contains
(
"."
)){
Objects
.
requireNonNull
(
file
);
if
(!
file
.
getName
().
contains
(
"."
))
{
file
=
new
File
(
file
.
getPath
()
+
".ini"
);
file
=
new
File
(
file
.
getPath
()
+
".ini"
);
}
}
this
.
file
=
file
;
this
.
file
=
file
;
try
{
try
{
if
(!
file
.
exists
())
{
if
(!
file
.
exists
()
&&
!
file
.
createNewFile
())
{
if
(!
file
.
createNewFile
())
{
throw
new
RuntimeException
(
"cannot create config file "
+
file
);
throw
new
RuntimeException
(
"cannot create config file "
+
file
);
}
}
}
Config
config
=
new
Config
();
Config
config
=
new
Config
();
config
.
setMultiSection
(
true
);
config
.
setMultiSection
(
true
);
...
@@ -58,9 +59,9 @@ public class MiraiSettings {
...
@@ -58,9 +59,9 @@ public class MiraiSettings {
public
synchronized
MiraiSettingMapSection
getMapSection
(
String
key
)
{
public
synchronized
MiraiSettingMapSection
getMapSection
(
String
key
)
{
if
(!
cacheSection
.
containsKey
(
key
))
{
if
(!
cacheSection
.
containsKey
(
key
))
{
MiraiSettingMapSection
section
=
new
MiraiSettingMapSection
();
MiraiSettingMapSection
section
=
new
MiraiSettingMapSection
();
if
(
ini
.
containsKey
(
key
))
{
if
(
ini
.
containsKey
(
key
))
{
section
.
putAll
(
ini
.
get
(
key
));
section
.
putAll
(
ini
.
get
(
key
));
}
}
cacheSection
.
put
(
key
,
section
);
cacheSection
.
put
(
key
,
section
);
...
@@ -69,9 +70,9 @@ public class MiraiSettings {
...
@@ -69,9 +70,9 @@ public class MiraiSettings {
}
}
public
synchronized
MiraiSettingListSection
getListSection
(
String
key
)
{
public
synchronized
MiraiSettingListSection
getListSection
(
String
key
)
{
if
(!
cacheSection
.
containsKey
(
key
))
{
if
(!
cacheSection
.
containsKey
(
key
))
{
MiraiSettingListSection
section
=
new
MiraiSettingListSection
();
MiraiSettingListSection
section
=
new
MiraiSettingListSection
();
if
(
ini
.
containsKey
(
key
))
{
if
(
ini
.
containsKey
(
key
))
{
section
.
addAll
(
ini
.
get
(
key
).
values
());
section
.
addAll
(
ini
.
get
(
key
).
values
());
}
}
cacheSection
.
put
(
key
,
section
);
cacheSection
.
put
(
key
,
section
);
...
@@ -80,10 +81,10 @@ public class MiraiSettings {
...
@@ -80,10 +81,10 @@ public class MiraiSettings {
}
}
public
synchronized
void
save
(){
public
synchronized
void
save
()
{
cacheSection
.
forEach
((
k
,
a
)
->
{
cacheSection
.
forEach
((
k
,
a
)
->
{
if
(!
ini
.
containsKey
(
k
))
{
if
(!
ini
.
containsKey
(
k
))
{
ini
.
put
(
k
,
""
,
new
HashMap
<>());
ini
.
put
(
k
,
""
,
new
HashMap
<>());
}
}
a
.
saveAsSection
(
ini
.
get
(
k
));
a
.
saveAsSection
(
ini
.
get
(
k
));
});
});
...
...
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