Browse Source

Release V1

master
Merith-TK 10 months ago
commit
4e553bb9e3
9 changed files with 337 additions and 0 deletions
  1. +4
    -0
      .gitignore
  2. +16
    -0
      Makefile
  3. +101
    -0
      archive.go
  4. BIN
      assets/icon.ico
  5. BIN
      assets/icon.png
  6. +57
    -0
      exec.go
  7. +90
    -0
      file.go
  8. +8
    -0
      go.mod
  9. +61
    -0
      main.go

+ 4
- 0
.gitignore View File

@ -0,0 +1,4 @@
rsrc.syso
go.sum
MinecraftData
Minecraft.portable.*

+ 16
- 0
Makefile View File

@ -0,0 +1,16 @@
default:
go build -o MineCraft.portable.exe -ldflags "-H windowsgui"
rcedit MineCraft.portable.exe \
--set-icon assets/icon.ico \
--set-version-string "FileDescription" "MineCraft Portable" \
--set-version-string "ProductName" "MineCraft Portable" \
--set-version-string "LegalCopyright" "Merith.TK [PortableLauncher]"
GOOS=linux go build -o MineCraft.portable.linux.amd64
clean:
rm MineCraft.portable.exe
rm MineCraft.portable.linux.amd64
javatest:
PATH=/mingw64/bin:/usr/bin:/d/Scoop/apps/go/current/bin go run ./

+ 101
- 0
archive.go View File

@ -0,0 +1,101 @@
package main
import (
"archive/tar"
"compress/gzip"
"io"
"os"
"path/filepath"
)
/*
### THIS IS LITTERALLY JUST FOR EXTRACTING FILES ###
*/
func ungzip(source, target string) error {
reader, err := os.Open(source)
if err != nil {
return err
}
defer reader.Close()
archive, err := gzip.NewReader(reader)
if err != nil {
return err
}
defer archive.Close()
target = filepath.Join(target, archive.Name)
writer, err := os.Create(target)
if err != nil {
return err
}
defer writer.Close()
_, err = io.Copy(writer, archive)
return err
}
func untar(tarball, target string) error {
reader, err := os.Open(tarball)
if err != nil {
return err
}
defer reader.Close()
tarReader := tar.NewReader(reader)
for {
header, err := tarReader.Next()
if err == io.EOF {
break
} else if err != nil {
return err
}
path := filepath.Join(target, header.Name)
info := header.FileInfo()
if info.IsDir() {
if err = os.MkdirAll(path, info.Mode()); err != nil {
return err
}
continue
}
file, err := os.OpenFile(path, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, info.Mode())
if err != nil {
return err
}
defer file.Close()
_, err = io.Copy(file, tarReader)
if err != nil {
return err
}
}
return err
}
func unlzma(source, target string) error {
reader, err := os.Open(source)
if err != nil {
return err
}
defer reader.Close()
archive, err := gzip.NewReader(reader)
if err != nil {
return err
}
defer archive.Close()
target = filepath.Join(target, archive.Name)
writer, err := os.Create(target)
if err != nil {
return err
}
defer writer.Close()
_, err = io.Copy(writer, archive)
return err
}

BIN
assets/icon.ico View File

Before After

BIN
assets/icon.png View File

Before After
Width: 256  |  Height: 256  |  Size: 9.5 KiB

+ 57
- 0
exec.go View File

@ -0,0 +1,57 @@
package main
import (
"fmt"
"os"
"os/exec"
)
/*
### THIS IS WHERE MY COMMANDS TO LAUNCH THE GAME ARE STORED ###
*/
var (
exeMinecraft = "https://launcher.mojang.com/download/Minecraft.exe"
// More Reliable link to the jar...
jarMinecraft = "https://cdn.merith.tk/_Releases/Other/OfficialMinecraft.jar"
)
func minecraftexe() {
filecheck("MinecraftData/minecraft.exe", exeMinecraft)
cmd := exec.Command("MinecraftData/minecraft.exe", "--workDir", ".minecraft")
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stdout
cmd.Stdin = os.Stdin
fmt.Println("[MineCraftPortable] Running Launcher")
fmt.Println("[MineCraftPortable] MineCraft will start Shortly")
cmd.Run()
}
func unknownexe(execute string) {
cmd := exec.Command("MinecraftData/" + execute)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stdout
cmd.Stdin = os.Stdin
fmt.Println("[MineCraftPortable] Running Launcher")
fmt.Println("[MineCraftPortable] Launcher will start Shortly")
cmd.Run()
}
func javaexe(jarfile string) {
jarfile = "MinecraftData/" + jarfile
java := "java"
cmd := exec.Command(java, "-version")
if err := cmd.Run(); err != nil {
java = "MinecraftData/runtime/jre-x64/bin/java.exe"
}
cmd = exec.Command(java, "-jar", jarfile)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stdout
cmd.Stdin = os.Stdin
fmt.Println("[MineCraftPortable] Running Launcher")
fmt.Println("[MineCraftPortable] MineCraft will start Shortly")
cmd.Run()
}

+ 90
- 0
file.go View File

@ -0,0 +1,90 @@
package main
import (
"crypto/md5"
"encoding/hex"
"errors"
"io"
"net/http"
"os"
)
/*
### This is for Misc File operations ###
*/
func filecheck(fileName string, URL string) error {
//Get the response bytes from the url
if _, err := os.Stat(fileName); os.IsNotExist(err) {
response, err := http.Get(URL)
if err != nil {
return err
}
defer response.Body.Close()
if response.StatusCode != 200 {
return errors.New("Received non 200 response code")
}
//Create a empty file
file, err := os.Create(fileName)
if err != nil {
return err
}
defer file.Close()
//Write the bytes to the fiel
_, err = io.Copy(file, response.Body)
if err != nil {
return err
}
}
return nil
}
func md5hash(filePath string) (string, error) {
//Initialize variable returnMD5String now in case an error has to be returned
var returnMD5String string
//Open the passed argument and check for any error
file, err := os.Open(filePath)
if err != nil {
return returnMD5String, err
}
//Tell the program to call the following function when the current function returns
defer file.Close()
//Open a new hash interface to write to
hash := md5.New()
//Copy the file in the hash interface and check for any error
if _, err := io.Copy(hash, file); err != nil {
return returnMD5String, err
}
//Get the 16 bytes hash
hashInBytes := hash.Sum(nil)[:16]
//Convert the bytes to a string
returnMD5String = hex.EncodeToString(hashInBytes)
return returnMD5String, nil
}
func fileWrite(filename string, data string) error {
file, err := os.Create(filename)
if err != nil {
return err
}
defer file.Close()
_, err = io.WriteString(file, data)
if err != nil {
return err
}
return file.Sync()
}

+ 8
- 0
go.mod View File

@ -0,0 +1,8 @@
module minecraft.portable
go 1.15
require (
github.com/gen2brain/dlgs v0.0.0-20200211102745-b9c2664df42f
github.com/gopherjs/gopherjs v0.0.0-20200217142428-fce0ec30dd00 // indirect
)

+ 61
- 0
main.go View File

@ -0,0 +1,61 @@
package main
import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"os"
)
var (
conf config
configfile = "MinecraftData" + "/config.portable.json"
)
type config struct {
Launcher string `json:"launcher"`
Java bool `json:"java"`
}
func main() {
if _, err := os.Stat("MinecraftData"); err != nil {
os.Mkdir("MinecraftData", 755)
}
os.Setenv("MinecraftData", "./")
os.Setenv("HOME", "./")
launcher, java := readjson()
if java == false {
if launcher == "minecraft.exe" {
minecraftexe()
} else {
unknownexe(launcher)
}
} else {
javaexe(launcher)
}
}
func createConfig() {
file, _ := os.Create(configfile)
defer file.Close()
_, _ = io.WriteString(file, `{"launcher":"minecraft.exe","java":false}`)
file.Sync()
main()
}
func readjson() (string, bool) {
str, err := ioutil.ReadFile(configfile)
if err != nil {
fmt.Println("Creating Config")
createConfig()
}
fmt.Println(str)
err = json.Unmarshal([]byte(str), &config)
return config.Launcher, config.Java
}

Loading…
Cancel
Save