Skip to content

Commit

Permalink
1.4
Browse files Browse the repository at this point in the history
  • Loading branch information
Wyvest committed May 21, 2022
1 parent 5e7ecda commit b1f2ce7
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 12 deletions.
10 changes: 8 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
plugins {
id 'java'
id 'org.jetbrains.kotlin.jvm' version '1.6.10'
id "com.github.johnrengelman.shadow" version "7.1.2"
}

java {
targetCompatibility = JavaVersion.VERSION_1_8
sourceCompatibility = JavaVersion.VERSION_1_8
}

group = 'net.wyvest'
version = '1.3'
version = '1.4'

repositories {
mavenCentral()
Expand All @@ -20,7 +26,7 @@ dependencies {
// WARNING: If you are confident the Kotlin Stdlib will already be on the classpath
// you can use implementation (This will not add the library to your jar decreasing the size)
// The Kotlin Stdlib is about 2MB
include 'org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.6.0'
include 'org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.6.21'
// How to normally add a dependency (If you don"t want it to be added to the jar)
// implementation "com.example:example:1.0.0"
// If you would like to include it (have the library inside your jar) instead use
Expand Down
73 changes: 63 additions & 10 deletions src/main/kotlin/Deleter.kt
Original file line number Diff line number Diff line change
@@ -1,22 +1,43 @@
import java.io.File
import javax.swing.JFrame
import javax.swing.UIManager
import javax.swing.WindowConstants
import javax.swing.*
import javax.swing.event.EventListenerList
import javax.swing.event.ListDataListener
import kotlin.system.exitProcess

var tries = 0
val frame = JFrame("Deleter")

fun main(args : Array<String>) {
var tries = 0
val text = JList(arrayOf("Deleter starting..."))

fun main(given : Array<String>) {
val joined = given.joinToString(separator = " ")
var quotation = false
var stringBuilder = StringBuilder()
val arrayList = ArrayList<String>()
for (char in joined) {
if (char.isWhitespace() && !quotation) {
arrayList.add(stringBuilder.toString())
stringBuilder = StringBuilder()
continue
} else if (char == '"') {
quotation = !quotation
continue
}
stringBuilder.append(char)
}
arrayList.add(stringBuilder.toString())
val frame = JFrame("Deleter")
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName())
val scroll = JScrollPane(text)
scroll.setBounds(0, 0, 500, 500)
frame.add(scroll)
frame.setSize(500, 500)
frame.isVisible = true
frame.isFocusable = true
frame.isAlwaysOnTop = true
frame.setLocationRelativeTo(null)
frame.isResizable = false
frame.defaultCloseOperation = WindowConstants.EXIT_ON_CLOSE
for (file in args) {
for (file in arrayList) {
tries = 0
delete(File(file))
}
Expand All @@ -26,17 +47,49 @@ fun main(args : Array<String>) {

private fun delete(file: File) {
if (!file.exists()) {
println("That file does not exist!")
append("\"${file.absolutePath}\" does not exist!")
return
}
if (!file.delete()) {
tries += 1
if (tries >= 4) {
println("Too many tries, cancelling.")
append("\nToo many tries for \"${file.absolutePath}\", cancelling.")
return
}
println("File failed to delete, trying again.")
append("\n\"${file.absolutePath}\" failed to delete, trying again in $tries seconds...")
Thread.sleep((1000 * tries).toLong())
delete(file)
} else {
append("Successfully deleted \"${file.absolutePath}\"!")
}
}

private fun append(string: String) {
println(string)
text.model = JListList(getList().also { it.add(string) })
}

private fun getList(): ArrayList<String> {
val list = arrayListOf<String>()
var i = 0
while (i < text.model.size) {
i++
list.add(text.model.getElementAt(i - 1))
}
return list
}

class JListList(private val list: List<String>): ListModel<String> {
private var listeners = EventListenerList()
override fun getSize(): Int = list.size

override fun getElementAt(index: Int): String = list[index]

override fun addListDataListener(l: ListDataListener) {
listeners.add(ListDataListener::class.java, l)
}

override fun removeListDataListener(l: ListDataListener) {
listeners.remove(ListDataListener::class.java, l)
}
}

0 comments on commit b1f2ce7

Please sign in to comment.