added basic support for downloading (not installing) modpack files
This commit is contained in:
parent
29bf715025
commit
3c8fb9a89f
@ -5,10 +5,12 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"compress/gzip"
|
"compress/gzip"
|
||||||
"context"
|
"context"
|
||||||
|
"encoding/json"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/zhyee/zipstream"
|
"github.com/zhyee/zipstream"
|
||||||
)
|
)
|
||||||
@ -25,6 +27,12 @@ type Instance struct {
|
|||||||
JavaVer string
|
JavaVer string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Version struct {
|
||||||
|
Version string
|
||||||
|
Data time.Time
|
||||||
|
File string
|
||||||
|
}
|
||||||
|
|
||||||
func (Prism) CheckInstalled() bool {
|
func (Prism) CheckInstalled() bool {
|
||||||
path, _ := os.UserConfigDir()
|
path, _ := os.UserConfigDir()
|
||||||
_, err := os.Stat(filepath.Join(path, "FCLauncher", "prism"))
|
_, err := os.Stat(filepath.Join(path, "FCLauncher", "prism"))
|
||||||
@ -114,3 +122,17 @@ func (p *Prism) Install() {
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
func (p *Prism)InstallModpack(modpack Modpack){
|
||||||
|
buff := new(bytes.Buffer)
|
||||||
|
HttpDownload(modpack.Id + "/versions.json", buff, nil)
|
||||||
|
var versions []Version
|
||||||
|
json.Unmarshal(buff.Bytes(), &versions)
|
||||||
|
version := versions[len(versions)-1]
|
||||||
|
dname, _ := os.MkdirTemp("", "fclauncher-*")
|
||||||
|
f, _ := os.OpenFile(filepath.Join(dname, modpack.Name), os.O_CREATE|os.O_RDWR, 0755)
|
||||||
|
defer f.Close()
|
||||||
|
HttpDownload(modpack.Id + "/" + version.File, f, p.ctx)
|
||||||
|
|
||||||
|
}
|
||||||
|
@ -19,7 +19,7 @@ type App struct {
|
|||||||
|
|
||||||
type Modpack struct {
|
type Modpack struct {
|
||||||
Name string
|
Name string
|
||||||
Nd string
|
Id string
|
||||||
Last_updated string
|
Last_updated string
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -39,7 +39,7 @@ func (a *App) Greet(name string) string {
|
|||||||
return fmt.Sprintf("Hello %s, It's show time!", name)
|
return fmt.Sprintf("Hello %s, It's show time!", name)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) GetModpacks() []string {
|
func (a *App) GetModpacks() []Modpack {
|
||||||
buff := new(bytes.Buffer)
|
buff := new(bytes.Buffer)
|
||||||
err := HttpDownload("modpacks.json", buff, nil)
|
err := HttpDownload("modpacks.json", buff, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -52,11 +52,7 @@ func (a *App) GetModpacks() []string {
|
|||||||
fmt.Println(err.Error())
|
fmt.Println(err.Error())
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
var names []string
|
return modpacks
|
||||||
for _, pack := range modpacks {
|
|
||||||
names = append(names, pack.Name)
|
|
||||||
}
|
|
||||||
return names
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *App) CheckPrerequisites() {
|
func (a *App) CheckPrerequisites() {
|
||||||
@ -84,6 +80,11 @@ func (a *App) CheckPrerequisites() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *App) InstallModpack(pack Modpack) {
|
||||||
|
a.status(fmt.Sprintf("Installing %s\n", pack.Name))
|
||||||
|
a.prism.InstallModpack(pack)
|
||||||
|
}
|
||||||
|
|
||||||
func (a *App) status(status string) {
|
func (a *App) status(status string) {
|
||||||
fmt.Printf("LOG: %s\n", status)
|
fmt.Printf("LOG: %s\n", status)
|
||||||
runtime.EventsEmit(a.ctx, "status", status)
|
runtime.EventsEmit(a.ctx, "status", status)
|
||||||
|
@ -4,12 +4,12 @@
|
|||||||
import Loading from './Loading.svelte'
|
import Loading from './Loading.svelte'
|
||||||
import {CheckPrerequisites} from '../wailsjs/go/main/App.js'
|
import {CheckPrerequisites} from '../wailsjs/go/main/App.js'
|
||||||
import { onMount } from 'svelte'
|
import { onMount } from 'svelte'
|
||||||
|
import { loading } from './global.ts'
|
||||||
|
|
||||||
let loading: boolean = true
|
|
||||||
let width: int = 10
|
let width: int = 10
|
||||||
|
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
CheckPrerequisites().then(() => loading = false)
|
CheckPrerequisites().then(() => $loading = false)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
@ -17,7 +17,7 @@
|
|||||||
|
|
||||||
<main>
|
<main>
|
||||||
<img alt="Wails logo" id="logo" src="{logo}">
|
<img alt="Wails logo" id="logo" src="{logo}">
|
||||||
{#if loading}
|
{#if $loading}
|
||||||
<Loading />
|
<Loading />
|
||||||
{:else}
|
{:else}
|
||||||
<Client />
|
<Client />
|
||||||
|
@ -1,22 +1,31 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import {GetModpacks} from '../wailsjs/go/main/App.js'
|
import {GetModpacks, InstallModpack} from '../wailsjs/go/main/App.js'
|
||||||
import {onMount} from 'svelte'
|
import {onMount} from 'svelte'
|
||||||
|
import {loading} from './global.ts'
|
||||||
|
|
||||||
let modpacks: string[] = []
|
let modpacks: string[] = []
|
||||||
|
let pack: Modpack
|
||||||
|
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
GetModpacks().then((result) => {
|
GetModpacks().then((result) => {
|
||||||
modpacks = result
|
modpacks = result
|
||||||
|
pack = modpacks[0]
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
function onclick(event) {
|
||||||
|
$loading = true
|
||||||
|
InstallModpack(pack).then(() => {$loading = false})
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<main>
|
<main>
|
||||||
<select name="pack">Select a Modpack:
|
<select bind:value={pack} name="pack">Select a Modpack:
|
||||||
{#each modpacks as pack}
|
{#each modpacks as pack}
|
||||||
<option value={pack}>{pack}</option>
|
<option value={pack}>{pack.Name}</option>
|
||||||
{/each}
|
{/each}
|
||||||
</select>
|
</select>
|
||||||
|
<button on:click={onclick}>Launch</button>
|
||||||
</main>
|
</main>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
|
@ -11,8 +11,8 @@
|
|||||||
})
|
})
|
||||||
|
|
||||||
EventsOn("download", (Completed, Total) => {
|
EventsOn("download", (Completed, Total) => {
|
||||||
completed = Completed / (1024*1024)
|
completed = (Completed / (1024*1024)).toFixed(2)
|
||||||
total = Total / (1024*1024)
|
total = (Total / (1024*1024)).toFixed(2)
|
||||||
downloading = true
|
downloading = true
|
||||||
})
|
})
|
||||||
|
|
||||||
|
2
fclauncher/frontend/src/global.ts
Normal file
2
fclauncher/frontend/src/global.ts
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
import { writable } from "svelte/store"
|
||||||
|
export const loading = writable(true)
|
5
fclauncher/frontend/wailsjs/go/main/App.d.ts
vendored
5
fclauncher/frontend/wailsjs/go/main/App.d.ts
vendored
@ -1,8 +1,11 @@
|
|||||||
// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL
|
// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL
|
||||||
// This file is automatically generated. DO NOT EDIT
|
// This file is automatically generated. DO NOT EDIT
|
||||||
|
import {main} from '../models';
|
||||||
|
|
||||||
export function CheckPrerequisites():Promise<void>;
|
export function CheckPrerequisites():Promise<void>;
|
||||||
|
|
||||||
export function GetModpacks():Promise<Array<string>>;
|
export function GetModpacks():Promise<Array<main.Modpack>>;
|
||||||
|
|
||||||
export function Greet(arg1:string):Promise<string>;
|
export function Greet(arg1:string):Promise<string>;
|
||||||
|
|
||||||
|
export function InstallModpack(arg1:main.Modpack):Promise<void>;
|
||||||
|
@ -13,3 +13,7 @@ export function GetModpacks() {
|
|||||||
export function Greet(arg1) {
|
export function Greet(arg1) {
|
||||||
return window['go']['main']['App']['Greet'](arg1);
|
return window['go']['main']['App']['Greet'](arg1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function InstallModpack(arg1) {
|
||||||
|
return window['go']['main']['App']['InstallModpack'](arg1);
|
||||||
|
}
|
||||||
|
21
fclauncher/frontend/wailsjs/go/models.ts
Executable file
21
fclauncher/frontend/wailsjs/go/models.ts
Executable file
@ -0,0 +1,21 @@
|
|||||||
|
export namespace main {
|
||||||
|
|
||||||
|
export class Modpack {
|
||||||
|
Name: string;
|
||||||
|
Id: string;
|
||||||
|
Last_updated: string;
|
||||||
|
|
||||||
|
static createFrom(source: any = {}) {
|
||||||
|
return new Modpack(source);
|
||||||
|
}
|
||||||
|
|
||||||
|
constructor(source: any = {}) {
|
||||||
|
if ('string' === typeof source) source = JSON.parse(source);
|
||||||
|
this.Name = source["Name"];
|
||||||
|
this.Id = source["Id"];
|
||||||
|
this.Last_updated = source["Last_updated"];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -8,7 +8,7 @@ import (
|
|||||||
"github.com/wailsapp/wails/v2/pkg/runtime"
|
"github.com/wailsapp/wails/v2/pkg/runtime"
|
||||||
)
|
)
|
||||||
|
|
||||||
const BlockSize = 1024
|
const BlockSize = 1024 * 64
|
||||||
|
|
||||||
func HttpDownload(path string, out io.Writer, ctx context.Context) error {
|
func HttpDownload(path string, out io.Writer, ctx context.Context) error {
|
||||||
res, err := http.Get("https://gitea.piwalker.net/fclauncher/" + path)
|
res, err := http.Get("https://gitea.piwalker.net/fclauncher/" + path)
|
||||||
|
Loading…
Reference in New Issue
Block a user