Flow Updater JSON Creator
Published: 2023-12-09 17:38:23

{% embed https://github.com/zuygui/flowupdater-json-creator %}

## Introduction

While discussing and assisting people on the [Support Launcher](https://discord.gg/zJkc7nZHRk) Discord server, a discord server for helping people to make customs Minecraft launchers, I realized that creating JSON files compatible with [Flow Updater](https://github.com/FlowArg/FlowUpdater) was time-consuming and tedious. This led me to the idea of developing a command-line tool to replace [the existing desktop application](https://github.com/FlowArg/FlowUpdaterJsonCreator).

## Flow Updater

Flow updater is a Java library to install, update and launch Minecraft (retrieved from officials servers) and mods loaded through Forge or any other mods loader. To load the mod list and other configurations, it is possible to host a JSON file and pass it into the library, ... So a JSON compatible with FlowUpdater looks like :

_Note:_ JSON (JavaScript Object Notation) is a data file format easy to read and write for humans and machines.

```json
{
  "curseFiles": [
    {
      "projectID": 123456, // random curseforge project id
      "fileID": 123456 // random curseforge file id
    }
  ]
}
```

Writing this JSON is very tedious and time-consuming because you have to find the project id and the file id for each mod. So I decided to write a CLI tool to make this task easier.

## Tech Stack

To build this software, I had to utilize several tools, including:

- [Rust](https://rust-lang.com), a compiled functional programming language developed by Mozilla (the company behind Firefox).
- [Request TTY](https://github.com/Lutetium-Vanadium/requestty/), a Rust crate that facilitates the creation of command-line forms.
- [Eternal API](https://docs.curseforge.com/), the new Curseforge API, which allows me to retrieve the necessary information from mods for JSON generation.
- [Serde JSON](https://github.com/serde-rs/json), an extension of the `serde` crate that enables the serialization and deserialization of Rust structs.

I've only mentioned the most significant elements present in the [source code](https://github.com/zuygui/flowupdater-json-creator).

## The goal

I wanna replace the Java application (GUI) by a CLI application in Rust. I also wanna make the application more fast and accessible. Finally, I wanna add new features to the application like locals mods support and archives exports.

## Development Steps

I began by developing a wrapper for the CurseForge API, which turned out to be a lengthy and challenging process but constituted the bulk of the work. Next, I coded the CLI, which was relatively straightforward. Instead of using the [`clap`](https://github.com/clap-rs/clap) crate, a Rust tool for generating CLIs, I opted for the following line of code:

```rs
fn main() {
       let args: Vec<String> = std::env::args().collect();
}
```

This code snippet captures the input to the program: the `main` function defines an immutable variable called `args`, which is a vector (a list with indefinite length, for the sake of simplicity here) of type `String`. Thus, we obtain a list of all the arguments given when executing the binary file (including the application's name). I concluded the development of the first version with the JSON file generation.

## What's Next?

Due to my heavy workload with school, I have less time to continue making progress on the project. This does not mean that I'm abandoning it; I'm simply moving forward at a slower pace. I sincerely thank [Bricklou](https://github.com/Bricklou) for helping me maintain the project. We are actively working on creating new features.

## The refactoring

With [Bricklou](https://github.com/bricklou), we have decided to refactor all the code of the app for a better readability and a better maintainability. The first version of code are always available at the [old](https://github.com/zuygui/flowupdater/tree/old) branch. The new version of the code is available at the [master](https://github.com/zuygui/flowupdater) branch. I've migrated all the backend code to the backend in a rust crate called [fujc_api](https://crates.io/crates/fujc_api) for a better integration to the (future) GUI app and CLI. Why have two backend when we can have one ?
For install the crate, you can use the following command :

```sh
cargo add fujc_api
```

or add the following line to your `Cargo.toml` file :

```toml
fujc_api = "0.1.0"
```

## The GUI

Bricklou suggested to implement a GUI app for a better accessibility. It's not already implemented but we are working on. We are using [Qt](https://www.qt.io/) for the GUI app, Qt XML, and the Qt binding for Rust. The source code isn't available yet but it will be available soon.

## Credits

I wanna thank [Bricklou](https://github.com/bricklou) for maintening the project with me. I also wanna thank [FlowArg](https://github.com/FlowArg) for creating the original project. Finally, I wanna thank [Asthowen](https://github.com/Asthowen) for helping me with Github CI.

## Conclusion

Thank you for reading this article on my blog. I hope you enjoyed it. Please feel free to leave a comment and give the GitHub repository of this blog a star ⭐.