Files
Lanceur-Geco/config.go
zogzog d8f3a29f8e v0.7.6 - Clone dossier non-vide et verification rapide
Changements :
- Clone dans dossier non-vide (git init + remote add + fetch + checkout)
- Verification rapide via git ls-remote au lieu de git fetch (timeout 15s)
- Support branche par repo dans config.ini (champ branch)
- Suppression fichiers Python et artefacts PyInstaller (_internal/)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-25 11:41:11 +01:00

87 lines
1.8 KiB
Go

package main
import (
"bufio"
"os"
"path/filepath"
"strings"
)
type RepoConfig struct {
Name string
URL string
Path string
Branch string // branche à suivre (défaut: "master")
}
type SelfUpdateConfig struct {
URL string
ExeName string
Branch string
}
func loadConfig() ([]RepoConfig, SelfUpdateConfig, error) {
cfgPath := filepath.Join(exeDir(), "config.ini")
f, err := os.Open(cfgPath)
if err != nil {
return nil, SelfUpdateConfig{}, err
}
defer f.Close()
var repos []RepoConfig
var su SelfUpdateConfig
section := ""
kv := map[string]string{}
flush := func() {
switch {
case strings.HasPrefix(section, "repo:"):
name := strings.TrimPrefix(section, "repo:")
if kv["url"] != "" && kv["path"] != "" {
branch := kv["branch"]
if branch == "" {
branch = "master"
}
repos = append(repos, RepoConfig{
Name: name,
URL: kv["url"],
Path: kv["path"],
Branch: branch,
})
}
case section == "self-update":
su.URL = strings.TrimRight(kv["url"], "/")
su.ExeName = kv["exe_name"]
if su.ExeName == "" {
su.ExeName = "GitUpdateChecker.exe"
}
su.Branch = kv["branch"]
if su.Branch == "" {
su.Branch = "master"
}
}
kv = map[string]string{}
}
scanner := bufio.NewScanner(f)
for scanner.Scan() {
line := strings.TrimSpace(scanner.Text())
if line == "" || strings.HasPrefix(line, ";") || strings.HasPrefix(line, "#") {
continue
}
if strings.HasPrefix(line, "[") && strings.HasSuffix(line, "]") {
flush()
section = strings.ToLower(strings.TrimSpace(line[1 : len(line)-1]))
continue
}
if idx := strings.IndexByte(line, '='); idx > 0 {
k := strings.TrimSpace(strings.ToLower(line[:idx]))
v := strings.TrimSpace(line[idx+1:])
kv[k] = v
}
}
flush()
return repos, su, scanner.Err()
}