-
Notifications
You must be signed in to change notification settings - Fork 0
/
patchCreator.go
66 lines (60 loc) · 1.94 KB
/
patchCreator.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package main
import (
"errors"
"fmt"
"io/fs"
"log"
"os"
"os/exec"
"strings"
)
func mkPatchRecurse(name string, srcDir string, oldSrcDir string) {
entries, _ := os.ReadDir(name)
for _, entry := range entries {
FName := name + "/" + entry.Name()
if entry.IsDir() {
os.MkdirAll(strings.ReplaceAll(FName, srcDir+"/", "patches/"), fs.ModePerm)
mkPatchRecurse(FName, srcDir, oldSrcDir)
} else {
patchFile := strings.ReplaceAll(FName, srcDir+"/", "patches/") + ".patch"
originalFile := strings.ReplaceAll(FName, srcDir+"/", oldSrcDir)
fmt.Printf("git diff --no-index --default-prefix -u --output \"%s\" \"%s\" \"%s\"\n",
patchFile,
originalFile,
FName, // modified
)
exec.Command("git", "diff", "--no-index", "--default-prefix", "-u", "--output",
patchFile,
originalFile,
FName, // modified
).Run()
f, _ := os.ReadFile(patchFile)
if len(f) == 0 {
os.RemoveAll(patchFile)
} else {
patchedContent := string(f)
patchedContent = strings.ReplaceAll(patchedContent, "temp_src_mod", "src")
patchedContent = strings.ReplaceAll(patchedContent, "temp_src", "src")
os.WriteFile(patchFile, []byte(patchedContent), fs.ModePerm)
}
}
}
}
func createPatches(version string) {
modified_source := "modifiedsources/Cosmic_Reach-" + version + "-Source.jar"
if _, err := os.Stat(modified_source); errors.Is(err, os.ErrNotExist) {
modified_source = "modifiedsources/Cosmic Reach-" + version + "-Source.jar"
if _, err := os.Stat(modified_source); errors.Is(err, os.ErrNotExist) {
log.Fatalf("Could not find any modified sources for cosmic reach %s which should be located in \"./modifiedsources\" as Cosmic Reach-%s-Source.jar",
version,
version,
)
}
}
unzipSource(modified_source, "temp_ext")
recursiveSort("temp_ext", "temp_src_mod")
os.RemoveAll("temp_ext")
mkPatchRecurse("temp_src_mod", "temp_src_mod", "temp_src/")
os.RemoveAll("temp_src_mod")
deleteEmptyDirs("patches")
}