diff --git a/.gitignore b/.gitignore index aa997ed..fd1ee98 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,12 @@ src-gen/ setup.log local.properties wurstpack_compiler.zip +buildproject/ +compiled.j.txt +myname/ +ptrtestproject/ +temp/ +testproject/ +.classpath +.project +.settings/ diff --git a/build.gradle b/build.gradle index 5bab9f6..f0552ec 100644 --- a/build.gradle +++ b/build.gradle @@ -32,6 +32,7 @@ dependencies { compile 'com.fasterxml.jackson.core:jackson-databind:2.9.9.3' compile 'com.fasterxml.jackson.module:jackson-module-kotlin:2.9.9' compile 'com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.9.9' + compile 'com.github.inwc3:wc3libs:fd4b2fd5aa' compile 'com.github.Frotty:SwingDarkFlatTable:a033300526' compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version" compile 'io.github.microutils:kotlin-logging:1.6.26' @@ -41,6 +42,12 @@ dependencies { testCompile 'org.testng:testng:6.14.3' } +allprojects { + dependencies { + implementation 'com.github.inwc3:wc3libs:fd4b2fd5aa' + } +} + test { useTestNG() } diff --git a/src/main/kotlin/ui/MainWindow.kt b/src/main/kotlin/ui/MainWindow.kt index ddce44a..ea91966 100644 --- a/src/main/kotlin/ui/MainWindow.kt +++ b/src/main/kotlin/ui/MainWindow.kt @@ -4,12 +4,12 @@ import config.CONFIG_FILE_NAME import config.WurstProjectBuildMapData import config.WurstProjectConfig import config.WurstProjectConfigData -import de.ralleytn.simple.registry.Registry import file.CompileTimeInfo import file.SetupApp import global.InstallationManager import global.Log import mu.KotlinLogging +import net.moonlightflower.wc3libs.port.StdGameExeFinder import net.ConnectionManager import net.NetStatus import tablelayout.Table @@ -227,8 +227,8 @@ object MainWindow : JFrame() { } private fun titleEvents(minimize: JButton, exit: JButton) { - minimize.addActionListener { e -> state = Frame.ICONIFIED } - exit.addActionListener { e -> + minimize.addActionListener { _ -> state = Frame.ICONIFIED } + exit.addActionListener { _ -> dispose() exitProcess(0) } @@ -236,6 +236,15 @@ object MainWindow : JFrame() { private var projectRootFile: File = File(".") + private fun discoverWc3Path(): Optional { + try { + return Optional.of(StdGameExeFinder().find().path) + } catch (e: Exception) { + log.info("Failed to discover wc3path with exception %s".format(e.toString())) + return Optional.empty() + } + } + private fun createConfigTable() { val that = this val configTable = Table() @@ -266,7 +275,7 @@ object MainWindow : JFrame() { if (projectNameTF.text.isEmpty()) { btnCreate.isEnabled = false } else { - projectRootTF.text = projectRootFile?.absolutePath + File.separator + projectNameTF.text + projectRootTF.text = projectRootFile.absolutePath + File.separator + projectNameTF.text if (!disabled) { btnCreate.isEnabled = true } @@ -317,23 +326,7 @@ object MainWindow : JFrame() { } } }) - if (System.getProperty("os.name").startsWith("Windows")) { - try { - val key = Registry.getKey(Registry.HKEY_CURRENT_USER + "\\SOFTWARE\\Blizzard Entertainment\\Warcraft III") - var wc3Path = key?.getValueByName("InstallPath")?.rawValue - if (wc3Path != null) { - if (!wc3Path.endsWith(File.separator)) wc3Path += File.separator - val gameFolder = Paths.get(wc3Path) - if (Files.exists(gameFolder)) { - gamePathTF.text = wc3Path - } - } else { - checkDefaultWinLocation() - } - } catch (e: Exception) { - checkDefaultWinLocation() - } - } + discoverWc3Path().map({ path -> gamePathTF.text = path }) gameTF.addCell(selectGamePath).height(24f).pad(0f, 2f, 0f, 2f) configTable.addCell(gameTF).growX() @@ -358,20 +351,6 @@ object MainWindow : JFrame() { contentTable.addCell(configTable).growX().pad(2f) } - private fun checkDefaultWinLocation() { - var gameFolder = Paths.get(System.getenv("ProgramFiles"))?.resolve("Warcraft III") - if (gameFolder != null && Files.exists(gameFolder)) { - gamePathTF.text = gameFolder.toAbsolutePath().toString() - } else { - gameFolder = Paths.get(System.getenv("ProgramFiles") + " (x86)")?.resolve("Warcraft III") - if (gameFolder != null && Files.exists(gameFolder)) { - gamePathTF.text = gameFolder.toAbsolutePath().toString() - } else { - log.warn("Didn't find warcraft installation.") - } - } - } - private fun handleImport() { try { val buildFile = importChooser.selectedFile.toPath()