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
8eda9565
Commit
8eda9565
authored
Feb 14, 2020
by
Him188
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix multiplatform BotConfiguration
parent
f8cbdf1c
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
64 additions
and
46 deletions
+64
-46
mirai-core/src/androidMain/kotlin/net/mamoe/mirai/utils/BotConfigurationAndroid.kt
...n/kotlin/net/mamoe/mirai/utils/BotConfigurationAndroid.kt
+2
-2
mirai-core/src/androidMain/kotlin/net/mamoe/mirai/utils/SystemDeviceInfo.kt
...roidMain/kotlin/net/mamoe/mirai/utils/SystemDeviceInfo.kt
+18
-1
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/utils/DeviceInfo.kt
...src/commonMain/kotlin/net.mamoe.mirai/utils/DeviceInfo.kt
+39
-0
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/utils/SystemDeviceInfo.kt
...mmonMain/kotlin/net.mamoe.mirai/utils/SystemDeviceInfo.kt
+2
-0
mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/utils/BotConfigurationJvm.kt
...mMain/kotlin/net/mamoe/mirai/utils/BotConfigurationJvm.kt
+2
-2
mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/utils/SystemDeviceInfo.kt
.../jvmMain/kotlin/net/mamoe/mirai/utils/SystemDeviceInfo.kt
+1
-41
No files found.
mirai-core/src/androidMain/kotlin/net/mamoe/mirai/utils/BotConfigurationAndroid.kt
View file @
8eda9565
...
...
@@ -90,13 +90,13 @@ actual open class BotConfiguration actual constructor() {
@Suppress
(
"NOTHING_TO_INLINE"
)
@BotConfigurationDsl
inline
operator
fun
FileBasedDeviceInfo
.
unaryPlus
()
{
deviceInfo
=
{
File
(
filepath
).
loadAsDeviceInfo
()
}
deviceInfo
=
{
File
(
filepath
).
loadAsDeviceInfo
(
it
)
}
}
@Suppress
(
"NOTHING_TO_INLINE"
)
@BotConfigurationDsl
inline
operator
fun
FileBasedDeviceInfo
.
ByDeviceDotJson
.
unaryPlus
()
{
deviceInfo
=
{
File
(
"device.json"
).
loadAsDeviceInfo
()
}
deviceInfo
=
{
File
(
"device.json"
).
loadAsDeviceInfo
(
it
)
}
}
actual
operator
fun
_NoNetworkLog
.
unaryPlus
()
{
...
...
mirai-core/src/androidMain/kotlin/net/mamoe/mirai/utils/SystemDeviceInfo.kt
View file @
8eda9565
...
...
@@ -16,8 +16,25 @@ import android.telephony.TelephonyManager
import
kotlinx.io.core.toByteArray
import
kotlinx.serialization.Serializable
import
kotlinx.serialization.Transient
import
kotlinx.serialization.UnstableDefault
import
kotlinx.serialization.json.Json
import
java.io.File
/**
* 加载一个设备信息. 若文件不存在或为空则随机并创建一个设备信息保存.
*/
@UseExperimental
(
UnstableDefault
::
class
)
fun
File
.
loadAsDeviceInfo
(
context
:
Context
):
DeviceInfo
{
if
(!
this
.
exists
()
||
this
.
length
()
==
0L
)
{
return
SystemDeviceInfo
(
context
).
also
{
this
.
writeText
(
Json
.
plain
.
stringify
(
SystemDeviceInfo
.
serializer
(),
it
))
}
}
return
Json
.
nonstrict
.
parse
(
DeviceInfoData
.
serializer
(),
this
.
readText
()).
also
{
it
.
context
=
context
}
}
/**
* 部分引用指向 [Build].
* 部分需要权限, 若无权限则会使用默认值.
...
...
@@ -99,7 +116,7 @@ actual open class SystemDeviceInfo actual constructor() : DeviceInfo() {
override
val
apn
:
ByteArray
get
()
=
"wifi"
.
toByteArray
()
@Serializable
object
Version
:
DeviceInfo
.
Version
{
actual
object
Version
:
DeviceInfo
.
Version
{
override
val
incremental
:
ByteArray
get
()
=
Build
.
VERSION
.
INCREMENTAL
.
toByteArray
()
override
val
release
:
ByteArray
get
()
=
Build
.
VERSION
.
RELEASE
.
toByteArray
()
override
val
codename
:
ByteArray
get
()
=
Build
.
VERSION
.
CODENAME
.
toByteArray
()
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/utils/DeviceInfo.kt
View file @
8eda9565
...
...
@@ -94,6 +94,45 @@ abstract class DeviceInfo {
}
}
@Serializable
class
DeviceInfoData
(
override
val
display
:
ByteArray
,
override
val
product
:
ByteArray
,
override
val
device
:
ByteArray
,
override
val
board
:
ByteArray
,
override
val
brand
:
ByteArray
,
override
val
model
:
ByteArray
,
override
val
bootloader
:
ByteArray
,
override
val
fingerprint
:
ByteArray
,
override
val
bootId
:
ByteArray
,
override
val
procVersion
:
ByteArray
,
override
val
baseBand
:
ByteArray
,
override
val
version
:
VersionData
,
override
val
simInfo
:
ByteArray
,
override
val
osType
:
ByteArray
,
override
val
macAddress
:
ByteArray
,
override
val
wifiBSSID
:
ByteArray
?,
override
val
wifiSSID
:
ByteArray
?,
override
val
imsiMd5
:
ByteArray
,
override
val
imei
:
String
,
override
val
apn
:
ByteArray
)
:
DeviceInfo
()
{
@Transient
override
lateinit
var
context
:
Context
@UseExperimental
(
ExperimentalUnsignedTypes
::
class
)
override
val
ipAddress
:
ByteArray
get
()
=
localIpAddress
().
split
(
"."
).
map
{
it
.
toUByte
().
toByte
()
}.
takeIf
{
it
.
size
==
4
}
?.
toByteArray
()
?:
byteArrayOf
()
override
val
androidId
:
ByteArray
get
()
=
display
@Serializable
class
VersionData
(
override
val
incremental
:
ByteArray
=
SystemDeviceInfo
.
Version
.
incremental
,
override
val
release
:
ByteArray
=
SystemDeviceInfo
.
Version
.
release
,
override
val
codename
:
ByteArray
=
SystemDeviceInfo
.
Version
.
codename
,
override
val
sdk
:
Int
=
SystemDeviceInfo
.
Version
.
sdk
)
:
Version
}
/**
* Defaults "%4;7t>;28<fc.5*6".toByteArray()
*/
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/utils/SystemDeviceInfo.kt
View file @
8eda9565
...
...
@@ -18,4 +18,6 @@ package net.mamoe.mirai.utils
expect
open
class
SystemDeviceInfo
:
DeviceInfo
{
constructor
()
constructor
(
context
:
Context
)
object
Version
:
DeviceInfo
.
Version
}
\ No newline at end of file
mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/utils/BotConfigurationJvm.kt
View file @
8eda9565
...
...
@@ -216,13 +216,13 @@ actual open class BotConfiguration actual constructor() {
@Suppress
(
"NOTHING_TO_INLINE"
)
@BotConfigurationDsl
inline
operator
fun
FileBasedDeviceInfo
.
unaryPlus
()
{
deviceInfo
=
{
File
(
filepath
).
loadAsDeviceInfo
()
}
deviceInfo
=
{
File
(
filepath
).
loadAsDeviceInfo
(
it
)
}
}
@Suppress
(
"NOTHING_TO_INLINE"
)
@BotConfigurationDsl
inline
operator
fun
FileBasedDeviceInfo
.
ByDeviceDotJson
.
unaryPlus
()
{
deviceInfo
=
{
File
(
"device.json"
).
loadAsDeviceInfo
()
}
deviceInfo
=
{
File
(
"device.json"
).
loadAsDeviceInfo
(
it
)
}
}
actual
operator
fun
_NoNetworkLog
.
unaryPlus
()
{
...
...
mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/utils/SystemDeviceInfo.kt
View file @
8eda9565
...
...
@@ -68,50 +68,10 @@ actual open class SystemDeviceInfo actual constructor() : DeviceInfo() {
override
val
apn
:
ByteArray
=
"wifi"
.
toByteArray
()
@Serializable
object
Version
:
DeviceInfo
.
Version
{
actual
object
Version
:
DeviceInfo
.
Version
{
override
val
incremental
:
ByteArray
=
"5891938"
.
toByteArray
()
override
val
release
:
ByteArray
=
"10"
.
toByteArray
()
override
val
codename
:
ByteArray
=
"REL"
.
toByteArray
()
override
val
sdk
:
Int
=
29
}
}
\ No newline at end of file
@Serializable
class
DeviceInfoData
(
override
val
display
:
ByteArray
,
override
val
product
:
ByteArray
,
override
val
device
:
ByteArray
,
override
val
board
:
ByteArray
,
override
val
brand
:
ByteArray
,
override
val
model
:
ByteArray
,
override
val
bootloader
:
ByteArray
,
override
val
fingerprint
:
ByteArray
,
override
val
bootId
:
ByteArray
,
override
val
procVersion
:
ByteArray
,
override
val
baseBand
:
ByteArray
,
override
val
version
:
VersionData
,
override
val
simInfo
:
ByteArray
,
override
val
osType
:
ByteArray
,
override
val
macAddress
:
ByteArray
,
override
val
wifiBSSID
:
ByteArray
?,
override
val
wifiSSID
:
ByteArray
?,
override
val
imsiMd5
:
ByteArray
,
override
val
imei
:
String
,
override
val
apn
:
ByteArray
)
:
DeviceInfo
()
{
@Transient
override
lateinit
var
context
:
Context
@UseExperimental
(
ExperimentalUnsignedTypes
::
class
)
override
val
ipAddress
:
ByteArray
get
()
=
localIpAddress
().
split
(
"."
).
map
{
it
.
toUByte
().
toByte
()
}.
takeIf
{
it
.
size
==
4
}
?.
toByteArray
()
?:
byteArrayOf
()
override
val
androidId
:
ByteArray
get
()
=
display
@Serializable
class
VersionData
(
override
val
incremental
:
ByteArray
=
SystemDeviceInfo
.
Version
.
incremental
,
override
val
release
:
ByteArray
=
SystemDeviceInfo
.
Version
.
release
,
override
val
codename
:
ByteArray
=
SystemDeviceInfo
.
Version
.
codename
,
override
val
sdk
:
Int
=
SystemDeviceInfo
.
Version
.
sdk
)
:
Version
}
\ No newline at end of file
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