|
|
|
@ -77,47 +77,47 @@ func JankImage(settings Conversion, in_file string, out_file string) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func UnfuckedPathSplit(path string) []string { |
|
|
|
func UnfuckedPathSplit(path string) []string { |
|
|
|
path = filepath.ToSlash(path) |
|
|
|
path = filepath.ToSlash(path) |
|
|
|
// WARN: have to use strings.Split because fsnotify uses /, even on windows
|
|
|
|
// WARN: have to use strings.Split because fsnotify uses /, even on windows
|
|
|
|
return strings.Split(path, "/")[1:] |
|
|
|
return strings.Split(path, "/")[1:] |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func SplitPathExt(path string) (string, string, bool) { |
|
|
|
func SplitPathExt(path string) (string, string, bool) { |
|
|
|
split_path := UnfuckedPathSplit(path) |
|
|
|
split_path := UnfuckedPathSplit(path) |
|
|
|
source_name := strings.Join(split_path, "/") // Render wants / even on windows
|
|
|
|
source_name := strings.Join(split_path, "/") // Render wants / even on windows
|
|
|
|
|
|
|
|
|
|
|
|
ext := filepath.Ext(source_name) |
|
|
|
ext := filepath.Ext(source_name) |
|
|
|
source_name, found := strings.CutSuffix(source_name, ext) |
|
|
|
source_name, found := strings.CutSuffix(source_name, ext) |
|
|
|
return source_name, ext, found |
|
|
|
return source_name, ext, found |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func RePrefixPath(path string, new_prefix string) string { |
|
|
|
func RePrefixPath(path string, new_prefix string) string { |
|
|
|
split_path := UnfuckedPathSplit(path) |
|
|
|
split_path := UnfuckedPathSplit(path) |
|
|
|
|
|
|
|
|
|
|
|
prefixed_path := append([]string{new_prefix}, split_path...) |
|
|
|
prefixed_path := append([]string{new_prefix}, split_path...) |
|
|
|
|
|
|
|
|
|
|
|
res := filepath.Join(prefixed_path...) |
|
|
|
res := filepath.Join(prefixed_path...) |
|
|
|
return filepath.ToSlash(res) |
|
|
|
return filepath.ToSlash(res) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func SamePath(a string, b string) bool { |
|
|
|
func SamePath(a string, b string) bool { |
|
|
|
return filepath.ToSlash(a) == filepath.ToSlash(b) |
|
|
|
return filepath.ToSlash(a) == filepath.ToSlash(b) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func MkdirPath(target_path string) error { |
|
|
|
func MkdirPath(target_path string) error { |
|
|
|
target_dir := filepath.Dir(target_path) |
|
|
|
target_dir := filepath.Dir(target_path) |
|
|
|
_, err := os.Stat(target_dir) |
|
|
|
_, err := os.Stat(target_dir) |
|
|
|
|
|
|
|
|
|
|
|
if os.IsNotExist(err) { |
|
|
|
if os.IsNotExist(err) { |
|
|
|
log.Println("MAKING: ", target_dir) |
|
|
|
log.Println("MAKING: ", target_dir) |
|
|
|
err = os.MkdirAll(target_dir, 0750) |
|
|
|
err = os.MkdirAll(target_dir, 0750) |
|
|
|
|
|
|
|
|
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
log.Fatal("making path to %s: %v", target_dir, err) |
|
|
|
log.Fatal("making path to %s: %v", target_dir, err) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return nil |
|
|
|
return nil |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func Included(config Settings, path string) bool { |
|
|
|
func Included(config Settings, path string) bool { |
|
|
|
@ -157,38 +157,39 @@ func HasChanged(old_info fs.FileInfo, new_path string) bool { |
|
|
|
return false |
|
|
|
return false |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return old_info.ModTime().After(new_info.ModTime()) |
|
|
|
return old_info.ModTime().After(new_info.ModTime()) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func RenderImages(config Settings, force bool) error { |
|
|
|
func RenderImages(config Settings, force bool) error { |
|
|
|
err := filepath.WalkDir(config.Source, |
|
|
|
err := filepath.WalkDir(config.Source, |
|
|
|
func(path string, d fs.DirEntry, err error) error { |
|
|
|
func(path string, d fs.DirEntry, err error) error { |
|
|
|
path = filepath.ToSlash(path) |
|
|
|
path = filepath.ToSlash(path) |
|
|
|
|
|
|
|
|
|
|
|
if !d.IsDir() && Included(config, path) { |
|
|
|
if !d.IsDir() && Included(config, path) { |
|
|
|
target := RePrefixPath(path, config.Target) |
|
|
|
target := RePrefixPath(path, config.Target) |
|
|
|
|
|
|
|
|
|
|
|
err = MkdirPath(target) |
|
|
|
err = MkdirPath(target) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
log.Fatalf("failed to make path %s: %v", path, err) |
|
|
|
log.Fatalf("failed to make path %s: %v", path, err) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fmt.Println("FILE: ", path, "TARGET:", target) |
|
|
|
fmt.Println("FILE: ", path, "TARGET:", target) |
|
|
|
convert := GetConversion(config, path) |
|
|
|
convert := GetConversion(config, path) |
|
|
|
|
|
|
|
|
|
|
|
path_info, err := d.Info() |
|
|
|
path_info, err := d.Info() |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
log.Fatalf("failed to stat %s: %v", path, err) |
|
|
|
log.Fatalf("failed to stat %s: %v", path, err) |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if force || HasChanged(path_info, target) { |
|
|
|
|
|
|
|
JankImage(convert, path, target) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
fmt.Println("SKIP:", path) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return nil |
|
|
|
if force || HasChanged(path_info, target) { |
|
|
|
|
|
|
|
// have to lowercase the target path to avoid windows issues
|
|
|
|
|
|
|
|
JankImage(convert, path, strings.ToLower(target)) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
fmt.Println("SKIP:", path) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return nil |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
return err |
|
|
|
return err |
|
|
|
|