diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100755 index 0000000..6be7cd1 --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,82 @@ +#------------------------------------------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information. +#------------------------------------------------------------------------------------------------------------- + +FROM golang:1 + +# Avoid warnings by switching to noninteractive +ENV DEBIAN_FRONTEND=noninteractive + +# This Dockerfile adds a non-root user with sudo access. Use the "remoteUser" +# property in devcontainer.json to use it. On Linux, the container user's GID/UIDs +# will be updated to match your local UID/GID (when using the dockerFile property). +# See https://aka.ms/vscode-remote/containers/non-root-user for details. +ARG USERNAME=vscode +ARG USER_UID=1000 +ARG USER_GID=$USER_UID + +# Configure apt, install packages and tools +RUN apt-get update \ + && apt-get -y install --no-install-recommends apt-utils dialog 2>&1 \ + # + # Verify git, process tools, lsb-release (common in install instructions for CLIs) installed + && apt-get -y install git iproute2 procps lsb-release \ + # + # Install Go tools w/module support + && mkdir -p /tmp/gotools \ + && cd /tmp/gotools \ + && GO111MODULE=on go get -v golang.org/x/tools/gopls@latest 2>&1 \ + && GO111MODULE=on go get -v \ + honnef.co/go/tools/...@latest \ + golang.org/x/tools/cmd/gorename@latest \ + golang.org/x/tools/cmd/goimports@latest \ + golang.org/x/tools/cmd/guru@latest \ + golang.org/x/lint/golint@latest \ + github.com/mdempsky/gocode@latest \ + github.com/cweill/gotests/...@latest \ + github.com/haya14busa/goplay/cmd/goplay@latest \ + github.com/sqs/goreturns@latest \ + github.com/josharian/impl@latest \ + github.com/davidrjenni/reftools/cmd/fillstruct@latest \ + github.com/ramya-rao-a/go-outline@latest \ + github.com/acroca/go-symbols@latest \ + github.com/godoctor/godoctor@latest \ + github.com/rogpeppe/godef@latest \ + github.com/zmb3/gogetdoc@latest \ + github.com/fatih/gomodifytags@latest \ + github.com/mgechev/revive@latest \ + github.com/go-delve/delve/cmd/dlv@latest 2>&1 \ + # + # Install Go tools w/o module support + && go get -v github.com/alecthomas/gometalinter \ + github.com/uudashr/gopkgs/cmd/gopkgs 2>&1 \ + # + # Install gocode-gomod + && go get -x -d github.com/stamblerre/gocode 2>&1 \ + && go build -o gocode-gomod github.com/stamblerre/gocode \ + && mv gocode-gomod $GOPATH/bin/ \ + # + # Install golangci-lint + && curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin 2>&1 \ + # + # Create a non-root user to use if preferred - see https://aka.ms/vscode-remote/containers/non-root-user. + && groupadd --gid $USER_GID $USERNAME \ + && useradd -s /bin/bash --uid $USER_UID --gid $USER_GID -m $USERNAME \ + # [Optional] Add sudo support + && apt-get install -y sudo \ + && echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME \ + && chmod 0440 /etc/sudoers.d/$USERNAME \ + # Add write permission for /go/pkg + && chmod -R a+rwX /go/pkg \ + # + # Clean up + && apt-get autoremove -y \ + && apt-get clean -y \ + && rm -rf /var/lib/apt/lists/* /go/src /tmp/gotools + +# Update this to "on" or "off" as appropriate +ENV GO111MODULE=auto + +# Switch back to dialog for any ad-hoc use of apt-get +ENV DEBIAN_FRONTEND=dialog diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100755 index 0000000..8cad055 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,29 @@ +{ + "name": "Go DevContainer", + "dockerFile": "Dockerfile", + "runArgs": [ "--cap-add=SYS_PTRACE", "--security-opt", "seccomp=unconfined" ], + + // Use 'appPort' to create a container with published ports. If the port isn't working, be sure + // your server accepts connections from all interfaces (0.0.0.0 or '*'), not just localhost. + "appPort": [9000], + + // Use 'settings' to set *default* container specific settings.json values on container create. + // You can edit these settings after create using File > Preferences > Settings > Remote. + "settings": { + "terminal.integrated.shell.linux": "/bin/bash", + "go.gopath": "/go", + "go.inferGopath": true, + "go.useLanguageServer": true + }, + + // Uncomment the next line to run commands after the container is created. + // "postCreateCommand": "go version", + + // Comment out the next line to run as root + "remoteUser": "vscode", + + // Add the IDs of extensions you want installed when the container is created in the array below. + "extensions": [ + "ms-vscode.go" + ] +} \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4268057 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +build/ +scripts/settings.sh \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..649866e --- /dev/null +++ b/LICENSE @@ -0,0 +1,22 @@ +MIT License + +Copyright (c) 2020 MrFlutters / Hotaru + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +LICENSE \ No newline at end of file diff --git a/loadOrder.txt b/loadOrder.txt new file mode 100644 index 0000000..2684576 --- /dev/null +++ b/loadOrder.txt @@ -0,0 +1,3 @@ +Morrowind.esm +Tribunal.esm +Bloodmoon.esm \ No newline at end of file diff --git a/scripts/build.sh b/scripts/build.sh new file mode 100755 index 0000000..84d1005 --- /dev/null +++ b/scripts/build.sh @@ -0,0 +1,24 @@ +#!/bin/sh + +prepareBuild(){ + echo -n "Preparing Build Enviroment...\n" + rm -rf ./build + mkdir -p ../build ./build/windows ./build/linux + echo -n "Done\n" +} + +# Build Linux +buildLinux(){ + echo -n "Building Linux Binary...\n" + go build -o ../build/linux/TES3MP-CRC32 ../src/main.go + echo -n "Done\n" +} +buildWindows(){ + echo -n "Building Windows Binary...\n" + GOOS=windows GOARCH=386 go build -o ../build/windows/TES3MP-CRC32.exe ../src/main.go + echo -n "Done\n" +} + +prepareBuild +buildLinux +buildWindows \ No newline at end of file diff --git a/scripts/release.sh b/scripts/release.sh new file mode 100755 index 0000000..4e4c203 --- /dev/null +++ b/scripts/release.sh @@ -0,0 +1,18 @@ +#!/bin/sh +. ./settings.sh + +github-release info -u $user -r $repo + +github-release upload \ + --user $user \ + --repo $repo \ + --tag $tag \ + --name "$repo-Linux" \ + --file ../build/linux/$buildname + +github-release upload \ + --user $user \ + --repo $repo \ + --tag $tag \ + --name "$repo-Windows.exe" \ + --file ../build/windows/$buildname.exe \ No newline at end of file diff --git a/src/main.go b/src/main.go new file mode 100644 index 0000000..c9b748d --- /dev/null +++ b/src/main.go @@ -0,0 +1,83 @@ +package main + +import ( + "bufio" + "encoding/hex" + "flag" + "fmt" + "hash/crc32" + "io" + "log" + "os" + "path/filepath" + "strings" +) + +// https://mrwaggel.be/post/generate-crc32-hash-of-a-file-in-golang-turorial/ +func hashFileCRC32(filePath string, polynomial uint32) (string, error) { + //Initialize an empty return string now in case an error has to be returned + var returnCRC32String string + + //Open the fhe file located at the given path and check for errors + file, err := os.Open(filePath) + if err != nil { + return returnCRC32String, err + } + + //Tell the program to close the file when the function returns + defer file.Close() + + //Create the table with the given polynomial + tablePolynomial := crc32.MakeTable(polynomial) + + //Open a new hash interface to write the file to + hash := crc32.New(tablePolynomial) + + //Copy the file in the interface + if _, err := io.Copy(hash, file); err != nil { + return returnCRC32String, err + } + + //Generate the hash + hashInBytes := hash.Sum(nil)[:] + + //Encode the hash to a string + returnCRC32String = hex.EncodeToString(hashInBytes) + + //Return the output + return returnCRC32String, nil +} + +func main() { + loadOrderFlag := flag.String("loadOrder", "", "Load order file") + dataFileFlag := flag.String("dataFiles", "", "Data Files Directory") + + flag.Parse() + + flag.VisitAll(func(f *flag.Flag) { + if f.Value.String() == "" { + fmt.Println(os.Args[0] + " --loadOrder ./loadOrder.txt" + " --dataFiles \"/home/tes3mp/Data Files\"") + os.Exit(1) + } + }) + + loadOrder, loadOrdererr := os.Open(*loadOrderFlag) + + if loadOrdererr != nil { + log.Fatal(loadOrdererr) + } + defer loadOrder.Close() + + scanner := bufio.NewScanner(loadOrder) + for scanner.Scan() { + file := *dataFileFlag + scanner.Text() + hash, err := hashFileCRC32(file, 0xedb88320) + if err == nil { + fmt.Println(filepath.Base(file) + ": " + "0x" + strings.ToUpper(hash)) + } + } + + if err := scanner.Err(); err != nil { + log.Fatal(err) + } +}