Compare commits

...

4 Commits
v1.0 ... main

Author SHA1 Message Date
a231eb993a
bump new version 2022-10-11 23:16:47 +03:00
b4d2691e65
Progress bar fix, new features 2022-10-11 23:16:30 +03:00
4148fa18bf small semaphore fix 2021-12-28 18:54:31 +03:00
7571aafdb8 main class name changed 2021-12-28 18:40:27 +03:00
4 changed files with 65 additions and 16 deletions

View File

@ -8,7 +8,7 @@ plugins {
}
group 'me.mestima'
version '1.0'
version '2.0'
mainClassName = 'me.mestima.zomboidmodscopier.ZomboidCopierKt'
repositories {

View File

@ -1,14 +1,20 @@
package me.mestima.zomboidmodscopier
import javafx.application.Platform
import javafx.fxml.FXML
import javafx.scene.control.Alert
import javafx.scene.control.Button
import javafx.scene.control.ProgressBar
import javafx.scene.control.TextField
import java.io.File
import java.util.concurrent.Semaphore
class CopierController {
@FXML
private lateinit var copyBtn: Button
//private val secondPerMod: Long = 2
@FXML
private lateinit var userBtn: Button
@FXML
private lateinit var pathName: TextField
@ -19,17 +25,35 @@ class CopierController {
@FXML
private lateinit var progress: ProgressBar
@FXML
private fun onChangeUsername() {
userBtn.isDisable = true
userName.isDisable = false
}
@FXML
private fun onCopy() {
var isCopying: Boolean = true
copyBtn.isDisable = true
userBtn.isDisable = true
pathName.isDisable = true
userName.isDisable = true
val startAlert: Alert = Alert(Alert.AlertType.INFORMATION)
startAlert.title = "Копирование"
startAlert.headerText = null
startAlert.contentText = "Копирование началось! Не закрывайте программу до окончания копирования. Это может привести к невообразимым последствиям..."
startAlert.show()
val path = pathName.text
val dest = File("C:\\Users\\${userName.text}\\Zomboid")
val queue = Semaphore(2)
val folder = File(path)
//val modsCount: Double = folder.list().size.toDouble()
//val progressPerMod: Double = 100.0 / modsCount
val modsCount: Double = folder.list().size.toDouble()
val progressPerMod: Double = 1.0 / modsCount
//var i: Long = 0
val lst = folder.list()
lst.forEach {
Thread {
@ -37,10 +61,27 @@ class CopierController {
val subfolder = File("$path\\$it")
subfolder.copyRecursively(dest, true)
if (isCopying) {
progress.progress += progressPerMod
println(progress.progress)
}
queue.release()
if (it == lst.last()) {
progress.progress = 100.0
if (progress.progress >= 1.0) {
Platform.runLater {
if (isCopying) {
isCopying = false
copyBtn.isDisable = false
userBtn.isDisable = false
pathName.isDisable = false
progress.progress = 0.0
val doneAlert: Alert = Alert(Alert.AlertType.INFORMATION)
doneAlert.title = "Копирование"
doneAlert.headerText = null
doneAlert.contentText = "Копирование завершено! Программу можно закрыть."
doneAlert.show()
}
}
}
}.start()
}
@ -48,6 +89,7 @@ class CopierController {
fun initialize() {
progress.progress = 0.0
userName.text = System.getProperty("user.name")
}
}

View File

@ -5,16 +5,16 @@ import javafx.fxml.FXMLLoader
import javafx.scene.Scene
import javafx.stage.Stage
class HelloApplication : Application() {
class ZomboidCopier : Application() {
override fun start(stage: Stage) {
val fxmlLoader = FXMLLoader(HelloApplication::class.java.getResource("main.fxml"))
val fxmlLoader = FXMLLoader(ZomboidCopier::class.java.getResource("main.fxml"))
val scene = Scene(fxmlLoader.load(), 483.0, 281.0)
stage.title = "Zomboid mods copier v1.0"
stage.title = "Zomboid mods copier v2.0"
stage.scene = scene
stage.show()
}
}
fun main() {
Application.launch(HelloApplication::class.java)
Application.launch(ZomboidCopier::class.java)
}

View File

@ -5,18 +5,25 @@
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.ProgressBar?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.VBox?>
<VBox alignment="CENTER" prefHeight="281.0" prefWidth="483.0" spacing="20.0" xmlns="http://javafx.com/javafx/17" xmlns:fx="http://javafx.com/fxml/1" fx:controller="me.mestima.zomboidmodscopier.CopierController">
<VBox alignment="CENTER" prefHeight="281.0" prefWidth="483.0" spacing="10.0" xmlns="http://javafx.com/javafx/18" xmlns:fx="http://javafx.com/fxml/1" fx:controller="me.mestima.zomboidmodscopier.CopierController">
<padding>
<Insets bottom="20.0" left="20.0" right="20.0" top="20.0" />
</padding>
<children>
<Label prefHeight="18.0" prefWidth="376.0" text="Путь до папки Steam\steamapps\workshop\content\108600" />
<Label prefHeight="18.0" prefWidth="445.0" text="Путь до папки Steam\steamapps\workshop\content\108600" />
<TextField id="pathName" fx:id="pathName" />
<Label prefHeight="18.0" prefWidth="125.0" text="Имя пользователя" />
<TextField id="userName" fx:id="userName" />
<HBox alignment="CENTER_LEFT" prefHeight="30.0" prefWidth="200.0">
<children>
<Label prefHeight="18.0" prefWidth="125.0" text="Имя пользователя" />
<Button fx:id="userBtn" mnemonicParsing="false" onAction="#onChangeUsername" prefHeight="25.0" prefWidth="318.0" text="Изменить имя пользователя" />
</children>
</HBox>
<TextField id="userName" fx:id="userName" disable="true" />
<ProgressBar id="progress" fx:id="progress" prefHeight="26.0" prefWidth="443.0" progress="0.0" />
<Button id="copyBtn" fx:id="copyBtn" mnemonicParsing="false" onAction="#onCopy" prefHeight="33.0" prefWidth="443.0" text="Копировать" />
<TextField editable="false" text="https://github.com/Mestima/ZomboidModsCopier" />
</children>
</VBox>