├── .gitignore ├── gfx ├── main-ui.png ├── main-ui-update.png ├── main-ui-no-update.png ├── main-ui-select-project.png ├── main-ui-update-finished.png ├── main-ui-project-selected.png ├── main-ui-select-wrong-project.png ├── main-ui-update-in-progress-2.png └── main-ui-update-in-progress.png ├── images └── showcase.JPG ├── src └── main │ ├── lib │ └── jfxrt.jar │ ├── resources │ ├── polar_upgrade_1024.png │ ├── applicationUI.fxml │ └── aboutUI.fxml │ └── java │ └── com │ └── afollestad │ └── polarupgradetool │ ├── jfx │ ├── InterfaceUpdateThread.kt │ ├── UICallback.kt │ ├── AboutScene.kt │ ├── UpgradeTool.kt │ └── WindowScene.kt │ ├── utils │ ├── SecurityUtil.kt │ ├── UpdateUtils.kt │ ├── UrlUtils.kt │ ├── UnzipUtil.kt │ ├── Util.kt │ ├── ZipUtil.kt │ ├── ManifestUtils.kt │ └── FileUtil.kt │ ├── xml │ ├── XmlElementExtractor.kt │ ├── XmlScanner.kt │ └── XmlMigrator.kt │ ├── GradleMigrator.kt │ ├── AttributeExtractor.kt │ ├── MainBase.kt │ └── Main.kt ├── polarupgradetool-1.0.10.jar ├── README.md ├── dependency-reduced-pom.xml └── pom.xml /.gitignore: -------------------------------------------------------------------------------- 1 | .idea/* 2 | gfx/icons/* 3 | target/* 4 | *.iml -------------------------------------------------------------------------------- /gfx/main-ui.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PDDStudio/polar-dashboard-upgrade-tool/master/gfx/main-ui.png -------------------------------------------------------------------------------- /images/showcase.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PDDStudio/polar-dashboard-upgrade-tool/master/images/showcase.JPG -------------------------------------------------------------------------------- /gfx/main-ui-update.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PDDStudio/polar-dashboard-upgrade-tool/master/gfx/main-ui-update.png -------------------------------------------------------------------------------- /src/main/lib/jfxrt.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PDDStudio/polar-dashboard-upgrade-tool/master/src/main/lib/jfxrt.jar -------------------------------------------------------------------------------- /gfx/main-ui-no-update.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PDDStudio/polar-dashboard-upgrade-tool/master/gfx/main-ui-no-update.png -------------------------------------------------------------------------------- /polarupgradetool-1.0.10.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PDDStudio/polar-dashboard-upgrade-tool/master/polarupgradetool-1.0.10.jar -------------------------------------------------------------------------------- /gfx/main-ui-select-project.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PDDStudio/polar-dashboard-upgrade-tool/master/gfx/main-ui-select-project.png -------------------------------------------------------------------------------- /gfx/main-ui-update-finished.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PDDStudio/polar-dashboard-upgrade-tool/master/gfx/main-ui-update-finished.png -------------------------------------------------------------------------------- /gfx/main-ui-project-selected.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PDDStudio/polar-dashboard-upgrade-tool/master/gfx/main-ui-project-selected.png -------------------------------------------------------------------------------- /gfx/main-ui-select-wrong-project.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PDDStudio/polar-dashboard-upgrade-tool/master/gfx/main-ui-select-wrong-project.png -------------------------------------------------------------------------------- /gfx/main-ui-update-in-progress-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PDDStudio/polar-dashboard-upgrade-tool/master/gfx/main-ui-update-in-progress-2.png -------------------------------------------------------------------------------- /gfx/main-ui-update-in-progress.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PDDStudio/polar-dashboard-upgrade-tool/master/gfx/main-ui-update-in-progress.png -------------------------------------------------------------------------------- /src/main/resources/polar_upgrade_1024.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PDDStudio/polar-dashboard-upgrade-tool/master/src/main/resources/polar_upgrade_1024.png -------------------------------------------------------------------------------- /src/main/java/com/afollestad/polarupgradetool/jfx/InterfaceUpdateThread.kt: -------------------------------------------------------------------------------- 1 | package com.afollestad.polarupgradetool.jfx 2 | 3 | import com.afollestad.polarupgradetool.Main 4 | 5 | /** 6 | * Project : polar-dashboard-upgrade-tool 7 | * Author : pddstudio 8 | * Year : 2016 9 | */ 10 | class InterfaceUpdateThread(internal val location: String, internal val uiCallback: UICallback) : Thread(), Runnable { 11 | 12 | override fun run() { 13 | Main.upgrade(location, uiCallback) 14 | } 15 | } -------------------------------------------------------------------------------- /src/main/java/com/afollestad/polarupgradetool/jfx/UICallback.kt: -------------------------------------------------------------------------------- 1 | package com.afollestad.polarupgradetool.jfx 2 | 3 | /** 4 | * Project : polar-dashboard-upgrade-tool 5 | * Author : pddstudio 6 | * Year : 2016 7 | */ 8 | interface UICallback { 9 | 10 | fun onProjectDetected(applicationName: String, applicationPackage: String, applicationVersionName: String, applicationVersionCode: String) 11 | 12 | fun onErrorOccurred(errorMessage: String) 13 | 14 | fun onArchiveDownloadStarted(sizeStr: String) 15 | 16 | fun onArchiveDownloadProgress(progressStr: String) 17 | 18 | fun onArchiveDownloadFailed(errorMessage: String) 19 | 20 | fun onArchiveDownloadSuccess() 21 | 22 | fun onStatusUpdate(statusMessage: String) 23 | 24 | fun onUpdateSuccessful() 25 | } -------------------------------------------------------------------------------- /src/main/java/com/afollestad/polarupgradetool/utils/SecurityUtil.kt: -------------------------------------------------------------------------------- 1 | package com.afollestad.polarupgradetool.utils 2 | 3 | import com.afollestad.polarupgradetool.Main 4 | 5 | import java.io.File 6 | 7 | /** 8 | * Project : polarupgradetool 9 | * Author : pddstudio 10 | * Year : 2016 11 | */ 12 | object SecurityUtil { 13 | 14 | private val DEV_CUSTOM = "dev_customization.xml" 15 | private val DEV_THEMING = "dev_theming.xml" 16 | 17 | fun checkIsPolarBased(basePath: String): Boolean { 18 | val resources = File(basePath + Main.VALUES_FOLDER_PATH) 19 | if (!resources.exists() || !resources.isDirectory || resources.listFiles() == null || resources.listFiles()!!.size <= 0) return false 20 | for (file in resources.listFiles()!!) { 21 | if (file.name == DEV_CUSTOM || file.name == DEV_THEMING) return true 22 | } 23 | return false 24 | } 25 | } -------------------------------------------------------------------------------- /src/main/java/com/afollestad/polarupgradetool/utils/UpdateUtils.kt: -------------------------------------------------------------------------------- 1 | package com.afollestad.polarupgradetool.utils 2 | 3 | /** 4 | * Project : polarupgradetool 5 | * Author : pddstudio 6 | * Year : 2016 7 | */ 8 | class UpdateUtils private constructor(private val updateCallback: UpdateUtils.UpdateCallback) { 9 | 10 | interface UpdateCallback { 11 | fun onUpdateCheckStarted() 12 | 13 | fun onUpdateCheckFailed(errorMsg: String) 14 | 15 | fun onUpdateCheckFinished(currentVersion: String, latestVersion: String) 16 | } 17 | 18 | fun execute() { 19 | UpdateThread().start() 20 | } 21 | 22 | private inner class UpdateThread : Thread(), Runnable { 23 | 24 | override fun run() { 25 | updateCallback.onUpdateCheckStarted() 26 | val pom = ManifestUtils.remoteApplicationModel 27 | if (pom == null) { 28 | updateCallback.onUpdateCheckFailed("Unable to resolve external pom model.") 29 | this.interrupt() 30 | } else if (!isInterrupted) { 31 | val currentVersion = ManifestUtils.getApplicationVersion(UpdateUtils::class.java) 32 | val externalVersion = pom.version 33 | updateCallback.onUpdateCheckFinished(currentVersion, externalVersion) 34 | } 35 | } 36 | } 37 | 38 | companion object { 39 | fun checkForUpdate(updateCallback: UpdateCallback): UpdateUtils { 40 | return UpdateUtils(updateCallback) 41 | } 42 | } 43 | } -------------------------------------------------------------------------------- /src/main/java/com/afollestad/polarupgradetool/utils/UrlUtils.kt: -------------------------------------------------------------------------------- 1 | package com.afollestad.polarupgradetool.utils 2 | 3 | import com.afollestad.polarupgradetool.jfx.UpgradeTool 4 | 5 | /** 6 | * Project : polarupgradetool 7 | * Author : pddstudio 8 | * Year : 2016 9 | */ 10 | object UrlUtils { 11 | 12 | private val URL_GITHUB_PUT = "https://github.com/afollestad/polar-dashboard-upgrade-tool" 13 | private val URL_GITHUB_POLAR = "https://github.com/afollestad/polar-dashboard" 14 | private val URL_GITHUB_AFOLLESTAD = "https://github.com/afollestad" 15 | private val URL_GITHUB_PDDSTUDIO = "https://github.com/PDDStudio" 16 | private val URL_GITHUB_WIKI = "https://github.com/PDDStudio/polar-dashboard-upgrade-tool/wiki/Polar-Dashboard-Upgrade-Tool---Wiki" 17 | private val URL_GITHUB_RELEASES = "https://github.com/afollestad/polar-dashboard-upgrade-tool/releases" 18 | 19 | fun openPolarUpgradeToolPage() { 20 | UpgradeTool.hostService?.showDocument(URL_GITHUB_PUT) 21 | } 22 | 23 | fun openPolarPage() { 24 | UpgradeTool.hostService?.showDocument(URL_GITHUB_POLAR) 25 | } 26 | 27 | fun openAfollestadGithubPage() { 28 | UpgradeTool.hostService?.showDocument(URL_GITHUB_AFOLLESTAD) 29 | } 30 | 31 | fun openPddstudioGithubPage() { 32 | UpgradeTool.hostService?.showDocument(URL_GITHUB_PDDSTUDIO) 33 | } 34 | 35 | fun openWikiPage() { 36 | UpgradeTool.hostService?.showDocument(URL_GITHUB_WIKI) 37 | } 38 | 39 | fun openReleasePage() { 40 | UpgradeTool.hostService?.showDocument(URL_GITHUB_RELEASES) 41 | } 42 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Polar Upgrade Tool 2 | 3 | 5 | 6 | PUT allows you to automatically migrate your icon packs to the latest versions of Polar, without any manual copying. **This project does not migrate your project to Polar from other dashboard templates, it upgrades existing Polar-using icon packs.** 7 | 8 | See [Polar's main repository](https://github.com/afollestad/polar-dashboard) for information about Polar. 9 | 10 | PUT was designed and developed by [Aidan Follestad](https://github.com/afollestad) and 11 | [Patrick J](https://github.com/PDDStudio). The icon was designed by [Anthony Nguyen](https://plus.google.com/+AHNguyen). 12 | 13 | # Download & Wiki 14 | You can find the latest version of PUT's packaged binary in the [Release Page of this Repository](https://github.com/afollestad/polar-dashboard-upgrade-tool/releases). 15 | 16 | In case you need more information about how to use this Tool head over to the [Wiki Page](https://github.com/PDDStudio/polar-dashboard-upgrade-tool/wiki/Polar-Dashboard-Upgrade-Tool---Wiki). 17 | 18 | There is also some information about the upgrade tool on [Polar's Web Guide](http://afollestad.github.io/polar-dashboard/upgrades.html). 19 | 20 | The Wiki should guide people which are not common with technical/development stuff through the whole process to get their Polar-using icon pack updated. 21 | 22 | # Building and Running 23 | 24 | ### Windows 25 | 26 | From the project root: 27 | 28 | ```Gradle 29 | build-and-deploy.bat 30 | ``` 31 | 32 | This will create a JAR in the `target` folder that you can execute. 33 | 34 | ### Unix (OSX) and Linux 35 | 36 | From the project root: 37 | 38 | ```Gradle 39 | ./build-and-deploy.sh 40 | ``` 41 | 42 | This will create a JAR in the `target` folder that you can execute. 43 | -------------------------------------------------------------------------------- /src/main/java/com/afollestad/polarupgradetool/utils/UnzipUtil.kt: -------------------------------------------------------------------------------- 1 | package com.afollestad.polarupgradetool.utils 2 | 3 | import java.io.* 4 | import java.util.zip.ZipEntry 5 | import java.util.zip.ZipInputStream 6 | 7 | /** 8 | * @author Aidan Follestad (afollestad) 9 | */ 10 | object UnzipUtil { 11 | 12 | private val BUFFER_SIZE = 4096 13 | 14 | @SuppressWarnings("ResultOfMethodCallIgnored") 15 | @Throws(IOException::class) 16 | fun unzip(zipFilePath: String, destDirectory: String) { 17 | val destDir = File(destDirectory) 18 | if (!destDir.exists()) 19 | destDir.mkdir() 20 | val zipIn = ZipInputStream(FileInputStream(zipFilePath)) 21 | var entry: ZipEntry? = zipIn.nextEntry 22 | // iterates over entries in the zip file 23 | while (entry != null) { 24 | val filePath = destDirectory + File.separator + entry.name 25 | if (!entry.isDirectory) { 26 | // if the entry is a file, extracts it 27 | extractFile(zipIn, filePath) 28 | } else { 29 | // if the entry is a directory, make the directory 30 | val dir = File(filePath) 31 | dir.mkdir() 32 | } 33 | zipIn.closeEntry() 34 | entry = zipIn.nextEntry 35 | } 36 | zipIn.close() 37 | } 38 | 39 | @Throws(IOException::class) 40 | private fun extractFile(zipIn: ZipInputStream, filePath: String) { 41 | var bos: BufferedOutputStream? = null 42 | try { 43 | bos = BufferedOutputStream(FileOutputStream(filePath)) 44 | val bytesIn = ByteArray(BUFFER_SIZE) 45 | var read: Int 46 | while (true) { 47 | read = zipIn.read(bytesIn); 48 | if (read == -1) break; 49 | bos.write(bytesIn, 0, read); 50 | } 51 | } finally { 52 | Util.closeQuietely(bos) 53 | } 54 | } 55 | } -------------------------------------------------------------------------------- /src/main/java/com/afollestad/polarupgradetool/jfx/AboutScene.kt: -------------------------------------------------------------------------------- 1 | package com.afollestad.polarupgradetool.jfx 2 | 3 | import com.afollestad.polarupgradetool.utils.ManifestUtils 4 | import com.afollestad.polarupgradetool.utils.UrlUtils 5 | import javafx.fxml.FXML 6 | import javafx.fxml.FXMLLoader 7 | import javafx.scene.Scene 8 | import javafx.scene.control.Label 9 | import javafx.scene.layout.VBox 10 | 11 | import java.io.IOException 12 | 13 | /** 14 | * Project : polarupgradetool 15 | * Author : pddstudio 16 | * Year : 2016 17 | */ 18 | class AboutScene { 19 | 20 | var scene: Scene 21 | private val aboutSceneController: AboutSceneController 22 | 23 | init { 24 | aboutSceneController = AboutSceneController() 25 | scene = Scene(aboutSceneController) 26 | aboutSceneController.setRootScene(scene) 27 | } 28 | 29 | private inner class AboutSceneController internal constructor() : VBox() { 30 | 31 | @FXML private val projectVersionLabel: Label? = null 32 | 33 | init { 34 | try { 35 | val fxmlLoader = FXMLLoader(javaClass.getResource("/aboutUI.fxml")) 36 | fxmlLoader.setRoot(this) 37 | fxmlLoader.setController(this) 38 | fxmlLoader.load() 39 | projectVersionLabel!!.text = "Version " + ManifestUtils.getApplicationVersion(javaClass) 40 | } catch (io: IOException) { 41 | io.printStackTrace() 42 | } 43 | 44 | } 45 | 46 | fun setRootScene(scene: Scene) { 47 | this@AboutScene.scene = scene 48 | } 49 | 50 | @FXML 51 | protected fun openGitProfileAidan() { 52 | UrlUtils.openAfollestadGithubPage() 53 | } 54 | 55 | @FXML 56 | protected fun openGitProfilePatrick() { 57 | UrlUtils.openPddstudioGithubPage() 58 | } 59 | 60 | @FXML 61 | protected fun openGitPUT() { 62 | UrlUtils.openPolarUpgradeToolPage() 63 | } 64 | 65 | @FXML 66 | protected fun openGitPolar() { 67 | UrlUtils.openPolarPage() 68 | } 69 | } 70 | } -------------------------------------------------------------------------------- /src/main/java/com/afollestad/polarupgradetool/xml/XmlElementExtractor.kt: -------------------------------------------------------------------------------- 1 | package com.afollestad.polarupgradetool.xml 2 | 3 | import com.afollestad.polarupgradetool.AttributeExtractor 4 | import com.afollestad.polarupgradetool.MainBase 5 | import com.afollestad.polarupgradetool.jfx.UICallback 6 | import java.io.File 7 | import java.nio.charset.Charset 8 | import java.util.* 9 | import java.util.regex.Pattern 10 | 11 | /** 12 | * @author Aidan Follestad (afollestad) 13 | */ 14 | class XmlElementExtractor(private val mFile: File, tagNames: Array?, names: Array?, private val uiCallback: UICallback?) { 15 | 16 | private val REGEX = "<%s name=\"%s\">[\\s\\S\\n]*<\\/%s>" 17 | private val mPatterns: Array 18 | 19 | init { 20 | if (tagNames == null || names == null || tagNames.size != names.size) 21 | throw IllegalArgumentException("tagNames and names must be non-null matching length arrays.") 22 | mPatterns = Array(tagNames.size, { 23 | it -> 24 | Pattern.compile(REGEX.format(tagNames[it], names[it], tagNames[it])) 25 | }) 26 | } 27 | 28 | fun find(): HashMap? { 29 | if (!mFile.exists()) { 30 | MainBase.LOG("[ERROR]: File ${mFile.absolutePath} does not exist.") 31 | uiCallback?.onErrorOccurred("File does not exist: ${mFile.absoluteFile}") 32 | return null 33 | } 34 | 35 | val result = HashMap(mPatterns.size) 36 | 37 | try { 38 | mFile.forEachLine(Charset.forName("UTF-8"), { 39 | for (p in mPatterns) { 40 | val matcher = p.matcher(it) 41 | if (matcher.find()) { 42 | val name = AttributeExtractor.getAttributeValue("name", it) 43 | val value = AttributeExtractor.getElementValue(it) 44 | result.put(name!!, value!!) 45 | break 46 | } 47 | } 48 | }) 49 | } catch (e: Exception) { 50 | MainBase.LOG("[ERROR] Failed to read ${mFile.absolutePath}: ${e.message}") 51 | uiCallback?.onErrorOccurred("Failed to read ${mFile.absolutePath}: ${e.message}") 52 | e.printStackTrace() 53 | return null 54 | } 55 | 56 | return result 57 | } 58 | } -------------------------------------------------------------------------------- /src/main/java/com/afollestad/polarupgradetool/utils/Util.kt: -------------------------------------------------------------------------------- 1 | package com.afollestad.polarupgradetool.utils 2 | 3 | import java.io.Closeable 4 | import java.io.File 5 | import java.math.RoundingMode 6 | import java.text.DecimalFormat 7 | 8 | /** 9 | * @author Aidan Follestad (afollestad) 10 | */ 11 | object Util { 12 | 13 | fun closeQuietely(c: Closeable?) { 14 | if (c == null) return 15 | try { 16 | c.close() 17 | } catch (ignored: Throwable) { 18 | } 19 | 20 | } 21 | 22 | fun round(value: Double): String { 23 | val df = DecimalFormat("#.##") 24 | df.roundingMode = RoundingMode.CEILING 25 | return df.format(value) 26 | } 27 | 28 | fun round(value: Float): String { 29 | val df = DecimalFormat("#.##") 30 | df.roundingMode = RoundingMode.CEILING 31 | return df.format(value.toDouble()) 32 | } 33 | 34 | fun readableFileSizeMB(size: Long): String { 35 | val value = size.toDouble() / 1000000 36 | return "%sMB".format(round(value)) 37 | } 38 | 39 | fun detectCodePackage(folder: File): String { 40 | var javaFolder = folder 41 | var pkg = "" 42 | 43 | var contents: Array? = javaFolder.listFiles() ?: return pkg 44 | // com 45 | javaFolder = contents!![0] 46 | pkg += javaFolder.name 47 | 48 | contents = javaFolder.listFiles() 49 | if (contents == null) return pkg 50 | // afollestad 51 | javaFolder = contents[0] 52 | pkg += "." + javaFolder.name 53 | 54 | contents = javaFolder.listFiles() 55 | if (contents == null) return pkg 56 | // polar 57 | javaFolder = contents[0] 58 | pkg += "." + javaFolder.name 59 | 60 | return pkg 61 | } 62 | 63 | fun skipPackage(folder: File): File { 64 | var javaFolder = folder 65 | var contents: Array? = javaFolder.listFiles() ?: return javaFolder 66 | // com 67 | javaFolder = contents!![0] 68 | 69 | contents = javaFolder.listFiles() 70 | if (contents == null) return javaFolder 71 | // afollestad 72 | javaFolder = contents[0] 73 | 74 | contents = javaFolder.listFiles() 75 | if (contents == null) return javaFolder 76 | // polar 77 | javaFolder = contents[0] 78 | 79 | return javaFolder 80 | } 81 | } -------------------------------------------------------------------------------- /src/main/java/com/afollestad/polarupgradetool/utils/ZipUtil.kt: -------------------------------------------------------------------------------- 1 | package com.afollestad.polarupgradetool.utils 2 | 3 | import com.afollestad.polarupgradetool.MainBase 4 | import java.io.File 5 | import java.io.FileOutputStream 6 | import java.util.* 7 | import java.util.zip.ZipEntry 8 | import java.util.zip.ZipOutputStream 9 | 10 | /** 11 | * @author Aidan Follestad (afollestad) 12 | */ 13 | object ZipUtil { 14 | 15 | private fun getAllFiles(dir: File): ArrayList { 16 | val fileList = ArrayList() 17 | val files = dir.listFiles() ?: return fileList 18 | for (file in files) { 19 | if ((file.name == ".git" || file.name == ".idea" || 20 | file.name == ".gradle" || file.name == "build" || 21 | file.name == ".DS_Store" || file.name.endsWith(".db")) && file.isDirectory) { 22 | continue 23 | } 24 | fileList.add(file) 25 | if (file.isDirectory) 26 | fileList.addAll(getAllFiles(file)) 27 | } 28 | return fileList 29 | } 30 | 31 | @Throws(Exception::class) 32 | fun writeZipFile(directoryToZip: File, destZipFile: File) { 33 | var fos: FileOutputStream? = null 34 | var zos: ZipOutputStream? = null 35 | val files = getAllFiles(directoryToZip) 36 | try { 37 | fos = FileOutputStream(destZipFile) 38 | zos = ZipOutputStream(fos) 39 | for (file in files) { 40 | if (!file.isDirectory) { 41 | // we only zip files, not directories 42 | addToZip(directoryToZip, file, zos) 43 | } 44 | } 45 | } finally { 46 | Util.closeQuietely(zos) 47 | Util.closeQuietely(fos) 48 | } 49 | } 50 | 51 | @Throws(Exception::class) 52 | private fun addToZip(directoryToZip: File, file: File, zos: ZipOutputStream) { 53 | // we want the zipEntry's path to be a relative path that is relative 54 | // to the directory being zipped, so chop off the rest of the path 55 | val zipFilePath = file.canonicalPath.substring(directoryToZip.canonicalPath.length + 1, 56 | file.canonicalPath.length) 57 | MainBase.LOG("[ZIP]: $zipFilePath") 58 | val zipEntry = ZipEntry(zipFilePath) 59 | zos.putNextEntry(zipEntry) 60 | file.forEachBlock { bytes, size -> 61 | zos.write(bytes, 0, size) 62 | } 63 | zos.closeEntry() 64 | } 65 | } -------------------------------------------------------------------------------- /src/main/java/com/afollestad/polarupgradetool/GradleMigrator.kt: -------------------------------------------------------------------------------- 1 | package com.afollestad.polarupgradetool 2 | 3 | import com.afollestad.polarupgradetool.jfx.UICallback 4 | import com.afollestad.polarupgradetool.utils.Util 5 | import java.io.* 6 | import java.nio.charset.Charset 7 | import java.util.* 8 | 9 | /** 10 | * @author Aidan Follestad (afollestad) 11 | */ 12 | class GradleMigrator(private val mProject: File, private val mLatest: File, private val uiCallback: UICallback?) { 13 | 14 | private fun processLineProperty(propertyName: String, line: String, propertyValue: String): String { 15 | val start = line.indexOf("$propertyName ") 16 | if (start == -1) return line 17 | return " $propertyName $propertyValue" 18 | } 19 | 20 | @SuppressWarnings("ResultOfMethodCallIgnored") 21 | fun process(): Boolean { 22 | val lines = ArrayList() 23 | try { 24 | mLatest.forEachLine(Charset.forName("UTF-8"), { 25 | var line = it 26 | line = line.replace("output.outputFile.parent, \"MyPolarPack", 27 | "output.outputFile.parent, \"${Main.USER_APPNAME}") 28 | line = processLineProperty("applicationId", line, "\"${Main.USER_PACKAGE}\"") 29 | line = processLineProperty("versionName", line, "\"${Main.USER_VERSION_NAME}\"") 30 | line = processLineProperty("versionCode", line, Main.USER_VERSION_CODE) 31 | lines.add(line) 32 | }) 33 | } catch (e: Exception) { 34 | MainBase.LOG("[ERROR]: Failed to migrate a Gradle file: ${e.message}") 35 | uiCallback?.onErrorOccurred("Failed to migrate Gradle file: ${e.message}") 36 | e.printStackTrace() 37 | return false 38 | } 39 | 40 | mProject.delete() 41 | var os: OutputStream? = null 42 | var writer: BufferedWriter? = null 43 | 44 | try { 45 | os = FileOutputStream(mProject) 46 | writer = BufferedWriter(OutputStreamWriter(os)) 47 | 48 | for (i in lines.indices) { 49 | if (i > 0) writer.newLine() 50 | writer.write(lines[i]) 51 | } 52 | } catch (e: Exception) { 53 | MainBase.LOG("[ERROR]: Failed to migrate a Gradle file: ${e.message}") 54 | uiCallback?.onErrorOccurred("Failed to migrate Gradle file: ${e.message}") 55 | e.printStackTrace() 56 | return false 57 | } finally { 58 | Util.closeQuietely(writer) 59 | Util.closeQuietely(os) 60 | } 61 | 62 | val cleanedPath = MainBase.cleanupPath(mProject.absolutePath) 63 | MainBase.LOG("[INFO]: Migrated Gradle file $cleanedPath") 64 | uiCallback?.onStatusUpdate("Migrated Gradle file: $cleanedPath") 65 | return true 66 | } 67 | } -------------------------------------------------------------------------------- /src/main/java/com/afollestad/polarupgradetool/xml/XmlScanner.kt: -------------------------------------------------------------------------------- 1 | package com.afollestad.polarupgradetool.xml 2 | 3 | /** 4 | * @author Aidan Follestad (afollestad) 5 | */ 6 | class XmlScanner(private val mXml: StringBuilder) { 7 | 8 | private var mIndex = 0 9 | private var mTagName: String = "" 10 | private var mTagValue: String = "" 11 | private var mTagStart: Int = 0 12 | private var mTagEnd: Int = 0 13 | private var mValueStart: Int = 0 14 | private var mValueEnd: Int = 0 15 | private var mReachedEnd = false 16 | 17 | fun tagName(): String { 18 | return mTagName 19 | } 20 | 21 | fun tagValue(): String { 22 | return mTagValue 23 | } 24 | 25 | fun reachedEnd(): Boolean { 26 | return mReachedEnd 27 | } 28 | 29 | fun currentTag(): String { 30 | return mXml.substring(mTagStart, mTagEnd) 31 | } 32 | 33 | fun nextTag(): String? { 34 | if (mReachedEnd) return null 35 | val next: Int 36 | val firstSpace: Int 37 | try { 38 | mTagStart = mXml.indexOf("<", mIndex) 39 | if (mTagStart < 0) { 40 | // No more tags in the file 41 | mReachedEnd = true 42 | return null 43 | } else if (mXml[mTagStart + 1] == '?') { 44 | // Skip header 45 | mIndex = mXml.indexOf("?>", mTagStart + 1) + 2 46 | return nextTag() 47 | } else if (mXml[mTagStart + 1] == '!') { 48 | // Skip comments 49 | mIndex = mXml.indexOf("-->", mTagStart + 1) + 3 50 | return nextTag() 51 | } 52 | 53 | next = mXml.indexOf(">", mTagStart) 54 | firstSpace = mXml.indexOf(" ", mTagStart) 55 | if (firstSpace == -1) { 56 | mReachedEnd = true 57 | return null 58 | } else if (firstSpace > next) { 59 | // Skip elements with no attributes 60 | mIndex = firstSpace + 1 61 | return nextTag() 62 | } else if (!mXml.substring(mTagStart, next).contains(" name=")) { 63 | // Skip elements with no name attribute 64 | mIndex = next + 1 65 | return nextTag() 66 | } 67 | 68 | mTagName = mXml.substring(mTagStart + 1, firstSpace) 69 | val endFindStr = "" 70 | mTagEnd = mXml.indexOf(endFindStr, next + 1) 71 | if (mTagEnd < 0) { 72 | // Didn't find an end to this tag, skip it 73 | mIndex = mTagEnd + 1 74 | return nextTag() 75 | } 76 | mValueStart = next + 1 77 | mValueEnd = mTagEnd 78 | mTagValue = mXml.substring(mValueStart, mValueEnd) 79 | mTagEnd += endFindStr.length 80 | 81 | val tag = mXml.substring(mTagStart, mTagEnd) 82 | mIndex = mTagEnd 83 | return tag 84 | } catch (t: Throwable) { 85 | throw RuntimeException(t) 86 | } 87 | 88 | } 89 | 90 | // public void reset() { 91 | // mIndex = 0; 92 | // mReachedEnd = false; 93 | // } 94 | 95 | fun setElementValue(value: String) { 96 | val endFindStr = "" 97 | mTagValue = value 98 | mXml.replace(mValueStart, mValueEnd, value) 99 | mValueEnd = mValueStart + mTagValue.length 100 | mTagEnd = mValueEnd + endFindStr.length 101 | mIndex = mTagEnd 102 | } 103 | 104 | override fun toString(): String { 105 | return mXml.substring(mIndex) 106 | } 107 | } -------------------------------------------------------------------------------- /src/main/resources/applicationUI.fxml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 20 | 21 | 22 | 23 | 24 | 32 | 33 | 41 | 42 | 43 | 44 | 45 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 |