Pull forge versions

This commit is contained in:
Samuel Walker 2024-10-31 21:20:20 -06:00
parent a614f71aa1
commit e5cf9f532e
7 changed files with 123 additions and 10 deletions

View File

@ -11,20 +11,18 @@ import (
"github.com/wailsapp/wails/v2/pkg/runtime" "github.com/wailsapp/wails/v2/pkg/runtime"
) )
const client_id string = "9305aeb8-5ecb-4e7a-b28f-c33aefcfbd8d" const client_id string = "9305aeb8-5ecb-4e7a-b28f-c33aefcfbd8d"
// App struct // App struct
type App struct { type App struct {
Ctx context.Context Ctx context.Context
PrismLauncher Prism PrismLauncher Prism
Java JavaManager Java JavaManager
Instance InstanceManager Instance InstanceManager
Modpacks ModpackManager Modpacks ModpackManager
Auth authenticationResp Auth authenticationResp
} }
// NewApp creates a new App application struct // NewApp creates a new App application struct
func NewApp() *App { func NewApp() *App {
a := &App{} a := &App{}
@ -42,7 +40,6 @@ func (a *App) startup(ctx context.Context) {
// Greet returns a greeting for the given name // Greet returns a greeting for the given name
func (a *App) CheckPrerequisites() { func (a *App) CheckPrerequisites() {
a.Status("Querrying Existing Instances") a.Status("Querrying Existing Instances")
a.Instance.SearchInstances() a.Instance.SearchInstances()

70
fclauncher/forge.go Normal file
View File

@ -0,0 +1,70 @@
package main
import (
"fmt"
"io"
"net/http"
"strings"
)
type Forge struct{}
type ForgeVersion struct {
Version string
Time string
Url string
}
func parseForgeVersions(html string) []ForgeVersion {
lines := strings.Split(html, "\n")
parsing := false
foundTR := false
buff := ""
versions := []ForgeVersion{}
for _, line := range lines {
if strings.Contains(line, "<tbody>") {
parsing = true
} else if strings.Contains(line, "</tbody>") {
parsing = false
} else if parsing {
if strings.Contains(line, "<tr>") {
buff = ""
foundTR = true
} else if strings.Contains(line, "</tr>") {
foundTR = false
versions = append(versions, parseForgeVersion(buff))
} else if foundTR {
buff += line + "\n"
}
}
}
return versions
}
func parseForgeVersion(html string) ForgeVersion {
lines := strings.Split(html, "\n")
version := ForgeVersion{}
for ind, line := range lines {
if strings.Contains(line, "<td class=\"download-version\">") {
version.Version = strings.TrimSpace(lines[ind+1])
} else if strings.Contains(line, "<td class=\"download-time\"") {
version.Time = strings.Split(strings.Split(line, "<td class=\"download-time\" title=\"")[1], "\">")[0]
} else if strings.Contains(line, "https://adfoc.us") && strings.Contains(line, "installer.jar") {
version.Url = strings.Split(strings.Split(line, "&url=")[1], "\">")[0]
}
}
return version
}
func (Forge) GetForgeVersions(mcVersion string) ([]ForgeVersion, error) {
resp, err := http.Get(fmt.Sprintf("https://files.minecraftforge.net/net/minecraftforge/forge/index_%s.html", mcVersion))
if err != nil {
return []ForgeVersion{}, fmt.Errorf("unable to access minecraft forge index: %e", err)
}
defer resp.Body.Close()
if resp.StatusCode != 200 {
return []ForgeVersion{}, fmt.Errorf("unable to access minecraft forge index: %s", err)
}
data, _ := io.ReadAll(resp.Body)
return parseForgeVersions(string(data)), nil
}

View File

@ -3,6 +3,7 @@
import {GetVersions} from '../wailsjs/go/main/App.js' import {GetVersions} from '../wailsjs/go/main/App.js'
import {GetFabricVersions} from '../wailsjs/go/main/Fabric.js' import {GetFabricVersions} from '../wailsjs/go/main/Fabric.js'
import {GetQuiltVersions} from '../wailsjs/go/main/Quilt.js' import {GetQuiltVersions} from '../wailsjs/go/main/Quilt.js'
import {GetForgeVersions} from '../wailsjs/go/main/Forge.js'
import {onMount} from 'svelte' import {onMount} from 'svelte'
import {loading, addingInstance} from './global' import {loading, addingInstance} from './global'
import {slide} from 'svelte/transition' import {slide} from 'svelte/transition'
@ -17,6 +18,8 @@
let fab_versions: string[] = [] let fab_versions: string[] = []
let quilt_ver: string = "" let quilt_ver: string = ""
let quilt_versions: string[] = [] let quilt_versions: string[] = []
let forge_ver: string = ""
let forge_versions: string[] = []
function updateLists(){ function updateLists(){
GetVersions().then((result) => { GetVersions().then((result) => {
@ -46,6 +49,14 @@
}) })
quilt_ver = quilt_versions[0] quilt_ver = quilt_versions[0]
}) })
GetForgeVersions(pack).then((result) => {
forge_versions = []
result.forEach((ver) => {
forge_versions.push(ver.Version)
})
forge_ver = forge_versions[0]
}).catch(() => { forge_versions = []; forge_ver = "" })
} }
@ -135,6 +146,12 @@
<option value={ver}>{ver}</option> <option value={ver}>{ver}</option>
{/each} {/each}
</select> </select>
{:else if loader == "forge"}
<select id="forge_ver" bind:value={forge_ver} name="forge_ver">Select Forge Version:
{#each forge_versions as ver}
<option value={ver}>{ver}</option>
{/each}
</select>
{/if} {/if}
<br/> <br/>
<button on:click={install}>Install</button> <button on:click={install}>Install</button>

View File

@ -0,0 +1,5 @@
// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL
// This file is automatically generated. DO NOT EDIT
import {main} from '../models';
export function GetForgeVersions(arg1:string):Promise<Array<main.ForgeVersion>>;

View File

@ -0,0 +1,7 @@
// @ts-check
// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL
// This file is automatically generated. DO NOT EDIT
export function GetForgeVersions(arg1) {
return window['go']['main']['Forge']['GetForgeVersions'](arg1);
}

View File

@ -139,6 +139,22 @@ export namespace main {
return a; return a;
} }
} }
export class ForgeVersion {
Version: string;
Time: string;
Url: string;
static createFrom(source: any = {}) {
return new ForgeVersion(source);
}
constructor(source: any = {}) {
if ('string' === typeof source) source = JSON.parse(source);
this.Version = source["Version"];
this.Time = source["Time"];
this.Url = source["Url"];
}
}
export class Instance { export class Instance {
InstanceName: string; InstanceName: string;
ModpackId: string; ModpackId: string;

View File

@ -33,6 +33,7 @@ func main() {
&app.Modpacks, &app.Modpacks,
&Fabric{}, &Fabric{},
&Quilt{}, &Quilt{},
&Forge{},
}, },
}) })