diff --git a/mirai-core-utils/src/commonMain/kotlin/jvm/JvmFile.kt b/mirai-core-utils/src/commonMain/kotlin/jvm/JvmFile.kt new file mode 100644 index 000000000..299f8775a --- /dev/null +++ b/mirai-core-utils/src/commonMain/kotlin/jvm/JvmFile.kt @@ -0,0 +1,54 @@ +/* + * Copyright 2019-2023 Mamoe Technologies and contributors. + * + * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. + * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. + * + * https://github.com/mamoe/mirai/blob/dev/LICENSE + */ + +package net.mamoe.mirai.utils.jvm + +import io.ktor.utils.io.errors.* + +@CompatibilityOnlyJvmFile +public expect class JvmFile { + public constructor(pathname: String) + public constructor(parent: String, child: String) + + public fun getName(): String? + public fun getParent(): String? + public fun getParentFile(): JvmFile? + + public fun getPath(): String + public fun isAbsolute(): Boolean + public fun getAbsolutePath(): String + public fun getAbsoluteFile(): JvmFile + + @Throws(IOException::class) + public fun getCanonicalPath(): String + + @Throws(IOException::class) + public fun getCanonicalFile(): JvmFile? + + @Throws(IOException::class) + public fun createNewFile(): Boolean + + public fun length(): Long + public fun delete(): Boolean + + public fun listFiles(): Array? + + public fun mkdir(): Boolean + public fun mkdirs(): Boolean + public fun renameTo(file: JvmFile): Boolean +} + +@Target(AnnotationTarget.CLASS, AnnotationTarget.TYPEALIAS, AnnotationTarget.FUNCTION) +@RequiresOptIn( + "JvmFile is only used for compatibility and for simplifying expect/actual structure. " + + "It allows you to use java.io.File in commonMain and is intended only for maintaining compatibility with legacy code in commonMain." + + "JvmFile is not implemented in Native and you must deprecate the implementation on nativeMain as HIDDEN." + + "Do not design new APIs using JvmFile." +) +public annotation class CompatibilityOnlyJvmFile \ No newline at end of file diff --git a/mirai-core-utils/src/jvmBaseMain/kotlin/jvm/JvmFile.kt b/mirai-core-utils/src/jvmBaseMain/kotlin/jvm/JvmFile.kt new file mode 100644 index 000000000..903abf305 --- /dev/null +++ b/mirai-core-utils/src/jvmBaseMain/kotlin/jvm/JvmFile.kt @@ -0,0 +1,13 @@ +/* + * Copyright 2019-2023 Mamoe Technologies and contributors. + * + * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. + * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. + * + * https://github.com/mamoe/mirai/blob/dev/LICENSE + */ + +package net.mamoe.mirai.utils.jvm + +@CompatibilityOnlyJvmFile +public actual typealias JvmFile = java.io.File \ No newline at end of file diff --git a/mirai-core-utils/src/nativeMain/kotlin/jvm/JvmFile.kt b/mirai-core-utils/src/nativeMain/kotlin/jvm/JvmFile.kt new file mode 100644 index 000000000..cc6d0ba53 --- /dev/null +++ b/mirai-core-utils/src/nativeMain/kotlin/jvm/JvmFile.kt @@ -0,0 +1,58 @@ +/* + * Copyright 2019-2023 Mamoe Technologies and contributors. + * + * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. + * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. + * + * https://github.com/mamoe/mirai/blob/dev/LICENSE + */ + +package net.mamoe.mirai.utils.jvm + +import io.ktor.utils.io.errors.* + +@Suppress("DEPRECATION_ERROR") +@Deprecated("JvmFile is not implemented on native", level = DeprecationLevel.HIDDEN) +@CompatibilityOnlyJvmFile +public actual class JvmFile { + public actual fun getName(): String? = throw NotImplementedError() + + public actual fun getParent(): String? = throw NotImplementedError() + + public actual fun getParentFile(): JvmFile? = throw NotImplementedError() + + public actual fun getPath(): String = throw NotImplementedError() + + public actual fun isAbsolute(): Boolean = throw NotImplementedError() + public actual fun getAbsolutePath(): String = throw NotImplementedError() + public actual fun getAbsoluteFile(): JvmFile = throw NotImplementedError() + + @Throws(IOException::class) + public actual fun getCanonicalPath(): String = throw NotImplementedError() + + @Throws(IOException::class) + public actual fun getCanonicalFile(): JvmFile? = throw NotImplementedError() + + @Throws(IOException::class) + public actual fun createNewFile(): Boolean = throw NotImplementedError() + + public actual fun length(): Long = throw NotImplementedError() + + public actual fun delete(): Boolean = throw NotImplementedError() + + public actual fun listFiles(): Array? = throw NotImplementedError() + + public actual fun mkdir(): Boolean = throw NotImplementedError() + + public actual fun mkdirs(): Boolean = throw NotImplementedError() + + public actual fun renameTo(file: JvmFile): Boolean = throw NotImplementedError() + + public actual constructor(pathname: String) { + throw NotImplementedError() + } + + public actual constructor(parent: String, child: String) { + throw NotImplementedError() + } +} \ No newline at end of file