mirror of
https://github.com/Mestima/ZomboidModsCopier.git
synced 2025-05-06 00:00:23 +00:00
Progress bar fix, new features
This commit is contained in:
parent
4148fa18bf
commit
b4d2691e65
@ -1,14 +1,20 @@
|
|||||||
package me.mestima.zomboidmodscopier
|
package me.mestima.zomboidmodscopier
|
||||||
|
|
||||||
|
import javafx.application.Platform
|
||||||
import javafx.fxml.FXML
|
import javafx.fxml.FXML
|
||||||
|
import javafx.scene.control.Alert
|
||||||
|
import javafx.scene.control.Button
|
||||||
import javafx.scene.control.ProgressBar
|
import javafx.scene.control.ProgressBar
|
||||||
import javafx.scene.control.TextField
|
import javafx.scene.control.TextField
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.util.concurrent.Semaphore
|
import java.util.concurrent.Semaphore
|
||||||
|
|
||||||
class CopierController {
|
class CopierController {
|
||||||
|
@FXML
|
||||||
|
private lateinit var copyBtn: Button
|
||||||
|
|
||||||
//private val secondPerMod: Long = 2
|
@FXML
|
||||||
|
private lateinit var userBtn: Button
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private lateinit var pathName: TextField
|
private lateinit var pathName: TextField
|
||||||
@ -19,17 +25,35 @@ class CopierController {
|
|||||||
@FXML
|
@FXML
|
||||||
private lateinit var progress: ProgressBar
|
private lateinit var progress: ProgressBar
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private fun onChangeUsername() {
|
||||||
|
userBtn.isDisable = true
|
||||||
|
userName.isDisable = false
|
||||||
|
}
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private fun onCopy() {
|
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 path = pathName.text
|
||||||
val dest = File("C:\\Users\\${userName.text}\\Zomboid")
|
val dest = File("C:\\Users\\${userName.text}\\Zomboid")
|
||||||
|
|
||||||
val queue = Semaphore(2)
|
val queue = Semaphore(2)
|
||||||
val folder = File(path)
|
val folder = File(path)
|
||||||
//val modsCount: Double = folder.list().size.toDouble()
|
val modsCount: Double = folder.list().size.toDouble()
|
||||||
//val progressPerMod: Double = 100.0 / modsCount
|
val progressPerMod: Double = 1.0 / modsCount
|
||||||
|
|
||||||
//var i: Long = 0
|
|
||||||
val lst = folder.list()
|
val lst = folder.list()
|
||||||
lst.forEach {
|
lst.forEach {
|
||||||
Thread {
|
Thread {
|
||||||
@ -37,18 +61,35 @@ class CopierController {
|
|||||||
|
|
||||||
val subfolder = File("$path\\$it")
|
val subfolder = File("$path\\$it")
|
||||||
subfolder.copyRecursively(dest, true)
|
subfolder.copyRecursively(dest, true)
|
||||||
|
if (isCopying) {
|
||||||
if (it == lst.last()) {
|
progress.progress += progressPerMod
|
||||||
progress.progress = 100.0
|
println(progress.progress)
|
||||||
}
|
}
|
||||||
|
|
||||||
queue.release()
|
queue.release()
|
||||||
|
|
||||||
|
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()
|
}.start()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun initialize() {
|
fun initialize() {
|
||||||
progress.progress = 0.0
|
progress.progress = 0.0
|
||||||
|
userName.text = System.getProperty("user.name")
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -5,18 +5,25 @@
|
|||||||
<?import javafx.scene.control.Label?>
|
<?import javafx.scene.control.Label?>
|
||||||
<?import javafx.scene.control.ProgressBar?>
|
<?import javafx.scene.control.ProgressBar?>
|
||||||
<?import javafx.scene.control.TextField?>
|
<?import javafx.scene.control.TextField?>
|
||||||
|
<?import javafx.scene.layout.HBox?>
|
||||||
<?import javafx.scene.layout.VBox?>
|
<?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>
|
<padding>
|
||||||
<Insets bottom="20.0" left="20.0" right="20.0" top="20.0" />
|
<Insets bottom="20.0" left="20.0" right="20.0" top="20.0" />
|
||||||
</padding>
|
</padding>
|
||||||
<children>
|
<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" />
|
<TextField id="pathName" fx:id="pathName" />
|
||||||
<Label prefHeight="18.0" prefWidth="125.0" text="Имя пользователя" />
|
<HBox alignment="CENTER_LEFT" prefHeight="30.0" prefWidth="200.0">
|
||||||
<TextField id="userName" fx:id="userName" />
|
<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" />
|
<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="Копировать" />
|
<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>
|
</children>
|
||||||
</VBox>
|
</VBox>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user