Compare commits

..

No commits in common. "master" and "v0.1.0" have entirely different histories.

8 changed files with 93 additions and 98 deletions

View File

@ -8,7 +8,7 @@ endif
DESTDIR:=
PREFIX:=/usr/local
VERSION=0.1.2
VERSION=0.1.0
FLAGS:=-buildmode=pie -modcacherw -mod=readonly -trimpath
LDFLAGS:= -ldflags "-s -w -X main.programVersion=${VERSION}"
@ -23,16 +23,10 @@ else
endif
install:
ifeq ($(shell go env GOOS),windows)
else
install -Dm 0755 bin/${EXEC_NAME} ${DESTDIR}${PREFIX}/bin/${EXEC_NAME}
endif
uninstall:
ifeq ($(shell go env GOOS),windows)
else
rm ${DESTDIR}${PREFIX}/bin/${EXEC_NAME}
endif
clean:
rm -f bin/*

View File

@ -1,6 +1,6 @@
# Maintainer: Alexander "Arav" Andreev <me@arav.su>
pkgname=mccl
pkgver=0.1.2
pkgver=0.1.0
pkgrel=1
pkgdesc="Console Minecraft launcher"
arch=('i686' 'x86_64' 'arm' 'armv6h' 'armv7h' 'aarch64')

View File

@ -1,7 +1,6 @@
package commands
import (
"bufio"
"errors"
"fmt"
"mccl/internal/manifest"
@ -31,11 +30,9 @@ func (rc *RunCommand) Run() error {
if rc.Id == "" {
return errors.New("an empty Minecraft version was provided")
}
if err := os.Chdir(rc.GameDir); err != nil {
return err
}
if rc.UseProfile {
if util.IsFileExist(path.Join(rc.GameDir, mcclprofile.ProfileFileName)) {
p, err := mcclprofile.Load(rc.GameDir)
@ -55,7 +52,6 @@ func (rc *RunCommand) Run() error {
}
}
}
return rc.run_client()
}
@ -143,23 +139,22 @@ func (rc *RunCommand) run_client() error {
}
cmd := exec.Command(path.Join(javaHome, "bin", "java"), cl...)
stdout, err := cmd.StdoutPipe()
cmd.Stderr = cmd.Stdout
if err != nil {
return err
}
defer stdout.Close()
// stdout, err := cmd.StdoutPipe()
// cmd.Stderr = cmd.Stdout
// if err != nil {
// return err
// }
// defer stdout.Close()
scanner := bufio.NewScanner(stdout)
go func() {
for scanner.Scan() {
fmt.Println(scanner.Text())
}
}()
// scanner := bufio.NewScanner(stdout)
// go func() {
// for scanner.Scan() {
// fmt.Println(scanner.Text())
// }
// }()
fmt.Printf("Minecraft version %s is started with username %s and player's UUID %s.\n",
fmt.Printf("Minecraft version %s is started with usename %s and player's UUID %s.\n",
manifst.Id, rc.Username, rc.AuthUuid)
if err := cmd.Run(); err != nil && (err.Error() != "exec: already started") {
return err
}

View File

@ -31,7 +31,7 @@ func main() {
if len(os.Args) < 2 {
usage()
os.Exit(1)
os.Exit(0)
}
var cmd commands.Command
@ -72,7 +72,6 @@ func main() {
func version() {
fmt.Fprintf(os.Stderr, "mccl ver. %s\nCopyright (c) 2023 Alexander \"Arav\" Andreev <me@arav.su>\n", programVersion)
fmt.Fprintln(os.Stderr, "URL: https://git.arav.su/Arav/mccl")
fmt.Fprintln(os.Stderr, "License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.")
}
@ -91,8 +90,8 @@ func usage() {
" \033[1mlist|l\033[0m directory\n"+
" List all installed versions in directory\n"+
"Explanation of arguments and options for commands:\n"+
" version version of a game (name of a dir inside versions dir)\n"+
" directory a path to where Minecraft will be installed / or will be runned from\n"+
" version minecraft's version \n"+
" directory a path to where Minecraft will be installed\n"+
" -u,--username username\n"+
" player's username (Anonymous by default)\n"+
" -U,--uuid UUID\n"+
@ -102,7 +101,7 @@ func usage() {
" --profile\n"+
" load/save username, UUID, and -Xmx from/to a file.\n"+
" Once saved, you can ommit -u,-U and --java-Xmx,\n"+
" since they will be stored in", mcclprofile.ProfileFileName)
" since they are stored in", mcclprofile.ProfileFileName)
}
type arguments struct {
@ -132,15 +131,74 @@ func parseArguments(args []string) (parsed arguments, err error) {
parsed.Username = "Anonymous"
parsed.Directory = "."
parsed.Uuid = "00000000-0000-0000-0000-000000000000"
for i := 0; i < len(args); i++ {
if args[i][0] != '-' {
if parsed.Command != "" {
return parsed, fmt.Errorf("there is already a command %s, but a second one (%s) was provided",
parsed.Command, args[i])
if len(args[i]) > 2 && args[i][0] == '-' && args[i][1] == '-' {
switch args[i][2:] {
case "version":
parsed.ShowVersion = true
case "help":
parsed.ShowHelp = true
case "demand-press-enter":
parsed.DemandPressEnter = true
case "username":
if len(args) == i+1 || args[i+1][0] == '-' {
err = errNoOptArg{ArgName: args[i]}
return
}
parsed.Username = args[i+1]
i++
case "uuid":
if len(args) == i+1 || args[i+1][0] == '-' {
err = errNoOptArg{ArgName: args[i]}
return
}
parsed.Uuid = args[i+1]
i++
case "java-Xmx":
if len(args) == i+1 || args[i+1][0] == '-' {
err = errNoOptArg{ArgName: args[i]}
return
}
parsed.JavaXmx = args[i+1]
i++
case "profile":
parsed.UseProfile = true
default:
err = fmt.Errorf("an unknown option %s was provided", args[i])
return
}
parsed.Command = args[i]
switch parsed.Command {
} else if args[i][0] == '-' && len(args[i]) > 1 {
for _, option := range args[i][1:] {
switch option {
case 'v':
parsed.ShowVersion = true
case 'h':
parsed.ShowHelp = true
case 'u':
if len(args) == i+1 || args[i+1][0] == '-' {
err = errNoOptArg{ArgName: args[i]}
return
}
parsed.Username = args[i+1]
i++
case 'U':
if len(args) == i+1 || args[i+1][0] == '-' {
err = errNoOptArg{ArgName: args[i]}
return
}
parsed.Uuid = args[i+1]
i++
default:
err = fmt.Errorf("an unknown option %c was provided", option)
return
}
}
} else {
if parsed.Command != "" {
err = fmt.Errorf("only one command should present")
return
}
switch parsed.Command = args[i]; parsed.Command {
case "i":
fallthrough
case "install":
@ -148,9 +206,9 @@ func parseArguments(args []string) (parsed arguments, err error) {
case "r":
fallthrough
case "run":
if i+3 > len(args) || args[i+1][0] == '-' {
return parsed, fmt.Errorf("a command %s is missing its version and directory arguments",
parsed.Command)
if len(args) <= i+3 || args[i+1][0] == '-' || args[i+2][0] == '-' {
err = fmt.Errorf("not enough arguments was provided")
return
}
parsed.GameVersion = args[i+1]
parsed.Directory = args[i+2]
@ -158,56 +216,16 @@ func parseArguments(args []string) (parsed arguments, err error) {
case "l":
fallthrough
case "list":
if i+1 >= len(args) || args[i+1][0] == '-' {
return parsed, fmt.Errorf("a command list is missing its directory argument")
if len(args) <= i+2 || args[i+1][0] == '-' {
err = fmt.Errorf("not enough arguments was provided")
return
}
parsed.Directory = args[i+1]
i++
}
continue
}
switch args[i] {
case "-v":
fallthrough
case "--version":
parsed.ShowVersion = true
case "-h":
fallthrough
case "--help":
parsed.ShowHelp = true
case "--demand-press-enter":
parsed.DemandPressEnter = true
case "-u":
fallthrough
case "--username":
if len(args) == i+1 || args[i+1][0] == '-' {
err = errNoOptArg{ArgName: args[i]}
default:
err = fmt.Errorf("an unknown command %s was provided", parsed.Command)
return
}
parsed.Username = args[i+1]
i++
case "-U":
fallthrough
case "--uuid":
if len(args) == i+1 || args[i+1][0] == '-' {
err = errNoOptArg{ArgName: args[i]}
return
}
parsed.Uuid = args[i+1]
i++
case "--java-Xmx":
if len(args) == i+1 || args[i+1][0] == '-' {
err = errNoOptArg{ArgName: args[i]}
return
}
parsed.JavaXmx = args[i+1]
i++
case "--profile":
parsed.UseProfile = true
default:
err = fmt.Errorf("an unknown option %s was provided", args[i])
return
}
}
return

View File

@ -1,6 +1,3 @@
//go:build unix
// +build unix
package util
func LocateJavaHome(component string, majorVersion int) (string, error) {

View File

@ -1,6 +1,3 @@
//go:build windows
// +build windows
package util
import (

View File

@ -1,6 +1,3 @@
//go:build unix
// +build unix
package util
import (

View File

@ -1,6 +1,3 @@
//go:build windows
// +build windows
package util
import (