Skip to content
This repository has been archived by the owner on Nov 12, 2024. It is now read-only.

Commit

Permalink
More work
Browse files Browse the repository at this point in the history
  • Loading branch information
soywiz committed Sep 4, 2016
1 parent ce5d6d1 commit ce55574
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 25 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## VitaOrganizer

![extra/screenshot.png]()
Binary file added extra/screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
91 changes: 66 additions & 25 deletions src/com/soywiz/vitaorganizer/VitaOrganizer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ import java.awt.image.BufferedImage
import java.io.ByteArrayInputStream
import java.io.ByteArrayOutputStream
import java.io.File
import java.net.URI
import java.net.URISyntaxException
import java.net.URL
import java.util.*
import java.util.zip.Deflater
import java.util.zip.ZipEntry
Expand All @@ -28,9 +31,9 @@ object VitaOrganizer : JPanel(BorderLayout()) {
//PsvitaDevice.discoverIp()
//SwingUtilities.invokeLater {
//Create and set up the window.
val frame = JFrame("VitaOrganizer 0.1")
val frame = JFrame("VitaOrganizer $currentVersion")
frame.defaultCloseOperation = JFrame.EXIT_ON_CLOSE
frame.iconImage = ImageIO.read(ClassLoader.getSystemResource("vitafrontblk.jpg"))
frame.iconImage = ImageIO.read(getResourceURL("vitafrontblk.jpg"))

//Create and set up the content pane.
val newContentPane = VitaOrganizer
Expand All @@ -44,6 +47,21 @@ object VitaOrganizer : JPanel(BorderLayout()) {
//}
}

val currentVersion: String get() = getResourceString("currentVersion.txt") ?: "unknown"

fun getResourceURL(name: String) = ClassLoader.getSystemResource(name)
fun getResourceBytes(name: String) = try {
ClassLoader.getSystemResource(name).readBytes()
} catch (e: Throwable) {
null
}

fun getResourceString(name: String) = try {
ClassLoader.getSystemResource(name).readText()
} catch (e: Throwable) {
null
}

class GameEntry(val gameId: String) {
val entry = VitaOrganizerCache.entry(gameId)
val psf by lazy {
Expand Down Expand Up @@ -238,7 +256,7 @@ object VitaOrganizer : JPanel(BorderLayout()) {
}
SwingUtilities.invokeLater {
statusLabel.text = "Sent game data ${entry.id}"
JOptionPane.showMessageDialog(VitaOrganizer, "Game sent successfully", "Actions", JOptionPane.INFORMATION_MESSAGE);
JOptionPane.showMessageDialog(VitaOrganizer, "Game ${entry.id} sent successfully", "Actions", JOptionPane.INFORMATION_MESSAGE);
}
}.start()
}
Expand Down Expand Up @@ -358,7 +376,7 @@ object VitaOrganizer : JPanel(BorderLayout()) {
fun disconnect() {
connected = false
button.text = connectText
synchronized (VITA_GAME_IDS) {
synchronized(VITA_GAME_IDS) {
VITA_GAME_IDS.clear()
}
updateEntries()
Expand All @@ -371,7 +389,7 @@ object VitaOrganizer : JPanel(BorderLayout()) {
PsvitaDevice.setIp(ip, 1337)
button.text = disconnectText.format(ip)
connectAddress.text = ip
synchronized (VITA_GAME_IDS) {
synchronized(VITA_GAME_IDS) {
VITA_GAME_IDS.clear()
}
var done = false
Expand All @@ -392,7 +410,7 @@ object VitaOrganizer : JPanel(BorderLayout()) {
if (!sizeFile.exists()) {
sizeFile.writeText("" + PsvitaDevice.getGameSize(gameId))
}
synchronized (VITA_GAME_IDS) {
synchronized(VITA_GAME_IDS) {
VITA_GAME_IDS += gameId
}
updated = true
Expand Down Expand Up @@ -454,11 +472,29 @@ object VitaOrganizer : JPanel(BorderLayout()) {
}
})
}
add(connectButton)
add(connectAddress)
add(object : JButton("Check for updates...") {
val checkUpdatesButton = object : JButton("Check for updates...") {

}
checkUpdatesButton.addMouseListener(object : MouseAdapter() {
override fun mouseClicked(e: MouseEvent) {
val text = URL("https://raw.githubusercontent.com/soywiz/vitaorganizer/master/lastVersion.txt").readText()
val parts = text.lines()
val lastVersion = parts[0]
val lastVersionUrl = parts[1]
if (lastVersion == currentVersion) {
JOptionPane.showMessageDialog(VitaOrganizer, "You have the lastest version: $currentVersion", "Actions", JOptionPane.INFORMATION_MESSAGE);
} else {
val result = JOptionPane.showConfirmDialog(VitaOrganizer, "There is a new version: $lastVersion\nYou have: $currentVersion\nWant to download last version?", "Actions", JOptionPane.YES_NO_OPTION);
if (result == JOptionPane.OK_OPTION) {
openWebpage(URL(lastVersionUrl))
}
}
println(parts)
}
})
add(connectButton)
add(connectAddress)
add(checkUpdatesButton)
}

add(header, SpringLayout.NORTH)
Expand Down Expand Up @@ -552,6 +588,27 @@ object VitaOrganizer : JPanel(BorderLayout()) {
updateFileList()
}

fun openWebpage(uri: URI) {
val desktop = if (Desktop.isDesktopSupported()) Desktop.getDesktop() else null
if (desktop != null && desktop.isSupported(Desktop.Action.BROWSE)) {
try {
desktop.browse(uri)
} catch (e: Exception) {
e.printStackTrace()
}

}
}

fun openWebpage(url: URL) {
try {
openWebpage(url.toURI())
} catch (e: URISyntaxException) {
e.printStackTrace()
}

}

fun updateFileList() {
synchronized(VPK_GAME_IDS) {
VPK_GAME_IDS.clear()
Expand Down Expand Up @@ -598,20 +655,4 @@ object VitaOrganizer : JPanel(BorderLayout()) {

return resizedImg
}

private fun printDebugData(table: JTable) {
val numRows = table.rowCount
val numCols = table.columnCount
val model = table.model

println("Value of data: ")
for (i in 0..numRows - 1) {
print(" row $i:")
for (j in 0..numCols - 1) {
print(" " + model.getValueAt(i, j))
}
println()
}
println("--------------------------")
}
}

0 comments on commit ce55574

Please sign in to comment.