| .idea | ||
| gradle/wrapper | ||
| src/main/java/dev/foxgirl/simpleupdatetool | ||
| .editorconfig | ||
| .gitignore | ||
| build.gradle | ||
| gradlew | ||
| gradlew.bat | ||
| README.md | ||
| settings.gradle | ||
Lua's Simple Update Tool
This is a simple and tiny Java program that I created for use with my Minecraft modpacks.
Since my modpacks and servers usually involve updates over time for new features or bugfixes, I often find myself hacking in some kind of automatic update system that is itself a mod (!!)
This isn't the most elegant solution though, as on Windows (which is the OS that 95% of my friends use) you can't modify or delete files that are actively in use without weird errors. And, by the time the update mod has loaded, all the other mod JARs have also been loaded and are in use. My approach usually involves spawning a new process to run the update mod and then shutting down the game, usually just executing the mod JAR's main class which happens to be an updater. But that also has issues, especially if I want to update the mod JAR itself, and bleehhhh it's all chaos.
Anyway this tool simplifies things a little bit. It takes in a "TODO" file which contains instructions on what to do, and then runs each instruction one by one, while displaying a helpful little window with logging output.
To use this tool, the modpack will do the following on startup:
- Figure out what files need to be updated
- Download any updates
- Prepare a TODO file
- Spawn a new process that runs this update tool
- Exit
Figuring out what needs to be updated and downloading updates is left up to the modpack, but I usually do something like:
- Download some https://modpack.example.com/version.json file and parse out the list of expected files
- List and hash and compare the current files against the expected files
- Download any missing files from https://modpack.example.com/files/FILENAME or similar
- Prepare a TODO file, start the update tool, and exit
If you wanna know how this thing actually works, it's all just one Java file: Main.java
Anyway, here's how to format a TODO file:
# comments start with a hashtag
# commands are an action verb followed by arguments, seperated by newlines
# wait for a process to exit by PID
# this will send a SIGTERM and then eventually a SIGKILL
wait
123456
# move a file
# this will try and use an atomic move operation,
# but if that fails it will just copy the file and delete the old one
move
src/main/resources/myfile.txt
dst/myfile.txt
# delete a file
delete
dst/myotherfile.txt
# print a message top the log
# this supports multiple lines,
# the first argument is the number of lines
# the remaining arguments are each line
print
1
This is a cool message!
# set the success message, printed after the update is complete
# works the same as print
successmsg
2
This is the success message!
You should (re)start the game now.
# set the error message, same as successmsg but for errors
errormsg
1
This is the error message!
Something went wrong, you should copy this output and then go tell Lua.
# that's everything!
You can save this as example.todo and then run:
$ java -jar ./simple-update-tool.jar ./example.todo
Although, it probably won't work with those example paths, ehehe. But you will be able to see the little Swing window that displays the output!
Note that the program won't exit on its own, so that the user can see the output and read any errors.
Written by Lua with love :3c https://foxgirl.dev/
License? Do whatever you want!