Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
542670eaed | |||
09a44fb454 | |||
cd555f0876 |
2
Makefile
2
Makefile
@ -8,7 +8,7 @@ endif
|
|||||||
DESTDIR:=
|
DESTDIR:=
|
||||||
PREFIX:=/usr/local
|
PREFIX:=/usr/local
|
||||||
|
|
||||||
VERSION=0.1.4
|
VERSION=0.1.5
|
||||||
|
|
||||||
FLAGS:=-buildmode=pie -modcacherw -mod=readonly -trimpath
|
FLAGS:=-buildmode=pie -modcacherw -mod=readonly -trimpath
|
||||||
LDFLAGS:= -ldflags "-s -w -X main.programVersion=${VERSION}"
|
LDFLAGS:= -ldflags "-s -w -X main.programVersion=${VERSION}"
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
# Maintainer: Alexander "Arav" Andreev <me@arav.su>
|
# Maintainer: Alexander "Arav" Andreev <me@arav.su>
|
||||||
pkgname=mccl
|
pkgname=mccl
|
||||||
pkgver=0.1.4
|
pkgver=0.1.5
|
||||||
pkgrel=1
|
pkgrel=1
|
||||||
pkgdesc="Console Minecraft launcher"
|
pkgdesc="Console Minecraft launcher"
|
||||||
arch=('i686' 'x86_64' 'arm' 'armv6h' 'armv7h' 'aarch64')
|
arch=('i686' 'x86_64' 'arm' 'armv6h' 'armv7h' 'aarch64')
|
||||||
|
@ -103,7 +103,13 @@ func (rc *RunCommand) run_client() error {
|
|||||||
p["auth_xuid"] = "null"
|
p["auth_xuid"] = "null"
|
||||||
p["user_type"] = "legacy"
|
p["user_type"] = "legacy"
|
||||||
p["version_type"] = manifst.Type
|
p["version_type"] = manifst.Type
|
||||||
p["natives_directory"] = path.Join("", "versions", manifst.Id, "natives")
|
|
||||||
|
nativesId := manifst.Id
|
||||||
|
if manifst.InheritsFrom != "" {
|
||||||
|
nativesId = manifst.InheritsFrom
|
||||||
|
}
|
||||||
|
p["natives_directory"] = path.Join("", "versions", nativesId, "natives")
|
||||||
|
|
||||||
p["launcher_name"] = "mccl"
|
p["launcher_name"] = "mccl"
|
||||||
p["launcher_version"] = "0.1.0"
|
p["launcher_version"] = "0.1.0"
|
||||||
p["classpath"] = manifst.BuildClasspath("", "versions")
|
p["classpath"] = manifst.BuildClasspath("", "versions")
|
||||||
|
167
cmd/mccl/commands/uninstall_command.go
Normal file
167
cmd/mccl/commands/uninstall_command.go
Normal file
@ -0,0 +1,167 @@
|
|||||||
|
package commands
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"mccl/internal/assets"
|
||||||
|
"mccl/internal/manifest"
|
||||||
|
"mccl/pkg/util"
|
||||||
|
"os"
|
||||||
|
"path"
|
||||||
|
)
|
||||||
|
|
||||||
|
type UninstallCommand struct {
|
||||||
|
Id string
|
||||||
|
GameDir string
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewUninstallCommand(id, gameDir string) *UninstallCommand {
|
||||||
|
return &UninstallCommand{Id: id, GameDir: gameDir}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (uc *UninstallCommand) Run() error {
|
||||||
|
if uc.Id == "" {
|
||||||
|
return errors.New("an empty Minecraft version was provided")
|
||||||
|
}
|
||||||
|
if uc.GameDir == "" {
|
||||||
|
return errors.New("an empty path was provided")
|
||||||
|
}
|
||||||
|
return uc.uninstall_client()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (uc *UninstallCommand) uninstall_client() error {
|
||||||
|
var err error
|
||||||
|
|
||||||
|
if uc.GameDir == "." {
|
||||||
|
execPath, _ := os.Executable()
|
||||||
|
uc.GameDir = path.Dir(execPath)
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, err := os.Stat(uc.GameDir); err != nil {
|
||||||
|
return os.ErrNotExist
|
||||||
|
}
|
||||||
|
|
||||||
|
manifests := make(map[string]*manifest.Manifest)
|
||||||
|
|
||||||
|
entries, err := os.ReadDir(path.Join(uc.GameDir, "versions"))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
for _, entry := range entries {
|
||||||
|
if entry.IsDir() {
|
||||||
|
data, err := util.ReadFile(path.Join(uc.GameDir, "versions", entry.Name(), entry.Name()+".json"))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
manifests[entry.Name()], err = manifest.New(data)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for id, manifest := range manifests {
|
||||||
|
if id == uc.Id {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if manifest.InheritsFrom == uc.Id {
|
||||||
|
return fmt.Errorf("%s inherits %s. Uninstall %s first", id, uc.Id, id)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
assetIndexInUse := manifests[uc.Id].InheritsFrom != ""
|
||||||
|
logConfigInUse := manifests[uc.Id].InheritsFrom != ""
|
||||||
|
libsToDelete := make(map[string]string)
|
||||||
|
|
||||||
|
for _, lib := range manifests[uc.Id].Libraries {
|
||||||
|
libsToDelete[lib.Name] = lib.Path()
|
||||||
|
}
|
||||||
|
|
||||||
|
for id, manifest := range manifests {
|
||||||
|
if id == uc.Id {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if !assetIndexInUse && manifests[uc.Id].Assets == manifest.Assets {
|
||||||
|
assetIndexInUse = true
|
||||||
|
}
|
||||||
|
|
||||||
|
if !logConfigInUse && manifests[uc.Id].Logging.Client.File.Id == manifest.Logging.Client.File.Id {
|
||||||
|
logConfigInUse = true
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, lib := range manifest.Libraries {
|
||||||
|
if name, ok := libsToDelete[lib.Name]; ok {
|
||||||
|
delete(libsToDelete, name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if !logConfigInUse {
|
||||||
|
dir := path.Join(uc.GameDir, "assets", "log_configs")
|
||||||
|
if err := os.Remove(path.Join(dir, manifests[uc.Id].Logging.Client.File.Id)); err != nil {
|
||||||
|
return fmt.Errorf("failed to remove assets/log_configs/%s: %s", manifests[uc.Id].Logging.Client.File.Id, err)
|
||||||
|
}
|
||||||
|
if d, err := os.ReadDir(dir); err == nil && len(d) == 0 {
|
||||||
|
if err := os.Remove(path.Join(dir, manifests[uc.Id].Logging.Client.File.Id)); err != nil {
|
||||||
|
return fmt.Errorf("failed to remove assets/log_configs directory: %s", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if !assetIndexInUse {
|
||||||
|
dir := path.Join(uc.GameDir, "assets")
|
||||||
|
|
||||||
|
assetFiles := make(map[string]*assets.Assets)
|
||||||
|
|
||||||
|
for _, manifest := range manifests {
|
||||||
|
if _, ok := assetFiles[manifest.Assets]; !ok {
|
||||||
|
data, err := os.ReadFile(path.Join(dir, "indexes", manifest.Assets+".json"))
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to read an index %s file: %s", manifest.Assets, err)
|
||||||
|
}
|
||||||
|
assetFiles[manifest.Assets], err = assets.New(data)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to load asset index %s: %s", manifest.Assets, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
toRemove := []string{}
|
||||||
|
|
||||||
|
for name, obj := range assetFiles[manifests[uc.Id].Assets].Objects {
|
||||||
|
inUse := false
|
||||||
|
for id, idx := range assetFiles {
|
||||||
|
if id == manifests[uc.Id].Assets {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if iobj, ok := idx.Objects[name]; ok && iobj.Hash == obj.Hash {
|
||||||
|
inUse = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if !inUse {
|
||||||
|
toRemove = append(toRemove, obj.Hash)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, hash := range toRemove {
|
||||||
|
if err := os.Remove(path.Join(dir, "objects", hash[:2], hash)); err != nil {
|
||||||
|
return fmt.Errorf("failed to remove an object %s/%s: %s", hash[:2], hash, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := os.Remove(path.Join(dir, "indexes", manifests[uc.Id].Assets+".json")); err != nil {
|
||||||
|
return fmt.Errorf("failed to remove %s: %s", path.Join("assets", "indexes", manifests[uc.Id].Assets+".json"), err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, path := range libsToDelete {
|
||||||
|
if err := os.Remove(path); err != nil {
|
||||||
|
return fmt.Errorf("failed to remove %s: %s", path, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user