Pull forge versions
This commit is contained in:
parent
a614f71aa1
commit
e5cf9f532e
@ -11,7 +11,6 @@ import (
|
||||
"github.com/wailsapp/wails/v2/pkg/runtime"
|
||||
)
|
||||
|
||||
|
||||
const client_id string = "9305aeb8-5ecb-4e7a-b28f-c33aefcfbd8d"
|
||||
|
||||
// App struct
|
||||
@ -24,7 +23,6 @@ type App struct {
|
||||
Auth authenticationResp
|
||||
}
|
||||
|
||||
|
||||
// NewApp creates a new App application struct
|
||||
func NewApp() *App {
|
||||
a := &App{}
|
||||
@ -42,7 +40,6 @@ func (a *App) startup(ctx context.Context) {
|
||||
|
||||
// Greet returns a greeting for the given name
|
||||
|
||||
|
||||
func (a *App) CheckPrerequisites() {
|
||||
a.Status("Querrying Existing Instances")
|
||||
a.Instance.SearchInstances()
|
||||
|
70
fclauncher/forge.go
Normal file
70
fclauncher/forge.go
Normal 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
|
||||
}
|
@ -3,6 +3,7 @@
|
||||
import {GetVersions} from '../wailsjs/go/main/App.js'
|
||||
import {GetFabricVersions} from '../wailsjs/go/main/Fabric.js'
|
||||
import {GetQuiltVersions} from '../wailsjs/go/main/Quilt.js'
|
||||
import {GetForgeVersions} from '../wailsjs/go/main/Forge.js'
|
||||
import {onMount} from 'svelte'
|
||||
import {loading, addingInstance} from './global'
|
||||
import {slide} from 'svelte/transition'
|
||||
@ -17,6 +18,8 @@
|
||||
let fab_versions: string[] = []
|
||||
let quilt_ver: string = ""
|
||||
let quilt_versions: string[] = []
|
||||
let forge_ver: string = ""
|
||||
let forge_versions: string[] = []
|
||||
|
||||
function updateLists(){
|
||||
GetVersions().then((result) => {
|
||||
@ -46,6 +49,14 @@
|
||||
})
|
||||
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>
|
||||
{/each}
|
||||
</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}
|
||||
<br/>
|
||||
<button on:click={install}>Install</button>
|
||||
|
5
fclauncher/frontend/wailsjs/go/main/Forge.d.ts
vendored
Executable file
5
fclauncher/frontend/wailsjs/go/main/Forge.d.ts
vendored
Executable 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>>;
|
7
fclauncher/frontend/wailsjs/go/main/Forge.js
Executable file
7
fclauncher/frontend/wailsjs/go/main/Forge.js
Executable 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);
|
||||
}
|
@ -139,6 +139,22 @@ export namespace main {
|
||||
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 {
|
||||
InstanceName: string;
|
||||
ModpackId: string;
|
||||
|
@ -33,6 +33,7 @@ func main() {
|
||||
&app.Modpacks,
|
||||
&Fabric{},
|
||||
&Quilt{},
|
||||
&Forge{},
|
||||
},
|
||||
})
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user